/* Karate Dojo
   Layout concept: a squared school exercise book by day, a chalkboard by night;
   a winding dojo path is home, lessons are worksheets, the terminal is always dark. */
:root {
  --paper: #F5F7FC;
  --grid: rgba(47, 98, 217, 0.075);
  --surface: #FFFFFF;
  --surface-2: #EEF2FA;
  --surface-3: #E3E9F6;
  --ink: #1B2140;
  --ink-2: #4E5677;
  --ink-3: #6B7392;
  --line: #D9E0EE;
  --pen: #2F62D9;
  --pen-dark: #1F47A8;
  --pen-ink: #FFFFFF;
  --pen-soft: #E3EBFC;
  --leaf: #13774A;
  --leaf-strong: #22A565;
  --leaf-dark: #17804C;
  --leaf-bg: #DCF3E6;
  --sun: #FFC53D;
  --sun-dark: #D99A00;
  --sun-soft: #FFF3CF;
  --sun-ink: #664600;
  --coral: #C3343D;
  --coral-bg: #FCE3E4;
  --violet: #6343CC;
  --violet-bg: #ECE7FC;
  --teal: #0D7480;
  --headband: #E0473E;
  --shadow: 0 1px 0 rgba(27, 33, 64, 0.05), 0 10px 28px -14px rgba(27, 33, 64, 0.28);
  --shadow-pop: 0 18px 50px -18px rgba(27, 33, 64, 0.45);
  --code-bg: #FBFCFF;
  --c-step: #7B35C4; --c-kw: #2456C8; --c-sec: #B4440E; --c-str: #13774A; --c-fuzzy: #A35100;
  --c-num: #B0215E; --c-com: #727A93; --c-tag: #0D7480; --c-var: #0B66C2; --c-op: #C3343D; --c-ph: #7B35C4; --c-name: #8A5A00;
  --term-bg: #10131C; --term-bar: #1B2030; --term-fg: #D9DEEC; --term-dim: #7F88A3; --term-green: #7FE3A9;
  --term-red: #FF8E8E; --term-cyan: #7CC8FF; --term-yellow: #F4D06F; --term-violet: #C6A6FF; --term-line: #262C3F;
  --panda-white: #FFFFFF; --panda-ink: #1D2131; --panda-pink: #F7A3B3;
  --f-display: 'Baloo 2', 'Nunito', ui-rounded, system-ui, sans-serif;
  --f-body: 'Nunito', ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --r-sm: 10px; --r-md: 16px; --r-lg: 22px;
  --ed-lh: 22px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161B29; --grid: rgba(255, 255, 255, 0.035); --surface: #1E2436; --surface-2: #262D42; --surface-3: #2F3750;
    --ink: #EEF1F8; --ink-2: #AEB6CC; --ink-3: #8E97B1; --line: #343C56;
    --pen: #86A8FF; --pen-dark: #5B7FDB; --pen-ink: #0E1430; --pen-soft: #263459;
    --leaf: #74DBA4; --leaf-strong: #3DBE7C; --leaf-dark: #23864F; --leaf-bg: #183A2B;
    --sun: #FFCE5C; --sun-dark: #C9971F; --sun-soft: #3A3218; --sun-ink: #FFE3A1;
    --coral: #FF8F94; --coral-bg: #46222A; --violet: #BCA8FF; --violet-bg: #2E2851; --teal: #6FD3DD;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.25), 0 12px 30px -14px rgba(0, 0, 0, 0.6);
    --shadow-pop: 0 20px 50px -16px rgba(0, 0, 0, 0.7);
    --code-bg: #191E2E;
    --c-step: #C9A2FF; --c-kw: #8DB0FF; --c-sec: #FFAA70; --c-str: #8BE0AE; --c-fuzzy: #FFC46B;
    --c-num: #FF8FBF; --c-com: #8690AC; --c-tag: #6FD3DD; --c-var: #79C3FF; --c-op: #FF8F94; --c-ph: #C9A2FF; --c-name: #F0C674;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #161B29; --grid: rgba(255, 255, 255, 0.035); --surface: #1E2436; --surface-2: #262D42; --surface-3: #2F3750;
  --ink: #EEF1F8; --ink-2: #AEB6CC; --ink-3: #8E97B1; --line: #343C56;
  --pen: #86A8FF; --pen-dark: #5B7FDB; --pen-ink: #0E1430; --pen-soft: #263459;
  --leaf: #74DBA4; --leaf-strong: #3DBE7C; --leaf-dark: #23864F; --leaf-bg: #183A2B;
  --sun: #FFCE5C; --sun-dark: #C9971F; --sun-soft: #3A3218; --sun-ink: #FFE3A1;
  --coral: #FF8F94; --coral-bg: #46222A; --violet: #BCA8FF; --violet-bg: #2E2851; --teal: #6FD3DD;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.25), 0 12px 30px -14px rgba(0, 0, 0, 0.6);
  --shadow-pop: 0 20px 50px -16px rgba(0, 0, 0, 0.7);
  --code-bg: #191E2E;
  --c-step: #C9A2FF; --c-kw: #8DB0FF; --c-sec: #FFAA70; --c-str: #8BE0AE; --c-fuzzy: #FFC46B;
  --c-num: #FF8FBF; --c-com: #8690AC; --c-tag: #6FD3DD; --c-var: #79C3FF; --c-op: #FF8F94; --c-ph: #C9A2FF; --c-name: #F0C674;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font: 16px/1.55 var(--f-body);
  min-height: 100vh;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 60; background: var(--surface); }
