/* ==========================================================================
   Lexiline — design tokens
   Style: editorial minimalism + soft cards (study-desk calm), accent-forward
   ========================================================================== */
:root {
  color-scheme: light;

  --bg: #F4F4F2;
  --bg-tint: #ECECF6;
  --surface: #FFFFFF;
  --surface-2: #F7F7FA;
  --surface-3: #EFEFF5;
  --border: #E3E3EC;
  --border-strong: #D2D2E0;

  --text: #14142B;
  --muted: #4B4B67;
  --faint: #75758F;
  --ink-inverse: #FFFFFF;

  --primary: #5346E0;
  --primary-hover: #4438C4;
  --primary-soft: #EDEBFF;
  --primary-text: #FFFFFF;

  --again: #D32F4B;
  --hard: #B26A00;
  --good: #1B7F5A;
  --easy: #1F6FB2;
  --again-soft: #FDECEF;
  --hard-soft: #FDF3E3;
  --good-soft: #E8F6F0;
  --easy-soft: #E9F2FA;

  --layer-1: #6C63FF;
  --layer-2: #9D4EDD;
  --layer-3: #12A5A5;
  --layer-4: #E5484D;
  --layer-5: #DE7C1B;
  --layer-6: #2F7FD1;
  --layer-7: #2F8F4E;
  --layer-8: #B4478F;

  --shadow-xs: 0 1px 2px rgba(20, 20, 43, .06);
  --shadow-sm: 0 2px 8px rgba(20, 20, 43, .06), 0 1px 2px rgba(20, 20, 43, .04);
  --shadow-md: 0 10px 30px rgba(20, 20, 43, .10), 0 2px 6px rgba(20, 20, 43, .05);
  --shadow-lg: 0 24px 60px rgba(20, 20, 43, .16);

  --r-xs: 8px; --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-xl: 28px; --r-full: 999px;
  --sp: 4px;

  --sidebar-w: 264px;
  --topbar-h: 68px;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --maxw: 1080px;
}

/* dark tokens applied once, then referenced by both selectors below */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0C0C17;
    --bg-tint: #14142A;
    --surface: #16162A;
    --surface-2: #1D1D33;
    --surface-3: #26263F;
    --border: #2C2C46;
    --border-strong: #3D3D5C;
    --text: #F2F2F7;
    --muted: #B7B7CC;
    --faint: #8F8FAB;
    --primary: #8B80FF;
    --primary-hover: #A29AFF;
    --primary-soft: #262351;
    --primary-text: #12102A;
    --again: #FF7A8F; --hard: #F0B357; --good: #4ED2A0; --easy: #6DB6F5;
    --again-soft: #351A21; --hard-soft: #33280F; --good-soft: #12301F; --easy-soft: #14293B;
    --layer-1: #8B80FF; --layer-2: #C08BF5; --layer-3: #35C7C7; --layer-4: #FF7A8F;
    --layer-5: #F0B357; --layer-6: #6DB6F5; --layer-7: #5FC07C; --layer-8: #E887C4;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, .35);
    --shadow-md: 0 12px 34px rgba(0, 0, 0, .45);
    --shadow-lg: 0 28px 70px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0C0C17;
  --bg-tint: #14142A;
  --surface: #16162A;
  --surface-2: #1D1D33;
  --surface-3: #26263F;
  --border: #2C2C46;
  --border-strong: #3D3D5C;
  --text: #F2F2F7;
  --muted: #B7B7CC;
  --faint: #8F8FAB;
  --primary: #8B80FF;
  --primary-hover: #A29AFF;
  --primary-soft: #262351;
  --primary-text: #12102A;
  --again: #FF7A8F; --hard: #F0B357; --good: #4ED2A0; --easy: #6DB6F5;
  --again-soft: #351A21; --hard-soft: #33280F; --good-soft: #12301F; --easy-soft: #14293B;
  --layer-1: #8B80FF; --layer-2: #C08BF5; --layer-3: #35C7C7; --layer-4: #FF7A8F;
  --layer-5: #F0B357; --layer-6: #6DB6F5; --layer-7: #5FC07C; --layer-8: #E887C4;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .35);
  --shadow-md: 0 12px 34px rgba(0, 0, 0, .45);
  --shadow-lg: 0 28px 70px rgba(0, 0, 0, .6);
}

/* ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
ul, ol { margin: 0; padding: 0; list-style: none; }
svg.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: var(--font-mono); font-variant-ligatures: none; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none !important; }
.stack-6 { display: flex; flex-direction: column; gap: 6px; }
.stack-10 { display: flex; flex-direction: column; gap: 10px; }
.stack-16 { display: flex; flex-direction: column; gap: 16px; }
.stack-24 { display: flex; flex-direction: column; gap: 24px; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--primary); color: var(--primary-text); padding: 10px 16px; border-radius: 0 0 10px 0;
}
.skip-link:focus { left: 0; }
::selection { background: var(--primary-soft); color: var(--text); }

/* ================= app shell ================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 16px 18px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 2px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }
.brand-svg { width: 26px; height: 26px; color: var(--muted); }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.brand-text small { color: var(--faint); font-size: 11.5px; letter-spacing: .02em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--muted); font-weight: 500; font-size: 14.5px;
  transition: background-color .16s ease, color .16s ease;
  cursor: pointer; min-height: 44px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.pill {
  margin-left: auto; font-style: normal; font-size: 11.5px; font-weight: 600;
  background: var(--primary); color: var(--primary-text);
  min-width: 22px; text-align: center; padding: 2px 7px; border-radius: var(--r-full);
}
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.streak-card {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--r-md); padding: 12px 14px; display: flex; gap: 12px; align-items: center;
}
.streak-card .ic { color: var(--layer-5); }
.streak-card b { font-size: 20px; font-family: var(--font-display); }
.streak-card .stack { display: flex; flex-direction: column; line-height: 1.15; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  min-height: var(--topbar-h);
  padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-title h1 { font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.topbar-title p { font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#view { padding: 28px; max-width: var(--maxw); width: 100%; margin: 0 auto; flex: 1; }
#view:focus { outline: none; }

/* ================= buttons ================= */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd); border-radius: var(--r-sm);
  font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease, opacity .16s ease;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { --btn-bg: var(--primary); --btn-fg: var(--primary-text); --btn-bd: var(--primary); box-shadow: var(--shadow-sm); }
.btn.primary:hover { --btn-bg: var(--primary-hover); --btn-bd: var(--primary-hover); color: var(--primary-text); }
.btn.ghost { --btn-bg: transparent; --btn-bd: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.subtle { --btn-bg: var(--surface-2); --btn-bd: var(--border); }
.btn.danger { --btn-bg: transparent; --btn-bd: var(--border); color: var(--again); }
.btn.danger:hover { background: var(--again-soft); border-color: var(--again); color: var(--again); }
.btn.icon { padding: 0; width: 44px; min-height: 44px; }
.btn.tiny { min-height: 34px; padding: 5px 10px; font-size: 13px; border-radius: var(--r-xs); }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; padding: 12px 22px; font-size: 16px; border-radius: var(--r-md); }

