/* Bucket Academy — design system, matched to bucket.foundation.
   Classical/editorial: bone parchment ground, basalt ink, aegean + gold + laurel
   accents, hairline rules, Fraunces serif body + Cinzel display caps.
   8-pt grid, ≥44px targets, 200-500ms motion, reduced-motion honored.
   UX structure (route loop, 3-depth atom, drills, nucleus map) preserved. */
:root {
  /* ground + ink */
  --bg:         #EFE8D4; /* bone */
  --bg-2:       #E8E0CB;
  --card:       #F5F0E1; /* raised parchment */
  --card-2:     #EDE6D3;
  --ink:        #1F1C16; /* basalt */
  --ink-dim:    #4A4238; /* parchment-dim */
  --ink-faint:  #6F6A5E; /* stone-300 */
  /* rules */
  --line:       rgba(31, 28, 22, 0.14);
  --line-strong:rgba(31, 28, 22, 0.26);
  /* accents */
  --aegean:     #2E6B6B;
  --aegean-deep:#1F4F4F;
  --gold:       #B8861E;
  --gold-deep:  #8A641A;
  --laurel:     #5A7A3A;
  --laurel-deep:#3E5A2A;
  /* shells */
  --prereq:     #2E6B6B; /* aegean  */
  --nucleus:    #8A641A; /* gold    */
  --frontier:   #5A7A3A; /* laurel  */
  --amber:      #8A641A;
  --radius: 12px;
  --shadow: 0 1px 0 rgba(255,255,255,0.5) inset, 0 8px 24px -16px rgba(31,28,22,0.45);
  --serif: "Fraunces", "Söhne", Georgia, "Times New Roman", serif;
  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--serif); }
body { line-height: 1.55; -webkit-font-smoothing: antialiased; font-optical-sizing: auto; }
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; padding-bottom: 96px; }
.screen { padding: 0 20px; animation: rise .34s cubic-bezier(.2,.7,.2,1); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, .screen { animation: none !important; transition: none !important; } }

/* ---- topbar ---- */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 22px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.brand { font-family: var(--display); font-weight: 600; letter-spacing: .06em; font-size: 17px; text-transform: uppercase; }
.brand span { color: var(--aegean); }
.branch-pill { font-family: var(--display); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-dim); background: var(--card); border: 1px solid var(--line); padding: 7px 12px; border-radius: 999px; cursor: pointer; min-height: 36px; display: inline-flex; align-items: center; gap: 6px; }
.branch-pill:hover { border-color: var(--line-strong); color: var(--aegean-deep); }
.branch-caret { opacity: .6; font-size: 9px; }

