/* juice.css
   Monochrome, with game feel. One stylesheet. No JavaScript. No dependencies.
   Three things sit on top of the monochrome base and each one is a token:
     --ledge   depth, which only ever means "you can press this"
     --spring  motion with weight (and --pop, for the moment something is earned)
     --reward  the one color, which appears only on what the user did
   Every value comes from tokens.json. One breakpoint: 720px. */
@import "./tokens.css";

@property --v { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --n { syntax: "<integer>"; inherits: false; initial-value: 0; }

/* ── Base ───────────────────────────────────────────────────────────── */
*, ::before, ::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; accent-color: var(--text); scrollbar-color: var(--border-strong) transparent; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--t-md) / 1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-weight: 500; line-height: 1.2; letter-spacing: -0.02em; text-wrap: balance; }
h1 { font-size: clamp(var(--t-xl), 6vw, var(--t-2xl)); font-weight: 700; line-height: 1.1; letter-spacing: -0.035em; }
h2 { font-size: var(--t-xl); }
h3 { font-size: var(--t-lg); }
h4 { font-size: var(--t-md); letter-spacing: 0; }
/* A headline can have a quiet half, for the fact that would otherwise sit above it as an eyebrow. */
:is(h1, h2, h3) > .muted { font-weight: 400; }
p { text-wrap: pretty; }
strong, b { font-weight: 500; }
small { font-size: var(--t-sm); }
a { color: inherit; text-underline-offset: 0.2em; }
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
hr { border: 0; border-top: 1px solid var(--border); }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
::selection { background: var(--text); color: var(--bg); }

code, kbd, pre { font-family: var(--font-mono); font-size: 0.875em; }
:not(pre) > code { padding: 0.15em 0.4em; white-space: nowrap; background: var(--surface-2); border-radius: var(--r-sm); }
pre { padding: var(--s-4); overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); line-height: 1.6; }
/* A key is something you press, so it gets a ledge too. */
kbd {
  display: inline-block; min-width: 1.75em; padding: 0 0.4em; text-align: center; line-height: 1.5; color: var(--text-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); box-shadow: 0 calc(var(--ledge) / 2) 0 var(--border-strong);
}