/* ================= surfaces ================= */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-xs);
}
.card.pad { padding: 22px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-h h2, .card-h h3 { font-size: 17px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); font-weight: 600; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-full);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 500; color: var(--muted);
}
.chip.pos { background: var(--primary-soft); color: var(--primary); border-color: transparent; font-weight: 600; }
.chip.topic { text-transform: capitalize; }
.chip.state-new { background: var(--easy-soft); color: var(--easy); border-color: transparent; }
.chip.state-learning { background: var(--hard-soft); color: var(--hard); border-color: transparent; }
.chip.state-review { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.state-due { background: var(--again-soft); color: var(--again); border-color: transparent; }
.chip button { background: none; border: 0; cursor: pointer; color: inherit; display: grid; place-items: center; padding: 0; }
.chip .ic { width: 14px; height: 14px; }

.divider { height: 1px; background: var(--border); border: 0; margin: 0; }
.empty {
  text-align: center; padding: 44px 20px; color: var(--muted);
  border: 1px dashed var(--border-strong); border-radius: var(--r-lg); background: var(--surface-2);
}
.empty .ic { width: 30px; height: 30px; color: var(--faint); margin-bottom: 10px; }

/* ================= home ================= */
.hero {
  position: relative; overflow: hidden;
  background:
    radial-gradient(120% 150% at 90% 0%, color-mix(in srgb, var(--primary) 18%, transparent) 0%, transparent 60%),
    var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: 28px; box-shadow: var(--shadow-sm);
}
.hero h2 { font-family: var(--font-display); font-size: 30px; font-weight: 600; letter-spacing: -.02em; }
.hero p.lead { color: var(--muted); max-width: 62ch; margin-top: 8px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 16px; display: flex; flex-direction: column; gap: 2px;
}
.tile b { font-family: var(--font-display); font-size: 26px; font-weight: 600; line-height: 1.1; }
.tile span { font-size: 12.5px; color: var(--faint); }
.tile.accent-due b { color: var(--again); }
.tile.accent-new b { color: var(--easy); }
.tile.accent-done b { color: var(--good); }
.chain-intro { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; }
.chain-step {
  border: 1px solid var(--border); border-top: 4px solid var(--c, var(--primary));
  border-radius: var(--r-sm); padding: 10px 10px 12px; background: var(--surface-2);
}
.chain-step b { display: block; font-size: 13px; }
.chain-step span { font-size: 11.5px; color: var(--faint); line-height: 1.35; display: block; margin-top: 2px; }
.chain-step i { font-style: normal; font-size: 10.5px; color: var(--c, var(--primary)); font-weight: 700; letter-spacing: .06em; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.topic-card {
  text-align: left; cursor: pointer; min-height: 44px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.topic-card:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.mini-bar { height: 6px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }

/* ================= study ================= */
.study-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 22px; align-items: start; }
.study-rail { position: sticky; top: calc(var(--topbar-h) + 20px); display: flex; flex-direction: column; gap: 14px; }
.rail-head { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.rail-list { display: flex; flex-direction: column; gap: 2px; position: relative; }
.rail-list::before { content: ""; position: absolute; left: 15px; top: 12px; bottom: 12px; width: 2px; background: var(--border); }
.rail-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 7px 8px; border-radius: var(--r-sm); font-size: 13.5px; color: var(--faint); cursor: pointer;
  background: none; border: 0; text-align: left; width: 100%;
}
.rail-item:hover { color: var(--text); }
.rail-dot {
  width: 14px; height: 14px; border-radius: 50%; flex: none; margin-left: 9px;
  border: 2px solid var(--border-strong); background: var(--surface); z-index: 1;
  transition: transform .18s ease, background-color .18s ease, border-color .18s ease;
}
.rail-item.open { color: var(--text); font-weight: 600; }
.rail-item.open .rail-dot { background: var(--c); border-color: var(--c); transform: scale(1.15); }
.rail-item.current .rail-dot { border-color: var(--c); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 22%, transparent); }

.study-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.study-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.progress { flex: 1 1 180px; height: 8px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; min-width: 120px; }
.progress i { display: block; height: 100%; background: var(--primary); transition: width .3s ease; }

.wordcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.wordcard-head {
  padding: 24px 26px 20px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent, var(--primary)) 9%, transparent), transparent 70%);
  border-bottom: 1px solid var(--border);
}
.headword { font-family: var(--font-display); font-size: 46px; font-weight: 600; letter-spacing: -.025em; line-height: 1.05; word-break: break-word; }
.headword .pos-suffix { font-family: var(--font-ui); font-size: 15px; font-weight: 500; color: var(--faint); letter-spacing: 0; }
.ipa { font-family: var(--font-mono); color: var(--muted); font-size: 15px; }
.wordcard-body { padding: 6px 0 0; }
.prompt { padding: 16px 26px 18px; color: var(--muted); font-size: 14.5px; border-bottom: 1px dashed var(--border); }

