:root {
  /* Tokyo Night (VS Code) — deliberately different from the research workbench's Ayu Mirage */
  --bg: #1A1B26; --panel: #1F2335; --panel2: #292E42; --line: #3B4261;
  --fg: #C0CAF5; --dim: #737AA2; --strong: #E6EAFF;
  --accent: #7AA2F7; --accent-ink: #16161E;
  --blue: #7DCFFF; --green: #9ECE6A; --red: #F7768E; --purple: #BB9AF7; --orange: #FF9E64; --cyan: #73DACA;
  --lv0: #3B4261; --lv1: #565F89; --lv2: #7AA2F7; --lv3: #73DACA; --lv4: #E0AF68;
  --r0: transparent; --r1: rgba(158,206,106,.18); --r2: rgba(158,206,106,.36); --r3: rgba(158,206,106,.55); --r4: rgba(158,206,106,.78); --r5: #9ECE6A;
  --radius: 10px;
  color-scheme: dark;
}
/* Light is opt-in (Setup → Theme); dark is the default everywhere. Tokyo Night Day. */
:root[data-theme="light"] {
  --bg: #E1E2E7; --panel: #EEF0F6; --panel2: #D5D6DB; --line: #B7B9C8;
  --fg: #343B58; --dim: #6C6E75; --strong: #1A1B26;
  --accent: #2E7DE9; --accent-ink: #FFFFFF;
  --blue: #007197; --green: #587539; --red: #F52A65; --purple: #7847BD; --orange: #B15C00; --cyan: #118C74;
  --lv0: #B7B9C8; --lv1: #8990B3; --lv2: #2E7DE9; --lv3: #118C74; --lv4: #8C6C3E;
  --r1: rgba(88,117,57,.16); --r2: rgba(88,117,57,.34); --r3: rgba(88,117,57,.55); --r4: rgba(88,117,57,.78); --r5: #587539;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--strong); line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; }
p { margin: 0 0 .6rem; }
code { background: var(--panel2); padding: .05em .35em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--dim); } .small { font-size: .85rem; } .pad { padding: 1rem; }
.strong { color: var(--strong); font-weight: 600; }
.right { text-align: right; } .nowrap { white-space: nowrap; }

/* header + nav */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem;
  background: var(--bg); border-bottom: 1px solid var(--line); padding: .5rem 1rem;
  padding-top: calc(.5rem + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: .45rem; color: var(--strong); font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
#tabs { display: flex; gap: .15rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
#tabs a {
  color: var(--dim); padding: .35rem .7rem; border-radius: 8px; white-space: nowrap; font-weight: 500;
}
#tabs a:hover { background: var(--panel); text-decoration: none; color: var(--fg); }
#tabs a[aria-current="page"] { background: var(--panel2); color: var(--accent); }
#tabs .badge { background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: .7rem; padding: 0 .4rem; margin-left: .25rem; font-weight: 700; }
.pill { font-size: .75rem; padding: .15rem .6rem; border-radius: 99px; border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.pill.ok { color: var(--cyan); border-color: var(--cyan); }
.pill.busy { color: var(--accent); border-color: var(--accent); }
.pill.err { color: var(--red); border-color: var(--red); }

main { max-width: 1200px; margin: 0 auto; padding: 1rem; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem 1rem; margin-bottom: 1rem; }
.page-head p { margin: 0; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; min-width: 0; }
.card > h2:first-child, .card > .row:first-child > h2 { margin-bottom: .6rem; }
.card.accent { border-left: 4px solid var(--c, var(--accent)); }
a.card { display: block; color: inherit; } a.card:hover { text-decoration: none; border-color: var(--dim); }

/* KPI strip */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
.kpi .n { font-size: 1.7rem; font-weight: 700; color: var(--strong); line-height: 1.15; }
.kpi .l { color: var(--dim); font-size: .8rem; }
.kpi .bar { margin-top: .4rem; }
a.kpi { color: inherit; display: block; } a.kpi:hover { text-decoration: none; border-color: var(--accent); }

/* forms */
label { display: block; font-size: .8rem; color: var(--dim); margin-bottom: .2rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=date], input[type=url], input[type=password], input[type=search], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; min-height: 2.4rem;
}
textarea { resize: vertical; min-height: 4.5rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.form { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); align-items: end; }
.form .wide { grid-column: 1 / -1; }
.form .half { grid-column: span 2; }
@media (max-width: 480px) { .form .half { grid-column: 1 / -1; } }
.check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--fg); margin: 0; }
.check input { width: auto; min-height: 0; }

.btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .9rem; cursor: pointer;
  min-height: 2.4rem; display: inline-flex; align-items: center; gap: .4rem; font-weight: 500;
}
.btn:hover { border-color: var(--dim); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--red); }
.btn.small { min-height: 0; padding: .15rem .55rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--blue); cursor: pointer; font-size: inherit; }
.linkbtn:hover { text-decoration: underline; }
.linkbtn.danger { color: var(--red); }

