:root {
  color-scheme: dark light;

  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c232c;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #79c0ff;
  --accent-strong: #58a6ff;
  --danger: #f85149;

  --happy: #7ee787;
  --suffering: #ff7b72;
  --meaning: #d2a8ff;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 0 0 1px var(--border);
  --nav-height: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #0969da;
  --accent-strong: #0550ae;
  --danger: #cf222e;

  --happy: #1a7f37;
  --suffering: #cf222e;
  --meaning: #8250df;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 0 0 1px var(--border);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 8px;
  max-width: 720px;
  margin: 0 auto;
}

.app-title {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  margin: 0;
  font-family: var(--font-mono);
}

.app-title .dot { color: var(--accent); }

.icon-button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.icon-button:hover { color: var(--text); border-color: var(--text-muted); }

.theme-icon-light { display: none; }
:root[data-theme="light"] .theme-icon-dark { display: none; }
:root[data-theme="light"] .theme-icon-light { display: block; }

main#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 20px 24px;
}

.view {
  animation: fade 0.18s ease-out;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: none; }
}

.view-heading {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 8px 0 4px;
}

.view-subheading {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 14px;
}

/* ===== Entry form ===== */

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.slider-group {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 16px 18px 12px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
}

.slider-label {
  font-weight: 600;
  font-size: 17px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.slider-hint {
  font-weight: 400;
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0;
}

.slider-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  min-width: 2ch;
  text-align: right;
}

.slider-group[data-axis="happy"] .slider-value { color: var(--happy); }
.slider-group[data-axis="suffering"] .slider-value { color: var(--suffering); }
.slider-group[data-axis="meaning"] .slider-value { color: var(--meaning); }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  background: transparent;
  padding: 0;
  margin: 0;
  touch-action: manipulation;
  cursor: pointer;
}

.slider:focus { outline: none; }
.slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent);
}

.slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--text);
  border: 3px solid var(--surface);
  margin-top: -11px;
  cursor: grab;
  transition: transform 0.1s ease;
}

.slider::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.05); }

.slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--text);
  border: 3px solid var(--surface);
  cursor: grab;
}

.slider-happy::-webkit-slider-thumb { background: var(--happy); }
.slider-happy::-moz-range-thumb { background: var(--happy); }
.slider-suffering::-webkit-slider-thumb { background: var(--suffering); }
.slider-suffering::-moz-range-thumb { background: var(--suffering); }
.slider-meaning::-webkit-slider-thumb { background: var(--meaning); }
.slider-meaning::-moz-range-thumb { background: var(--meaning); }

.slider-scale {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.note-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-label {
  font-weight: 600;
  font-size: 15px;
}

.note-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 13px;
}

.note-input {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font: inherit;
  transition: border-color 0.15s ease;
}

.note-input:focus {
  outline: none;
  border-color: var(--accent-strong);
}

.note-input::placeholder { color: var(--text-muted); }

/* ===== Buttons ===== */

.primary-button,
.secondary-button,
.danger-button {
  font: inherit;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  border: 1px solid transparent;
}

.primary-button {
  background: var(--accent-strong);
  color: #fff;
  font-size: 16px;
}

.primary-button:hover { background: color-mix(in srgb, var(--accent-strong) 85%, black); }
.primary-button:active { transform: translateY(1px); }

.secondary-button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  font-size: 14px;
  padding: 10px 14px;
}

.secondary-button:hover { border-color: var(--text-muted); }

.danger-button {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
  font-size: 14px;
  padding: 10px 14px;
}

.danger-button:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.save-status {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 14px;
  min-height: 1.25em;
}

.save-status.is-success { color: var(--happy); }
.save-status.is-error { color: var(--danger); }

/* ===== History ===== */

.range-toggle {
  display: inline-flex;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 18px;
  gap: 2px;
}

.range-button {
  background: transparent;
  color: var(--text-muted);
  border: 0;
  padding: 8px 16px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.range-button:hover { color: var(--text); }

.range-button.is-active {
  background: var(--surface-2);
  color: var(--text);
}

.chart-wrap {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 240px;
  position: relative;
  margin-bottom: 24px;
}

#history-chart { width: 100%; height: 280px; }

.empty-state {
  color: var(--text-muted);
  text-align: center;
  margin: 80px 0;
  font-size: 14px;
}

.list-heading {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 12px;
}

.entry-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry-item {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 10px;
}

.entry-time {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.entry-values {
  display: flex;
  gap: 14px;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.entry-values .happy { color: var(--happy); }
.entry-values .suffering { color: var(--suffering); }
.entry-values .meaning { color: var(--meaning); }

.entry-values .label {
  color: var(--text-muted);
  margin-right: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.entry-note {
  margin-top: 6px;
  color: var(--text);
  font-size: 14px;
  grid-column: 1 / -1;
  white-space: pre-wrap;
  word-break: break-word;
}

.entry-delete {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 12px;
  transition: color 0.15s ease, background 0.15s ease;
}

.entry-delete:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ===== About / prose ===== */

.prose p { margin: 0 0 14px; }
.prose h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 28px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.prose .muted { color: var(--text-muted); font-size: 14px; }

.axis-list {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 16px 0;
}

.axis-list dt {
  font-weight: 600;
  margin-top: 10px;
}

.axis-list dt:first-child { margin-top: 0; }

.axis-list dt:nth-of-type(1) { color: var(--happy); }
.axis-list dt:nth-of-type(2) { color: var(--suffering); }
.axis-list dt:nth-of-type(3) { color: var(--meaning); }

.axis-list dd {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.pdf-range {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 8px 0 12px;
}

.pdf-range-label {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Bottom nav ===== */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
}

.nav-button {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font: inherit;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  padding: 10px 4px;
  transition: color 0.15s ease;
}

.nav-button.is-active { color: var(--text); }
.nav-button:hover { color: var(--text); }

/* Desktop layout tweaks */
@media (min-width: 640px) {
  main#app { padding: 16px 24px 40px; }
  .view-heading { font-size: 26px; }
  .entry-form { gap: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
