/* =========================================================================
   Coffee Spoons — shared design system
   Palette and type lifted from the course deck: poster orange, navy slate,
   cream, olive. Light and dark themes are both first-class.
   ========================================================================= */

/* ---------- Tokens: light (also the un-stamped default) ------------------ */
:root {
  /* Grounds & ink */
  --bg:            #fffdf9;
  --bg-soft:       #faf3e4;
  --bg-inset:      #f3ead6;
  --bg-panel:      #33323f;   /* the deck's navy slate */
  --bg-panel-soft: #3d3c4c;
  --bg-panel-deep: #2a2935;

  --text:          #33323f;
  --text-soft:     #4f4e5f;
  --text-muted:    #6d6b7b;
  --on-panel:      #f4f1e8;
  --on-panel-soft: #b9b6c6;
  --on-panel-mute: #a3a0b4;

  --border:        #e7ddc7;
  --border-strong: #d5c8ab;
  --border-panel:  #4b4a5c;

  /* Accent — Coffee Spoons orange */
  --accent:        #d94413;
  --accent-strong: #a8320c;
  --accent-soft:   #fdf0e7;
  --accent-ring:   rgba(217, 68, 19, .3);
  --accent-on-dark:#ff8047;
  --on-accent:     #ffffff;

  /* Extraction semantics */
  --under:      #c9a227;   /* sour, acid yellow  */
  --ideal:      #5d6b3d;   /* olive, the sweet spot */
  --over:       #a81616;   /* the deck's red     */
  --under-soft: #fbf3dc;
  --ideal-soft: #f0f3e7;
  --over-soft:  #fbeeed;

  /* Type */
  --font-display: "Archivo Black", "Archivo", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-sans:    "Archivo", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Metrics */
  --measure: 720px;
  --wide: 1000px;
  --radius: 12px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(51,50,63,.05), 0 8px 30px rgba(51,50,63,.08);
  --shadow-panel: 0 2px 6px rgba(28,27,36,.18), 0 20px 60px rgba(28,27,36,.26);
}

/* ---------- Tokens: dark (system preference, unless light is stamped) ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #1e1d26;
    --bg-soft:       #262530;
    --bg-inset:      #2e2d39;
    --bg-panel:      #2a2935;
    --bg-panel-soft: #35343f;
    --bg-panel-deep: #201f29;

    --text:          #f0ede4;
    --text-soft:     #cbc7d3;
    --text-muted:    #918da0;
    --on-panel:      #f0ede4;
    --on-panel-soft: #b9b6c6;
    --on-panel-mute: #a3a0b4;

    --border:        #3a3945;
    --border-strong: #4c4b59;
    --border-panel:  #45444f;

    --accent:        #ff6b33;
    --accent-strong: #ff8a5c;
    --accent-soft:   #33231c;
    --accent-ring:   rgba(255, 107, 51, .34);
    --on-accent:     #1e1d26;

    --under:      #e0bb45;
    --ideal:      #93a866;
    --over:       #e3564e;
    --under-soft: #302a17;
    --ideal-soft: #232a1c;
    --over-soft:  #33201f;

    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 30px rgba(0,0,0,.35);
    --shadow-panel: 0 2px 6px rgba(0,0,0,.4), 0 20px 60px rgba(0,0,0,.45);
  }
}

/* ---------- Tokens: dark (explicitly stamped) ---------------------------- */
:root[data-theme="dark"] {
  --bg:            #1e1d26;
  --bg-soft:       #262530;
  --bg-inset:      #2e2d39;
  --bg-panel:      #2a2935;
  --bg-panel-soft: #35343f;
  --bg-panel-deep: #201f29;

  --text:          #f0ede4;
  --text-soft:     #cbc7d3;
  --text-muted:    #918da0;
  --on-panel:      #f0ede4;
  --on-panel-soft: #b9b6c6;
  --on-panel-mute: #a3a0b4;

  --border:        #3a3945;
  --border-strong: #4c4b59;
  --border-panel:  #45444f;

  --accent:        #ff6b33;
  --accent-strong: #ff8a5c;
  --accent-soft:   #33231c;
  --accent-ring:   rgba(255, 107, 51, .34);
  --on-accent:     #1e1d26;

  --under:      #e0bb45;
  --ideal:      #93a866;
  --over:       #e3564e;
  --under-soft: #302a17;
  --ideal-soft: #232a1c;
  --over-soft:  #33201f;

  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 30px rgba(0,0,0,.35);
  --shadow-panel: 0 2px 6px rgba(0,0,0,.4), 0 20px 60px rgba(0,0,0,.45);
}