/* chips, bars */
.chip { display: inline-block; border-radius: 99px; padding: 0 .55rem; font-size: .75rem; border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.chip.c { border-color: var(--c); color: var(--c); }
.chip.warn { border-color: var(--orange); color: var(--orange); }
.chip.bad { border-color: var(--red); color: var(--red); }
.chip.good { border-color: var(--cyan); color: var(--cyan); }
.bar { height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; display: flex; }
.bar > i { display: block; height: 100%; background: var(--cyan); }
.bar.stack > i { border-right: 1px solid var(--panel); }
.bar.stack > i:last-child { border-right: 0; }
.lv0 { background: var(--lv0) !important; } .lv1 { background: var(--lv1) !important; } .lv2 { background: var(--lv2) !important; } .lv3 { background: var(--lv3) !important; } .lv4 { background: var(--lv4) !important; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: .75rem; color: var(--dim); font-weight: 600; padding: .3rem .5rem; border-bottom: 1px solid var(--line); text-transform: uppercase; letter-spacing: .03em; }
.tbl td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl-wrap { overflow-x: auto; }

/* level stepper */
.steps { display: inline-flex; gap: 2px; }
.steps button {
  width: 1.7rem; height: 1.7rem; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--dim);
  cursor: pointer; font-size: .75rem; padding: 0;
}
.steps button:hover { border-color: var(--dim); }
.steps button.on { color: var(--accent-ink); border-color: transparent; font-weight: 700; }

/* birds-eye map */
.mapcourse { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: .5rem 1rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.mapcourse:last-child { border-bottom: 0; }
@media (max-width: 640px) { .mapcourse { grid-template-columns: 1fr; } }
.cells { display: flex; flex-wrap: wrap; gap: 3px; align-content: flex-start; }
.cell { width: 16px; height: 16px; border-radius: 4px; border: 1px solid var(--line); background: var(--r0); display: block; position: relative; }
.cell:hover { outline: 2px solid var(--accent); text-decoration: none; }
.cell.r1 { background: var(--r1); } .cell.r2 { background: var(--r2); } .cell.r3 { background: var(--r3); } .cell.r4 { background: var(--r4); } .cell.r5 { background: var(--r5); }
.cell.r1, .cell.r2, .cell.r3, .cell.r4, .cell.r5 { border-color: transparent; }
.cell.od::after { content: ""; position: absolute; right: -3px; top: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--orange); border: 1px solid var(--bg); }
.legend { display: flex; flex-wrap: wrap; gap: .25rem .9rem; align-items: center; font-size: .8rem; color: var(--dim); }
.legend .cell { display: inline-block; vertical-align: middle; margin-right: .25rem; }

/* heatmap */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); grid-auto-columns: 12px; gap: 3px; overflow-x: auto; padding-bottom: .3rem; }
.heat i { width: 12px; height: 12px; border-radius: 3px; background: var(--panel2); display: block; }
.heat i.h1 { background: var(--r2); } .heat i.h2 { background: var(--r3); } .heat i.h3 { background: var(--r4); } .heat i.h4 { background: var(--r5); }
.heat i.fut { visibility: hidden; }
.heat i.now { outline: 1px solid var(--accent); }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.entry .meta { color: var(--dim); font-size: .8rem; display: flex; flex-wrap: wrap; gap: .25rem .6rem; align-items: center; }
.entry .body { margin-top: .15rem; }
.gapline { color: var(--orange); font-size: .9rem; }
.empty { color: var(--dim); padding: 1rem; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.prose { overflow-wrap: anywhere; }
.prose a { text-decoration: underline; }

/* review card */
.flash { max-width: 720px; margin: 0 auto; }
.flash .prompt { font-size: 1.35rem; color: var(--strong); margin: .5rem 0 1rem; overflow-wrap: anywhere; }
.flash .hint { color: var(--dim); font-size: .9rem; }
.flash .answer { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; margin: 1rem 0; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-top: 1rem; }
.grades .btn { flex-direction: column; justify-content: center; gap: 0; min-height: 3.2rem; }
.grades small { color: var(--dim); font-weight: 400; }
.grades .btn:nth-child(1) { border-color: var(--red); } .grades .btn:nth-child(2) { border-color: var(--orange); }
.grades .btn:nth-child(3) { border-color: var(--cyan); } .grades .btn:nth-child(4) { border-color: var(--blue); }
.progress-hint { text-align: center; margin-bottom: .5rem; }

details.more > summary { cursor: pointer; color: var(--blue); font-size: .85rem; }
details.more[open] > summary { margin-bottom: .5rem; }

/* dialog + toast */
dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; width: min(560px, calc(100vw - 2rem)); max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(0,0,0,.55); }
#toast { position: fixed; bottom: calc(1rem + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); color: var(--strong); padding: .5rem 1rem; border-radius: 8px; z-index: 50; max-width: calc(100vw - 2rem); box-shadow: 0 4px 16px rgba(0,0,0,.35); }
#toast.err { border-color: var(--red); }

.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; }

@media (max-width: 640px) {
  main { padding: .75rem; }
  .top { flex-wrap: wrap; padding: .4rem .75rem; }
  #tabs { order: 3; flex-basis: 100%; }
  .brand { flex: 1; }
  .grades { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: no-preference) { .bar > i { transition: width .3s; } }

/* canvases */
.cv { width: 100%; height: 68vh; min-height: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); touch-action: none; cursor: grab; display: block; }
.cv:active { cursor: grabbing; }
.cv .node { cursor: pointer; }
.cv .nb { fill: var(--bg); stroke-width: 1.5; }
.cv .node:hover .nb { fill: var(--panel2); }
.cv .node.sel .nb { stroke-width: 3; }
.cv .node.from .nb { stroke-dasharray: 5 3; stroke-width: 3; }
.cv .nt { fill: var(--strong); font: 600 12px system-ui, sans-serif; pointer-events: none; }
.cv .ns { fill: var(--dim); font: 10.5px system-ui, sans-serif; pointer-events: none; }
.cv .cl { font: 600 13px system-ui, sans-serif; }
.cv .edge { fill: none; stroke-width: 1.6; opacity: .85; }
.pickbox { max-height: 14rem; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; display: grid; gap: .2rem; background: var(--bg); }
.chip.c { max-width: 18rem; overflow: hidden; text-overflow: ellipsis; }

.row select, .card > select { max-width: 22rem; }