.display { font-size: clamp(var(--t-2xl), 9vw, var(--t-3xl)); font-weight: 700; line-height: 1; letter-spacing: -0.045em; }
.wordmark { font-size: var(--t-lg); font-weight: 700; line-height: 1; letter-spacing: -0.05em; text-decoration: none; }
.label { font: 500 var(--t-xs) / 1.5 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
/* A number the user is building. Loud, like the headline and the main button. */
.score { font-family: var(--font-display); font-weight: 700; line-height: 1.1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

/* ── Icon ───────────────────────────────────────────────────────────── */
.i { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ── Press ──────────────────────────────────────────────────────────── */
/* The one depth in the system. Anything on a ledge can be pressed, and nothing else has one.
   Hover rises a pixel, press travels the full ledge, release springs back. On stays down. */
.btn, .option, a.card, button.card {
  --lift: var(--ledge); --edge: var(--border-strong);
  box-shadow: 0 var(--lift) 0 var(--edge);
  cursor: pointer;
  transition: translate var(--spring), box-shadow var(--spring), scale var(--spring), background var(--dur), border-color var(--dur);
}
@media (hover: hover) {
  .btn:hover, .option:hover, a.card:hover, button.card:hover { translate: 0 -1px; box-shadow: 0 calc(var(--lift) + 1px) 0 var(--edge); }
}
.btn:active, .option:active, a.card:active, button.card:active, .option:has(:checked) { translate: 0 var(--lift); box-shadow: 0 0 0 var(--edge); }
.btn:active, .option:active, a.card:active, button.card:active { transition-duration: calc(var(--dur) / 3); transition-timing-function: ease-out; }

/* ── Button ─────────────────────────────────────────────────────────── */
.btn {
  --h: var(--h-md); --edge: color-mix(in oklab, var(--text), var(--bg) 50%);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); flex: none;
  height: var(--h); padding: 0 calc(var(--h) * 0.45);
  background: var(--text); color: var(--bg);
  border: 1px solid transparent; border-radius: var(--r-full);
  font-size: var(--t-sm); font-weight: 500; line-height: 1; white-space: nowrap; text-decoration: none;
  user-select: none;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; box-shadow: none; }
.btn.secondary { --edge: var(--border-strong); background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { --edge: color-mix(in oklab, var(--danger), black 30%); background: var(--danger); color: var(--bg); }
/* Only for collecting something already earned. Never for the ordinary next step. */
.btn.reward { --edge: color-mix(in oklab, var(--reward), black 25%); }
/* Ghost has no ledge. It is the quiet one, so it answers with a squeeze instead of travel. */
.btn.ghost, .btn.ghost:hover, .btn.ghost:active { background: transparent; color: var(--text); box-shadow: none; translate: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.ghost:active { scale: 0.92; }
.btn.sm { --h: var(--h-sm); --lift: calc(var(--ledge) / 2); }
/* The large button is the main thing to do on a screen, so it speaks in the display voice. */
.btn.lg { --h: var(--h-lg); font-family: var(--font-display); font-size: var(--t-md); font-weight: 700; }
.btn.icon { width: var(--h); padding: 0; }
.btn.block { width: 100%; }

/* ── Field, input ───────────────────────────────────────────────────── */
.field { display: grid; gap: var(--s-2); font-size: var(--t-sm); }
.field > label { font-weight: 500; }
.field > small { color: var(--text-2); }
.field:has([aria-invalid="true"]) > small { color: var(--danger); }

.input {
  display: block; width: 100%; height: var(--h-lg); padding: 0 var(--s-4);
  background: transparent; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  font-size: var(--t-md);
  transition: border-color var(--dur);
}
.input::placeholder { color: var(--text-3); }
.input:hover { border-color: var(--text-3); }
.input:focus-visible { outline-offset: -1px; }
/* A wrong answer shakes its head once, then says what to do. */
.input[aria-invalid="true"] { border-color: var(--danger); animation: shake calc(var(--dur) * 2); }
.input:disabled { opacity: 0.4; pointer-events: none; }
textarea.input { height: auto; min-height: calc(var(--h-lg) * 2); padding-block: var(--s-3); resize: vertical; field-sizing: content; }
select.input {
  appearance: none; padding-right: var(--s-12); cursor: pointer;
  background:
    linear-gradient(45deg, transparent 50%, currentColor 50%) calc(100% - 21px) 50% / 5px 5px no-repeat,
    linear-gradient(135deg, currentColor 50%, transparent 50%) calc(100% - 16px) 50% / 5px 5px no-repeat;
}
@keyframes shake { 20% { translate: -6px; } 40% { translate: 5px; } 60% { translate: -3px; } 80% { translate: 2px; } }

/* ── Check, radio, switch ───────────────────────────────────────────── */
.check {
  appearance: none; display: inline-grid; place-content: center; flex: none;
  width: 20px; height: 20px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  cursor: pointer; transition: background var(--dur), border-color var(--dur), scale var(--spring);
}
.check[type="radio"] { border-radius: 50%; }
.check::before {
  content: ""; width: 10px; height: 10px; background: var(--bg); scale: 0; transition: scale var(--dur);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0, 43% 62%);
}
.check[type="radio"]::before { clip-path: circle(40%); }
.check:active { scale: 0.85; }
.check:checked { background: var(--text); border-color: var(--text); }
.check:checked::before { scale: 1; transition: scale var(--pop); } /* the mark lands; it does not fade in */

.switch {
  appearance: none; position: relative; flex: none; width: 40px; height: 24px;
  background: var(--border-strong); border-radius: var(--r-full);
  cursor: pointer; transition: background var(--dur);
}
.switch::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  background: var(--bg); border-radius: var(--r-full); transition: translate var(--spring), width var(--dur);
}
.switch:active::before { width: 24px; } /* the thumb squashes under the finger */
.switch:checked { background: var(--text); }
.switch:checked::before { translate: 16px; }
.switch:checked:active::before { translate: 12px; }

/* A whole row that selects: shipping method, plan, answer. Picked options stay down. */
.option {
  display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
}
.option:hover { background: var(--surface); }
.option:has(:checked) { border-color: var(--text); background: var(--surface); }
/* An answer that has been checked. Right is green, wrong is red and shakes its head once. */
.option.success { border-color: var(--success); background: color-mix(in oklab, var(--success) 12%, var(--bg)); }
.option.danger { border-color: var(--danger); background: color-mix(in oklab, var(--danger) 10%, var(--bg)); animation: shake calc(var(--dur) * 2); }
.option:is(.success, .danger) small { color: inherit; }

/* ── Composer ───────────────────────────────────────────────────────── */
.composer {
  display: grid; gap: var(--s-2); width: 100%; padding: var(--s-3);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  transition: border-color var(--dur);
}
.composer:focus-within { border-color: var(--border-strong); }
.composer textarea {
  display: block; width: 100%; min-height: 1.5em; max-height: 40dvh; padding: var(--s-1) var(--s-2);
  background: none; border: 0; outline: 0; resize: none; field-sizing: content;
}
.composer textarea::placeholder { color: var(--text-3); }

/* ── Chip, badge ────────────────────────────────────────────────────── */
.chip {
  position: relative; display: inline-flex; align-items: center; gap: var(--s-2); flex: none;
  height: var(--h-sm); padding: 0 var(--s-3);
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border); border-radius: var(--r-full);
  font-size: var(--t-sm); white-space: nowrap; text-decoration: none;
  transition: background var(--dur), color var(--dur), scale var(--spring);
}
.chip:is(a, button, label) { cursor: pointer; }
.chip:is(a, button, label):hover { background: var(--surface-2); color: var(--text); }
.chip:is(a, button, label):active { scale: 0.94; }
.chip:is([aria-pressed="true"], :has(:checked)) { background: var(--text); border-color: var(--text); color: var(--bg); }

.badge {
  display: inline-flex; align-items: center; gap: var(--s-1); height: var(--s-6); padding: 0 var(--s-2);
  background: var(--surface-2); border-radius: var(--r-full);
  font-size: var(--t-xs); font-weight: 500; white-space: nowrap;
  transition: background var(--dur), color var(--dur);
}

/* ── Segmented ──────────────────────────────────────────────────────── */
.segmented { display: inline-flex; flex: none; padding: var(--s-1); border: 1px solid var(--border); border-radius: var(--r-full); }
.segmented > * {
  position: relative; display: inline-flex; align-items: center; height: calc(var(--h-md) - var(--s-2) - 2px); padding: 0 var(--s-3);
  background: none; color: var(--text-2); border: 0; border-radius: var(--r-full);
  font-size: var(--t-sm); font-weight: 500; white-space: nowrap; text-decoration: none;
  cursor: pointer; transition: background var(--dur), color var(--dur);
}
.segmented > :hover { color: var(--text); }
.segmented > :is([aria-current], [aria-selected="true"], :has(:checked)) { background: var(--text); color: var(--bg); }
/* Where anchors exist, the selection is one thumb that slides between the options. */
@supports (anchor-scope: --seg) {
  .segmented { position: relative; anchor-scope: --seg; overflow: clip; }
  .segmented::before {
    content: ""; position: absolute; position-anchor: --seg; inset: anchor(top) anchor(right) anchor(bottom) anchor(left);
    background: var(--text); border-radius: var(--r-full); transition: inset var(--spring);
  }
  .segmented > :is([aria-current], [aria-selected="true"], :has(:checked)) { anchor-name: --seg; background: none; }
}

:is(.chip, .segmented > *, .option):has(:focus-visible) { outline: 2px solid var(--text); outline-offset: 2px; }

/* ── Card ───────────────────────────────────────────────────────────── */
.card { display: block; padding: var(--s-6); border: 1px solid var(--border); border-radius: var(--r-md); color: inherit; text-decoration: none; }
a.card, button.card { border-color: var(--border-strong); background: none; font: inherit; text-align: left; }
a.card:hover, button.card:hover { background: var(--surface); }

/* ── Item, rows ─────────────────────────────────────────────────────── */
.item {
  display: flex; align-items: center; gap: var(--s-3); flex: none;
  width: 100%; min-height: var(--h-md); padding: var(--s-2) var(--s-3);
  background: none; color: inherit; border: 0; border-radius: var(--r-sm);
  font-size: var(--t-sm); text-align: left; text-decoration: none;
  transition: background var(--dur);
}
.item:is(a, button, label) { cursor: pointer; }
.item:is(a, button, label):hover, .item[aria-current] { background: var(--surface-2); }

.rows > * { padding-block: var(--s-4); }
.rows > * + * { border-top: 1px solid var(--border); }

/* ── Divider ────────────────────────────────────────────────────────── */
.divider { display: flex; align-items: center; gap: var(--s-3); color: var(--text-3); font-size: var(--t-xs); }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ── Disclosure ─────────────────────────────────────────────────────── */
.disclosure { border-bottom: 1px solid var(--border); }
.disclosure > summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  padding: var(--s-4) 0; font-weight: 500; cursor: pointer; list-style: none;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after { content: "+"; color: var(--text-2); font-size: var(--t-lg); font-weight: 400; line-height: 1; transition: rotate var(--spring); }
.disclosure[open] > summary::after { rotate: 45deg; }
.disclosure > :not(summary) { padding-bottom: var(--s-4); color: var(--text-2); }

/* ── Table ──────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table :is(th, td) { padding: var(--s-3) var(--s-4) var(--s-3) 0; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table :is(th, td):last-child { padding-right: 0; }
.table th { font: 500 var(--t-xs) / 1.5 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .fit { width: 1%; text-align: right; } /* hugs its content: action and icon columns */

/* ── Avatar, spinner, skeleton ──────────────────────────────────────── */
.avatar {
  display: inline-grid; place-items: center; flex: none; width: var(--h-sm); aspect-ratio: 1; overflow: hidden;
  background: var(--surface-2); border-radius: 50%; font-size: var(--t-xs); font-weight: 500;
}
.avatar > img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: var(--s-16); font-size: var(--t-lg); }