/* branch picker sheet */
.sheet-back { position: fixed; inset: 0; background: rgba(31,28,22,.32); display: flex; align-items: flex-end; justify-content: center; z-index: 60; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet { width: 100%; max-width: 720px; background: var(--bg); border-top-left-radius: 18px; border-top-right-radius: 18px; border: 1px solid var(--line); padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -16px 48px -20px rgba(31,28,22,.5); animation: rise .26s ease; }
.sheet-title { font-family: var(--display); text-transform: uppercase; letter-spacing: .1em; font-size: 12px; color: var(--ink-faint); margin: 2px 4px 12px; }
.branch-row { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; margin-bottom: 8px; cursor: pointer; font: inherit; color: var(--ink); }
.branch-row:hover { background: var(--card-2); }
.branch-row.on { border-color: var(--aegean); box-shadow: inset 0 0 0 1px var(--aegean); }
.branch-row-name { font-family: var(--display); text-transform: uppercase; letter-spacing: .06em; font-size: 13px; }
.branch-row-sub { font-size: 13px; color: var(--ink-faint); }

/* ---- hero ---- */
.hero { padding: 20px 0 8px; }
.kicker { font-family: var(--display); text-transform: uppercase; letter-spacing: .16em; font-size: 11px; color: var(--gold-deep); }
.hero h1 { font-family: var(--serif); font-weight: 500; font-size: 36px; letter-spacing: -.01em; margin: 8px 0 8px; line-height: 1.1; }
.sub { color: var(--ink-dim); margin: 0 0 18px; font-size: 16px; }

.btn { appearance: none; border: 1px solid var(--line-strong); background: var(--card); color: var(--ink); font-family: var(--display); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; padding: 14px 22px; border-radius: 10px; cursor: pointer; min-height: 48px; transition: transform .12s ease, background .2s, border-color .2s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--laurel-deep); color: var(--bg); border-color: transparent; }
.btn.primary:hover { background: var(--aegean-deep); }
.btn.wide { width: 100%; margin-top: 12px; }
.btn.ghost { background: transparent; }
.btn.danger { color: #8a2f24; border-color: rgba(138,47,36,.4); }
.ghost { background: none; border: none; color: var(--ink-dim); font: inherit; cursor: pointer; padding: 8px 0; }
button.hidden, .hidden { display: none !important; }

/* ---- stats ---- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0 24px; }
.stats.big { grid-template-columns: repeat(2, 1fr); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 10px; text-align: center; }
.sicon { font-size: 16px; color: var(--gold-deep); }
.sval { font-family: var(--display); font-size: 22px; font-weight: 600; letter-spacing: .01em; }
.slabel { font-size: 11px; color: var(--ink-faint); letter-spacing: .02em; }

.section-label { font-family: var(--display); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; color: var(--ink-faint); margin: 20px 0 10px; }
.route-list, .mastery-list { display: flex; flex-direction: column; gap: 8px; }
.route-row, .mrow { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 14px; cursor: pointer; transition: background .18s, transform .12s, border-color .18s; }
.route-row:active, .mrow:active { transform: scale(.99); }
.route-row:hover, .mrow:hover { background: var(--card-2); border-color: var(--line-strong); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.shell-dot-prereq { background: var(--prereq); } .shell-dot-nucleus { background: var(--nucleus); } .shell-dot-frontier { background: var(--frontier); }
.rtitle, .mt { flex: 1; font-weight: 500; }
.rtag { font-family: var(--display); text-transform: uppercase; font-size: 10px; letter-spacing: .08em; padding: 4px 9px; border-radius: 999px; color: var(--ink-faint); border: 1px solid var(--line); }
.rtag.new { color: var(--bg); background: var(--gold-deep); border: none; }
.mbar { width: 84px; height: 5px; background: var(--line); border-radius: 4px; overflow: hidden; }
.mbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--laurel-deep), var(--gold)); }

/* ---- tabbar ---- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); background: rgba(239,232,212,.9); backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tabbar-4 { grid-template-columns: repeat(4, 1fr); }
.hero-study { width: 100%; margin-top: 10px; }

/* ---- study / read mode ---- */
.study-h1 { font-family: var(--serif); font-weight: 500; font-size: 30px; letter-spacing: -.01em; margin: 16px 0 4px; }
.study-sub { color: var(--ink-dim); font-size: 15px; margin: 0 0 14px; }
.study-depth { position: sticky; top: 64px; z-index: 5; }
.study-section { font-family: var(--display); text-transform: uppercase; letter-spacing: .14em; font-size: 12px; color: var(--gold-deep); margin: 26px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.study-block { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: 12px; padding: 16px 18px; margin-bottom: 12px; }
.study-block.shell-edge-prereq { border-left-color: var(--prereq); }
.study-block.shell-edge-nucleus { border-left-color: var(--nucleus); }
.study-block.shell-edge-frontier { border-left-color: var(--frontier); }
.sb-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.sb-num { font-family: var(--mono); font-size: 12px; color: var(--ink-faint); flex: none; }
.sb-title { font-family: var(--serif); font-weight: 600; font-size: 19px; flex: 1; }
.sb-ipa { font-family: var(--mono); font-size: 13px; color: var(--gold-deep); }
.sb-gloss { color: var(--ink-faint); font-size: 14px; }
.sb-mastery { font-family: var(--display); text-transform: uppercase; font-size: 9px; letter-spacing: .08em; color: var(--ink-faint); border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px; }
.sb-mastery.on { color: var(--laurel-deep); border-color: var(--laurel); }
.sb-text { font-size: 16.5px; line-height: 1.62; color: var(--ink); margin: 4px 0 10px; }
.sb-note { font-size: 14px; color: var(--ink-dim); font-style: italic; margin: 8px 0 0; }
.sb-more { margin-top: 10px; }
.sb-more summary { font-family: var(--display); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; color: var(--ink-faint); cursor: pointer; padding: 4px 0; }
.sb-more[open] summary { color: var(--aegean-deep); margin-bottom: 8px; }
.sb-drill { margin-top: 12px; background: none; border: none; color: var(--aegean-deep); font-family: var(--display); text-transform: uppercase; letter-spacing: .06em; font-size: 11px; cursor: pointer; padding: 6px 0 0; }
.lang-study .sb-head { align-items: baseline; }
.tab { background: none; border: none; color: var(--ink-faint); font-family: var(--display); text-transform: uppercase; letter-spacing: .08em; font-size: 10px; padding: 12px 0 calc(14px + env(safe-area-inset-bottom)); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tab span { font-size: 17px; }
.tab.on { color: var(--aegean-deep); }

/* ---- art / concept card ---- */
.art { border-radius: var(--radius); padding: 26px 22px 18px; margin: 16px 0 6px; position: relative; overflow: hidden; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); min-height: 156px; display: flex; flex-direction: column; justify-content: center; }
.art::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.art.shell-prereq::before { background: var(--prereq); } .art.shell-nucleus::before { background: var(--nucleus); } .art.shell-frontier::before { background: var(--frontier); }
.art-badge { position: absolute; top: 14px; right: 14px; font-family: var(--display); text-transform: uppercase; font-size: 10px; letter-spacing: .1em; color: var(--ink-faint); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; background: var(--bg); }
.art-eq { font-size: 22px; color: var(--ink); overflow-x: auto; }
.art-title { margin-top: 12px; font-family: var(--display); text-transform: uppercase; letter-spacing: .04em; color: var(--ink-dim); font-size: 12px; }

.atom-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 0 0; }
.prog { color: var(--ink-faint); font-size: 13px; font-family: var(--mono); }
.atom-body h2 { font-family: var(--serif); font-weight: 500; font-size: 27px; letter-spacing: -.01em; margin: 18px 0 12px; }
.depth-tabs { display: inline-flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-bottom: 14px; }
.depth-tabs button { background: none; border: none; color: var(--ink-dim); font-family: var(--display); text-transform: uppercase; letter-spacing: .06em; font-size: 11px; padding: 8px 14px; border-radius: 7px; cursor: pointer; }
.depth-tabs button.on { background: var(--aegean-deep); color: var(--bg); }
.depth-content p { color: var(--ink); margin: 0 0 10px; font-size: 16.5px; line-height: 1.6; }
.depth-content .note { color: var(--ink-dim); font-size: 14px; }
.eqbox { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 8px 0; overflow-x: auto; }
.cite { font-size: 12px; color: var(--ink-faint); margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; font-style: italic; }

.drill { margin-top: 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.drill-label { font-family: var(--display); text-transform: uppercase; letter-spacing: .1em; font-size: 11px; color: var(--aegean); }
.q { font-size: 18px; font-weight: 500; margin: 8px 0 4px; }
.q-eq { overflow-x: auto; }
.answer { margin-top: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px; animation: rise .26s ease; }
.a-label { font-family: var(--display); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-faint); }
.a-text { margin-top: 4px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.rbtn { border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink); font-family: var(--display); text-transform: uppercase; letter-spacing: .05em; font-size: 11px; padding: 13px 0; border-radius: 10px; cursor: pointer; min-height: 48px; }
.rbtn.again { color: var(--gold-deep); border-color: rgba(138,100,26,.4); } /* amber, never red */
.rbtn.good { color: var(--laurel-deep); }
.rbtn.easy { color: var(--aegean-deep); }
.rbtn:active { transform: scale(.96); }
.unlocks { margin-top: 16px; color: var(--ink-dim); font-size: 14px; background: var(--card); border: 1px dashed var(--line-strong); border-radius: 10px; padding: 12px 14px; }

.celebrate { text-align: center; padding: 60px 12px; }
.celebrate .big { font-size: 50px; color: var(--gold); animation: pop .5s cubic-bezier(.2,1.4,.3,1); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.celebrate h1 { font-family: var(--serif); font-weight: 500; font-size: 30px; letter-spacing: -.01em; }

.map-help { color: var(--ink-dim); font-size: 14px; margin: 16px 2px; }
.ph { font-family: var(--serif); font-weight: 500; font-size: 28px; color: var(--ink); letter-spacing: -.01em; margin: 14px 2px; }
.graph-holder { display: flex; justify-content: center; }
.graph { width: 100%; height: auto; }
.edge { stroke: var(--line-strong); stroke-width: 1; opacity: .55; }
.node-base { fill: var(--card); stroke: var(--line-strong); stroke-width: 1.5; }
.node.shell-prereq .node-base { stroke: var(--prereq); } .node.shell-nucleus .node-base { stroke: var(--nucleus); } .node.shell-frontier .node-base { stroke: var(--frontier); }
.node.shell-prereq .node-fill { fill: var(--prereq); } .node.shell-nucleus .node-fill { fill: var(--nucleus); } .node.shell-frontier .node-fill { fill: var(--frontier); }
.node { cursor: pointer; } .node:hover .node-base { stroke-width: 2.5; }
.node:not(.seen) { opacity: .5; }

.bar-row { display: flex; align-items: center; gap: 12px; margin: 9px 0; }
.bar-label { width: 100px; font-family: var(--display); text-transform: uppercase; font-size: 11px; letter-spacing: .06em; color: var(--ink-dim); }
.bar { flex: 1; height: 9px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 6px; }
.shell-bar-prereq { background: var(--prereq); } .shell-bar-nucleus { background: var(--nucleus); } .shell-bar-frontier { background: var(--frontier); }
.bar-pct { width: 40px; text-align: right; font-size: 13px; color: var(--ink-dim); font-family: var(--mono); }

.settings { margin: 24px 0; }
.set-row { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 13px 16px; margin-bottom: 8px; }
.set-row input[type=number] { width: 64px; background: var(--bg); border: 1px solid var(--line-strong); color: var(--ink); border-radius: 8px; padding: 7px; font: inherit; text-align: center; }
code { background: var(--card); padding: 2px 6px; border-radius: 6px; font-family: var(--mono); font-size: .9em; }

/* KaTeX inherits ink color on the parchment ground */
.katex { color: var(--ink); }

/* ---- optional sign-in (bkt-su9): topbar pill + email-OTP modal ---- */
.auth-pill { font-family: var(--display); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-dim); background: var(--card); border: 1px solid var(--line); padding: 7px 12px; border-radius: 999px; cursor: pointer; min-height: 36px; display: inline-flex; align-items: center; gap: 7px; margin-left: 8px; }
.auth-pill:hover { border-color: var(--line-strong); color: var(--aegean-deep); }
.auth-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); box-shadow: inset 0 0 0 1px rgba(31,28,22,.2); }
.auth-dot.on { background: var(--laurel); box-shadow: 0 0 0 2px rgba(90,122,58,.22); }
.auth-dot.syncing { background: var(--gold); animation: auth-pulse 1s ease-in-out infinite; }
@keyframes auth-pulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

