/* Certified Somm — design system + components.
   Wine-cellar dark, garnet-committed, candle-gold accent. OKLCH throughout.
   See DESIGN.md for token rationale. */

:root {
  /* Surfaces (tinted-dark: the cellar IS the brand) */
  --bg: oklch(0.16 0.032 350);
  --surface: oklch(0.205 0.038 350);
  --surface-2: oklch(0.245 0.042 350);
  --surface-3: oklch(0.30 0.046 350);
  --line: oklch(0.32 0.03 350);
  --line-soft: oklch(0.28 0.028 350);

  /* Ink (warm parchment) */
  --ink: oklch(0.94 0.012 80);
  --ink-muted: oklch(0.76 0.012 80);
  --ink-faint: oklch(0.62 0.010 80);

  /* Brand */
  --primary: oklch(0.55 0.165 18);
  --primary-press: oklch(0.47 0.16 18);
  --primary-soft: oklch(0.55 0.165 18 / 0.16);
  --on-primary: oklch(0.98 0.01 80);
  --accent: oklch(0.80 0.11 80);
  --accent-soft: oklch(0.80 0.11 80 / 0.16);

  /* Recall grades */
  --again: oklch(0.60 0.17 25);
  --hard: oklch(0.77 0.12 65);
  --good: oklch(0.70 0.10 150);
  --easy: oklch(0.77 0.10 165);

  /* Type */
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --t-xs: 0.75rem;
  --t-sm: 0.875rem;
  --t-base: 1rem;
  --t-md: 1.125rem;
  --t-lg: 1.375rem;
  --t-xl: 1.75rem;
  --t-2xl: 2.25rem;

  /* Spacing */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-8: 48px; --s-10: 64px;

  /* Shape */
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-pill: 999px;
  --shadow: 0 6px 24px oklch(0 0 0 / 0.35);

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 200ms;

  /* Z-scale */
  --z-nav: 100; --z-sticky: 200; --z-backdrop: 900; --z-modal: 1000; --z-toast: 1100;

  --tap: 44px;
  --maxw: 660px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  font-size: var(--t-base);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  /* subtle cellar depth, not a gradient text gimmick */
  background-image: radial-gradient(120% 80% at 50% -10%, oklch(0.22 0.05 350) 0%, var(--bg) 60%);
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; text-wrap: balance; letter-spacing: -0.01em; }
p { text-wrap: pretty; max-width: 68ch; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

/* ---------- App shell ---------- */
.app { max-width: var(--maxw); margin-inline: auto; padding: 0 var(--s-4) calc(var(--tap) + var(--s-8)); }

.appbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) 0 var(--s-3);
  background: linear-gradient(var(--bg) 70%, transparent);
  backdrop-filter: none;
}
.brand { display: flex; align-items: center; gap: var(--s-2); }
.brand .glyph { width: 28px; height: 28px; flex: none; }
.brand b { font-family: var(--font-display); font-size: var(--t-md); font-weight: 600; letter-spacing: -0.01em; }
.brand small { display: block; font-family: var(--font-ui); font-size: var(--t-xs); color: var(--ink-faint); letter-spacing: 0.02em; }

.screen { padding-top: var(--s-3); animation: screen-in var(--dur) var(--ease); }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.screen h1 { font-size: var(--t-2xl); margin-bottom: var(--s-2); }
.screen .lede { color: var(--ink-muted); margin-bottom: var(--s-5); }
.eyebrow { font-size: var(--t-sm); color: var(--accent); font-weight: 600; }