/* ---------- Base --------------------------------------------------------- */
* { box-sizing: border-box; }

/* The UA rule for [hidden] is display:none, which any author `display` beats.
   Controls here are flex/grid, so restate it with enough weight to win. */
[hidden] { display: none !important; }

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-ring); }

:where(a, button, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Page shell --------------------------------------------------- */
.page { max-width: var(--wide); margin: 0 auto; padding: 0 28px 96px; }

.masthead {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
  padding: 26px 0 0;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.brand .mark { flex: 0 0 auto; display: block; }
.brand b {
  font-family: var(--font-display); font-size: 15px; letter-spacing: -.005em;
  line-height: 1.15; display: block; font-weight: 400;
}
.brand span { display: block; font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.masthead .crumb {
  font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-muted); font-family: var(--font-sans);
}

/* Chapter switcher. Sits where the crumb does on a single-chapter page. */
.chapnav { display: flex; gap: 4px; flex-wrap: wrap; }
.chapnav a {
  font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-muted); text-decoration: none;
  padding: 5px 11px; border-radius: 999px; border: 1px solid transparent;
}
.chapnav a:hover { color: var(--text); border-color: var(--border-strong); }
.chapnav a[aria-current="page"] {
  color: var(--accent-strong); background: var(--accent-soft); border-color: var(--accent-ring);
}

/* Everything on the right of the masthead: chapter switcher, then language. */
.mast-end { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* Language switcher. Two states, so it reads as one control rather than links. */
.langsel {
  display: inline-flex; align-items: center;
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 2px; background: var(--bg-soft);
}
.langsel button {
  font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .06em;
  color: var(--text-muted); background: none; border: 0; cursor: pointer;
  padding: 4px 10px; border-radius: 999px; line-height: 1.4;
}
.langsel button:hover { color: var(--text); }
.langsel button.on {
  color: var(--on-accent); background: var(--accent);
}

/* Reading column. The instrument panel sits outside it, at full page width. */
.prose { max-width: var(--measure); margin: 0 auto; }

/* ---------- Typography --------------------------------------------------- */
.eyebrow {
  display: inline-block;
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent-strong); margin: 0 0 14px;
}
h1, h2, h3 { text-wrap: balance; }
h1 {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(38px, 6.2vw, 58px); line-height: 1.02; letter-spacing: -.028em;
  margin: 0 0 16px;
}
h1 .hl { color: var(--accent); }
.lead { font-size: 20.5px; line-height: 1.55; color: var(--text-soft); margin: 0 0 34px; }
h2 {
  font-family: var(--font-display); font-weight: 400;
  font-size: 27px; line-height: 1.18; letter-spacing: -.02em;
  margin: 56px 0 12px;
}
h3 { font-size: 18.5px; font-weight: 700; margin: 34px 0 6px; letter-spacing: -.008em; }
p { margin: 0 0 18px; }
a { color: var(--accent-strong); text-underline-offset: 2px; text-decoration-color: var(--accent-ring); }
a:hover { text-decoration-color: var(--accent); }
strong { font-weight: 650; color: var(--text); }
.prose ul, .prose ol { margin: 0 0 18px; padding-left: 24px; }
.prose li { margin: 7px 0; }
.prose li::marker { color: var(--accent); font-weight: 700; }
hr { border: none; border-top: 1px solid var(--border); margin: 44px 0; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- Callouts ----------------------------------------------------- */
.callout {
  display: grid; grid-template-columns: auto 1fr; gap: 13px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 16px 19px; margin: 26px 0;
  font-size: 15.5px; line-height: 1.6;
}
.callout .ico { font-size: 17px; line-height: 1.55; }
.callout p:last-child { margin-bottom: 0; }
.callout .h { font-weight: 700; display: block; margin-bottom: 3px; }
.callout.key  { border-left-color: var(--accent); background: var(--accent-soft); }
.callout.tip  { border-left-color: var(--ideal);  background: var(--ideal-soft); }
.callout.warn { border-left-color: var(--over);   background: var(--over-soft); }

/* ---------- The instrument panel ----------------------------------------- */
.rig {
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: 18px;
  box-shadow: var(--shadow-panel);
  padding: 24px;
  margin: 34px 0 8px;
  color: var(--on-panel);
}
.rig-head { display: flex; align-items: center; gap: 11px; flex-wrap: wrap; margin-bottom: 3px; }
.rig-head h3 {
  margin: 0; font-family: var(--font-display); font-weight: 400;
  font-size: 19px; letter-spacing: -.015em; color: var(--on-panel);
}
.rig-head .badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent-on-dark); background: transparent;
  border: 1px solid rgba(255,128,71,.45); border-radius: 999px; padding: 3px 10px;
}
.rig-sub { font-size: 14px; color: var(--on-panel-mute); margin: 0 0 20px; max-width: 62ch; }