.spinner { display: inline-block; flex: none; width: 1em; height: 1em; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.6s linear infinite; }
.skeleton { min-height: 1em; background: var(--surface-2); border-radius: var(--r-sm); color: transparent; animation: pulse 1s ease-in-out infinite alternate; }
@keyframes spin { to { rotate: 1turn; } }
@keyframes pulse { to { opacity: 0.4; } }

/* ── Progress: bar, ring, pips ──────────────────────────────────────── */
/* The native element. Black while it fills, gold once it is full. */
progress {
  appearance: none; display: block; flex: none; width: 100%; height: var(--s-2); overflow: hidden;
  background: var(--surface-2); color: var(--text); border: 0; border-radius: var(--r-full);
}
progress::-webkit-progress-bar { background: none; }
progress::-webkit-progress-value { background: currentColor; border-radius: var(--r-full); transition: width var(--spring), background var(--dur); }
progress::-moz-progress-bar { background: currentColor; border-radius: var(--r-full); }
progress:is([value="100"], .reward) { background: var(--surface-2); color: var(--reward); }
progress.lg { height: var(--s-4); } /* the bar at the top of a lesson or a flow */

/* Set --v from 0 to 100. Put a number, an icon or an avatar inside. */
.ring {
  --w: var(--s-2);
  --c: color-mix(in oklab, var(--reward) clamp(0%, (var(--v) - 99) * 100%, 100%), var(--text));
  --cap: radial-gradient(circle at 50% calc(var(--w) / 2), color-mix(in oklab, var(--c) clamp(0%, var(--v) * 100%, 100%), transparent) calc(var(--w) / 2 - 0.5px), transparent calc(var(--w) / 2));
  display: inline-grid; place-items: center; flex: none; width: var(--size, 96px); aspect-ratio: 1;
  transition: --v var(--spring);
}
.ring > * { grid-area: 1 / 1; }
.ring::before, .ring::after { content: ""; grid-area: 1 / 1; width: 100%; height: 100%; border-radius: 50%; }
.ring::before {
  background: var(--cap), conic-gradient(var(--c) calc(var(--v) * 1%), var(--surface-2) 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - var(--w) - 1px), black calc(100% - var(--w)), black calc(100% - 1px), transparent);
}
.ring::after { background: var(--cap); rotate: calc(min(var(--v), 100) * 3.6deg); }
.ring.sm { --size: var(--h-lg); --w: var(--s-1); }