.layer { border-bottom: 1px solid var(--border); }
.layer:last-child { border-bottom: 0; }
.layer-head {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 26px; background: none; border: 0; text-align: left; cursor: pointer; min-height: 52px;
}
.layer-head:hover { background: var(--surface-2); }
.layer-index {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c);
}
.layer-title { font-weight: 600; font-size: 14.5px; }
.layer-hint { margin-left: auto; color: var(--faint); font-size: 12.5px; }
.layer.locked { opacity: .45; }
.layer.locked .layer-head { cursor: default; }
.layer-body { padding: 2px 26px 20px 64px; animation: reveal .22s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.layer-body .chev { transition: transform .18s ease; }
.layer.open .chev { transform: rotate(90deg); }

.meaning-list { display: flex; flex-direction: column; gap: 10px; }
.meaning { display: flex; gap: 10px; align-items: baseline; }
.meaning .vi { font-weight: 600; }
.meaning .en { color: var(--muted); font-size: 14px; }
.core-meaning { font-size: 19px; font-weight: 600; }
.note {
  border-left: 3px solid var(--c, var(--primary)); background: var(--surface-2);
  padding: 9px 12px; border-radius: 0 var(--r-xs) var(--r-xs) 0; font-size: 13.5px; color: var(--muted);
}
.pair-list { display: flex; flex-direction: column; gap: 8px; }
.pair {
  display: grid; grid-template-columns: minmax(90px, max-content) minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2);
}
.pair b { font-family: var(--font-mono); font-size: 14px; }
.pair .vi { color: var(--muted); font-size: 13.5px; }
.pair .why { color: var(--faint); font-size: 12.5px; }
.collo {
  display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 4px 14px;
  padding: 9px 12px; border-radius: var(--r-sm); background: var(--surface-2); margin-bottom: 8px;
}
.collo code { font-family: var(--font-mono); font-size: 13.5px; color: var(--text); }
.collo .vi { color: var(--muted); font-size: 13.5px; }
.collo .tag { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; grid-column: 1 / -1; }
.pattern-box {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.formula {
  font-family: var(--font-mono); font-size: 15px; font-weight: 500;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r-sm);
  padding: 10px 12px; overflow-x: auto; white-space: nowrap;
}
.formula em { font-style: normal; color: var(--c, var(--primary)); font-weight: 600; }
.pos-slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.slot { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 11px 12px; background: var(--surface-2); }
.slot .label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); font-weight: 700; }
.slot .val { font-size: 13.5px; margin-top: 5px; }
.slot.mid { border-color: var(--c); background: color-mix(in srgb, var(--c) 10%, transparent); }
.slot.mid .val b { font-family: var(--font-mono); }
.example { padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-2); margin-bottom: 8px; }
.example .en { font-size: 15px; }
.example .vi { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.example .who { font-size: 11.5px; color: var(--faint); margin-top: 4px; }
.typing-area { display: flex; flex-direction: column; gap: 12px; }

/* rating bar */
.rate-bar {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
  padding: 16px 26px 20px; background: var(--surface-2); border-top: 1px solid var(--border);
}
.rate {
  border: 1px solid var(--btn-bd); border-radius: var(--r-md); background: var(--surface);
  padding: 11px 12px; cursor: pointer; text-align: left; min-height: 60px;
  display: flex; flex-direction: column; gap: 2px; justify-content: center;
  transition: transform .12s ease, border-color .16s ease, background-color .16s ease;
}
.rate:hover { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, var(--surface)); }
.rate:active { transform: translateY(1px); }
.rate .k { font-size: 11px; color: var(--faint); font-family: var(--font-mono); }
.rate .t { font-weight: 700; font-size: 15px; color: var(--c); }
.rate .d { font-size: 12px; color: var(--muted); }
.rate.again { --c: var(--again); --btn-bd: color-mix(in srgb, var(--again) 40%, var(--border)); }
.rate.hard { --c: var(--hard); --btn-bd: color-mix(in srgb, var(--hard) 40%, var(--border)); }
.rate.good { --c: var(--good); --btn-bd: color-mix(in srgb, var(--good) 40%, var(--border)); }
.rate.easy { --c: var(--easy); --btn-bd: color-mix(in srgb, var(--easy) 40%, var(--border)); }
.rate-bar[hidden] { display: none; }
.reveal-cta { padding: 16px 26px 20px; border-top: 1px solid var(--border); background: var(--surface-2); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.session-done { text-align: center; padding: 40px 24px; }
.session-done .big { font-family: var(--font-display); font-size: 32px; font-weight: 600; }
.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 22px 0; }

/* ================= deck ================= */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.input, .select, .textarea {
  min-height: 44px; padding: 10px 12px; width: 100%;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  transition: border-color .16s ease, box-shadow .16s ease;
}
.textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-wrap { position: relative; flex: 1 1 220px; }
.search-wrap .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 18px; height: 18px; }
.search-wrap .input { padding-left: 38px; }

.word-list { display: flex; flex-direction: column; gap: 8px; }
.word-row {
  display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.6fr) auto;
  gap: 14px; align-items: center; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 12px 14px; cursor: pointer;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.word-row:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.word-row .w { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.word-row .ipa { font-size: 12.5px; }
.word-row .vi { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.word-row .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.due-in { font-size: 12px; color: var(--faint); font-family: var(--font-mono); }

/* ================= stats ================= */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 132px; }
.bar-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; max-width: 46px; height: 4px; background: var(--primary); border-radius: 6px 6px 2px 2px;
  transition: height .3s ease; position: relative;
}
.bar[data-empty="1"] { background: var(--surface-3); }
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-3); display: block; }
.heat i[data-l="1"] { background: color-mix(in srgb, var(--good) 30%, var(--surface-3)); }
.heat i[data-l="2"] { background: color-mix(in srgb, var(--good) 55%, var(--surface-3)); }
.heat i[data-l="3"] { background: color-mix(in srgb, var(--good) 78%, var(--surface-3)); }
.heat i[data-l="4"] { background: var(--good); }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--faint); }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: block; }

