:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --ink: #1d2421;
  --ink-2: #4c5652;
  --muted: #7b847f;
  --line: #e0dcd2;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe8;
  --good: #2f7d4a;
  --good-soft: #e1f2e6;
  --bad: #b5402f;
  --bad-soft: #f8e3df;
  --warn: #a8680c;
  --warn-soft: #fbefd9;
  --info-soft: #e3edf8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131715; --surface: #1b201e; --surface-2: #232927; --ink: #e8ece9; --ink-2: #b9c2bd;
    --muted: #8a948f; --line: #2f3633; --accent: #5cbf9f; --accent-ink: #0d1411; --accent-soft: #1f3a31;
    --good: #6cc48a; --good-soft: #1d3424; --bad: #ec8a78; --bad-soft: #3d2420; --warn: #e5b061;
    --warn-soft: #3a2e17; --info-soft: #1d2b3b; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131715; --surface: #1b201e; --surface-2: #232927; --ink: #e8ece9; --ink-2: #b9c2bd;
  --muted: #8a948f; --line: #2f3633; --accent: #5cbf9f; --accent-ink: #0d1411; --accent-soft: #1f3a31;
  --good: #6cc48a; --good-soft: #1d3424; --bad: #ec8a78; --bad-soft: #3d2420; --warn: #e5b061;
  --warn-soft: #3a2e17; --info-soft: #1d2b3b; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.65 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: clamp(1.5rem, 3.5vw, 2.1rem); font-weight: 700; }