/* Discrete progress: steps in a flow, days in a week. Small dots, or .lg to hold a letter. */
.pips { display: flex; align-items: center; gap: var(--s-2); }
.pips > * {
  display: grid; place-items: center; flex: none; width: var(--s-2); height: var(--s-2);
  background: var(--border-strong); color: var(--text-3); border-radius: var(--r-full);
  font-size: var(--t-xs); font-style: normal; font-weight: 500; line-height: 1;
  transition: width var(--spring), background var(--dur), color var(--dur);
}
.pips > .on, .pips > [aria-current] { background: var(--text); color: var(--bg); }
.pips:not(.lg) > [aria-current] { width: var(--s-6); }
.pips.lg > * { width: var(--h-sm); height: var(--h-sm); background: var(--surface-2); }
.pips.lg > .on { background: var(--text); }
.pips.lg > [aria-current] { background: none; color: var(--text); outline: 2px solid var(--text); outline-offset: -2px; }
.pips > .reward, .pips.lg > .reward { background: var(--reward); color: var(--reward-ink); }

/* ── Charts: bars, line, meter ──────────────────────────────────────── */
/* One series per chart, drawn in ink. The title says what it is, so no legend and no second color.
   Bars rise and lines draw in when they appear. --chart sets the height. */
.bars { display: flex; align-items: flex-end; gap: var(--s-1); height: var(--chart, 160px); border-bottom: 1px solid var(--border); }
.bars > * {
  position: relative; flex: 1; height: calc(var(--v) * 1%); min-height: 2px;
  background: var(--border-strong); border-radius: var(--s-1) var(--s-1) 0 0; outline-offset: 2px;
  transition: height var(--spring), background var(--dur);
}
.bars > :is(:hover, :focus, :last-child) { background: var(--text); }
/* The readout: point at a bar, or tab to it, and its aria-label is printed above it. */
.bars > [aria-label]:is(:hover, :focus)::after {
  content: attr(aria-label); position: absolute; bottom: calc(100% + var(--s-1)); left: 50%; z-index: 1; translate: -50%;
  padding: var(--s-1) var(--s-2); background: var(--text); color: var(--bg); border-radius: var(--r-sm);
  font: 500 var(--t-xs) / 1.5 var(--font-mono); white-space: nowrap; pointer-events: none;
}
.bars > :first-child::after { left: 0; translate: none; }
.bars > :last-child::after { left: auto; right: 0; translate: none; }