h1, h2, h3, h4 { font-family: var(--f-display); line-height: 1.15; margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); font-weight: 800; }
h2 { font-size: 1.55rem; font-weight: 800; }
h3 { font-size: 1.2rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--pen); }
button { font: inherit; color: inherit; }
code, .code, pre { font-family: var(--f-mono); font-size: 0.875em; }
:focus-visible { outline: 3px solid var(--pen); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.eyebrow { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
.muted { color: var(--ink-2); }
.mark { background: linear-gradient(transparent 52%, var(--sun) 52%, var(--sun) 88%, transparent 88%); padding: 0 2px; border-radius: 2px; }
:root[data-theme="dark"] .mark { background: linear-gradient(transparent 52%, rgba(255, 206, 92, 0.38) 52%, rgba(255, 206, 92, 0.38) 90%, transparent 90%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mark { background: linear-gradient(transparent 52%, rgba(255, 206, 92, 0.38) 52%, rgba(255, 206, 92, 0.38) 90%, transparent 90%); } }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons ---------- */
.btn {
  --b: var(--pen); --bd: var(--pen-dark); --bi: var(--pen-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border: 0; border-radius: 14px;
  background: var(--b); color: var(--bi); font-weight: 800; font-size: 1rem; cursor: pointer;
  box-shadow: 0 4px 0 var(--bd); transform: translateY(0); transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--bd); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-green { --b: var(--leaf-strong); --bd: var(--leaf-dark); --bi: #fff; }
.btn-sun { --b: var(--sun); --bd: var(--sun-dark); --bi: #3D2A00; }
.btn-ghost { --b: var(--surface); --bd: var(--line); --bi: var(--ink); border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line); }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: 0.9rem; border-radius: 12px; }
.btn-icon { width: 44px; min-height: 44px; padding: 0; }
.link-btn { background: none; border: 0; color: var(--pen); font-weight: 700; cursor: pointer; padding: 6px 4px; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 800; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.chip.guided { background: var(--leaf-bg); color: var(--leaf); }
.chip.assisted { background: var(--pen-soft); color: var(--pen); }
.chip.solo { background: var(--violet-bg); color: var(--violet); }
.chip.xp { background: var(--sun-soft); color: var(--sun-ink); }
.chip.boss { background: var(--coral-bg); color: var(--coral); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50;
  background: var(--surface); border-bottom: 2px solid var(--line);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar-in { max-width: 1240px; margin: 0 auto; min-height: 64px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-family: var(--f-display); font-weight: 800; font-size: 1.3rem; flex: none; }
.brand svg { width: 38px; height: 38px; display: block; }
.nav { display: flex; gap: 2px; margin-left: 8px; }
.nav a { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 12px; color: var(--ink-2); text-decoration: none; font-weight: 800; font-size: 0.95rem; position: relative; min-height: 44px; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.is-on { background: var(--pen-soft); color: var(--pen); }
.badge { position: absolute; top: 2px; right: 0; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--coral); color: #fff; font-size: 0.7rem; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--surface); }
.badge.bump { animation: bump 0.5s cubic-bezier(.3, 1.6, .5, 1); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; position: relative; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.xp-chip { display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 6px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); min-height: 44px; }
.xp-chip:hover { border-color: var(--pen); }
.belt-swatch { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; }
.belt-swatch svg { width: 26px; height: 26px; }
.xp-meta { display: grid; gap: 3px; min-width: 92px; }
.xp-meta b { font-size: 0.85rem; line-height: 1; font-variant-numeric: tabular-nums; }
.xp-bar { height: 7px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.xp-bar i { display: block; height: 100%; border-radius: 5px; background: var(--sun); transition: width 0.8s cubic-bezier(.2, .8, .2, 1); }
.streak { display: flex; align-items: center; gap: 3px; font-weight: 800; color: var(--sun-ink); font-variant-numeric: tabular-nums; padding: 0 6px; }
.streak .icon { color: #F08A2C; fill: #FFC53D; stroke: #E06A10; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--pen); color: var(--pen-ink); display: grid; place-items: center; font-weight: 800; font-size: 0.9rem; }
.sync-dot { position: absolute; right: 6px; bottom: 6px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--surface); background: var(--ink-3); }
.sync-dot.is-synced { background: var(--leaf-strong); }
.sync-dot.is-syncing { background: var(--sun); animation: pulse 1s infinite; }
.sync-dot.is-error { background: var(--coral); }

/* bottom nav on phones */
.bottomnav { display: none; }
@media (max-width: 860px) {
  .nav { display: none; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--surface); border-top: 2px solid var(--line);
    padding: 4px max(8px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }
  .bottomnav a { display: grid; justify-items: center; gap: 1px; padding: 6px 0; color: var(--ink-3); text-decoration: none; font-size: 0.7rem; font-weight: 800; position: relative; min-height: 48px; }
  .bottomnav a.is-on { color: var(--pen); }
  .bottomnav .badge { right: calc(50% - 22px); }
  .xp-meta { display: none; }
  .brand span:not(.brand-ic) { display: none; }
  .streak span.lbl { display: none; }
  main.view { padding-bottom: 110px; }
}

/* ---------- layout ---------- */
main.view {
  max-width: 1240px; margin: 0 auto; padding-block: 28px 120px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 24px; min-width: 0;
}
.panel { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-lg); padding: 22px; min-width: 0; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-weight: 700; color: var(--ink-3); font-size: 0.9rem; }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { color: var(--pen); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.enter { animation: rise 0.45s cubic-bezier(.2, .8, .2, 1) both; }

/* ---------- home / map ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
.hero-card { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-lg); padding: 26px; display: grid; gap: 14px; align-content: start; position: relative; overflow: hidden; }
.hero-card h1 { max-width: 18ch; }
.hero-card .lede { color: var(--ink-2); max-width: 52ch; font-size: 1.05rem; }
.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; display: grid; gap: 2px; text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--pen); }
.stat b { font-family: var(--f-display); font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--ink-2); font-size: 0.85rem; font-weight: 700; }
.side-stack { display: grid; gap: 12px; align-content: start; }
.today { background: var(--sun-soft); border: 2px dashed var(--sun-dark); border-radius: var(--r-md); padding: 16px; display: grid; gap: 10px; }
.today b { color: var(--sun-ink); }
@media (max-width: 860px) { .hero { grid-template-columns: minmax(0, 1fr); } }

.path { position: relative; display: grid; gap: 0; padding: 64px 0 40px; }
.path-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: center; min-height: 150px; position: relative; }
.path-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.path-svg path { fill: none; stroke: var(--line); stroke-width: 6; stroke-dasharray: 2 14; stroke-linecap: round; }
.path-svg path.done { stroke: var(--leaf-strong); stroke-dasharray: none; opacity: 0.55; }
.node { grid-row: 1; display: flex; align-items: center; gap: 14px; position: relative; z-index: 1; justify-self: center; text-decoration: none; color: inherit; }
.node.c0 { grid-column: 1; } .node.c1 { grid-column: 2; } .node.c2 { grid-column: 3; }
.node-btn { width: 92px; height: 92px; border-radius: 50%; flex: none; display: grid; place-items: center; position: relative; background: var(--surface); border: 0; cursor: pointer; }
.node-btn .ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.node-btn .ring circle { fill: none; stroke-width: 7; }
.node-btn .ring .bg { stroke: var(--surface-3); }
.node-btn .ring .fg { stroke: var(--leaf-strong); stroke-linecap: round; transition: stroke-dashoffset 1s cubic-bezier(.2, .8, .2, 1); }
.node-face { width: 70px; height: 70px; border-radius: 50%; display: grid; place-items: center; background: var(--pen); color: var(--pen-ink); box-shadow: 0 5px 0 var(--pen-dark); transition: transform 0.15s; }
.node-face .icon { width: 32px; height: 32px; stroke-width: 2.2; }
.node:hover .node-face { transform: translateY(-3px) rotate(-4deg); }
.node.is-done .node-face { background: var(--leaf-strong); color: #fff; box-shadow: 0 5px 0 var(--leaf-dark); }
.node.is-locked .node-face { background: var(--surface-3); color: var(--ink-3); box-shadow: 0 5px 0 var(--line); }
.node.is-current .node-face { animation: glow 2.2s ease-in-out infinite; }
.node-label { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-md); padding: 10px 14px; display: grid; gap: 2px; max-width: 220px; box-shadow: var(--shadow); }
.node-label .eyebrow { font-size: 0.68rem; }
.node-label b { font-family: var(--f-display); font-size: 1.08rem; line-height: 1.2; }
.node-label span { color: var(--ink-2); font-size: 0.85rem; }
.node-num { position: absolute; top: -4px; right: -4px; width: 28px; height: 28px; border-radius: 50%; background: var(--sun); color: #3D2A00; font-weight: 800; font-size: 0.85rem; display: grid; place-items: center; border: 3px solid var(--surface); font-family: var(--f-display); }
.here svg, .empty svg, .modal-art svg { display: block; width: 100%; height: auto; }
.modal-art { width: 170px; }
.here { position: absolute; left: 50%; bottom: calc(100% - 6px); transform: translateX(-50%); width: 58px; animation: hop 1.6s ease-in-out infinite; pointer-events: none; }
@media (max-width: 860px) {
  .path-row { grid-template-columns: minmax(0, 1fr); min-height: 130px; }
  .node.c0, .node.c1, .node.c2 { grid-column: 1; }
  .node.c0 { justify-self: start; } .node.c1 { justify-self: center; } .node.c2 { justify-self: end; }
  .node.c2 { flex-direction: row-reverse; }
  .node-label { max-width: 170px; }
  .node-btn { width: 80px; height: 80px; } .node-face { width: 60px; height: 60px; }
}

/* ---------- level ---------- */
.level-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 18px; align-items: center; }
.level-ic { width: 72px; height: 72px; border-radius: 22px; background: var(--pen); color: var(--pen-ink); display: grid; place-items: center; box-shadow: 0 5px 0 var(--pen-dark); }
.level-ic .icon { width: 36px; height: 36px; }
@media (max-width: 640px) { .level-head { grid-template-columns: auto minmax(0, 1fr); } .level-head > :last-child { grid-column: 1 / -1; } }
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--line); }
.tab { padding: 10px 16px; border: 0; background: none; font-weight: 800; color: var(--ink-3); cursor: pointer; border-bottom: 4px solid transparent; margin-bottom: -2px; min-height: 44px; }
.tab.is-on { color: var(--pen); border-color: var(--pen); }

.lesson { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.sheet {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-lg); padding: 28px 28px 22px 64px; position: relative; min-width: 0;
  background-image: linear-gradient(90deg, transparent 44px, rgba(224, 71, 62, 0.35) 44px, rgba(224, 71, 62, 0.35) 46px, transparent 46px);
}
.sheet::before { content: ""; position: absolute; left: 16px; top: 26px; bottom: 26px; width: 12px; background: radial-gradient(circle, var(--paper) 5px, transparent 6px) 0 0 / 12px 46px repeat-y; }
@media (max-width: 640px) { .sheet { padding: 22px 18px 18px 40px; background-image: linear-gradient(90deg, transparent 26px, rgba(224, 71, 62, 0.35) 26px, rgba(224, 71, 62, 0.35) 28px, transparent 28px); } .sheet::before { left: 6px; } }
.sheet h2 { margin-bottom: 12px; }
.prose { display: grid; gap: 12px; max-width: 68ch; font-size: 1.05rem; }
.prose code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; color: var(--ink); }
.sheet-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-3); transition: background 0.2s, transform 0.2s; }
.dots i.on { background: var(--pen); transform: scale(1.25); }
.dots i.done { background: var(--leaf-strong); }

.codebox { position: relative; border-radius: var(--r-md); border: 2px solid var(--line); background: var(--code-bg); overflow: hidden; min-width: 0; }
.codebox pre { margin: 0; padding: 16px 18px; overflow-x: auto; line-height: 1.65; font-size: 0.9rem; white-space: pre; tab-size: 2; }
.codebox .codebar { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 6px 8px; border-top: 2px solid var(--line); background: var(--surface-2); }
.k-step { color: var(--c-step); font-weight: 700; }
.k-kw { color: var(--c-kw); font-weight: 700; }
.k-sec { color: var(--c-sec); font-weight: 700; }
.k-title { color: var(--ink); font-weight: 600; }
.k-str { color: var(--c-str); }
.k-fuzzy { color: var(--c-fuzzy); font-weight: 600; }
.k-num { color: var(--c-num); }
.k-com { color: var(--c-com); font-style: italic; }
.k-tag { color: var(--c-tag); font-weight: 700; }
.k-var { color: var(--c-var); }
.k-op { color: var(--c-op); font-weight: 700; }
.k-ph { color: var(--c-ph); background: var(--violet-bg); border-radius: 4px; }
.k-name { color: var(--c-name); }
.k-js { color: var(--c-step); font-weight: 600; }
.k-pipe { color: var(--ink-3); }
.k-pun { color: var(--ink-2); }

/* glossary terms */
.term { text-decoration: underline dotted; text-decoration-thickness: 2px; text-underline-offset: 3px; text-decoration-color: var(--pen); cursor: help; }
.term:hover, .term:focus-visible { background: var(--pen-soft); border-radius: 4px; }
.term-code { text-decoration-color: currentColor; text-decoration-thickness: 1px; }

/* ---------- quest list ---------- */
.quests { display: grid; gap: 12px; }
.qcard { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px 16px; border-radius: var(--r-md); border: 2px solid var(--line); background: var(--surface); text-decoration: none; color: inherit; transition: transform 0.12s, border-color 0.12s; }
.qcard:hover { transform: translateX(4px); border-color: var(--pen); }
.qcard .qic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); }
.qcard.is-solved .qic { background: var(--leaf-bg); color: var(--leaf); }
.qcard b { font-family: var(--f-display); font-size: 1.1rem; }
.qcard .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- quest ---------- */
.quest { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 1020px) { .quest { grid-template-columns: minmax(0, 1fr); } }
.quest-main { display: grid; gap: 16px; min-width: 0; }
.quest-side { display: grid; gap: 14px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 84px); }
@media (max-width: 1020px) { .quest-side { position: static; } }
.story {
  background: var(--sun-soft); border: 2px solid var(--sun-dark); border-radius: var(--r-lg); padding: 20px 22px; display: grid; gap: 10px; position: relative;
}
.story p { white-space: pre-line; font-size: 1.05rem; }
.story .eyebrow { color: var(--sun-ink); }
.task { font-weight: 700; font-size: 1.05rem; }
.tip { border-radius: var(--r-md); padding: 14px 16px; background: var(--leaf-bg); color: var(--ink); display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; }
.tip .icon { color: var(--leaf); margin-top: 2px; }
details.peek { border: 2px dashed var(--line); border-radius: var(--r-md); padding: 10px 14px; background: var(--surface); }
details.peek summary { cursor: pointer; font-weight: 800; color: var(--pen); min-height: 28px; }
details.peek pre { margin: 10px 0 0; white-space: pre-wrap; overflow-x: auto; }
.given { display: grid; gap: 6px; }
.given pre { margin: 0; padding: 12px 14px; border-radius: var(--r-md); background: var(--term-bg); color: var(--term-fg); overflow-x: auto; font-size: 0.85rem; line-height: 1.55; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.feedback { border-radius: var(--r-md); padding: 14px 16px; font-weight: 700; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; }
.feedback.bad { background: var(--coral-bg); color: var(--coral); }
.feedback.warn { background: var(--sun-soft); color: var(--sun-ink); }
.feedback .fb-text { white-space: pre-line; }
.success { border: 3px solid var(--leaf-strong); background: var(--surface); border-radius: var(--r-lg); padding: 20px; display: grid; gap: 12px; animation: pop 0.5s cubic-bezier(.2, 1.4, .4, 1); }
.success h3 { color: var(--leaf); font-size: 1.5rem; }
.reward-row { display: flex; gap: 10px; flex-wrap: wrap; }
.reward { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); font-weight: 800; }
.reward.xp { background: var(--sun-soft); color: var(--sun-ink); }
.reward.card { background: var(--violet-bg); color: var(--violet); }