h2 { font-size: 1.3rem; margin-top: 1.8em; }
h3 { font-size: 1.05rem; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: .85rem; }
.center { text-align: center; }
.eyebrow { color: var(--muted); font-size: .85rem; margin: 0 0 .3em; letter-spacing: .02em; }
.lede { color: var(--ink-2); max-width: 60ch; }
.empty { color: var(--muted); font-style: italic; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { display: flex; align-items: center; gap: 20px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; }
.crumbs { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .9rem; flex-wrap: wrap; min-width: 0; }
.crumbs b { color: var(--ink); font-weight: 500; }
main.wrap { padding-top: 28px; padding-bottom: 48px; }
.foot { color: var(--muted); font-size: .8rem; padding-bottom: 32px; }

/* buttons & pills */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-ink); padding: 8px 16px; border-radius: 999px; font: inherit; font-weight: 500; cursor: pointer; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-lg { padding: 12px 28px; font-size: 1.05rem; }
.btn-sm { padding: 2px 12px; font-size: .85rem; }
.btn-block { display: flex; justify-content: center; width: 100%; margin-bottom: 8px; }
.btn-good { background: var(--good); border-color: var(--good); }
.btn-bad { background: var(--bad); border-color: var(--bad); }
.linkish { background: none; border: 0; color: var(--bad); cursor: pointer; font: inherit; padding: 0; }
.badge { background: var(--accent-ink); color: var(--accent); border-radius: 999px; padding: 0 8px; font-size: .8rem; }
.pill { display: inline-block; font-size: .78rem; padding: 1px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-good { background: var(--good-soft); color: var(--good); }
.trial-start { margin-top: 10px; }
.trial-start .linkish { color: var(--muted); font-size: .9rem; text-decoration: underline; }
.pill-bad { background: var(--bad-soft); color: var(--bad); }

/* home */
.hero { padding: 12px 0 8px; }
.year { margin-top: 28px; }
.year-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 14px; }
.year-head h2 { margin: 0; }
.year:not(.is-current) { opacity: .72; }
.terms { display: grid; grid-template-columns: 1fr; gap: 16px; }
.term { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.term.is-now { border-color: var(--accent); box-shadow: var(--shadow); }
.term h3 { display: flex; gap: 8px; align-items: center; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.subject-card { display: grid; gap: 2px; padding: 14px 16px; border-radius: 10px; color: var(--ink);
  background: var(--surface-2); border-left: 5px solid var(--subject); }
.subject-card:hover { text-decoration: none; background: var(--accent-soft); }
.subject-card .code { font-family: var(--mono); font-weight: 500; color: var(--subject); }
.subject-card .name { font-weight: 600; font-size: 1.1rem; }
.subject-card .name-en { color: var(--ink-2); font-size: .9rem; }
.subject-card .meta { color: var(--muted); font-size: .8rem; margin-top: 4px; }

/* subject */
.subject-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; align-items: flex-end;
  border-left: 6px solid var(--subject); padding-left: 18px; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.assessments { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.assess { display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; min-width: 200px; flex: 1; }
.exam-list { display: grid; gap: 8px; }
.exam-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 16px; color: var(--ink); }
.exam-row:hover { text-decoration: none; border-color: var(--accent); }
.exam-title { font-weight: 600; flex: 1 1 260px; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.topic { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; }
.topic-main { display: grid; padding: 14px 16px 8px; color: var(--ink); flex: 1; }
.topic-main:hover { text-decoration: none; }
.topic-main:hover .topic-title { color: var(--accent); }
.lecture { font-family: var(--mono); font-size: .75rem; color: var(--muted); }
.topic-title { font-weight: 600; }
.topic-links { display: flex; gap: 14px; flex-wrap: wrap; padding: 8px 16px 12px; border-top: 1px dashed var(--line); font-size: .88rem; }
.content-errors { margin-top: 32px; color: var(--bad); font-size: .85rem; }

/* lesson */
.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.lesson { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px clamp(16px, 4vw, 40px); min-width: 0; }
.lesson-side { position: sticky; top: 76px; display: grid; gap: 14px; }
.side-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.side-box textarea { width: 100%; font: inherit; font-size: .92rem; border: 1px solid var(--line); border-radius: 8px; padding: 8px;
  background: var(--bg); color: var(--ink); resize: vertical; }
.pager { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); margin-top: 32px; padding-top: 16px; font-size: .92rem; }
@media (max-width: 860px) { .lesson-layout { grid-template-columns: 1fr; } .lesson-side { position: static; } }

/* prose (rendered markdown) */
.prose > :first-child { margin-top: 0; }
.prose h1 { margin-bottom: .6em; }
.prose h2 { border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.prose table { border-collapse: collapse; margin: 12px 0; font-size: .92rem; display: block; overflow-x: auto; max-width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 5px 10px; vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 600; text-align: left; }
.prose td[align="right"], .prose th[align="right"] { font-family: var(--mono); font-size: .88rem; white-space: nowrap; }
.prose code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.prose pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { margin: 12px 0; padding: 4px 16px; border-left: 4px solid var(--line); color: var(--ink-2); }
.prose img { max-width: 100%; }
/* glossary acronyms (content/glossary.yaml, static/glossary.js) */
abbr.gl { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; cursor: help; }
abbr.gl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 2px; }
.gl-tip { position: fixed; z-index: 50; max-width: min(320px, calc(100vw - 16px)); padding: 6px 10px; border-radius: 8px;
  background: var(--ink); color: var(--bg); font-size: .85rem; line-height: 1.45; box-shadow: var(--shadow); pointer-events: none; }
.formula, .tip, .warn { border-radius: 10px; padding: 12px 16px; margin: 14px 0; }
.formula { background: var(--accent-soft); border-left: 4px solid var(--accent); }
.tip { background: var(--info-soft); border-left: 4px solid #4a7fb5; }
.warn { background: var(--warn-soft); border-left: 4px solid var(--warn); }
.formula > :last-child, .tip > :last-child, .warn > :last-child { margin-bottom: 0; }
details { margin: 8px 0; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.prose details { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }

/* flashcards */
.deck { max-width: 680px; margin: 24px auto; }
.flash { min-height: 260px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 32px; display: grid; align-content: center; gap: 18px; cursor: pointer; font-size: 1.1rem; }
.flash-back { border-top: 1px dashed var(--line); padding-top: 18px; color: var(--ink-2); }
.card-ask { font-size: .85rem; color: var(--ink-2); margin-bottom: 8px; }
.card-ask p { margin: 0; }
.deck-controls { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.done { text-align: center; padding: 48px 16px; }

/* exam intro */
.exam-intro { max-width: 760px; }
.facts { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.facts div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 18px; display: grid; min-width: 110px; }
.facts b { font-size: 1.6rem; font-family: var(--mono); font-weight: 500; }
.facts span { color: var(--muted); font-size: .85rem; }
table.plan, table.history { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 8px 0 16px; }
.plan th, .plan td, .history th, .history td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.plan th, .history th { font-size: .82rem; color: var(--muted); font-weight: 500; background: var(--surface-2); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
td.bad, .sec-time.bad { color: var(--bad); font-weight: 600; }
.history .actions { display: flex; gap: 12px; align-items: center; }
.history form { display: inline; }
.sec-time { display: inline-block; margin-right: 10px; font-family: var(--mono); }
@media (max-width: 640px) { table.history { display: block; overflow-x: auto; } }

/* exam mode */
.exam-bar { position: sticky; top: 56px; z-index: 15; display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; box-shadow: var(--shadow); }
.exam-bar.low { border-color: var(--warn); background: var(--warn-soft); }
.exam-bar.overtime { border-color: var(--bad); background: var(--bad-soft); }
.exam-bar.overtime .clock b { color: var(--bad); }
.clock { display: grid; }
.clock b { font-family: var(--mono); font-size: 1.6rem; font-weight: 500; line-height: 1.1; }
.sec-clock { flex: 1 1 220px; }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.meter div { height: 100%; background: var(--accent); transition: width .5s; }
.meter div.near { background: var(--warn); }
.meter div.over { background: var(--bad); }
.bar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.alert { margin: 12px 0; padding: 10px 16px; border-radius: var(--radius); }
.alert-warn { background: var(--bad-soft); color: var(--ink); border: 1px solid var(--bad); }
.alert-info { background: var(--info-soft); }
.sec-tabs { display: flex; gap: 8px; overflow-x: auto; margin: 14px 0; padding-bottom: 4px; }
.sec-tab { display: grid; text-align: left; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px;
  padding: 6px 14px; font: inherit; cursor: pointer; min-width: 150px; }
.sec-tab.active { border-color: var(--accent); background: var(--accent-soft); }
.sec-tab.over .small { color: var(--bad); }
.exam-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px clamp(14px, 3vw, 28px); margin-bottom: 16px; }
.sec-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.instr { color: var(--ink-2); }
.context { background: var(--surface-2); border-radius: 10px; padding: 14px; margin: 12px 0; }
.item { border-top: 1px dashed var(--line); padding: 16px 0; }
.item:first-of-type { border-top: 0; }
.item-head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.qno { background: var(--surface-2); border-radius: 6px; padding: 0 8px; font-family: var(--mono); font-size: .85rem; }
.options { display: grid; gap: 6px; margin: 8px 0; padding: 0; list-style: none; }
.opt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt input { margin-top: 6px; }
.opt .prose p { margin: 0; }
.opt-key { font-weight: 600; color: var(--muted); min-width: 1.2em; }
.num-in { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.num-in input, .self-score input { font: inherit; font-family: var(--mono); padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); width: 180px; }
textarea.written { width: 100%; font: inherit; font-family: var(--mono); font-size: .9rem; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.sec-foot { display: flex; justify-content: flex-end; margin-top: 12px; }
.overlay { position: fixed; inset: 0; background: rgba(10, 15, 12, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.overlay[hidden] { display: none; }
.overlay-box { background: var(--surface); border-radius: 16px; padding: 28px; max-width: 460px; text-align: center; }

/* results */
.result-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; flex-wrap: wrap; }
.score-big b { font-size: 3rem; font-family: var(--mono); font-weight: 500; color: var(--accent); }
.score-big span { color: var(--muted); font-size: 1.2rem; }
.review .item.wrong { border-left: 3px solid var(--bad); padding-left: 12px; }
.review .item.ok { border-left: 3px solid var(--good); padding-left: 12px; }
.review-opts li { display: flex; gap: 10px; padding: 6px 12px; border-radius: 8px; border: 1px solid transparent; }
.review-opts li .prose p { margin: 0; }
.review-opts li.correct { background: var(--good-soft); border-color: var(--good); }
.review-opts li.chosen-wrong { background: var(--bad-soft); border-color: var(--bad); text-decoration: line-through; }
.explain { background: var(--surface-2); border-radius: 8px; padding: 10px 14px; font-size: .93rem; }
.solution { background: var(--surface-2); border-radius: 8px; padding: 10px 14px; }
.src-ref { margin: 10px 0 0; font-size: .82rem; color: var(--muted); }
.rubric { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 8px; font-size: .9rem; }
.your-answer pre { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-family: var(--mono); font-size: .88rem; margin: 4px 0 10px; }
.self-score { display: flex; gap: 10px; align-items: center; margin-top: 10px; font-weight: 500; }
.self-score input { width: 90px; }
.self-score input.saved { border-color: var(--good); }
.self-score input.err { border-color: var(--bad); }
.score-chip { font-family: var(--mono); }

/* number hint, table answers (Excel-like grid), suggested marks */
.num-read .bad, .grid-bal .bad { color: var(--bad); }
.grid-bal .good { color: var(--good); }
.grid-wrap { overflow-x: auto; max-width: 100%; margin: 6px 0; }
.grid-in, .grid-answer { border-collapse: collapse; font-size: .9rem; }
.grid-in th, .grid-in td { border: 1px solid var(--line); padding: 0; }
.grid-in thead th { background: var(--surface-2); }
.grid-in .rn { background: var(--surface-2); color: var(--muted); font-weight: 400; font-size: .75rem; padding: 0 6px; text-align: right; min-width: 2.4em; }
.grid-in input { border: 0; background: transparent; color: var(--ink); font: inherit; padding: 5px 8px; width: 100%; min-width: 6ch; }
.grid-in thead input { font-weight: 600; }
.grid-in input.n { font-family: var(--mono); text-align: right; }
.grid-in input:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--bg); }
.grid-in tfoot td { font-family: var(--mono); text-align: right; padding: 4px 8px; color: var(--ink-2); background: var(--surface-2); white-space: nowrap; }
.grid-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.grid-help { margin: 4px 0 0; }
.grid-answer th, .grid-answer td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; vertical-align: top; }
.grid-answer th { background: var(--surface-2); font-weight: 600; }
.grid-answer .num { font-family: var(--mono); text-align: right; white-space: nowrap; }
.your-answer .grid-wrap { background: var(--bg); margin: 4px 0 10px; }
.suggest { background: var(--info-soft); border-radius: 8px; padding: 10px 14px; margin: 0 0 10px; font-size: .93rem; }
.suggest p { margin: 0 0 6px; }
.suggest ul { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 4px; }
.suggest .mark { display: inline-block; width: 1.3em; font-weight: 700; }
.suggest li.ok .mark { color: var(--good); }
.suggest li.part .mark { color: var(--warn); }
.suggest li.miss .mark { color: var(--bad); }
.alert-pending { background: var(--warn-soft); border: 1px solid var(--warn); }

/* login */
.logout { margin-left: auto; }
.logout .linkish { color: var(--muted); font-size: .88rem; }
.login-box { max-width: 380px; margin: 40px auto; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 14px; }
.login-box label { display: grid; gap: 4px; font-weight: 500; }
.login-box input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }

/* subject phases */
.phase { margin-top: 36px; }
.phase h2 { border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.phase h3 { margin-top: 18px; }
.phase-note { background: var(--warn-soft); border-left: 4px solid var(--warn); border-radius: 10px; padding: 10px 16px; color: var(--ink); max-width: 80ch; }

/* nav + home planner card */
.nav-link { margin-left: auto; font-size: .9rem; white-space: nowrap; }
.nav-link + .logout { margin-left: 16px; }
.planner-card { display: flex; gap: 14px; align-items: center; margin-top: 14px; padding: 14px 18px; max-width: 640px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); }
.planner-card:hover { text-decoration: none; border-color: var(--accent); }
.planner-icon { font-size: 1.8rem; }
.home-tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 12px; }
.home-tools .planner-card { margin: 0; max-width: none; padding: 8px 14px; gap: 12px; line-height: 1.4; }
.home-tools .planner-icon { font-size: 1.4rem; }
.home-tools .planner-card > span:last-child { display: grid; min-width: 0; }
.home-tools .small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* timetable */
.tt-wrap { overflow-x: auto; margin: 10px 0 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.tt { min-width: 860px; }
.tt-head, .tt-row { display: grid; grid-template-columns: 92px 1fr; }
.tt-head { background: var(--surface-2); font-size: .78rem; color: var(--muted); }
.tt-hours { display: flex; }
.tt-hours span { flex: 1; padding: 6px 4px; border-left: 1px solid var(--line); }
.tt-day { padding: 10px 12px; font-size: .88rem; font-weight: 500; border-right: 1px solid var(--line); display: flex; align-items: center; }
.tt-row { border-top: 1px solid var(--line); min-height: 58px; }
.tt-row .tt-day { border-left: 5px solid var(--day); }
.tt-mon { --day: #e8d44d; } .tt-tue { --day: #f28cb1; } .tt-wed { --day: #5cbf7a; } .tt-thu { --day: #f2a65a; }
.tt-fri { --day: #5aa9e6; } .tt-sat { --day: #9b7fd1; } .tt-sun { --day: #e06666; }
.tt-lane { position: relative; background-image: linear-gradient(to right, var(--line) 1px, transparent 1px);
  background-size: calc(100% / var(--cols)) 100%; }
.tt-block { position: absolute; top: 5px; bottom: 5px; border: 2px solid var(--c); border-left-width: 6px; border-radius: 8px;
  background: var(--surface); padding: 2px 8px; font-size: .78rem; line-height: 1.3; overflow: hidden; }
.tt-block small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt-block.planned { border-style: dashed; }
.tt-block.clash { border-color: var(--bad); background: var(--bad-soft); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-right: 6px; }

/* credit bars */
.credit-bar-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 16px 0; }
.credit-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: .9rem; margin-bottom: 8px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.credit-bar { display: flex; height: 14px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.credit-bar.thin { height: 6px; margin: 4px 0 6px; }
.sw-pass { background: var(--good); } .sw-prog { background: var(--accent); opacity: .85; }
.sw-plan { background: repeating-linear-gradient(45deg, var(--accent-soft), var(--accent-soft) 4px, var(--accent) 4px, var(--accent) 6px); }
.sw-none { background: var(--surface-2); border: 1px solid var(--line); }
.course-table td { vertical-align: top; }

/* term cards */
.term-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }
.term-card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--ink); }
.term-card:hover { text-decoration: none; border-color: var(--accent); }
.term-card.is-now { border-color: var(--accent); box-shadow: var(--shadow); }
.term-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 6px; }
.term-courses { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.term-courses li { padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* requirements */
.area { margin-bottom: 18px; }
.req { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; }
.req-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.req-head .ok { color: var(--good); font-weight: 600; }
.req-courses { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-block; font-family: var(--mono); font-size: .78rem; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); margin: 2px 4px 2px 0; }
.chip-passed { background: var(--good-soft); color: var(--good); }
.chip-in_progress { background: var(--accent-soft); color: var(--accent); }
.chip-planned { background: var(--surface); color: var(--accent); border: 1px dashed var(--accent); }

/* term page */
.plan-items { display: grid; gap: 8px; }
.plan-item { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.plan-item.has-clash { border-color: var(--bad); }
.plan-item-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.plan-item p { margin: 4px 0 0; }
.bad { color: var(--bad); } .warn-text { color: var(--warn); }
.slot-form, .add-form { display: grid; gap: 8px; margin-top: 8px; }
.add-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; max-width: 720px; }
.slot-row, .custom-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.slot-form input, .slot-form select, .add-form input, .add-form select { font: inherit; font-size: .9rem; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); max-width: 100%; }
.add-form label, .slot-form label { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.add-form select[name="code"] { min-width: 0; flex: 1; }
form.inline { display: inline; }
.suggest { margin-top: 20px; }
.slot-form .btn, .add-form .btn { justify-self: start; }
.edit-slots summary { font-size: .9rem; }

/* read-only flashcard list for parents */
.card-list { width: 100%; border-collapse: collapse; margin: 8px 0 24px; }
.card-list th, .card-list td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.card-list td.prose > :first-child { margin-top: 0; }
.card-list td.prose > :last-child { margin-bottom: 0; }
.card-list td:first-child, .card-list td:last-child { white-space: nowrap; }
@media (max-width: 640px) {
  .card-list thead { display: none; }
  .card-list tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .card-list td { display: block; border: 0; padding: 2px 0; }
}

/* time tracker: header countdown chip + /time page */
.time-chip { margin-left: auto; display: inline-flex; align-items: baseline; gap: 6px; padding: 2px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: .8rem; white-space: nowrap; }
.time-chip:hover { text-decoration: none; filter: brightness(.97); }
.time-chip[hidden] { display: none; }
.time-chip .tc-clock { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.time-chip + .nav-link { margin-left: 12px; }

.tp-terms { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tp-countdowns { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 12px 0; }
.tp-cd { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; display: grid; }
.tp-cd-clock { font-family: var(--mono); font-weight: 500; font-size: 1.05rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tp-cd.is-past { opacity: .5; }
.tp-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; }
.tp-today-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tp-bar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin: 10px 0 4px; }
.tp-bar i { display: block; height: 100%; }
.tp-c-cls { background: #3e7be6; } .tp-c-fix { background: var(--muted); opacity: .5; }
.tp-c-study { background: var(--accent); } .tp-c-rest { background: var(--warn); opacity: .7; }
.tp-before { padding-left: 1.2em; }
.tp-mode { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin-top: 24px; }
.tp-mode button { font: inherit; font-size: .88rem; border: 0; background: var(--surface); color: var(--ink-2); padding: 4px 14px; cursor: pointer; }
.tp-mode button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tp-scroll { overflow-x: auto; }
.tp-table { min-width: 640px; }
.tp-table td, .tp-table th { white-space: nowrap; }
.tp-table .tp-study { color: var(--accent); font-weight: 600; }
.tp-table .tp-rest { color: var(--warn); }
.tp-table tr.is-now td { background: var(--accent-soft); }
.tp-table tr.is-past td { color: var(--muted); }
.tp-table tr.is-past td.tp-study, .tp-table tr.is-past td.tp-rest { color: var(--muted); font-weight: 400; }
@media (max-width: 640px) {
  .time-chip .tc-label, .time-chip .tc-hms { display: none; }
  .time-chip { padding: 2px 8px; }
  .topbar-inner { gap: 10px; }
  .tp-countdowns { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tp-cd { padding: 6px 10px; }
  .tp-cd-clock { font-size: .9rem; }
  .tp-cd.is-past { display: none; }

}

/* reference sources */
.ref-toc { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; }
.ref-list { display: grid; gap: 10px; }
.ref-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }
.ref-item p { margin: 4px 0; }
.ref-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ref-url { overflow-wrap: anywhere; }
.ref-meta code { font-size: .8rem; }

/* weekly study plan */
.nav-link-2 { margin-left: 14px; }
.wk-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.wk-summary { display: flex; gap: 18px; align-items: center; }
.wk-pct { display: grid; text-align: center; min-width: 90px; }
.wk-pct b { font-family: var(--mono); font-size: 2rem; font-weight: 500; line-height: 1.1; }
.wk-sum-body { flex: 1; min-width: 0; }
.wk-sum-body p { margin: 6px 0; }
.wk-subjects { display: flex; gap: 6px; flex-wrap: wrap; }
.wk-overdue { background: var(--bad-soft); border-radius: var(--radius); padding: 4px 16px 12px; margin: 12px 0; }
.wk-overdue h2 { margin-top: .6em; }
.wk-overdue-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.wk-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
.wk-day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; min-width: 0; }
.wk-day.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.wk-day.is-past { background: var(--surface-2); }
.wk-day.kind-holiday, .wk-day.kind-midterm, .wk-day.kind-final { background: var(--warn-soft); }
.wk-day-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.wk-classes { color: var(--ink-2); margin-bottom: 4px; }
.wk-tasks { display: grid; gap: 6px; margin-top: 8px; }
.wk-free { margin: 4px 0; }
.wk-task { background: var(--bg); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px; padding: 6px 8px; font-size: .88rem; }
.wk-task-head { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.wk-min { margin-left: auto; }
.wk-title { display: block; color: var(--ink); line-height: 1.35; margin: 2px 0; }
.wk-icon { font-weight: 700; width: 1em; text-align: center; color: var(--muted); }
.wk-task.st-done, .wk-task.st-late { opacity: .7; }
.wk-task.st-done .wk-icon, .wk-task.st-late .wk-icon { color: var(--good); }
.wk-task.st-done .wk-title { text-decoration: line-through; }
.wk-task.st-overdue { border-color: var(--bad); border-left-color: var(--c); }
.wk-task.st-overdue .wk-icon { color: var(--bad); }
.wk-move summary { cursor: pointer; color: var(--muted); }
.wk-move form { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.wk-move select { font: inherit; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.lesson-done { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 28px 0 8px; padding: 12px 16px;
  background: var(--accent-soft); border-radius: var(--radius); }
/* week page uses the whole window; 7 days per row only when each gets ≥ ~180px, else Mon–Thu / Fri–Sun */
.page-wide .wrap { max-width: 1800px; }
@media (max-width: 1340px) { .wk-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 980px) { .wk-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .wk-grid { grid-template-columns: 1fr; }
  .wk-summary { flex-direction: column; align-items: stretch; }
  .nav-hide-sm, .nav-calc-label { display: none; }
  .nav-link-2 { margin-left: 10px; }
}
/* month calendar */
.mo-cal { width: 100%; min-width: 620px; border-collapse: separate; border-spacing: 4px; table-layout: fixed; }
.mo-cal th { font-size: .82rem; color: var(--muted); font-weight: 500; }
.mo-cal .mo-week { width: 64px; text-align: left; }
.mo-week a { font-family: var(--mono); color: var(--ink); }
.mo-pct { display: block; font-family: var(--mono); font-size: .78rem; color: var(--muted); }
.mo-pct.good { color: var(--good); } .mo-pct.bad { color: var(--bad); }
.mo-day { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; height: 64px; vertical-align: top; padding: 0; }
.mo-day a { display: block; height: 100%; padding: 4px 6px; color: var(--ink); }
.mo-day a:hover { text-decoration: none; background: var(--surface-2); }
.mo-day.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.mo-day.kind-none { opacity: .35; }
.kind-holiday.mo-day, .mo-key.kind-holiday { background: var(--info-soft); }
.kind-midterm.mo-day, .kind-final.mo-day, .mo-key.kind-midterm, .mo-key.kind-final { background: var(--warn-soft); }
.mo-key { padding: 0 6px; border-radius: 4px; }
.mo-cal tr.is-now .mo-week a { color: var(--accent); font-weight: 600; }
.mo-date { font-size: .78rem; color: var(--muted); }
.mo-dots { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.mo-dots i { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--c); }
.mo-dots i.st-done, .mo-dots i.st-late { background: var(--c); }
.mo-dots i.st-overdue { border-color: var(--bad); }
.wk-kind { color: var(--ink-2); }
.mo-tip { max-width: min(360px, calc(100vw - 16px)); }
.mo-tip b { display: block; margin-bottom: 4px; }
.mo-tip ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.mo-tip li { display: flex; gap: 6px; align-items: baseline; }
.mo-tip li i { flex: none; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--c); }
.mo-tip li i.st-done, .mo-tip li i.st-late { background: var(--c); }
.mo-tip li i.st-overdue { border-color: var(--bad); }
.mo-tip .tip-min { margin-left: auto; padding-left: 8px; opacity: .75; white-space: nowrap; }

/* calculator window (/calc, body.popup) */
.popup .topbar, .popup .foot { display: none; }
.popup main.wrap { max-width: 720px; padding-top: 10px; padding-bottom: 24px; }
.nav-calc + .nav-link-2 { margin-left: 14px; }
.calc-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.calc-top select, .calc-fields select, .calc-fields input, .calc-fields textarea, .calc-inv input, .calc-inv select {
  font: inherit; font-size: .92rem; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.calc-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.calc-tabs button { font: inherit; font-size: .85rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  padding: 3px 12px; border-radius: 999px; cursor: pointer; }
.calc-tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.calc-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.calc-card h2 { font-size: 1.02rem; margin: 0 0 2px; }
.calc-card h3 { font-size: .95rem; margin: 14px 0 4px; }
.calc-hint { color: var(--muted); font-size: .82rem; margin: 0 0 8px; }
.calc-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 10px; }
.calc-fields label { display: grid; gap: 2px; font-size: .8rem; color: var(--ink-2); }
.calc-fields label.wide { grid-column: 1 / -1; }
.calc-fields input { font-family: var(--mono); text-align: right; min-width: 0; }
.calc-fields textarea { font-family: var(--mono); resize: vertical; }
.calc-out { margin-top: 10px; }
.calc-res { width: 100%; border-collapse: collapse; }
.calc-res th { text-align: left; font-weight: 400; color: var(--ink-2); font-size: .88rem; padding: 4px 8px 4px 0; vertical-align: top; }
.calc-res td { text-align: right; padding: 4px 0; }
.calc-val { font: inherit; font-family: var(--mono); font-weight: 600; background: none; border: 0; color: var(--ink); cursor: copy; padding: 0; }
.calc-val.copied { color: var(--good); }
.calc-how { font-size: .75rem; color: var(--muted); font-family: var(--mono); }
.calc-note { font-size: .8rem; color: var(--muted); margin: 6px 0 0; }
.calc-err { color: var(--bad) !important; }
.calc-scroll { overflow-x: auto; margin-top: 8px; }
.calc-sched { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
.calc-sched th { background: var(--surface-2); color: var(--muted); font-weight: 500; padding: 4px 8px; text-align: right; white-space: nowrap; }
.calc-sched td { border-bottom: 1px solid var(--line); padding: 3px 8px; text-align: right; font-family: var(--mono); white-space: nowrap; }
.calc-sched th:first-child, .calc-sched td:first-child { text-align: left; font-family: var(--font); }
.calc-reset { font-size: .8rem; color: var(--muted); margin: 6px 0 0 6px; }
.calc-del { color: var(--muted); }
.calc-expr { width: 100%; font: 500 1.35rem var(--mono); padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); text-align: right; }
.calc-result { font: 600 1.6rem var(--mono); text-align: right; min-height: 2.2rem; margin: 6px 2px 10px; overflow-wrap: anywhere; }
.calc-result.calc-err { font-size: .95rem; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.calc-keys button { font: 500 1.1rem var(--mono); padding: 12px 0; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); cursor: pointer; }
.calc-keys button:active { filter: brightness(.95); }
.calc-keys .k-fn { background: var(--surface-2); }
.calc-keys .k-op { background: var(--accent-soft); color: var(--accent); }
.calc-keys [data-key="="] { background: var(--accent); color: var(--accent-ink); }
.calc-history { padding-left: 1.4em; margin: 4px 0; font-family: var(--mono); font-size: .85rem; max-height: 220px; overflow-y: auto; }
.calc-history button { color: var(--ink-2); text-align: left; }
.calc-inv { border-collapse: collapse; font-size: .85rem; }
.calc-inv th { color: var(--muted); font-weight: 500; text-align: left; padding: 2px 4px; }
.calc-inv td { padding: 2px 4px; }
.calc-inv input { width: 74px; font-family: var(--mono); text-align: right; }
.calc-inv input:disabled { opacity: .35; }
.calc-foot { margin-top: 8px; }

/* reference library (/library) */
.lib-block { margin: 28px 0; }
.lib-code { font-family: var(--mono); font-size: .85rem; background: var(--surface-2); border-radius: 6px; padding: 0 8px; color: var(--ink); white-space: nowrap; }
a.lib-code:hover { text-decoration: none; background: var(--accent-soft); }
.change-group h3 { margin: 14px 0 4px; font-size: 1rem; }
.change-group ul { margin: 0 0 8px; padding-left: 1.2em; display: grid; gap: 6px; }
.change-group .pill { margin-left: 4px; }
.lib-log { padding-left: 1.2em; }
.lib-log ul { padding-left: 1.2em; margin: 2px 0 8px; }
.lib-filter { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.lib-filter input[type=search] { font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); flex: 1 1 260px; min-width: 0; }
.lib-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.lib-chips button.pill { border: 1px solid var(--line); cursor: pointer; font: inherit; font-size: .82rem; }
.lib-chips button.pill.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.lib-section { margin: 14px 0 22px; }
.lib-intro { color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.lib-item[hidden], .lib-section[hidden] { display: none; }
.lib-topics a { white-space: nowrap; }
.lib-actions { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; margin-top: 4px; }
.bm-quick summary, .bm-edit summary, .bm-add summary { cursor: pointer; color: var(--accent); }
.bm-quick[open] { flex-basis: 100%; }
.bm-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin: 6px 0; }
.bm-form label { display: grid; gap: 2px; font-size: .8rem; color: var(--muted); }
.bm-form label.grow { flex: 1 1 200px; }
.bm-form input { font: inherit; font-size: .9rem; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); width: 100%; }
.bm-form input[type=number] { width: 90px; }
.bm-note { margin: 2px 0; white-space: pre-wrap; }
.ref-item.flash { outline: 2px solid var(--accent); outline-offset: 2px; }
.lib-legal { margin-top: 32px; }
.topic-ref { border-style: dashed; }
.std-list { list-style: none; padding: 0; margin: 0 0 6px; display: grid; gap: 6px; }

/* typing progress from Typo (SK02) */
.typing-panel .assess b { font-size: 1.5rem; }
.typing-courses { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 8px 0 16px; }
.typing-courses > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }

/* ── /calendar ─────────────────────────────────────────────────────────── */
.cal-term { margin: 18px 0; }
.cal-term.is-done h2 { color: var(--muted); }
.cal-list { list-style: none; padding: 0; margin: 8px 0; border-top: 1px solid var(--line); }
.cal-row { display: grid; grid-template-columns: minmax(150px, 210px) 1fr; gap: 4px 14px; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.cal-date { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.cal-imp .cal-what, li.cal-imp > b { font-weight: 600; }
.cal-past { opacity: .55; }
.cal-now { background: var(--good-soft); }
.cal-next { background: var(--accent-soft); }
.cal-k-holiday { color: var(--muted); font-size: .9rem; }
.cal-k-term .cal-what { color: var(--accent); }
.cal-steps li { margin: 8px 0; }
@media (max-width: 560px) { .cal-row { grid-template-columns: 1fr; } .cal-date { font-size: .85rem; } }