/* ================= modal + toast ================= */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: color-mix(in srgb, #06060F 62%, transparent);
  backdrop-filter: blur(3px); display: grid; place-items: center; padding: 18px; animation: fade .16s ease both;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; max-height: 88vh; overflow: auto;
  animation: pop .2s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99) } to { opacity: 1; transform: none } }
.modal.lg { max-width: 820px; }
.modal-h { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-h h3 { font-size: 17px; }
.modal-h .btn { margin-left: auto; }
.modal-b { padding: 22px; }
.modal-f { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 22px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.kbd-grid { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 18px; align-items: center; font-size: 14px; }
kbd {
  font-family: var(--font-mono); font-size: 12px; padding: 3px 7px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px; white-space: nowrap;
}
.toasts { position: fixed; z-index: 120; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--r-sm); box-shadow: var(--shadow-md); padding: 11px 14px;
  font-size: 14px; max-width: 340px; animation: slide .2s ease both;
}
.toast.err { border-left-color: var(--again); }
.toast.ok { border-left-color: var(--good); }
@keyframes slide { from { opacity: 0; transform: translateX(12px) } to { opacity: 1; transform: none } }

.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.pack-more { border-top: 1px solid var(--border); padding-top: 12px; }
.pack-more summary { cursor: pointer; user-select: none; }
.pack-more summary:hover { color: var(--primary); }
.pack-more[open] > .pack-grid { margin-top: 12px; }
.pack-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); cursor: pointer; min-height: 52px;
  transition: border-color .16s ease, background-color .16s ease;
}
.pack-item:hover { border-color: var(--primary); }
.pack-item input { flex: none; }
.pack-item .grow { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; color: var(--text); }
.pack-item b { font-size: 14px; }
.pack-item .chip { flex: none; font-size: 11.5px; }

input[type="range"] { accent-color: var(--primary); height: 28px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 18px; height: 18px; cursor: pointer; }
label > span { font-size: 14.5px; color: var(--muted); }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s ease infinite; border-radius: var(--r-xs); height: 14px; }
@keyframes sk { from { background-position: 200% 0 } to { background-position: -200% 0 } }

/* ================= responsive ================= */
.only-mobile { display: none; }
.tabbar { display: none; }
@media (max-width: 1080px) {
  .study-shell { grid-template-columns: minmax(0, 1fr); }
  .study-rail { position: static; order: -1; min-width: 0; }
  .rail-list { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; min-width: 0; }
  .rail-list::before { display: none; }
  .rail-item { flex-direction: column; gap: 6px; min-width: 84px; text-align: center; font-size: 12px; padding: 8px 6px; }
  .rail-dot { margin-left: 0; }
  .chain-intro { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(290px, 84vw);
    transform: translateX(-102%); transition: transform .24s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar[data-open="true"] { transform: none; }
  .only-mobile { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .topbar-title h1 { font-size: 19px; }
  #view { padding: 18px 16px 92px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 4px; font-size: 11px; color: var(--faint); min-height: 56px; }
  .tabbar a[aria-current] { color: var(--primary); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .headword { font-size: 36px; }
  .layer-body { padding: 2px 18px 18px 18px; }
  .layer-head, .wordcard-head, .prompt, .rate-bar, .reveal-cta { padding-left: 18px; padding-right: 18px; }
  .pos-slots { grid-template-columns: minmax(0, 1fr); }
  .rate-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pair { grid-template-columns: minmax(0, 1fr); gap: 3px; }
  .collo { grid-template-columns: minmax(0, 1fr); }
  .collo code { word-break: break-word; }
  .word-row { grid-template-columns: 1fr auto; }
  .word-row .col-vi { grid-column: 1 / -1; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chain-intro { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toasts { left: 12px; right: 12px; bottom: 74px; align-items: stretch; }
  .toast { max-width: none; }
  .bars { gap: 4px; }
  .bar-col .tiny { font-size: 9.5px; white-space: nowrap; }
  .bar { max-width: 22px; }
}
@media (max-width: 420px) {
  .hero h2 { font-size: 25px; }
  .headword { font-size: 30px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