/* --accent-strong is tuned for the page, not for the permanently dark panel;
   inside the rig a link has to reach for the on-dark accent to clear AA. */
.rig a { color: var(--accent-on-dark); text-decoration-color: rgba(255,128,71,.45); }
.rig a:hover { text-decoration-color: var(--accent-on-dark); }

.rig-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
@media (max-width: 880px) { .rig-grid { grid-template-columns: minmax(0, 1fr); } }

/* Controls */
.controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 22px; }
@media (max-width: 560px) { .controls { grid-template-columns: minmax(0, 1fr); } }
.control { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.control label {
  font-size: 12.5px; font-weight: 600; color: var(--on-panel-soft);
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  text-transform: uppercase; letter-spacing: .06em;
}
.control label .v {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--accent-on-dark); font-weight: 700; font-size: 13px;
  text-transform: none; letter-spacing: 0;
}
.control .hint { font-size: 11.5px; color: var(--on-panel-mute); min-height: 1.35em; }
.control .hint.split { display: flex; justify-content: space-between; gap: 10px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 5px;
  background: var(--border-panel); border-radius: 999px; outline: none;
  margin: 9px 0 3px; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-on-dark); border: 3px solid var(--bg-panel);
  box-shadow: 0 0 0 1px var(--border-panel); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent-on-dark);
  border: 3px solid var(--bg-panel); box-shadow: 0 0 0 1px var(--border-panel); cursor: pointer;
}
input[type="range"]:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.seg-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.seg-row .k {
  font-size: 12.5px; font-weight: 600; color: var(--on-panel-soft);
  text-transform: uppercase; letter-spacing: .06em;
}
.seg { display: inline-flex; border: 1px solid var(--border-panel); border-radius: 8px; overflow: hidden; }
.seg button {
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--on-panel-soft);
  background: var(--bg-panel-soft); border: none; border-right: 1px solid var(--border-panel);
  padding: 7px 12px; cursor: pointer; transition: background .12s, color .12s;
}
.seg button:last-child { border-right: none; }
.seg button:hover { background: var(--bg-panel-deep); color: var(--on-panel); }
.seg button.on { background: var(--accent-strong); color: var(--on-accent); }
.seg button:focus-visible { outline: 2px solid var(--accent-on-dark); outline-offset: -2px; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.presets .k {
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--on-panel-mute); align-self: center; margin-right: 2px;
}
.chip {
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--on-panel-soft);
  background: transparent; border: 1px solid var(--border-panel);
  border-radius: 999px; padding: 5px 13px; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { border-color: var(--accent-on-dark); color: var(--on-panel); }
.chip.on { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }

/* Gauge */
.gauge { margin-top: 22px; }
.gauge-scale {
  position: relative; height: 34px; border-radius: 8px; overflow: hidden;
  display: grid; grid-template-columns: 6fr 4fr 8fr;  /* 12–18 · 18–22 · 22–30 %EY */
  border: 1px solid var(--border-panel);
}
.gauge-zone {
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase;
  color: rgba(255,255,255,.94);
}
.gauge-zone.u { background: #8a7016; }
.gauge-zone.i { background: #56663a; }
.gauge-zone.o { background: #7d1512; }
/* A pointer above the scale, so it never sits on top of a zone label. */
.gauge-needle {
  position: absolute; top: 0; width: 0; height: 0; margin-left: -7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid var(--on-panel);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5));
  transition: left .22s cubic-bezier(.4,.9,.3,1);
}
.gauge-wrap { position: relative; padding: 13px 0 0; }
.gauge-ticks {
  display: flex; justify-content: space-between; margin-top: 8px;
  font-family: var(--font-mono); font-size: 10.5px; color: var(--on-panel-mute);
  font-variant-numeric: tabular-nums;
}

.mode-note { font-size: 12.5px; color: var(--on-panel-mute); font-style: italic; }

/* Readouts */
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; margin-top: 18px; }
/* A value the model computed rather than one you set. */
.readout.derived { border-color: rgba(255,128,71,.42); }
.readout .val.derived { color: var(--accent-on-dark); }
.readout {
  background: var(--bg-panel-deep); border: 1px solid var(--border-panel);
  border-radius: 10px; padding: 11px 14px; min-width: 0;
}
.readout .k {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--on-panel-mute); font-weight: 700;
}
.readout .val {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 24px; font-weight: 700; line-height: 1.2; margin-top: 3px; color: var(--on-panel);
}
.readout .val small { font-size: 12px; font-weight: 600; color: var(--on-panel-mute); }
.readout .sub { font-size: 11.5px; color: var(--on-panel-mute); margin-top: 1px; }

/* The cup */
.cup-col { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.cup-art { width: 100%; max-width: 230px; }
.verdict {
  text-align: center; width: 100%;
  border: 1px solid var(--border-panel); border-radius: 12px;
  background: var(--bg-panel-deep); padding: 13px 15px;
}
.verdict .state {
  font-family: var(--font-display); font-weight: 400; font-size: 20px;
  letter-spacing: -.01em; line-height: 1.15;
}
.verdict .state.u { color: var(--under); }
.verdict .state.i { color: #a3bd6e; }
.verdict .state.o { color: #ef6f66; }
.verdict .words {
  display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-top: 9px;
}
.verdict .words span {
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 5px;
  background: rgba(255,255,255,.07); color: var(--on-panel-soft);
  border: 1px solid var(--border-panel);
}

/* Sensory bars */
.bars { display: grid; gap: 9px; margin-top: 18px; }
.bar { display: grid; grid-template-columns: 74px 1fr 34px; align-items: center; gap: 11px; }
.bar .lab { font-size: 12.5px; font-weight: 600; color: var(--on-panel-soft); }
.bar .track {
  display: block; height: 8px; background: var(--bg-panel-deep);
  border: 1px solid var(--border-panel); border-radius: 999px; overflow: hidden;
}
/* display:block matters — a bare inline span ignores width and height. */
.bar .fill { display: block; height: 100%; border-radius: 999px; transition: width .22s ease, background .22s ease; }
.bar .pct {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--on-panel-mute);
  text-align: right; font-variant-numeric: tabular-nums;
}

/* Chart */
.chart-wrap { margin-top: 20px; }
.rig canvas { display: block; width: 100%; touch-action: none; border-radius: 10px; }
.legend {
  display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 12px;
  color: var(--on-panel-mute); margin-top: 9px;
}
.legend i { display: inline-block; width: 13px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.legend i.band { height: 9px; border-radius: 2px; }

/* Advice */
.advice { margin-top: 16px; display: grid; gap: 8px; }
.msg {
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
  font-size: 14.5px; line-height: 1.55; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border-panel); background: var(--bg-panel-deep); color: var(--on-panel-soft);
}
.msg strong { color: var(--on-panel); font-weight: 700; }
.msg.good { border-color: rgba(147,168,102,.45); background: rgba(147,168,102,.1); }
.msg.warn { border-color: rgba(224,187,69,.4);  background: rgba(224,187,69,.09); }
.msg.bad  { border-color: rgba(227,86,78,.4);   background: rgba(227,86,78,.09); }
.msg .ico { font-size: 15px; line-height: 1.5; }

.rig-foot {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border-panel);
  font-size: 12.5px; color: var(--on-panel-mute); display: flex; gap: 14px;
  align-items: baseline; flex-wrap: wrap; justify-content: space-between;
}
.rig-foot .btn {
  font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--on-panel-soft);
  background: transparent; border: 1px solid var(--border-panel); border-radius: 7px;
  padding: 5px 11px; cursor: pointer;
}
.rig-foot .btn:hover { border-color: var(--accent-on-dark); color: var(--on-panel); }

.figcap { font-size: 13.5px; color: var(--text-muted); margin: 10px 0 0; text-align: center; }