.auth-back { position: fixed; inset: 0; background: rgba(31,28,22,.36); display: flex; align-items: center; justify-content: center; z-index: 70; padding: 18px; animation: fade .2s ease; }
.auth-card { width: 100%; max-width: 400px; background: var(--bg); border: 1px solid var(--line); border-radius: 18px; padding: 24px 22px calc(20px + env(safe-area-inset-bottom)); box-shadow: 0 24px 64px -24px rgba(31,28,22,.6); animation: rise .26s ease; }
.auth-title { font-family: var(--display); text-transform: uppercase; letter-spacing: .08em; font-size: 16px; color: var(--ink); margin-bottom: 8px; }
.auth-sub { font-size: 14px; line-height: 1.5; color: var(--ink-dim); margin: 0 0 16px; }
.auth-sub b { color: var(--ink); font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-input { width: 100%; background: var(--card); border: 1px solid var(--line-strong); color: var(--ink); border-radius: 10px; padding: 13px 14px; font: inherit; font-size: 16px; }
.auth-input:focus { outline: none; border-color: var(--aegean); box-shadow: inset 0 0 0 1px var(--aegean); }
.auth-input.code { font-family: var(--mono); letter-spacing: .5em; text-align: center; font-size: 22px; }
.auth-err { font-size: 13px; color: #8a2f24; line-height: 1.4; }
.auth-link { display: inline-block; background: none; border: none; color: var(--aegean-deep); font: inherit; font-size: 13px; cursor: pointer; padding: 10px 0 0; text-decoration: underline; text-underline-offset: 3px; }
.auth-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); text-align: center; }
.auth-foot .auth-link { color: var(--ink-faint); text-decoration: none; }
.auth-foot .auth-link:hover { color: var(--ink-dim); }
/* ---- Go deeper / Related in Bucket (resource + canon links) ---- */
.deeper { margin-top: 20px; }
.link-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.ext-link, .int-link { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; font-size: 14px; transition: background .16s, border-color .16s; }
.ext-link:hover, .int-link:hover { background: var(--card-2); border-color: var(--line-strong); }
.int-link { color: var(--aegean-deep); }
.lk-ico { font-size: 13px; opacity: .8; flex: none; width: 16px; text-align: center; }