/* An inline SVG with preserveAspectRatio="none" and one polyline or path inside. */
.line { display: block; width: 100%; height: var(--chart, 160px); overflow: visible; border-bottom: 1px solid var(--border); clip-path: inset(-8px); transition: clip-path calc(var(--dur) * 6) cubic-bezier(0.2, 0.8, 0.2, 1); }
.line > * { fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }

@starting-style {
  .bars > * { height: 0; }
  .line { clip-path: inset(-8px 100% -8px -8px); }
}

/* The native element for a measurement: a share, a quota, a score out of ten.
   A meter states a fact, so unlike progress it never turns gold. */
meter {
  -webkit-appearance: none; appearance: none; display: block; flex: none; width: 100%; height: var(--s-2); overflow: hidden;
  background: var(--surface-2); border: 0; border-radius: var(--r-full);
}
meter::-webkit-meter-inner-element { display: block; }
meter::-webkit-meter-bar { height: var(--s-2); background: none; border: 0; border-radius: 0; }
meter::-webkit-meter-optimum-value, meter::-webkit-meter-suboptimum-value, meter::-webkit-meter-even-less-good-value { background: var(--text); border-radius: var(--r-full); transition: width var(--spring); }
meter::-moz-meter-bar { background: var(--text); border-radius: var(--r-full); }

/* ── Empty, art ─────────────────────────────────────────────────────── */
/* What a screen says when there is nothing to show yet, or something went wrong:
   one drawing, one sentence, one way forward. */
.empty { display: grid; justify-items: center; align-content: center; gap: var(--s-3); padding: var(--s-12) var(--s-4); text-align: center; }
.empty > p { max-width: 40ch; color: var(--text-2); }
/* Line drawings from art.svg. Same stroke as the icons, faint setting, ink subject, and gold only on the goal. */
.art { width: 240px; max-width: 100%; aspect-ratio: 3 / 2; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; color: var(--text); }