/* Coffee belt map. Land and dots are drawn from real lon/lat by the widget,
   so a dot always lands where the country actually is. The map is decorative
   duplication of the origin chips — those stay the accessible control. */
.belt { margin: 2px 0 12px; }
.belt svg {
  display: block; width: 100%; height: auto;
  background: var(--bg-panel-deep);
  border: 1px solid var(--border-panel); border-radius: 12px;
}
.belt-land { fill: #464555; stroke: #57566a; stroke-width: .7; stroke-linejoin: round; }
.belt-band { fill: rgba(255,128,71,.12); }
.belt-tropic { stroke: rgba(255,128,71,.45); stroke-width: 1; stroke-dasharray: 5 4; fill: none; }
.belt-cap {
  fill: var(--on-panel-mute); font-family: var(--font-sans);
  font-size: 8px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
}
.belt-hit { fill: transparent; cursor: pointer; }
.belt-dot {
  fill: var(--on-panel-mute); stroke: var(--bg-panel-deep); stroke-width: 1.5;
  pointer-events: none; transition: fill .18s ease;
}
.belt-g:hover .belt-dot { fill: var(--on-panel); }
.belt-g.on .belt-dot { fill: var(--accent-on-dark); }
.belt-ring { fill: none; stroke: var(--accent-on-dark); stroke-width: 1.4; opacity: 0; pointer-events: none; }
.belt-g.on .belt-ring { opacity: .8; }
.belt-lab {
  fill: var(--on-panel); font-family: var(--font-sans); font-size: 9px; font-weight: 700;
  opacity: 0; pointer-events: none; paint-order: stroke;
  stroke: var(--bg-panel-deep); stroke-width: 2.6; stroke-linejoin: round;
}
.belt-g:hover .belt-lab, .belt-g.on .belt-lab { opacity: 1; }

/* Roast strip. Reuses the gauge's wrapper, needle and tick row; only the
   scale itself differs — a continuous bean gradient rather than three zones.
   The labels live under it because white on light-roast tan fails contrast. */
.roast-scale {
  position: relative; height: 26px; border-radius: 8px;
  border: 1px solid var(--border-panel);
  background: linear-gradient(90deg, #d8bb92 0%, #b7873f 26%, #8b5327 52%, #5b3218 78%, #2c1a11 100%);
}

/* The bean, shaded to the roast — the flavour page's answer to the cup. */
.bean-art { width: 100%; max-width: 200px; }

/* ---------- Cupping sheet ------------------------------------------------
   The third widget records rather than predicts, so its components are
   inputs first: two dials per attribute, a word picker, and an overlay
   comparison once there is more than one cup on the table. */

.cups { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.cup-tab {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--on-panel-soft);
  background: transparent; border: 1px solid var(--border-panel);
  border-radius: 999px; padding: 5px 14px; cursor: pointer;
  max-width: 15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cup-tab i { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; display: block; }
.cup-tab:hover { border-color: var(--accent-on-dark); color: var(--on-panel); }
.cup-tab.on { background: var(--bg-panel-deep); border-color: var(--accent-on-dark); color: var(--on-panel); }
.cup-add {
  font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--accent-on-dark);
  background: transparent; border: 1px dashed var(--border-panel);
  border-radius: 999px; padding: 5px 13px; cursor: pointer;
}
.cup-add:hover { border-color: var(--accent-on-dark); }
.cup-full { font-size: 12px; color: var(--on-panel-mute); font-style: italic; }

.cup-name { display: grid; gap: 3px; margin-bottom: 20px; max-width: 420px; }
.cup-name label, .notes label {
  font-size: 12.5px; font-weight: 600; color: var(--on-panel-soft);
  text-transform: uppercase; letter-spacing: .06em;
}
.cup-name .hint { font-size: 11.5px; color: var(--on-panel-mute); }
.rig input[type="text"], .rig textarea {
  font-family: inherit; font-size: 15px; color: var(--on-panel);
  background: var(--bg-panel-deep); border: 1px solid var(--border-panel);
  border-radius: 8px; padding: 9px 12px; width: 100%; resize: vertical;
}
.rig input[type="text"]::placeholder, .rig textarea::placeholder { color: var(--on-panel-mute); }
.rig input[type="text"]:focus-visible, .rig textarea:focus-visible {
  outline: none; border-color: var(--accent-on-dark); box-shadow: 0 0 0 3px var(--accent-ring);
}

/* One card per attribute. Quantity and quality sit in the same card on
   purpose — the pair is the lesson, and separating them would hide it. */
.attrs { display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); gap: 14px; }
.attr {
  border: 1px solid var(--border-panel); border-radius: 12px;
  background: var(--bg-panel-deep); padding: 14px 16px 16px;
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.attr-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.attr-head h4 {
  margin: 0; font-family: var(--font-display); font-weight: 400;
  font-size: 16px; letter-spacing: -.01em; color: var(--on-panel);
}
.attr-shape { font-size: 11.5px; font-style: italic; color: var(--on-panel-mute); text-align: right; }
.attr-shape.good { color: #a3bd6e; font-style: normal; }
.attr-shape.warn { color: var(--under); font-style: normal; }
.attr-shape.bad  { color: #ef6f66; font-style: normal; }
.attr-help { font-size: 12.5px; line-height: 1.5; color: var(--on-panel-mute); margin: 0 0 6px; }
.attr .control + .control { margin-top: 4px; }

/* The quality read-out: a bar that grows out of a centre line, because a
   minus is a different thing from a small plus, not a shorter one. */
.qbar {
  position: relative; height: 8px; margin-top: 12px;
  background: var(--bg-panel); border: 1px solid var(--border-panel); border-radius: 999px;
}
.qbar .mid {
  position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px;
  background: var(--on-panel-mute); opacity: .6;
}
.qbar .fill {
  position: absolute; top: 0; bottom: 0; display: block; border-radius: 999px;
  transition: left .18s ease, width .18s ease, background .18s ease;
}

/* Descriptor picker */
.picker { margin-top: 22px; border-top: 1px solid var(--border-panel); padding-top: 18px; }
.picker-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.picker-head .k {
  font-size: 12.5px; font-weight: 600; color: var(--on-panel-soft);
  text-transform: uppercase; letter-spacing: .06em;
}
.picker-head .sub { font-size: 12.5px; color: var(--on-panel-mute); }
.picker-cats { margin-bottom: 14px; }
.picker-words { display: flex; flex-wrap: wrap; gap: 7px; }
.chip.word { font-weight: 500; }
.picked { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; min-height: 28px; align-items: center; }
.picked-empty { font-size: 12.5px; color: var(--on-panel-mute); font-style: italic; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 12px; font-weight: 600; color: var(--on-panel);
  background: rgba(255,255,255,.07); border: 1px solid var(--border-panel);
  border-radius: 6px; padding: 4px 8px; cursor: pointer;
}
.tag i { width: 8px; height: 8px; border-radius: 2px; display: block; }
.tag span { color: var(--on-panel-mute); font-weight: 700; }
.tag:hover { border-color: #ef6f66; }
.tag:hover span { color: #ef6f66; }

/* Notes and the overall dial share the rig's two-column grid. */
.notes { display: grid; gap: 4px; align-content: start; }
.overall { display: grid; gap: 6px; align-content: start; }
.overall .hint { font-size: 12px; color: var(--on-panel-mute); }

/* Comparison. One row per attribute, one bar per cup, stacked so the
   difference is seen rather than remembered. */
.compare { margin-top: 24px; border-top: 1px solid var(--border-panel); padding-top: 18px; }
.cmp-rows { display: grid; gap: 12px; margin-top: 14px; }
.cmp-row { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; }
.cmp-lab { font-size: 12.5px; font-weight: 600; color: var(--on-panel-soft); }
.cmp-track {
  display: grid; gap: 3px; position: relative;
  background: var(--bg-panel-deep); border: 1px solid var(--border-panel);
  border-radius: 8px; padding: 5px 32px 5px 6px;
}
/* The numbers live in the right-hand gutter that padding opens up, so a long
   bar never runs underneath its own value. The centre line has to be pulled
   back by half of that gutter to stay over the middle of the bars. */
.cmp-track.diverging::before {
  content: ""; position: absolute; left: calc(50% - 13px); top: 2px; bottom: 2px; width: 1px;
  background: var(--on-panel-mute); opacity: .55;
}
.cmp-bar { position: relative; display: block; height: 13px; }
.cmp-fill {
  position: absolute; top: 0; bottom: 0; display: block; border-radius: 3px;
  min-width: 2px; transition: left .18s ease, width .18s ease;
}
.cmp-num {
  position: absolute; right: -28px; top: 0; line-height: 13px;
  font-family: var(--font-mono); font-size: 10px; color: var(--on-panel-mute);
  font-variant-numeric: tabular-nums;
}
.cmp-legend {
  display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px;
  font-size: 12px; color: var(--on-panel-mute);
}
.cmp-legend i {
  display: inline-block; width: 13px; height: 3px; border-radius: 2px;
  margin-right: 6px; vertical-align: middle;
}

/* Export row. Copy leads, because a sandboxed page cannot start a download. */
.export {
  display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin-top: 20px;
}
.export .btn {
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--on-panel-soft);
  background: transparent; border: 1px solid var(--border-panel); border-radius: 8px;
  padding: 7px 14px; cursor: pointer;
}
.export .btn:hover { border-color: var(--accent-on-dark); color: var(--on-panel); }
.export .btn.primary {
  background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent);
}
.export .btn.primary:hover { color: var(--on-accent); }
.export-note { font-size: 12.5px; color: var(--accent-on-dark); }

/* ---------- Chapter cards ------------------------------------------------ */
.chapters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr));
  gap: 18px; margin: 34px 0 8px;
}
.chapter-card {
  display: flex; flex-direction: column; gap: 7px;
  text-decoration: none; color: inherit;
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg-soft);
  padding: 20px 22px; box-shadow: var(--shadow);
  transition: border-color .18s ease, transform .18s ease;
}
.chapter-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.chapter-card .n {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent-strong);
}
.chapter-card h3 {
  margin: 0; font-family: var(--font-display); font-weight: 400;
  font-size: 21px; letter-spacing: -.015em; line-height: 1.2;
}
.chapter-card p { margin: 0; font-size: 15px; line-height: 1.55; color: var(--text-soft); }
.chapter-card .go {
  margin-top: auto; padding-top: 12px;
  font-size: 13.5px; font-weight: 700; color: var(--accent-strong);
}
.chapter-card.soon {
  border-style: dashed; background: transparent; box-shadow: none; cursor: default;
}
.chapter-card.soon:hover { border-color: var(--border-strong); transform: none; }
.chapter-card.soon .n, .chapter-card.soon .go { color: var(--text-muted); }
.chapter-card.soon h3 { color: var(--text-muted); }

