@font-face { font-family: "Bricolage Desk"; src: url("/fonts/bricolage.woff") format("woff"); font-weight: 500 800; font-display: swap; }
@font-face { font-family: "JetBrains Desk"; src: url("/fonts/jetbrains-mono.woff") format("woff"); font-weight: 100 800; font-display: swap; }

/* Layout: neo-brutalist study desk. Fixed rail of sections (bottom bar on phones), one working panel, a docked timer. Ink borders + hard offset shadows; colour blocks borrowed from an exam answer sheet (pencil yellow), a seal stamp (red) and a jade marker. */
:root {
  --paper: #F6F7F2;
  --card: #FFFFFF;
  --ink: #16181D;
  --muted: #5B606B;
  --line: #16181D;
  --pencil: #FFD23F;
  --seal: #D9363E;
  --jade: #1FA67A;
  --sky: #7CC4F5;
  --lilac: #C9B6F2;
  --soft: #ECEEE6;
  --shadow: #16181D;
  --good: #1FA67A;
  --warn: #E59A00;
  --bad: #D9363E;
  --on-accent: #16181D;
  --f-display: "Bricolage Desk", "Segoe UI", system-ui, sans-serif;
  --f-body: "Bricolage Desk", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --f-zh: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", sans-serif;
  --f-han: "Songti SC", "STSong", "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --f-mono: "JetBrains Desk", ui-monospace, Menlo, Consolas, monospace;
  --bw: 2.5px;
  --sh: 4px 4px 0 var(--shadow);
  --sh-sm: 3px 3px 0 var(--shadow);
  --r: 6px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --paper: #15171B; --card: #1E2127; --ink: #F1F2EC; --muted: #A7ACB6; --line: #F1F2EC;
  --pencil: #F2C531; --seal: #F0575E; --jade: #34C493; --sky: #5DB2EA; --lilac: #B29DE8; --soft: #262A31;
  --shadow: #000000; --good: #34C493; --warn: #F2B53A; --bad: #F0575E; --on-accent: #16181D; color-scheme: dark } }
:root[data-theme="dark"] {
  --paper: #15171B; --card: #1E2127; --ink: #F1F2EC; --muted: #A7ACB6; --line: #F1F2EC;
  --pencil: #F2C531; --seal: #F0575E; --jade: #34C493; --sky: #5DB2EA; --lilac: #B29DE8; --soft: #262A31;
  --shadow: #000000; --good: #34C493; --warn: #F2B53A; --bad: #F0575E; --on-accent: #16181D; color-scheme: dark }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { background: var(--paper); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.5; }
:lang(zh), .zh { font-family: var(--f-zh); }
h1, h2, h3 { font-family: var(--f-display); line-height: 1.15; margin: 0; text-wrap: balance; }
h1 { font-size: 1.55rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 800; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.app { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100%; }
.rail { position: sticky; top: env(safe-area-inset-top, 0px); align-self: start; height: 100vh; border-right: var(--bw) solid var(--line); background: var(--card); display: flex; flex-direction: column; padding: 16px 12px; padding-left: max(12px, env(safe-area-inset-left, 0px)); gap: 6px; }
.brand { display: flex; flex-direction: column; gap: 2px; padding: 4px 6px 14px; border-bottom: var(--bw) solid var(--line); margin-bottom: 8px; }
.brand b { font-family: var(--f-display); font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em; }
.brand span { font-size: 0.78rem; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: var(--bw) solid transparent; border-radius: var(--r); text-decoration: none; color: var(--ink); font-weight: 600; }
.nav a .zh { font-size: 0.85rem; color: var(--muted); margin-left: auto; }
.nav a:hover { border-color: var(--line); }
.nav a[aria-current="page"] { background: var(--pencil); border-color: var(--line); box-shadow: var(--sh-sm); color: var(--on-accent); }
.nav a[aria-current="page"] .zh { color: var(--on-accent); }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 0.8rem; color: var(--muted); }

.main { min-width: 0; padding-block: 20px 120px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.wrap { max-width: 1000px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.topbar .spacer { flex: 1; }

.box { background: var(--card); border: var(--bw) solid var(--line); border-radius: var(--r); box-shadow: var(--sh); padding: 16px; min-width: 0; }
.box.flat { box-shadow: none; }
.box.yellow { background: var(--pencil); color: var(--on-accent); }
.box.sky { background: var(--sky); color: var(--on-accent); }
.box.jade { background: var(--jade); color: var(--on-accent); }
.box.lilac { background: var(--lilac); color: var(--on-accent); }
.box.yellow .muted, .box.sky .muted, .box.jade .muted, .box.lilac .muted { color: var(--on-accent); opacity: 0.75; }
.box.yellow .eyebrow, .box.sky .eyebrow, .box.jade .eyebrow, .box.lilac .eyebrow { color: var(--on-accent); opacity: 0.8; }
.fam.new .muted { color: var(--on-accent); opacity: 0.75; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.eyebrow { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.big { font-family: var(--f-display); font-weight: 800; font-size: 2rem; line-height: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 14px; background: var(--card); border: var(--bw) solid var(--line); border-radius: var(--r); box-shadow: var(--sh-sm); font-weight: 700; cursor: pointer; text-decoration: none; color: var(--ink); transition: transform .06s, box-shadow .06s; }
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--shadow); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: var(--sh-sm); }
.btn.primary { background: var(--pencil); color: var(--on-accent); }
.btn.red { background: var(--seal); color: #fff; }
.btn.green { background: var(--jade); color: var(--on-accent); }
.btn.blue { background: var(--sky); color: var(--on-accent); }
.btn.ghost { box-shadow: none; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border: 2px solid var(--line); border-radius: 999px; font-size: 0.8rem; font-weight: 700; background: var(--card); white-space: nowrap; }
.chip.y { background: var(--pencil); color: var(--on-accent); }
.chip.g { background: var(--jade); color: var(--on-accent); }
.chip.r { background: var(--seal); color: #fff; }
.chip.b { background: var(--sky); color: var(--on-accent); }
.chip.l { background: var(--lilac); color: var(--on-accent); }

.meter { height: 16px; border: var(--bw) solid var(--line); border-radius: 999px; background: var(--soft); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--jade); border-right: var(--bw) solid var(--line); }

input[type="text"], input[type="number"], textarea, select { width: 100%; background: var(--card); border: var(--bw) solid var(--line); border-radius: var(--r); padding: 10px 12px; }
textarea { min-height: 96px; resize: vertical; font-family: var(--f-zh); font-size: 1.05rem; line-height: 1.7; }
label { font-weight: 700; font-size: 0.9rem; }

/* Today */
.countdown { display: flex; align-items: baseline; gap: 10px; }
.countdown .big { font-size: 3rem; }
.blocks { display: flex; flex-direction: column; gap: 8px; }
.block { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border: 2px solid var(--line); border-radius: var(--r); background: var(--card); }
.block.rest { background: var(--soft); border-style: dashed; }
.block.done { opacity: 0.55; }
.block input { width: 20px; height: 20px; accent-color: var(--jade); }
.bars { width: 100%; height: auto; display: block; }

/* Flashcard */
.cardstage { display: grid; place-items: center; min-height: 360px; text-align: center; padding: 26px 16px; }
.han { font-family: var(--f-han); font-weight: 900; font-size: clamp(3rem, 12vw, 5.6rem); line-height: 1.1; letter-spacing: 0.02em; }
.han.md { font-size: clamp(2rem, 7vw, 3rem); }
.py { font-family: var(--f-mono); font-size: 1.2rem; font-weight: 700; }
.gl { font-size: 1.15rem; }
.rate { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.rate .btn { flex-direction: column; gap: 0; min-height: 58px; }
.rate .btn small { font-family: var(--f-mono); font-weight: 500; font-size: 0.72rem; }
.siblings { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.siblings span { font-family: var(--f-zh); padding: 2px 8px; border: 2px solid var(--line); border-radius: 4px; background: var(--soft); }
.siblings span.me { background: var(--pencil); color: var(--on-accent); }
.kbd { font-family: var(--f-mono); font-size: 0.72rem; border: 1.5px solid var(--line); border-radius: 4px; padding: 0 5px; }

/* Families */
.famgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.fam { text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 12px; border: var(--bw) solid var(--line); border-radius: var(--r); background: var(--card); box-shadow: var(--sh-sm); cursor: pointer; }
.fam .han { font-size: 2.4rem; font-weight: 900; }
.fam.new { background: var(--lilac); color: var(--on-accent); }
.fam .muted { font-size: 0.78rem; }
.fam .meter { height: 8px; border-width: 2px; }
.wordlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.word { border: 2px solid var(--line); border-radius: var(--r); padding: 10px; background: var(--card); display: flex; flex-direction: column; gap: 2px; }
.word b { font-family: var(--f-zh); font-size: 1.3rem; }

/* Grammar & drills */
.pattern { font-family: var(--f-zh); font-size: 1.1rem; font-weight: 700; background: var(--pencil); color: var(--on-accent); border: var(--bw) solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.ex { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; align-items: start; padding: 8px 0; border-bottom: 1.5px dashed var(--muted); }
.ex:last-child { border-bottom: 0; }
.ex .zh { font-size: 1.12rem; }
.chunks { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; padding: 8px; border: 2px dashed var(--line); border-radius: var(--r); }
.chunk { font-family: var(--f-zh); font-size: 1.1rem; padding: 6px 12px; border: 2px solid var(--line); border-radius: 4px; background: var(--card); box-shadow: 2px 2px 0 var(--shadow); cursor: pointer; }
.chunk.placed { background: var(--sky); color: var(--on-accent); }
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.opt { text-align: left; font-family: var(--f-zh); font-size: 1.05rem; padding: 10px 12px; border: 2px solid var(--line); border-radius: var(--r); background: var(--card); cursor: pointer; box-shadow: 2px 2px 0 var(--shadow); }
.opt.right { background: var(--jade); color: var(--on-accent); }
.opt.wrong { background: var(--seal); color: #fff; }
.feedback { border-left: 6px solid var(--line); padding: 8px 12px; background: var(--soft); border-radius: 0 var(--r) var(--r) 0; }
.feedback.ok { border-left-color: var(--good); }
.feedback.no { border-left-color: var(--bad); }
.unitlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.unit { text-align: left; display: flex; flex-direction: column; gap: 6px; padding: 12px; border: var(--bw) solid var(--line); border-radius: var(--r); background: var(--card); box-shadow: var(--sh-sm); cursor: pointer; }

/* Reading */
.passage { font-family: var(--f-zh); font-size: 1.28rem; line-height: 2.1; }
.tok { cursor: pointer; border-radius: 3px; padding: 0 1px; }
.tok.l4 { background: color-mix(in srgb, var(--pencil) 55%, transparent); box-shadow: inset 0 -2px 0 var(--line); }
.tok.hi { background: var(--sky); color: var(--on-accent); }
.tok ruby rt { font-family: var(--f-mono); font-size: 0.5em; color: var(--muted); }
.pop { position: fixed; z-index: 40; max-width: min(300px, calc(100vw - 32px)); background: var(--card); border: var(--bw) solid var(--line); border-radius: var(--r); box-shadow: var(--sh); padding: 10px 12px; }

/* Writing / speaking */
.scene { font-size: clamp(3rem, 12vw, 4.6rem); line-height: 1.1; letter-spacing: 0.08em; text-align: center; padding: 18px; background: var(--soft); border: var(--bw) solid var(--line); border-radius: var(--r); }
.panels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.panel { font-size: clamp(2rem, 8vw, 3rem); text-align: center; padding: 16px 6px; border: var(--bw) solid var(--line); border-radius: var(--r); background: var(--soft); position: relative; }
.panel b { position: absolute; top: 4px; left: 8px; font-family: var(--f-mono); font-size: 0.8rem; }
.count { font-family: var(--f-mono); font-weight: 700; }
.count.ok { color: var(--good); }
.count.low { color: var(--bad); }
.prep { display: flex; align-items: center; gap: 14px; }
.prep .clock { font-family: var(--f-mono); font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Timer */
.dial { width: min(260px, 70vw); aspect-ratio: 1; max-width: 100%; margin: 0 auto; display: block; }
.timer-big { font-family: var(--f-mono); font-size: clamp(3rem, 14vw, 4.5rem); font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; }
.dock { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 30; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; background: var(--card); border: var(--bw) solid var(--line); border-radius: 999px; box-shadow: var(--sh); }
.dock.rest { background: var(--jade); color: var(--on-accent); }
.dock.focus { background: var(--pencil); color: var(--on-accent); }
.dock .num { font-size: 1.15rem; font-weight: 700; }
.banner { position: fixed; left: 50%; transform: translateX(-50%); top: calc(16px + env(safe-area-inset-top, 0px)); z-index: 50; width: min(520px, calc(100vw - 32px)); background: var(--pencil); color: var(--on-accent); border: var(--bw) solid var(--line); border-radius: var(--r); box-shadow: var(--sh); padding: 14px 16px; display: flex; gap: 12px; align-items: center; }
.banner.rest { background: var(--jade); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 45; background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: var(--r); font-weight: 700; }

.padwrap { width: min(280px, 100%); aspect-ratio: 1; border: var(--bw) solid var(--line); border-radius: var(--r); background-color: var(--card);
  background-image: linear-gradient(var(--soft), var(--soft)), linear-gradient(var(--soft), var(--soft)), linear-gradient(45deg, transparent calc(50% - 1px), var(--soft) calc(50% - 1px), var(--soft) calc(50% + 1px), transparent calc(50% + 1px)), linear-gradient(-45deg, transparent calc(50% - 1px), var(--soft) calc(50% - 1px), var(--soft) calc(50% + 1px), transparent calc(50% + 1px));
  background-size: 2px 100%, 100% 2px, 100% 100%, 100% 100%; background-position: center, center, center, center; background-repeat: no-repeat; box-shadow: var(--sh-sm); }
.pad { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
table.t { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.t th, table.t td { border: 2px solid var(--line); padding: 6px 8px; text-align: left; }
table.t th { background: var(--soft); }
.scroll { overflow-x: auto; }
.seg { display: inline-flex; max-width: 100%; border: var(--bw) solid var(--line); border-radius: var(--r); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; align-self: flex-start; }
.seg::-webkit-scrollbar { display: none; }
.seg button { border: 0; border-right: 2px solid var(--line); background: var(--card); padding: 6px 12px; font-weight: 700; cursor: pointer; white-space: nowrap; flex: 0 0 auto; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 35; border-right: 0; border-top: var(--bw) solid var(--line); flex-direction: row; padding: 6px; padding-left: max(6px, env(safe-area-inset-left, 0px)); padding-right: max(6px, env(safe-area-inset-right, 0px)); padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); overflow-x: auto; }
  .brand, .rail-foot { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav a { flex-direction: column; gap: 0; padding: 4px 8px; font-size: 0.72rem; white-space: nowrap; }
  .nav a .zh { margin: 0; font-size: 0.95rem; order: -1; color: inherit; }
  .main { padding-block: 16px 150px; }
  .dock { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
  .toast { bottom: calc(140px + env(safe-area-inset-bottom, 0px)); }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .opts { grid-template-columns: minmax(0, 1fr); }
  .rate { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .countdown .big { font-size: 2.4rem; }
}

.banner-text { gap: 2px; flex: 1; }
html, body { height: auto; }
body { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.site-foot { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.8rem; }
.site-foot a { color: var(--muted); }
.notice { position: sticky; top: 0; z-index: 60; background: var(--ink); color: var(--paper); border-bottom: var(--bw) solid var(--line); padding: 12px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px)); padding-top: calc(12px + env(safe-area-inset-top, 0px)); display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.notice p { flex: 1 1 320px; min-width: 0; font-size: 0.92rem; }
.notice a { color: var(--pencil); font-weight: 700; }
.notice .btn { background: var(--pencil); color: var(--on-accent); }
.doc { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; padding-block: 24px 64px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.doc h2 { margin-top: 10px; }
.doc p, .doc li { max-width: 68ch; }
.doc ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; }
.doc .box p + p { margin-top: 8px; }
.doc a { color: inherit; }