/* ── Quest ──────────────────────────────────────────────────────────── */
/* A task with a payoff. Checking it lands the mark, throws sparks and turns its badge gold. */
.quest { display: flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.quest small { display: block; color: var(--text-2); }
.quest .check { position: relative; }
.quest:has(:checked) > .grow { color: var(--text-3); text-decoration: line-through; }
.quest:has(:checked) small { color: inherit; }
.quest:has(:checked) .badge { background: var(--reward); color: var(--reward-ink); }

/* Sparks: twelve dots that leave the centre, shrink by half and fade. --r is how far they fly. */
.quest .check::after, .burst::after {
  --a: var(--reward); --b: var(--text); --dot: 5px; --r: 26px; --end: calc(var(--dot) / -4);
  --rest: 0 0 var(--a), 0 0 var(--b), 0 0 var(--a), 0 0 var(--a), 0 0 var(--b), 0 0 var(--a), 0 0 var(--a), 0 0 var(--b), 0 0 var(--a), 0 0 var(--a), 0 0 var(--b), 0 0 var(--a);
  --away:
    calc(var(--r) * 1) calc(var(--r) * -0.09) 0 var(--end) var(--a), calc(var(--r) * 0.61) calc(var(--r) * -0.43) 0 var(--end) var(--b),
    calc(var(--r) * 0.54) calc(var(--r) * -1.02) 0 var(--end) var(--a), calc(var(--r) * -0.07) calc(var(--r) * -0.85) 0 var(--end) var(--a),
    calc(var(--r) * -0.62) calc(var(--r) * -0.91) 0 var(--end) var(--b), calc(var(--r) * -0.63) calc(var(--r) * -0.3) 0 var(--end) var(--a),
    calc(var(--r) * -1.05) calc(var(--r) * 0.09) 0 var(--end) var(--a), calc(var(--r) * -0.68) calc(var(--r) * 0.42) 0 var(--end) var(--b),
    calc(var(--r) * -0.49) calc(var(--r) * 1.04) 0 var(--end) var(--a), calc(var(--r) * 0.03) calc(var(--r) * 0.75) 0 var(--end) var(--a),
    calc(var(--r) * 0.55) calc(var(--r) * 0.95) 0 var(--end) var(--b), calc(var(--r) * 0.74) calc(var(--r) * 0.43) 0 var(--end) var(--a);
  content: ""; position: absolute; inset: 50% auto auto 50%; border-radius: 50%; pointer-events: none;
  --fly: calc(var(--dur) * 4) cubic-bezier(0.1, 0.7, 0.3, 1);
}
/* On a quest the sparks are a transition, so a box that was already checked stays quiet on load. */
.quest .check::after { width: 0; height: 0; box-shadow: var(--rest); }
.quest .check:checked::after {
  width: var(--dot); height: var(--dot); margin: calc(var(--dot) / -2); box-shadow: var(--away); opacity: 0;
  transition: box-shadow var(--fly), opacity calc(var(--dur) * 4) ease-in;
}
/* .burst plays once whenever its element appears: a dialog opening, a toast, a gem unlocking. */
.burst { position: relative; }
.burst::after {
  --dot: 8px; --r: 72px;
  width: var(--dot); height: var(--dot); margin: calc(var(--dot) / -2); box-shadow: var(--away); opacity: 0;
  animation: burst var(--fly) backwards;
}
@keyframes burst { from { box-shadow: var(--rest); opacity: 1; } 60% { opacity: 1; } }

/* ── Gem ────────────────────────────────────────────────────────────── */
/* The one shape that is neither pill nor rectangle. It marks a level or an achievement.
   Gray until it is earned. Wrap its content in an element so it stays upright. */
.gem {
  --size: var(--h-lg);
  display: inline-grid; place-items: center; flex: none; width: var(--size); aspect-ratio: 1; margin: calc(var(--size) * 0.21);
  background: var(--surface-2); color: var(--text-3); border-radius: calc(var(--size) / 6); rotate: 45deg;
  font-size: var(--t-md); font-weight: 700; line-height: 1;
  transition: background var(--dur), color var(--dur);
}
.gem > * { rotate: -45deg; font-weight: inherit; }
.gem.sm { --size: var(--s-4); font-size: var(--t-xs); }
.gem.lg { --size: var(--s-16); font-size: var(--t-xl); }
.gem { font-family: var(--font-display); }
/* A gem that goes somewhere is pressable, so it sits on a ledge like everything else that is.
   The gem is turned 45 degrees, so its ledge is offset on both axes to point straight down. */
a.gem, button.gem {
  --edge: var(--border-strong);
  border: 0; text-decoration: none; cursor: pointer;
  box-shadow: calc(var(--ledge) * 0.71) calc(var(--ledge) * 0.71) 0 var(--edge);
  transition: translate var(--spring), box-shadow var(--spring), background var(--dur);
}
a.gem.reward, button.gem.reward { --edge: color-mix(in oklab, var(--reward), black 25%); }
a.gem[aria-current], button.gem[aria-current] { --edge: color-mix(in oklab, var(--text), var(--bg) 50%); background: var(--text); color: var(--bg); }
@media (hover: hover) { a.gem:hover, button.gem:hover { translate: 0 -1px; } }
a.gem:active, button.gem:active { translate: 0 var(--ledge); box-shadow: 0 0 0 var(--edge); transition-duration: calc(var(--dur) / 3); transition-timing-function: ease-out; }

/* ── Path ───────────────────────────────────────────────────────────── */
/* A course as a road: one gem per stop, swaying left and right as it goes down.
   Done is gold, here is inverted, and what is still locked is flat because you cannot press it. */
.path { --sway: var(--s-16); display: grid; justify-items: center; gap: var(--s-6); padding: 0; list-style: none; }
.path > * { display: grid; justify-items: center; gap: var(--s-1); translate: calc(var(--x, 0) * var(--sway)); font-size: var(--t-sm); text-align: center; }
.path > :nth-child(8n + 2), .path > :nth-child(8n + 4) { --x: 0.7; }
.path > :nth-child(8n + 3) { --x: 1; }
.path > :nth-child(8n + 6), .path > :nth-child(8n + 8) { --x: -0.7; }
.path > :nth-child(8n + 7) { --x: -1; }
.path > :has(span.gem) { color: var(--text-3); }

/* ── Count ──────────────────────────────────────────────────────────── */
/* A whole number that counts up to --n when it appears or changes. For scores, not for money. */
.count { counter-reset: n var(--n); font-variant-numeric: tabular-nums; transition: --n calc(var(--dur) * 6) cubic-bezier(0.2, 0.8, 0.2, 1); }
.count::after { content: counter(n); }

@starting-style {
  .ring { --v: 0 !important; }
  .count { --n: 0 !important; }
}

/* ── Thread, message, prose ─────────────────────────────────────────── */
.thread { display: flex; flex-direction: column; gap: var(--s-6); }
.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 85%; padding: var(--s-3) var(--s-4); background: var(--surface); border-radius: var(--r-lg); }
.prose { line-height: 1.65; }
.prose > * + * { margin-top: 1em; }
.prose :is(ul, ol) { padding-left: 1.25em; }
.prose li + li { margin-top: 0.35em; }