/* ---------- Bottom nav ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav);
  display: flex; justify-content: center; gap: 2px;
  padding: var(--s-2) var(--s-2) calc(var(--s-2) + env(safe-area-inset-bottom, 0px));
  background: oklch(0.18 0.034 350 / 0.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.tabbar .tabs { display: flex; gap: 2px; width: 100%; max-width: var(--maxw); }
.tab {
  flex: 1; min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: transparent; color: var(--ink-faint);
  font-family: var(--font-ui); font-size: 0.68rem; font-weight: 600; letter-spacing: 0.01em;
  border-radius: var(--r-md); cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--ink); background: var(--primary-soft); }
.tab[aria-current="page"] svg { color: var(--primary); }
.tab:hover { color: var(--ink-muted); }
.tab .badge {
  position: absolute; transform: translate(14px, -14px);
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--primary); color: var(--on-primary);
  font-size: 0.62rem; line-height: 18px; border-radius: var(--r-pill); text-align: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0 var(--s-5);
  font-family: var(--font-ui); font-size: var(--t-base); font-weight: 600;
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-md);
  cursor: pointer; user-select: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: transparent; color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-press); }
.btn-block { width: 100%; }
.btn-lg { min-height: 52px; font-size: var(--t-md); }
.btn-ghost { background: transparent; }

/* ---------- Cards / panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: var(--s-5);
}
.stack > * + * { margin-top: var(--s-4); }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* ---------- Progress ---------- */
.progress { height: 10px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 100%; transform-origin: left center; transform: scaleX(var(--p, 0)); background: var(--accent); transition: transform 400ms var(--ease); }
.progress.garnet > span { background: var(--primary); }
.metricline { display: flex; align-items: baseline; gap: var(--s-2); font-size: var(--t-sm); color: var(--ink-muted); }
.metricline b { color: var(--ink); font-size: var(--t-base); }

/* ---------- Home pillars ---------- */
.pillars { display: grid; gap: var(--s-3); grid-template-columns: 1fr; margin-top: var(--s-5); }
.pillar {
  display: flex; align-items: center; gap: var(--s-4); text-align: left;
  width: 100%; padding: var(--s-4); min-height: 64px;
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-md);
  color: var(--ink); cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.pillar:hover { border-color: var(--line); background: var(--surface-2); transform: translateY(-1px); }
.pillar .ic { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: var(--r-md); background: var(--primary-soft); color: var(--primary); }
.pillar .ic svg { width: 22px; height: 22px; }
.pillar h3 { font-family: var(--font-ui); font-size: var(--t-base); font-weight: 600; }
.pillar p { font-size: var(--t-sm); color: var(--ink-muted); margin: 0; }
.pillar .chev { margin-left: auto; color: var(--ink-faint); }

/* ---------- Flashcard ---------- */
.review-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s-4); }
.review-head .count { font-size: var(--t-sm); color: var(--ink-muted); }
.flashcard {
  position: relative; min-height: 280px;
  display: flex; flex-direction: column; justify-content: center; gap: var(--s-4);
  padding: var(--s-6) var(--s-5); text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.flashcard .tagrow { position: absolute; top: var(--s-3); left: var(--s-3); right: var(--s-3); display: flex; gap: var(--s-2); flex-wrap: wrap; justify-content: center; }
.chip {
  font-size: var(--t-xs); color: var(--ink-muted); background: var(--surface-2);
  border: 1px solid var(--line-soft); border-radius: var(--r-pill); padding: 2px 10px; letter-spacing: 0.02em;
}
.flashcard .front { font-family: var(--font-display); font-size: var(--t-xl); line-height: 1.2; }
.flashcard .back { font-size: var(--t-md); color: var(--ink); line-height: 1.5; animation: reveal var(--dur) var(--ease); }
.flashcard .divider { height: 1px; background: var(--line); width: 60%; margin: 0 auto; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.leech-flag { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-xs); color: var(--hard); }

.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-2); margin-top: var(--s-4); }
.grade {
  min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2);
  color: var(--ink); cursor: pointer; font-weight: 600; font-size: var(--t-sm);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.grade small { font-size: 0.66rem; color: var(--ink-faint); font-weight: 500; }
.grade:active { transform: translateY(1px); }
.grade[data-g="again"] { box-shadow: inset 0 -3px 0 var(--again); }
.grade[data-g="hard"] { box-shadow: inset 0 -3px 0 var(--hard); }
.grade[data-g="good"] { box-shadow: inset 0 -3px 0 var(--good); }
.grade[data-g="easy"] { box-shadow: inset 0 -3px 0 var(--easy); }
.grade:hover { background: var(--surface-3); }