.side-card { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-lg); padding: 16px; display: grid; gap: 12px; }
.potential { display: flex; align-items: baseline; gap: 6px; }
.potential b { font-family: var(--f-display); font-size: 2.2rem; line-height: 1; color: var(--sun-ink); font-variant-numeric: tabular-nums; }
.potential.drop b { animation: drop 0.5s; }
.hint-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; counter-reset: h; }
.hint-list li { counter-increment: h; background: var(--pen-soft); border-radius: 12px; padding: 10px 12px 10px 40px; position: relative; animation: rise 0.35s both; white-space: pre-line; }
.hint-list li::before { content: counter(h); position: absolute; left: 10px; top: 9px; width: 22px; height: 22px; border-radius: 50%; background: var(--pen); color: var(--pen-ink); font-weight: 800; font-size: 0.8rem; display: grid; place-items: center; }
.hint-list li.sol { background: var(--violet-bg); padding-left: 12px; }
.hint-list li.sol::before { display: none; }
.hint-list li.sol pre { margin: 6px 0 0; white-space: pre; overflow-x: auto; font-size: 0.8rem; }
.hint-meter { display: flex; gap: 6px; }
.hint-meter i { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-3); }
.hint-meter i.used { background: var(--pen); }
.hint-meter i.sol { background: var(--violet); }