/* ── Overlays: menu, dialog, toast ──────────────────────────────────── */
.menu {
  inset: auto; margin: var(--s-2) 0; min-width: 220px; padding: var(--s-2);
  position-area: bottom span-right; position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-md);
}
.menu > hr { margin: var(--s-2) 0; }

.dialog {
  width: min(440px, 100% - 2 * var(--s-4)); margin: auto; padding: var(--s-6); overflow: visible;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.dialog::backdrop { background: var(--scrim); }
.actions { display: flex; justify-content: flex-end; gap: var(--s-3); }

.toast {
  inset: auto auto calc(var(--s-6) + env(safe-area-inset-bottom)) 50%; translate: -50% 0; margin: 0;
  padding: var(--s-3) var(--s-4); background: var(--text); color: var(--bg); border: 0; border-radius: var(--r-full);
  font-size: var(--t-sm); font-weight: 500; white-space: nowrap;
}
.toast:popover-open { display: flex; align-items: center; gap: var(--s-2); }
.toast .gem { margin-block: 0; }

/* The answer to an answer: a bar that rises from the bottom, says right or wrong and why, and moves on. */
.verdict {
  inset: auto 0 0; width: 100%; max-width: none; margin: 0; padding: var(--s-6) max(var(--s-4), (100% - 720px) / 2) calc(var(--s-6) + env(safe-area-inset-bottom));
  background: var(--surface); color: var(--text); border: 0; border-top: 1px solid var(--border); box-shadow: 0 var(--s-8) 0 var(--surface);
  transition: translate var(--spring);
}
.verdict:popover-open { display: flex; align-items: center; gap: var(--s-4); }
.verdict.success { background: color-mix(in oklab, var(--success) 12%, var(--bg)); box-shadow: 0 var(--s-8) 0 color-mix(in oklab, var(--success) 12%, var(--bg)); color: var(--text); }
.verdict.danger { background: color-mix(in oklab, var(--danger) 10%, var(--bg)); box-shadow: 0 var(--s-8) 0 color-mix(in oklab, var(--danger) 10%, var(--bg)); color: var(--text); }
.verdict.success strong { color: var(--success); }
.verdict.danger strong { color: var(--danger); }
@starting-style { .verdict:popover-open { translate: 0 100%; } }

/* Overlays arrive with weight: they overshoot a little and settle. */
.menu, .dialog { transition: opacity var(--dur), translate var(--spring), scale var(--spring); }
.toast { transition: opacity var(--dur), translate var(--pop), scale var(--pop); }
@starting-style {
  .menu:popover-open, .dialog[open] { opacity: 0; translate: 0 var(--s-2); scale: 0.94; }
  .toast:popover-open { opacity: 0; translate: -50% var(--s-4); scale: 0.8; }
}

/* ── Navigation: app shell, topbar, sidebar, tabbar ─────────────────── */
.app { display: grid; grid-template-columns: auto minmax(0, 1fr); min-height: 100dvh; }
.topbar { display: flex; align-items: center; gap: var(--s-3); min-height: calc(var(--h-md) + 2 * var(--s-2)); padding: var(--s-2) var(--s-4); }
.topbar.sticky { position: sticky; top: 0; z-index: 10; background: var(--bg); }

/* Add the popover attribute and the sidebar becomes a drawer on mobile. Without it, it hides. */
.sidebar {
  position: sticky; inset: 0 auto auto; display: flex; flex-direction: column; gap: var(--s-1);
  width: 260px; height: 100dvh; margin: 0; padding: var(--s-3); overflow-y: auto;
  background: var(--bg); color: var(--text); border: 0; border-right: 1px solid var(--border);
}
.tabbar { display: none; }

/* ── Mobile: sidebars become drawers, menus and dialogs become sheets ── */
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); max-height: none; transition: translate calc(var(--dur) * 2) cubic-bezier(0.2, 0.8, 0.2, 1); }
  .sidebar:not(:popover-open) { display: none; }
  .sidebar::backdrop, .menu::backdrop { background: var(--scrim); }
  @starting-style { .sidebar:popover-open { translate: -100% 0; } }

  /* The solid strip under a sheet covers the gap when the spring overshoots. It is not a shadow. */
  .menu, .dialog {
    inset: auto 0 0; width: 100%; max-width: 100%; margin: 0;
    padding: var(--s-4) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom));
    border-width: 1px 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: 0 var(--s-8) 0 var(--surface);
  }
  .menu { position-area: none; position-try-fallbacks: none; }
  .menu .item { min-height: var(--h-lg); font-size: var(--t-md); }
  .dialog { padding-top: var(--s-6); }
  .actions { flex-direction: column-reverse; }
  .actions > .btn { --h: var(--h-lg); width: 100%; font-size: var(--t-md); }
  .verdict:popover-open { flex-wrap: wrap; }
  .verdict > .btn { flex-basis: 100%; }
  @starting-style { .menu:popover-open, .dialog[open] { translate: 0 var(--s-12); scale: 1; } }

  .tabbar {
    position: fixed; inset: auto 0 0; z-index: 10; display: flex;
    padding: var(--s-1) var(--s-2) calc(var(--s-1) + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--border);
  }
  .tabbar > a {
    display: grid; justify-items: center; gap: 2px; flex: 1; padding: var(--s-2) 0;
    color: var(--text-3); font-size: var(--t-xs); font-weight: 500; text-decoration: none;
  }
  .tabbar > a[aria-current] { color: var(--text); }
  .tabbar .i { width: 22px; height: 22px; transition: scale var(--spring); }
  .tabbar > a:active .i { scale: 0.8; transition: scale calc(var(--dur) / 3); }
  :has(> .tabbar) { padding-bottom: calc(var(--s-16) + var(--s-2) + env(safe-area-inset-bottom)); }
}