/* ---------- Empty / done states ---------- */
.empty { text-align: center; padding: var(--s-8) var(--s-4); }
.empty .ring { width: 76px; height: 76px; margin: 0 auto var(--s-4); display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.empty h2 { font-size: var(--t-xl); margin-bottom: var(--s-2); }
.empty p { margin-inline: auto; }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r-pill); }
.seg button {
  min-height: 38px; padding: 0 var(--s-4); border: 0; background: transparent; color: var(--ink-muted);
  font-family: var(--font-ui); font-weight: 600; font-size: var(--t-sm); border-radius: var(--r-pill); cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }

/* ---------- Tasting grid ---------- */
.flight-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); margin-bottom: var(--s-5); }
.flight {
  padding: var(--s-4); border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface);
  text-align: left; cursor: pointer; color: var(--ink); min-height: 72px;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.flight:hover { background: var(--surface-2); }
.flight[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.flight .swatch { width: 18px; height: 18px; border-radius: 50%; display: inline-block; vertical-align: -3px; margin-right: 8px; }
.flight .swatch.white { background: oklch(0.88 0.06 95); }
.flight .swatch.red { background: var(--primary); }
.flight b { font-family: var(--font-display); font-size: var(--t-md); }
.flight span.s { display: block; font-size: var(--t-xs); color: var(--ink-muted); margin-top: 2px; }

.gridsec { margin-top: var(--s-4); }
.gridsec > h3 { font-family: var(--font-ui); font-size: var(--t-sm); text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-bottom: var(--s-2); }
.gridline { padding: var(--s-3) 0; border-bottom: 1px solid var(--line-soft); }
.gridline .lbl { font-size: var(--t-sm); color: var(--ink-muted); margin-bottom: var(--s-2); }
.opts { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.opt {
  font-size: var(--t-sm); padding: 6px 12px; min-height: 36px; display: inline-flex; align-items: center;
  background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r-pill); color: var(--ink-muted); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.opt[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.opt.static { cursor: default; }

.callbox { margin-top: var(--s-2); padding: var(--s-3) var(--s-4); background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--line-soft); }
.callbox .call { font-size: var(--t-base); }
.callbox .why { font-size: var(--t-sm); color: var(--ink-muted); margin-top: var(--s-1); }
.callbox .why::before { content: "Why "; color: var(--accent); font-weight: 600; }

.deduction { margin-top: var(--s-5); padding: var(--s-5); border-radius: var(--r-lg); border: 1px solid var(--primary); background: var(--primary-soft); }
.deduction h3 { font-size: var(--t-lg); }
.deduction dl { display: grid; grid-template-columns: auto 1fr; gap: var(--s-2) var(--s-4); margin-top: var(--s-3); font-size: var(--t-sm); }
.deduction dt { color: var(--ink-faint); }
.deduction dd { color: var(--ink); }
.deduction .reason { margin-top: var(--s-3); font-size: var(--t-sm); color: var(--ink-muted); }

/* ---------- Service checklist ---------- */
.checklist { margin-top: var(--s-4); }
.step {
  display: flex; align-items: flex-start; gap: var(--s-3); width: 100%; text-align: left;
  padding: var(--s-3) var(--s-3); min-height: var(--tap);
  background: transparent; border: 0; border-bottom: 1px solid var(--line-soft); color: var(--ink); cursor: pointer;
}
.step .box {
  flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 8px;
  border: 1.5px solid var(--line); display: grid; place-items: center; color: transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.step .num { font-size: var(--t-sm); color: var(--ink-faint); width: 18px; flex: none; text-align: right; margin-top: 2px; }
.step .txt { font-size: var(--t-base); line-height: 1.45; }
.step[aria-checked="true"] .box { background: var(--good); border-color: var(--good); color: oklch(0.18 0.03 150); }
.step[aria-checked="true"] .txt { color: var(--ink-faint); text-decoration: line-through; text-decoration-color: var(--line); }

.notelist { margin-top: var(--s-3); }
.notelist li { list-style: none; padding: var(--s-2) 0 var(--s-2) var(--s-5); position: relative; font-size: var(--t-sm); color: var(--ink-muted); border-bottom: 1px solid var(--line-soft); }
.notelist li::before { content: ""; position: absolute; left: 4px; top: 14px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.faultlist li::before { background: var(--again); }

.principle { padding: var(--s-3) 0; border-bottom: 1px solid var(--line-soft); }
.principle b { font-size: var(--t-base); }
.principle p { font-size: var(--t-sm); color: var(--ink-muted); margin-top: 2px; }

/* ---------- Theory ---------- */
.prose > p + p { margin-top: var(--s-4); }
.def { margin-top: var(--s-4); }
.def h2 { font-size: var(--t-xl); margin-top: var(--s-5); margin-bottom: var(--s-2); }
.def h3 { font-family: var(--font-ui); font-size: var(--t-sm); text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin: var(--s-5) 0 var(--s-2); }
.def p { color: var(--ink); margin-top: var(--s-3); }
.tier { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s-4); padding: var(--s-3) 0; border-bottom: 1px solid var(--line-soft); }
.tier .name { font-weight: 600; }
.tier .share { color: var(--accent); font-variant-numeric: tabular-nums; font-size: var(--t-sm); align-self: center; }
.tier .mean { grid-column: 1 / -1; font-size: var(--t-sm); color: var(--ink-muted); }
.factlist li { list-style: none; padding: var(--s-2) 0 var(--s-2) var(--s-5); position: relative; font-size: var(--t-sm); border-bottom: 1px solid var(--line-soft); }
.factlist li::before { content: ""; position: absolute; left: 4px; top: 13px; width: 7px; height: 7px; border-radius: 2px; background: var(--primary); transform: rotate(45deg); }
.gc-group { margin-top: var(--s-3); }
.gc-group h4 { font-family: var(--font-display); font-size: var(--t-md); margin-bottom: var(--s-1); }
.gc-group ul { padding-left: var(--s-5); }
.gc-group li { font-size: var(--t-sm); color: var(--ink-muted); margin-top: 2px; }

.callout { margin-top: var(--s-4); padding: var(--s-4); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line-soft); font-size: var(--t-sm); color: var(--ink-muted); }
.callout b { color: var(--ink); }

.sources { margin-top: var(--s-6); font-size: var(--t-xs); color: var(--ink-faint); }
.sources a { color: var(--ink-muted); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }

/* ---------- Theory index ---------- */
.group-head { font-family: var(--font-display); font-size: var(--t-lg); margin: var(--s-6) 0 var(--s-3); }
.group-head:first-of-type { margin-top: var(--s-4); }
.modlist { display: grid; gap: var(--s-2); }
.modrow {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; text-align: left;
  padding: var(--s-4); min-height: 56px;
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-md);
  color: var(--ink); cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.modrow:hover { border-color: var(--line); background: var(--surface-2); transform: translateY(-1px); }
.modmain { flex: 1; min-width: 0; }
.modmain b { display: block; font-family: var(--font-ui); font-size: var(--t-base); font-weight: 600; }
.modsub { font-size: var(--t-xs); color: var(--ink-faint); }
.modmeta { font-variant-numeric: tabular-nums; font-size: var(--t-sm); color: var(--accent); background: var(--accent-soft); border-radius: var(--r-pill); padding: 2px 9px; min-width: 26px; text-align: center; }
.modrow .chev { color: var(--ink-faint); display: inline-flex; }

/* ---------- Orientation maps ---------- */
.mapfig { margin: var(--s-3) 0 0; }
.mapfig svg { width: 100%; height: auto; display: block; }
.mapcap { font-size: var(--t-xs); color: var(--ink-faint); margin-top: var(--s-2); text-align: center; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- Wider screens: roomier, still single column ---------- */
@media (min-width: 720px) {
  .pillars { grid-template-columns: 1fr 1fr; }
  .screen h1 { font-size: 2.5rem; }
}