/* Prev / next, at the foot of a chapter. */
.chapter-nav {
  max-width: var(--measure); margin: 52px auto 0;
  display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(258px, 1fr));
}
.chapter-link {
  display: flex; flex-direction: column; gap: 2px;
  text-decoration: none; color: inherit;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-soft); padding: 16px 18px;
}
.chapter-link:hover { border-color: var(--accent); }
.chapter-link .k {
  font-size: 11px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-muted);
}
.chapter-link .t {
  font-family: var(--font-display); font-weight: 400; font-size: 17px;
  letter-spacing: -.01em; color: var(--text);
}
.chapter-link .d { font-size: 14px; line-height: 1.5; color: var(--text-soft); margin-top: 3px; }

/* ---------- Tables ------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 24px 0; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); border-bottom: 2px solid var(--border-strong);
}
td.n { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.small { font-size: 13px; color: var(--text-muted); }

/* ---------- Footer ------------------------------------------------------- */
.foot {
  margin-top: 72px; padding-top: 26px; border-top: 1px solid var(--border);
  font-size: 14px; color: var(--text-muted);
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}

@media (max-width: 620px) {
  body { font-size: 16px; }
  .page { padding: 0 18px 72px; }
  .rig { padding: 18px 15px; border-radius: 14px; }
  .readouts { grid-template-columns: minmax(0, 1fr); }
  .bar { grid-template-columns: 64px 1fr 30px; }
  .chapters { grid-template-columns: minmax(0, 1fr); }
  .cmp-row { grid-template-columns: minmax(0, 1fr); gap: 5px; }
  .attrs { grid-template-columns: minmax(0, 1fr); }
  /* The map's type is sized in viewBox units, so at phone width it shrinks to
     an illegible smudge. Drop it and let the map be the belt picture; the
     highlighted dot and the chip row still say which origin is selected. */
  .belt-cap, .belt-lab { display: none; }
}