/* ---- polyglot language atom ---- */
.lang-card { align-items: flex-start; text-align: left; }
.lang-word { font-family: var(--serif); font-weight: 600; font-size: 40px; line-height: 1.05; color: var(--ink); letter-spacing: -.01em; }
.lang-ipa { font-family: var(--mono); font-size: 15px; color: var(--gold-deep); margin-top: 4px; }
.lang-ref { margin: 6px 0 4px; }
.lang-row, .ex-row { display: flex; gap: 10px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.lang-row:last-child { border-bottom: none; }
.lang-name { font-family: var(--display); text-transform: uppercase; letter-spacing: .06em; font-size: 10px; color: var(--ink-faint); min-width: 78px; flex: none; }
.lang-w { color: var(--ink); }
.lang-w i, .lang-ans i { font-family: var(--mono); font-style: normal; color: var(--gold-deep); font-size: .85em; }
.lang-note { margin: 12px 0; padding: 11px 14px; background: var(--card); border-left: 3px solid var(--gold); border-radius: 0 10px 10px 0; color: var(--ink-dim); font-size: 14.5px; font-style: italic; }
.lang-ex { margin-top: 12px; }
.lang-ans { font-family: var(--serif); font-size: 22px; font-weight: 600; }

/* ---- language settings ---- */
.set-hint { font-size: 12px; color: var(--ink-faint); margin: 10px 2px 6px; }
.lang-sel { background: var(--bg); border: 1px solid var(--line-strong); color: var(--ink); border-radius: 8px; padding: 7px 10px; font: inherit; }
.lang-known { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.lang-chip { font-family: var(--display); text-transform: uppercase; letter-spacing: .05em; font-size: 11px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--card); color: var(--ink-dim); cursor: pointer; min-height: 38px; }
.lang-chip.on { background: var(--aegean-deep); color: var(--bg); border-color: transparent; }
