/* Tokens: taste refs/tokens.md. Light = flat grey shell; dark = matte neutral near-black. */
:root {
  --shell: #EFEFEF; --card: #F9F9F9; --surface: #FFFFFF; --inset: #F6F6F3;
  --line: #E7E7E7; --line-strong: #DEDEDE;
  --ink: #0A0A0A; --ink-2: #3A3A3A; --muted: #878787; --faint: #A3A3A3;
  --primary: #1C1C1C; --on-primary: #FFFFFF;
  --blue: #2050F0; --blue-tint: #E7EDF9; --blue-hairline: #C9DBF5;
  --success: #2C9C68; --success-tint: #E3F3EA; --danger: #DC4438; --danger-tint: #FBE7E5;
  --warn: #D49C1C; --alert: #EC7C1C; --amber-tint: #FFEAC8;
  --hero: linear-gradient(160deg, #5A78FC 0%, #2553F0 45%, #1C42C7 100%);
  --r-chip: 6px; --r-control: 8px; --r-tile: 10px; --r-card: 16px;
  --ease: cubic-bezier(.2,.7,.2,1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --shell: #0A0A0A; --card: #141414; --surface: #161616; --inset: #1C1C1C;
    --line: #262626; --line-strong: #363636;
    --ink: #EDEDED; --ink-2: #C7C7C7; --muted: #A1A1A1; --faint: #6B6B6B;
    --primary: #EDEDED; --on-primary: #0A0A0A;
    --blue: #3D6BF5; --blue-tint: #14181F; --blue-hairline: #25324A;
    --success: #4CB782; --success-tint: #12201A; --danger: #E5574B; --danger-tint: #261412;
    --warn: #E0A93A; --alert: #F08A3B; --amber-tint: #2A2112;
    --hero: linear-gradient(160deg, #3552D6 0%, #1A3BB0 45%, #12297F 100%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --shell: #0A0A0A; --card: #141414; --surface: #161616; --inset: #1C1C1C;
  --line: #262626; --line-strong: #363636;
  --ink: #EDEDED; --ink-2: #C7C7C7; --muted: #A1A1A1; --faint: #6B6B6B;
  --primary: #EDEDED; --on-primary: #0A0A0A;
  --blue: #3D6BF5; --blue-tint: #14181F; --blue-hairline: #25324A;
  --success: #4CB782; --success-tint: #12201A; --danger: #E5574B; --danger-tint: #261412;
  --warn: #E0A93A; --alert: #F08A3B; --amber-tint: #2A2112;
  --hero: linear-gradient(160deg, #3552D6 0%, #1A3BB0 45%, #12297F 100%);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--shell); color: var(--ink);
  font: 400 15px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-wrap: anywhere;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* ---------- Home ---------- */
.home { max-width: 640px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 8px; height: 44px; margin-bottom: 16px; }
.brand { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; margin-right: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark { width: 28px; height: 28px; border-radius: var(--r-control); background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.stat { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px; border-radius: 9999px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 500; }
.stat.flame svg { color: var(--alert); }
.stat.bolt svg { color: var(--blue); }
.icon-btn { width: 36px; height: 36px; border-radius: var(--r-control); display: grid; place-items: center; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--surface); }

.hero { background: var(--hero); color: #fff; border-radius: var(--r-card); padding: 24px; margin-bottom: 32px; }
.hero-label { display: inline-flex; height: 24px; align-items: center; padding: 0 10px; border-radius: 9999px; border: 1px solid rgba(255,255,255,.4); font-size: 12px; font-weight: 500; }
.hero-rank { font-size: clamp(32px, 9vw, 44px); line-height: 1.05; letter-spacing: -0.02em; font-weight: 500; margin: 16px 0 4px; }
.hero-sub { font-size: 14px; opacity: .8; }
.hero-tiles { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; margin: 20px 0; }
.hero-tile { background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.25); border-radius: var(--r-tile); padding: 10px 12px; min-width: 0; }
.hero-tile b { display: block; font-size: 22px; font-weight: 500; line-height: 1.1; }
.hero-tile span { font-size: 12px; opacity: .8; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; border-radius: 9999px; background: rgba(255,255,255,.22); overflow: hidden; }
.bar > i { display: block; height: 100%; background: #fff; border-radius: inherit; transition: width .6s var(--ease); }
.hero-cta { margin-top: 20px; width: 100%; height: 48px; border-radius: var(--r-control); background: #fff; color: #0A0A0A; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; min-width: 0; }
.hero-cta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.section-label { font-size: 12px; font-weight: 500; color: var(--muted); margin: 0 0 8px 4px; }
.section { margin-bottom: 40px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 6px; }
.level { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px; border-radius: var(--r-tile); min-width: 0; }
.level + .level { margin-top: 2px; }
.level:not(:disabled):hover { background: var(--surface); }
.level:disabled { cursor: default; }
.level-num { width: 40px; height: 40px; border-radius: var(--r-tile); display: grid; place-items: center; font-weight: 600; font-size: 15px; background: var(--inset); border: 1px solid var(--line); flex: none; color: var(--ink-2); }
.level.done .level-num { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.level.current .level-num { background: var(--blue); color: #fff; border-color: var(--blue); }
.level:disabled .level-num { color: var(--faint); }
.level-body { min-width: 0; flex: 1; display: block; }
.level-title { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.level:disabled .level-title { color: var(--muted); }
.level-sub { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.level-meta { flex: none; display: flex; align-items: center; gap: 2px; color: var(--faint); }
.level-meta .on { color: var(--warn); }

.notes .note { padding: 12px 14px; border-radius: var(--r-tile); }
.note + .note { border-top: 1px solid var(--line); border-radius: 0; }
.note-h { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.note p { margin: 0; font-size: 14px; color: var(--ink-2); }
.empty { padding: 16px; font-size: 14px; color: var(--muted); }

.gloss-search { width: 100%; height: 40px; border-radius: var(--r-control); border: 1px solid var(--line-strong); background: var(--surface); padding: 0 12px; margin-bottom: 8px; font: inherit; font-size: 16px; color: var(--ink); }
.gloss-search:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.gloss-row { display: grid; grid-template-columns: minmax(96px, 34%) minmax(0,1fr); gap: 12px; padding: 10px 12px; font-size: 14px; }
.gloss-row + .gloss-row { border-top: 1px solid var(--line); }
.gloss-row b { font-weight: 500; }
.gloss-row span { color: var(--ink-2); }

/* ---------- Player (scroll feed) ---------- */
.player { position: fixed; inset: 0; background: var(--shell); }
.pbar { position: absolute; z-index: 2; top: 0; left: 0; right: 0; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 12px; background: var(--shell); background: color-mix(in srgb, var(--shell) 80%, transparent); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.pbar-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; width: 100%; }
.segs { flex: 1; display: flex; gap: 3px; min-width: 0; }
.segs i { flex: 1; height: 4px; border-radius: 9999px; background: var(--line-strong); transition: background .25s; }
.segs i.on { background: var(--ink); }
.pxp { font-size: 13px; font-weight: 500; display: inline-flex; gap: 4px; align-items: center; color: var(--ink-2); }
.pxp svg { color: var(--blue); }
.feed { height: 100%; overflow-y: auto; scroll-snap-type: y proximity; overscroll-behavior: contain; scroll-behavior: smooth; }
.slide { min-height: 100vh; min-height: 100dvh; scroll-snap-align: start; display: flex; align-items: center; padding: calc(64px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }
.slide-inner { width: 100%; max-width: 560px; margin: 0 auto; }
.kicker { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 9999px; font-size: 12px; font-weight: 500; background: var(--blue-tint); color: var(--blue); border: 1px solid var(--blue-hairline); margin-bottom: 16px; }
.slide h2 { font-size: clamp(26px, 7vw, 36px); line-height: 1.12; letter-spacing: -0.02em; font-weight: 500; margin: 0 0 16px; }
.slide .body { font-size: 17px; line-height: 1.55; color: var(--ink-2); margin: 0; }
.ex { margin-top: 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-tile); padding: 14px 16px; }
.ex-h { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.ex-h svg { width: 14px; height: 14px; color: var(--alert); }
.ex p { margin: 0; font-size: 15px; color: var(--ink); }
.hint { margin-top: 32px; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.hint svg { width: 14px; height: 14px; animation: bob 1.6s var(--ease) infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }

.flow { display: flex; flex-direction: column; gap: 0; margin-top: 8px; }
.flow-step { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-tile); padding: 12px 14px; min-width: 0; }
.flow-n { width: 28px; height: 28px; border-radius: var(--r-control); background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; }
.flow-step b { display: block; font-weight: 600; }
.flow-step div span { font-size: 14px; color: var(--ink-2); }
.flow-arrow { height: 14px; margin-left: 27px; border-left: 2px solid var(--line-strong); }

/* interactive cards */
.q { font-size: clamp(22px, 6vw, 28px); line-height: 1.2; letter-spacing: -0.01em; font-weight: 500; margin: 0 0 20px; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt { text-align: left; min-height: 52px; padding: 12px 14px; border-radius: var(--r-tile); background: var(--surface); border: 1px solid var(--line-strong); display: flex; align-items: center; gap: 12px; transition: background .15s, border-color .15s; }
.opt:not(:disabled):hover { border-color: var(--ink-2); }
.opt:disabled { cursor: default; }
.opt-key { width: 26px; height: 26px; border-radius: var(--r-chip); background: var(--inset); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; color: var(--muted); }
.opt.right { background: var(--success-tint); border-color: var(--success); }
.opt.right .opt-key { background: var(--success); color: #fff; border-color: var(--success); }
.opt.wrong { background: var(--danger-tint); border-color: var(--danger); }
.opt.wrong .opt-key { background: var(--danger); color: #fff; border-color: var(--danger); }
.opt.dim { opacity: .55; }
.verdict { margin-top: 16px; padding: 14px 16px; border-radius: var(--r-tile); background: var(--card); border: 1px solid var(--line); font-size: 15px; animation: rise .3s var(--ease); }
.verdict b { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.verdict.good b { color: var(--success); }
.verdict.bad b { color: var(--danger); }
.verdict p { margin: 0; color: var(--ink-2); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { height: 36px; padding: 0 12px; border-radius: var(--r-control); background: var(--surface); border: 1px solid var(--line-strong); font-size: 14px; font-weight: 500; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.sel { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.chip.used { visibility: hidden; }
.defs { display: flex; flex-direction: column; gap: 6px; }
.def { text-align: left; padding: 12px 14px; border-radius: var(--r-tile); background: var(--card); border: 1px dashed var(--line-strong); font-size: 15px; min-height: 48px; display: flex; flex-direction: column; gap: 2px; }
.def.armed { border-color: var(--ink-2); background: var(--surface); }
.def.ok { border-style: solid; border-color: var(--success); background: var(--success-tint); cursor: default; }
.def .tag { font-size: 12px; font-weight: 600; color: var(--success); }
.sub-hint { font-size: 13px; color: var(--muted); margin: -8px 0 16px; }

.order-picked { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.order-picked .flow-step { background: var(--success-tint); border-color: var(--success); animation: rise .25s var(--ease); }
.order-picked .flow-n { background: var(--success); color: #fff; }
.order-pool { display: flex; flex-direction: column; gap: 6px; }
.order-pool .opt { min-height: 48px; }

.field-label { font-size: 13px; font-weight: 500; margin: 16px 0 8px; display: block; }
.field { width: 100%; min-height: 72px; resize: vertical; border-radius: var(--r-control); border: 1px solid var(--line-strong); background: var(--surface); padding: 10px 12px; font-size: 16px; }
.field:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.btn { height: 48px; padding: 0 18px; border-radius: var(--r-control); background: var(--primary); color: var(--on-primary); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); }
.btn:disabled { opacity: .4; cursor: default; }
.row { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.row .btn { flex: 1 1 140px; }

.done-card { text-align: center; }
.done-seal { width: 72px; height: 72px; margin: 0 auto 20px; border-radius: var(--r-card); background: var(--primary); color: var(--on-primary); display: grid; place-items: center; }
.done-seal svg { width: 36px; height: 36px; }
.stars { display: flex; justify-content: center; gap: 6px; margin: 8px 0 20px; color: var(--line-strong); }
.stars svg { width: 32px; height: 32px; }
.stars .on { color: var(--warn); animation: pop .4s var(--ease) both; }
.stars .on:nth-child(2) { animation-delay: .12s; } .stars .on:nth-child(3) { animation-delay: .24s; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
.done-tiles { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; text-align: left; }
.done-tiles div { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-tile); padding: 12px; min-width: 0; }
.done-tiles b { display: block; font-size: 22px; font-weight: 500; }
.done-tiles span { font-size: 12px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* xp float */
.xp-pop { position: fixed; z-index: 5; left: 50%; top: calc(56px + env(safe-area-inset-top)); transform: translateX(-50%); background: var(--primary); color: var(--on-primary); font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 9999px; animation: xp 1.1s var(--ease) forwards; pointer-events: none; }
@keyframes xp { 0% { opacity: 0; transform: translate(-50%, 8px); } 20% { opacity: 1; transform: translate(-50%, 0); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -10px); } }

/* sheet */
.scrim { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
@media (min-width: 700px) { .scrim { align-items: center; } }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 480px; background: var(--surface); border-radius: var(--r-card) var(--r-card) 0 0; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); animation: rise .25s var(--ease); max-height: 90dvh; overflow-y: auto; border: 1px solid var(--line); }
@media (min-width: 700px) { .sheet { border-radius: var(--r-card); } }
.sheet h3 { margin: 0 0 16px; font-size: 18px; font-weight: 600; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--inset); border: 1px solid var(--line); border-radius: var(--r-control); padding: 3px; gap: 3px; }
.seg button { height: 34px; border-radius: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.sheet .help { font-size: 14px; color: var(--ink-2); margin: 0; }
.sheet ol { margin: 8px 0 0; padding-left: 20px; font-size: 14px; color: var(--ink-2); }
.danger-link { color: var(--danger); font-size: 14px; font-weight: 500; margin-top: 24px; }

#toast { position: fixed; z-index: 20; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--primary); color: var(--on-primary); padding: 10px 16px; border-radius: var(--r-control); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }

@media (min-width: 900px) {
  .slide h2 { font-size: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