/* ── Layout and utilities ───────────────────────────────────────────── */
.container { width: 100%; max-width: 1120px; margin-inline: auto; padding-inline: clamp(var(--s-4), 4vw, var(--s-8)); }
.container.narrow { max-width: 760px; }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min, 240px)), 1fr)); }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.center { align-items: center; text-align: center; }
.grow { flex: 1; min-width: 0; }
.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); } .gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); }
.gap-6 { gap: var(--s-6); } .gap-8 { gap: var(--s-8); } .gap-12 { gap: var(--s-12); } .gap-16 { gap: var(--s-16); }

.t-xs { font-size: var(--t-xs); } .t-sm { font-size: var(--t-sm); } .t-md { font-size: var(--t-md); }
.t-lg { font-size: var(--t-lg); } .t-xl { font-size: var(--t-xl); line-height: 1.2; letter-spacing: -0.02em; }
.t-2xl { font-size: var(--t-2xl); line-height: 1.1; letter-spacing: -0.03em; }
.muted { color: var(--text-2); }
.danger { color: var(--danger); }
.success { color: var(--success); }
/* The earned color. A fill behind dark ink, never ink itself. Add it only to something the user did. */
.reward { background: var(--reward); color: var(--reward-ink); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll-x { position: relative; overflow-x: auto; } /* wrap wide tables; relative keeps hidden content inside */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (min-width: 721px) { .mobile-only { display: none !important; } }
@media (max-width: 720px) { .desktop-only { display: none !important; } }