/* drag & drop */
.drag-code { line-height: 2.5; }
.bank { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px; border: 2px dashed var(--line); border-radius: var(--r-md); min-height: 64px; background: var(--surface); align-items: center; }
.bank.is-over { border-color: var(--pen); background: var(--pen-soft); }
.tok {
  display: inline-flex; align-items: center; min-height: 40px; padding: 4px 12px; border-radius: 10px; border: 2px solid var(--line); border-bottom-width: 4px;
  background: var(--surface); font-family: var(--f-mono); font-size: 0.88rem; font-weight: 600; cursor: grab; touch-action: none; user-select: none; color: var(--ink);
  transition: border-color 0.12s, transform 0.12s, background 0.12s;
}
.tok.prose { font-family: var(--f-body); font-weight: 700; font-size: 0.95rem; }
.tok:hover { border-color: var(--pen); transform: translateY(-2px); }
.tok.is-sel { border-color: var(--pen); background: var(--pen-soft); box-shadow: 0 0 0 3px var(--pen-soft); }
.tok.is-ghost { position: fixed; z-index: 200; pointer-events: none; transform: rotate(-3deg) scale(1.06); box-shadow: var(--shadow-pop); border-color: var(--pen); cursor: grabbing; margin: 0; }
.tok.is-hidden { opacity: 0.25; }
.tok.ok { border-color: var(--leaf-strong); background: var(--leaf-bg); }
.tok.bad { border-color: var(--coral); background: var(--coral-bg); animation: shake 0.4s; }
.slot {
  display: inline-flex; vertical-align: middle; align-items: center; justify-content: center; min-width: 84px; min-height: 40px; margin: 2px 2px; padding: 2px;
  border-radius: 10px; border: 2px dashed var(--pen); background: var(--pen-soft); cursor: pointer; line-height: 1.2;
}
.slot:empty::after { content: "?"; font-family: var(--f-display); font-weight: 800; color: var(--pen); }
.slot.is-over { background: var(--sun-soft); border-color: var(--sun-dark); border-style: solid; }
.slot.filled { border-style: solid; border-color: transparent; background: transparent; min-width: 0; padding: 0; }
.slot .tok { margin: 0; }
.fill-in { font-family: var(--f-mono); font-size: 0.88rem; font-weight: 600; min-height: 36px; border: 2px solid var(--pen); background: var(--pen-soft); border-radius: 9px; padding: 2px 8px; color: var(--ink); vertical-align: middle; }
.fill-in:focus { outline: none; box-shadow: 0 0 0 3px var(--pen-soft); background: var(--surface); }
.fill-in.ok { border-color: var(--leaf-strong); background: var(--leaf-bg); }
.fill-in.bad { border-color: var(--coral); background: var(--coral-bg); animation: shake 0.4s; }

