:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #f1eefb;
  --text: #1c1b22;
  --text-muted: #5f5d6b;
  --border: #e4e1ee;
  --primary: #fb3678;
  --primary-contrast: #ffffff;
  --danger: #d6336c;
  --good: #2bb673;
  --bad: #d6336c;
  --shadow: 0 2px 12px rgba(40, 30, 80, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14131a;
    --surface: #1d1c25;
    --surface-2: #262533;
    --text: #ececf2;
    --text-muted: #a0a0b0;
    --border: #2e2d3a;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app-header {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-mark {
  color: var(--primary);
  width: 1.2em;
  height: 1.2em;
  flex-shrink: 0;
}

.tagline {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.app-footer {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 32px;
  text-align: center;
}

.app-footer nav {
  display: flex;
  gap: 8px;
  justify-content: center;
  font-size: 0.9rem;
}

.app-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.app-footer a:hover,
.app-footer a:focus { color: var(--primary); text-decoration: underline; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border: 1px solid var(--border);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Slider */
.slider-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.mood-value {
  font-size: 2.4rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
  line-height: 1;
}

.mood-max {
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 400;
}

#mood-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 36px;
  margin: 0;
}

#mood-slider:focus { outline: none; }

#mood-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--bad), #e6b800, var(--good));
}

#mood-slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--bad), #e6b800, var(--good));
}

#mood-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--primary);
  margin-top: -10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  cursor: pointer;
}

#mood-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  cursor: pointer;
}

#mood-slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(194,24,91,.3); }
#mood-slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px rgba(194,24,91,.3); }

.slider-legend {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  padding: 0 4px;
}

/* Emoji row */
.emoji-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0 16px;
}

.emoji-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.emoji-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 1.2rem;
  line-height: 1;
}

.emoji-chip button {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.emoji-chip button:hover { color: var(--danger); }

.emoji-form {
  display: flex;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
}

.emoji-form input {
  flex: 1;
  font-size: 1.2rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

/* Quick emoji picker */
.emoji-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
}

.emoji-quick-btn {
  font-size: 1.4rem;
  line-height: 1;
  padding: 6px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: transform .1s ease, background .1s ease, border-color .1s ease;
}

.emoji-quick-btn:hover { transform: scale(1.08); }
.emoji-quick-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.emoji-quick-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(194, 24, 91, .25);
}

/* Notes */
.notes-label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

#notes-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  resize: vertical;
  min-height: 56px;
}

.capture-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  transition: filter .15s ease, background .15s ease;
}

.btn:hover { filter: brightness(0.97); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover { filter: brightness(0.97); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.entry-delete:hover { color: var(--danger); }

/* History */
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.range-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  border: 1px solid var(--border);
}

.range-toggle button {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.range-toggle button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.chart {
  width: 100%;
  height: 240px;
  margin-bottom: 16px;
}

.entries-heading {
  margin: 8px 0 8px;
  font-size: 1rem;
}

.entries-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}

.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.entry-main { display: flex; gap: 12px; flex: 1; min-width: 0; }

.mood-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-contrast);
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.entry-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.entry-emojis { font-size: 1rem; }

.entry-notes {
  margin: 4px 0 0;
  font-size: 0.95rem;
  word-wrap: break-word;
}

.entry-notes:empty { display: none; }

.entry-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Data tools */
.data-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.data-actions .btn { cursor: pointer; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  z-index: 100;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}

.toast.show { opacity: 1; }

/* Static info pages */
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.page h1 { font-size: 1.6rem; margin-top: 24px; }
.page h2 { font-size: 1.15rem; margin-top: 24px; }
.page p, .page li { line-height: 1.6; }
.page a { color: var(--primary); }

/* vis.js theming overrides */
.vis-graph2d .vis-major,
.vis-graph2d .vis-minor { color: var(--text-muted) !important; }
.vis-time-axis .vis-text { color: var(--text-muted) !important; }
.vis-panel.vis-background { background: transparent !important; }
.vis-data-axis .vis-y-axis .vis-text { color: var(--text-muted) !important; }
.vis-data-axis .vis-grid.vis-horizontal,
.vis-time-axis .vis-grid.vis-vertical { border-color: var(--border) !important; }
.vis-panel.vis-left,
.vis-panel.vis-center,
.vis-panel.vis-right,
.vis-panel.vis-top,
.vis-panel.vis-bottom { border-color: var(--border) !important; }