.bins { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.bin { border: 2px dashed var(--line); border-radius: var(--r-md); padding: 12px; display: grid; gap: 10px; align-content: start; min-height: 150px; background: var(--surface); transition: border-color 0.15s, background 0.15s; }
.bin-title { font-family: var(--f-display); font-weight: 800; font-size: 1.05rem; display: flex; gap: 8px; align-items: center; }
.bin-body { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; min-height: 60px; }
.bin.is-over { border-color: var(--pen); background: var(--pen-soft); }
.pairs { display: grid; gap: 10px; }
.pair { display: grid; grid-template-columns: minmax(130px, auto) minmax(0, 1fr); gap: 12px; align-items: center; padding: 8px 12px 8px 8px; border-radius: var(--r-md); border: 2px solid var(--line); background: var(--surface); }
.pair .slot { min-width: 130px; }
@media (max-width: 560px) { .pair { grid-template-columns: minmax(0, 1fr); } }

.order { display: grid; gap: 8px; }
.oline { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 6px 6px 10px; border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 12px; background: var(--surface); touch-action: none; user-select: none; }
.oline .grip { cursor: grab; color: var(--ink-3); width: 28px; display: grid; place-items: center; min-height: 36px; }
.oline code { white-space: pre; overflow-x: auto; font-size: 0.88rem; }
.oline .arrows { display: flex; gap: 2px; }
.oline .arrows button { width: 36px; height: 36px; border: 0; border-radius: 9px; background: var(--surface-2); cursor: pointer; display: grid; place-items: center; color: var(--ink-2); }
.oline .arrows button:hover { background: var(--pen-soft); color: var(--pen); }
.oline.is-drag { opacity: 0.35; }
.oline.ok { border-color: var(--leaf-strong); background: var(--leaf-bg); }
.oline.bad { border-color: var(--coral); }

.choices { display: grid; gap: 10px; }
.choice { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: center; text-align: left; padding: 14px 16px; border: 2px solid var(--line); border-bottom-width: 4px; border-radius: var(--r-md); background: var(--surface); cursor: pointer; transition: border-color 0.12s, transform 0.12s; }
.choice:hover { border-color: var(--pen); transform: translateY(-1px); }
.choice .letter { width: 32px; height: 32px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; font-family: var(--f-display); }
.choice.is-sel { border-color: var(--pen); background: var(--pen-soft); }
.choice.is-sel .letter { background: var(--pen); color: var(--pen-ink); }
.choice.ok { border-color: var(--leaf-strong); background: var(--leaf-bg); }
.choice.bad { border-color: var(--coral); background: var(--coral-bg); animation: shake 0.4s; }
.choice code { white-space: pre-wrap; word-break: break-word; }
.why { font-size: 0.9rem; color: var(--ink-2); grid-column: 2; }

.predict { display: grid; gap: 10px; }
.pitem { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; border: 2px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.pitem code { white-space: pre-wrap; word-break: break-word; font-size: 0.88rem; }
.pitem .seg { display: flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; }
.pitem .seg button { border: 0; background: var(--surface); padding: 0 14px; min-height: 40px; font-weight: 800; cursor: pointer; color: var(--ink-2); }
.pitem .seg button + button { border-left: 2px solid var(--line); }
.pitem .seg button.on.yes { background: var(--leaf-strong); color: #fff; }
.pitem .seg button.on.no { background: var(--coral); color: #fff; }
.pitem.ok { border-color: var(--leaf-strong); }
.pitem.bad { border-color: var(--coral); animation: shake 0.4s; }
.pitem .why { grid-column: 1 / -1; }
@media (max-width: 560px) { .pitem { grid-template-columns: minmax(0, 1fr); } }

/* ---------- editor ---------- */
.editor {
  --min-lines: 10;
  display: grid; grid-template-columns: auto minmax(0, 1fr); border: 2px solid var(--line); border-radius: var(--r-md); background: var(--code-bg); overflow: hidden;
  font-family: var(--f-mono); font-size: 14px; line-height: var(--ed-lh); min-width: 0; transition: border-color 0.15s, box-shadow 0.15s;
}
.editor.is-focus { border-color: var(--pen); box-shadow: 0 0 0 4px var(--pen-soft); }
.ed-gutter { padding: 12px 0; background: var(--surface-2); color: var(--ink-3); text-align: right; user-select: none; overflow: hidden; min-width: 44px; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.ed-gutter div { padding: 0 10px 0 12px; height: var(--ed-lh); }
.ed-gutter div.is-active { color: var(--ink); font-weight: 700; }
.ed-gutter div.is-error { background: var(--coral); color: #fff; font-weight: 800; }
.ed-gutter div.is-ok { background: var(--leaf-strong); color: #fff; }
.ed-body { position: relative; overflow: auto; min-height: calc(var(--min-lines) * var(--ed-lh) + 24px); max-height: 560px; }
.ed-inner { position: relative; min-width: 100%; display: inline-block; vertical-align: top; }
.ed-hl, .ed-input { margin: 0; padding: 12px 16px; font: inherit; line-height: inherit; white-space: pre; tab-size: 2; letter-spacing: 0; border: 0; word-wrap: normal; }
.ed-hl { pointer-events: none; color: var(--ink); min-height: calc(var(--min-lines) * var(--ed-lh) + 24px); }
.ed-input { position: absolute; inset: 0; width: 100%; height: 100%; resize: none; overflow: hidden; background: transparent; color: transparent; caret-color: var(--ink); outline: none; }
.ed-input::selection { background: rgba(47, 98, 217, 0.28); color: transparent; }
.ed-active { position: absolute; left: 0; right: 0; top: 12px; height: var(--ed-lh); background: var(--pen-soft); opacity: 0; transform: translateY(calc(var(--line, 0) * var(--ed-lh))); pointer-events: none; }
.editor.is-focus .ed-active { opacity: 0.6; }
.ed-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kbd { font-family: var(--f-mono); font-size: 0.75rem; padding: 2px 6px; border-radius: 6px; border: 1.5px solid var(--line); border-bottom-width: 3px; background: var(--surface); color: var(--ink-2); }

/* ---------- terminal ---------- */
.terminal { border-radius: var(--r-md); overflow: hidden; background: var(--term-bg); color: var(--term-fg); border: 2px solid #0A0C12; box-shadow: var(--shadow); min-width: 0; }
.term-bar { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 12px; background: var(--term-bar); border-bottom: 1px solid var(--term-line); }
.term-dots { display: flex; gap: 6px; }
.term-dots i { width: 12px; height: 12px; border-radius: 50%; background: #FF5F57; }
.term-dots i:nth-child(2) { background: #FEBC2E; } .term-dots i:nth-child(3) { background: #28C840; }
.term-title { font-family: var(--f-mono); font-size: 0.78rem; color: var(--term-dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-tabs { display: flex; gap: 2px; }
.term-tab { border: 0; background: transparent; color: var(--term-dim); font-family: var(--f-mono); font-size: 0.78rem; padding: 0 10px; min-height: 32px; border-radius: 7px; cursor: pointer; }
.term-tab.is-on { background: var(--term-line); color: var(--term-fg); }
.term-screen { padding: 12px 14px 16px; height: 360px; overflow: auto; font-size: 12.5px; line-height: 1.55; white-space: pre; outline: none; }
.term-screen:focus-visible { box-shadow: inset 0 0 0 2px var(--term-cyan); }
.t-line { min-height: 1.55em; }
.t-idle { color: var(--term-dim); white-space: pre-wrap; }
.t-prompt { color: var(--term-green); font-weight: 700; }
.t-dim, .t-debug { color: var(--term-dim); }
.t-info { color: #B6BED3; }
.t-req .t-arrow { color: var(--term-cyan); }
.t-res .t-arrow { color: var(--term-green); }
.t-resbad .t-arrow, .t-resbad .t-strong { color: var(--term-red); }
.t-res .t-strong { color: var(--term-green); font-weight: 700; }
.t-req .t-strong { color: var(--term-cyan); font-weight: 700; }
.t-hname { color: #9AA3BC; }
.t-body { color: var(--term-fg); }
.t-key { color: var(--term-violet); } .t-str { color: var(--term-green); } .t-num { color: var(--term-yellow); } .t-lit { color: #FF9BD2; }
.t-lvl { font-weight: 700; color: var(--term-cyan); } .t-lvl-error { color: var(--term-red); } .t-lvl-info { color: var(--term-green); }
.t-print { color: var(--term-yellow); font-weight: 700; }
.t-warn { color: var(--term-yellow); }
.t-scenario { color: var(--term-violet); font-weight: 700; margin-top: 4px; }
.t-error, .t-fail { color: var(--term-red); font-weight: 600; white-space: pre-wrap; }
.t-errstep { color: #FFD1D1; background: rgba(255, 90, 90, 0.14); }
.t-pass { color: var(--term-green); font-weight: 700; }
.t-rule { color: #4A536E; }
.t-cursor { display: inline-block; width: 8px; height: 1.1em; background: var(--term-fg); vertical-align: text-bottom; animation: blink 1s steps(1) infinite; margin-left: 2px; }
.term-report { padding: 14px; height: 360px; overflow: auto; display: grid; gap: 10px; align-content: start; font-size: 0.9rem; }
.rep-head { font-family: var(--f-display); font-weight: 800; font-size: 1.15rem; }
.rep-head.is-pass { color: var(--term-green); } .rep-head.is-fail { color: var(--term-red); }
.rep-sc { border: 1px solid var(--term-line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 4px; background: #151925; }
.rep-sc-title { font-weight: 800; }
.rep-pill { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 8px; border-radius: 99px; background: var(--term-line); }
.rep-sc.is-passed .rep-pill { background: #1E4D35; color: var(--term-green); }
.rep-sc.is-failed .rep-pill { background: #5A2329; color: var(--term-red); }
.rep-step { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: baseline; }
.rep-step code { white-space: pre-wrap; word-break: break-word; font-size: 0.82rem; }
.rep-step.is-passed .rep-ic { color: var(--term-green); } .rep-step.is-failed .rep-ic { color: var(--term-red); } .rep-step.is-skipped { color: var(--term-dim); }
.rep-ln { color: var(--term-dim); font-size: 0.75rem; }
.rep-err { margin: 2px 0 4px 26px; color: var(--term-red); white-space: pre-wrap; font-size: 0.8rem; }

/* ---------- playground ---------- */
.play { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
@media (max-width: 1020px) { .play { grid-template-columns: minmax(0, 1fr); } }
.files { display: flex; gap: 4px; flex-wrap: wrap; }
.file-tab { border: 2px solid var(--line); background: var(--surface); border-radius: 10px; padding: 0 10px; min-height: 36px; font-family: var(--f-mono); font-size: 0.8rem; cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.file-tab.is-on { border-color: var(--pen); color: var(--pen); background: var(--pen-soft); }
.api-list { display: grid; gap: 8px; }
.api-row { display: grid; gap: 4px; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.api-row code { font-size: 0.82rem; font-weight: 700; }
.api-row p { font-size: 0.85rem; color: var(--ink-2); }
.verb { display: inline-block; min-width: 54px; text-align: center; border-radius: 6px; padding: 1px 6px; margin-right: 6px; font-size: 0.72rem; color: #fff; font-family: var(--f-mono); font-weight: 800; }
.verb.GET { background: #1F7A4C; } .verb.POST { background: #2456C8; } .verb.PUT { background: #9A5B00; } .verb.PATCH { background: #6343CC; } .verb.DELETE { background: #B5303A; }
.snips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- glossary ---------- */
.gloss-top { display: grid; gap: 12px; }
.search-field { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 0 14px; min-height: 50px; }
.search-field:focus-within { border-color: var(--pen); box-shadow: 0 0 0 4px var(--pen-soft); }
.search-field input { border: 0; outline: none; background: transparent; flex: 1; font: inherit; font-size: 1.05rem; color: var(--ink); min-width: 0; min-height: 46px; }
.cats { display: flex; flex-wrap: wrap; gap: 6px; }
.cat { border: 2px solid var(--line); background: var(--surface); border-radius: 999px; padding: 0 12px; min-height: 36px; font-weight: 800; font-size: 0.85rem; cursor: pointer; color: var(--ink-2); }
.cat.is-on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.gloss { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.gcard { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; display: grid; gap: 8px; align-content: start; scroll-margin-top: 100px; min-width: 0; }
.gcard.flash { animation: flash 1.6s; }
.gcard h3 { font-family: var(--f-mono); font-size: 1rem; font-weight: 700; color: var(--pen); }
.gcard p { font-size: 0.95rem; }
.gcard pre { margin: 0; padding: 8px 10px; background: var(--code-bg); border: 1.5px solid var(--line); border-radius: 10px; overflow-x: auto; font-size: 0.8rem; line-height: 1.55; }
.gcard .row { gap: 4px; }
.star { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--ink-3); }
.star:hover { background: var(--surface-2); }
.star.on { color: var(--sun-dark); }
.star.on .icon { fill: var(--sun); }
.star.pop { animation: bump 0.5s cubic-bezier(.3, 1.6, .5, 1); }

/* ---------- tooltip popover ---------- */
.pop {
  position: fixed; z-index: 150; width: min(340px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); border: 2px solid var(--ink);
  border-radius: 16px; box-shadow: var(--shadow-pop); padding: 14px 16px 12px; display: grid; gap: 8px; animation: popin 0.16s ease-out;
}
.pop h4 { font-family: var(--f-mono); font-size: 1rem; color: var(--pen); }
.pop p { font-size: 0.92rem; }
.pop pre { margin: 0; padding: 8px 10px; background: var(--code-bg); border-radius: 10px; border: 1.5px solid var(--line); overflow-x: auto; font-size: 0.78rem; line-height: 1.5; }
.pop .row { gap: 4px; }
.pop a.ext { font-weight: 800; font-size: 0.85rem; display: inline-flex; gap: 4px; align-items: center; min-height: 36px; }

/* ---------- flashcards ---------- */
.boxes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .boxes { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 420px) { .boxes { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.box { border: 2px solid var(--line); background: var(--surface); border-radius: var(--r-md); padding: 14px 12px 12px; display: grid; gap: 6px; justify-items: center; text-align: center; cursor: pointer; position: relative; min-height: 150px; align-content: end; transition: transform 0.15s, border-color 0.15s; }
.box:hover { transform: translateY(-3px); border-color: var(--pen); }
.box.is-on { border-color: var(--pen); box-shadow: 0 0 0 4px var(--pen-soft); }
.stack { position: relative; width: 64px; height: 50px; margin-bottom: 4px; }
.stack i { position: absolute; inset: 0; border-radius: 8px; background: var(--surface); border: 2px solid var(--ink-3); }
.stack i:nth-child(1) { transform: translate(-6px, 6px) rotate(-6deg); }
.stack i:nth-child(2) { transform: translate(3px, 3px) rotate(4deg); }
.stack i:nth-child(3) { background: var(--violet-bg); border-color: var(--violet); }
.stack.empty i { opacity: 0.3; }
.box b { font-family: var(--f-display); font-size: 1.6rem; line-height: 1; font-variant-numeric: tabular-nums; }
.box .lbl { font-weight: 800; font-size: 0.9rem; }
.box .due { font-size: 0.75rem; font-weight: 800; color: var(--coral); }
.box .due.none { color: var(--ink-3); }
.box.glow { animation: glowbox 1.4s; }
.review { display: grid; gap: 16px; justify-items: center; }
.flip { width: min(560px, 100%); aspect-ratio: 16 / 10; perspective: 1400px; cursor: pointer; border: 0; background: none; padding: 0; max-width: 100%; }
.flip-in { position: relative; width: 100%; height: 100%; transition: transform 0.6s cubic-bezier(.3, 1.3, .5, 1); transform-style: preserve-3d; }
.flip.is-flipped .flip-in { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: var(--r-lg); border: 3px solid var(--ink); background: var(--surface); padding: 24px; display: grid; align-content: center; gap: 12px; text-align: left; box-shadow: 0 8px 0 var(--ink); overflow: auto; }
.face.back { transform: rotateY(180deg); background: var(--violet-bg); }
.face .eyebrow { position: absolute; top: 14px; left: 20px; }
.face p { font-size: 1.15rem; font-weight: 700; font-family: var(--f-display); }
.face pre { margin: 0; white-space: pre-wrap; font-size: 0.85rem; line-height: 1.55; }
.card-list { display: grid; gap: 8px; }
.card-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); align-items: center; }
.card-row .new { background: var(--sun); color: #3D2A00; border-radius: 6px; font-size: 0.7rem; font-weight: 800; padding: 1px 6px; margin-left: 6px; }

/* ---------- notes & bookmarks ---------- */
.notes { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.note { background: #FFF8D6; color: #2A2A1E; border-radius: 6px 6px 18px 6px; padding: 16px; display: grid; gap: 8px; box-shadow: 0 10px 20px -14px rgba(0, 0, 0, 0.5); transform: rotate(-0.6deg); align-content: start; min-width: 0; }
.note:nth-child(2n) { transform: rotate(0.7deg); background: #E8F6EE; }
.note:nth-child(3n) { background: #E9EFFF; transform: rotate(-0.2deg); }
.note h3 { font-size: 1.05rem; }
.note p { white-space: pre-wrap; font-size: 0.95rem; word-break: break-word; }
.note a { color: #1F47A8; font-weight: 800; font-size: 0.85rem; }
.note .row button { color: #2A2A1E; }
.note-form { display: grid; gap: 10px; }
.input, textarea.input { width: 100%; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; background: var(--surface); color: var(--ink); min-height: 46px; }
textarea.input { min-height: 120px; resize: vertical; }
.input:focus { outline: none; border-color: var(--pen); box-shadow: 0 0 0 4px var(--pen-soft); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 120; width: min(420px, 100vw); background: var(--surface); border-left: 2px solid var(--line); box-shadow: var(--shadow-pop);
  padding: calc(18px + env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) 18px; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 14px; animation: slidein 0.25s cubic-bezier(.2, .8, .2, 1);
}
.drawer-body { overflow: auto; display: grid; gap: 12px; align-content: start; }
.mini-note { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: grid; gap: 4px; }
.mini-note p { white-space: pre-wrap; font-size: 0.92rem; }
.marks { display: grid; gap: 18px; }
.mark-group { display: grid; gap: 8px; }
.mark-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); }
.mark-row a { font-weight: 800; text-decoration: none; color: var(--ink); }
.mark-row a:hover { color: var(--pen); }
.empty { text-align: center; padding: 30px 16px; display: grid; gap: 10px; justify-items: center; color: var(--ink-2); border: 2px dashed var(--line); border-radius: var(--r-lg); background: var(--surface); }
.empty svg { width: 90px; }

/* ---------- profile ---------- */
.profile { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .profile { grid-template-columns: minmax(0, 1fr); } }
.belt-big { display: grid; justify-items: center; gap: 8px; text-align: center; }
.belt-big svg { width: 200px; }
.belt-ladder { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.belt-ladder i { width: 26px; height: 10px; border-radius: 3px; border: 1.5px solid rgba(0, 0, 0, 0.25); }
.belt-ladder i.off { opacity: 0.25; }
.achs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.ach { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; padding: 12px; border-radius: var(--r-md); border: 2px solid var(--line); background: var(--surface); }
.ach .medal { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-3); }
.ach.on .medal { background: var(--sun); color: #3D2A00; box-shadow: 0 3px 0 var(--sun-dark); }
.ach b { font-size: 0.95rem; } .ach p { font-size: 0.8rem; color: var(--ink-2); }
.ach:not(.on) { opacity: 0.75; }
.settings { display: grid; gap: 10px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); min-height: 52px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; position: absolute; inset: 0; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-3); border: 2px solid var(--line); transition: background 0.2s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s cubic-bezier(.3, 1.5, .5, 1); }
.switch input:checked + span { background: var(--leaf-strong); border-color: var(--leaf-strong); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 3px solid var(--pen); outline-offset: 2px; }
.seg-ctl { display: flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg-ctl button { border: 0; background: var(--surface); padding: 0 12px; min-height: 38px; font-weight: 800; cursor: pointer; color: var(--ink-2); font-size: 0.85rem; }
.seg-ctl button.on { background: var(--ink); color: var(--surface); }

/* ---------- mascot ---------- */
.mascot { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 90; display: flex; align-items: flex-end; gap: 8px; pointer-events: none; }
.mascot > * { pointer-events: auto; }
.mascot-btn { width: 112px; height: 128px; border: 0; background: none; padding: 0; cursor: pointer; filter: drop-shadow(0 8px 10px rgba(20, 24, 40, 0.25)); }
.mascot-btn svg { width: 100%; height: 100%; overflow: visible; }
.bubble { max-width: min(330px, calc(100vw - 160px)); background: var(--surface); border: 2px solid var(--ink); border-radius: 18px 18px 4px 18px; padding: 12px 14px; box-shadow: 0 6px 0 var(--ink); font-weight: 700; font-size: 0.95rem; position: relative; margin-bottom: 70px; animation: popin 0.25s cubic-bezier(.2, 1.5, .4, 1); }
.bubble .who { display: block; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--headband); font-weight: 800; margin-bottom: 2px; }
.bubble-x { position: absolute; top: -12px; right: -12px; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); background: var(--surface); cursor: pointer; display: grid; place-items: center; font-weight: 800; line-height: 1; }
.mascot.is-mini .mascot-btn { width: 66px; height: 76px; }
.mascot.is-mini .bubble { margin-bottom: 40px; }
@media (max-width: 860px) {
  .mascot { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .mascot-btn { width: 72px; height: 84px; }
  .bubble { margin-bottom: 44px; font-size: 0.88rem; max-width: calc(100vw - 120px); }
}

/* panda */
.panda .p-head { transform-box: view-box; transform-origin: 60px 88px; animation: bob 3.4s ease-in-out infinite; }
.panda .p-eyes { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.panda .p-tail1 { transform-box: view-box; transform-origin: 98px 40px; animation: flutter 1.4s ease-in-out infinite; }
.panda .p-tail2 { transform-box: view-box; transform-origin: 98px 42px; animation: flutter 1.7s ease-in-out infinite reverse; }
.panda .p-arm-l { transform-box: view-box; transform-origin: 34px 92px; transition: transform 0.35s cubic-bezier(.3, 1.6, .5, 1); }
.panda .p-arm-r { transform-box: view-box; transform-origin: 86px 92px; transition: transform 0.35s cubic-bezier(.3, 1.6, .5, 1); }
.panda .p-happy, .panda .p-m-open, .panda .p-m-oops, .panda .p-think, .panda .p-spark, .panda .p-sweat { display: none; }
.panda.mood-happy .p-eyes, .panda.mood-cheer .p-eyes { display: none; }
.panda.mood-happy .p-happy, .panda.mood-cheer .p-happy { display: inline; }
.panda.mood-happy .p-m-idle, .panda.mood-cheer .p-m-idle { display: none; }
.panda.mood-happy .p-m-open, .panda.mood-cheer .p-m-open { display: inline; }
.panda.mood-cheer { animation: jump 0.7s cubic-bezier(.3, 1.4, .5, 1) 2; }
.panda.mood-cheer .p-arm-l { transform: rotate(130deg); }
.panda.mood-cheer .p-arm-r { transform: rotate(-130deg); }
.panda.mood-cheer .p-spark { display: inline; animation: sparkle 0.9s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.panda.mood-think .p-think { display: inline; animation: floaty 2s ease-in-out infinite; }
.panda.mood-think .p-head { animation: tilt 2.4s ease-in-out infinite; }
.panda.mood-think .p-arm-r { transform: rotate(-110deg); }
.panda.mood-oops .p-m-idle { display: none; }
.panda.mood-oops .p-m-oops { display: inline; }
.panda.mood-oops .p-sweat { display: inline; animation: drip 1.2s ease-in infinite; }
.panda.mood-oops .p-head { animation: nope 0.5s ease-in-out 2; }
.panda.mood-wave .p-arm-r { animation: wave 0.5s ease-in-out 4 alternate; }

/* ---------- toasts, modal, search, confetti ---------- */
.toasts { position: fixed; top: calc(76px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 160; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: min(420px, calc(100vw - 32px)); }
.toast { pointer-events: auto; background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 14px; font-weight: 800; box-shadow: var(--shadow-pop); display: flex; gap: 10px; align-items: center; animation: toastin 0.35s cubic-bezier(.2, 1.4, .4, 1); }
.toast.ach { background: var(--sun); color: #3D2A00; }
.toast.out { animation: toastout 0.3s forwards; }
.scrim { position: fixed; inset: 0; z-index: 170; background: rgba(14, 18, 32, 0.55); display: grid; place-items: center; padding: 16px; animation: fade 0.2s; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border: 3px solid var(--ink); border-radius: 26px; box-shadow: 0 10px 0 var(--ink); max-width: 460px; width: 100%; padding: 26px; display: grid; gap: 14px; justify-items: center; text-align: center; animation: pop 0.45s cubic-bezier(.2, 1.4, .4, 1); max-height: calc(100vh - 40px); overflow: auto; }
.modal svg.big { width: 170px; }
.modal h2 { font-size: 1.8rem; }
.search-modal { align-items: start; padding-top: 10vh; }
.search-box { width: min(640px, 100%); background: var(--surface); border-radius: 20px; border: 2px solid var(--line); box-shadow: var(--shadow-pop); overflow: hidden; display: grid; max-height: 75vh; grid-template-rows: auto minmax(0, 1fr); }
.search-box .search-field { border: 0; border-bottom: 2px solid var(--line); border-radius: 0; }
.results { overflow: auto; padding: 8px; display: grid; gap: 2px; align-content: start; }
.res { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: center; padding: 10px; border-radius: 12px; text-decoration: none; color: var(--ink); border: 0; background: none; text-align: left; cursor: pointer; width: 100%; }
.res:hover, .res.is-on { background: var(--pen-soft); }
.res .kind { font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); min-width: 70px; text-align: center; }
.res b { display: block; }
.res span.sub { color: var(--ink-2); font-size: 0.85rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 180; overflow: hidden; }
.confetti i { position: absolute; width: 10px; height: 14px; border-radius: 2px; }
.xp-fly { position: fixed; z-index: 181; font-family: var(--f-display); font-weight: 800; font-size: 1.5rem; color: var(--sun-ink); background: var(--sun); padding: 2px 12px; border-radius: 12px; box-shadow: 0 4px 0 var(--sun-dark); pointer-events: none; }
.card-fly { position: fixed; z-index: 181; width: 60px; height: 42px; border-radius: 8px; background: var(--violet-bg); border: 2px solid var(--violet); pointer-events: none; }

/* ---------- keyframes ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(0.85); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes popin { from { transform: translateY(6px) scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.45); } 100% { transform: scale(1); } }
@keyframes pulse { 50% { opacity: 0.4; } }
@keyframes glow { 0%, 100% { box-shadow: 0 5px 0 var(--pen-dark), 0 0 0 0 rgba(47, 98, 217, 0.45); } 50% { box-shadow: 0 5px 0 var(--pen-dark), 0 0 0 14px rgba(47, 98, 217, 0); } }
@keyframes glowbox { 0%, 100% { box-shadow: 0 0 0 0 rgba(99, 67, 204, 0); } 30% { box-shadow: 0 0 0 8px rgba(99, 67, 204, 0.35); transform: scale(1.04); } }
@keyframes flash { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 20%, 60% { box-shadow: 0 0 0 5px var(--sun); } }
@keyframes hop { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -8px); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(2.5px); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes flutter { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(14deg); } }
@keyframes jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-16px); } }
@keyframes tilt { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(-2deg); } }
@keyframes nope { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-7deg); } 75% { transform: rotate(7deg); } }
@keyframes wave { from { transform: rotate(-120deg); } to { transform: rotate(-150deg); } }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes sparkle { 0% { transform: scale(0.4); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }
@keyframes drip { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(8px); opacity: 0; } }
@keyframes blink-c { 50% { opacity: 0; } }
@keyframes toastin { from { transform: translateY(-16px) scale(0.9); opacity: 0; } }
@keyframes toastout { to { transform: translateY(-10px); opacity: 0; } }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } }
@keyframes drop { 0% { transform: translateY(-6px); color: var(--coral); } 100% { transform: none; } }
.t-cursor { animation-name: blink-c; }

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