/* PandaChinese — ink on paper. Printed-exam serif for characters, system sans for the interface.
   The seal-red stamp (HSK level) and the 田字格 guide behind the character are the signature details. */

:root {
  --paper: #f1f3ef;
  --surface: #fafbf8;
  --sunken: #e7ebe6;
  --ink: #16211c;
  --ink-2: #4d5c55;
  --ink-3: #6b7a73;
  --line: #d3dad4;
  --line-strong: #b7c2ba;
  --jade: #1d6a56;
  --jade-ink: #ffffff;
  --jade-soft: #dcebe4;
  --seal: #b03528;
  --seal-soft: #f4dcd7;
  --amber: #85600f;
  --amber-soft: #f1e6c8;
  --blue: #285b87;
  --blue-soft: #d9e6f1;
  --focus: #1d6a56;
  --shadow: 0 1px 0 rgba(22, 33, 28, 0.04), 0 6px 20px -12px rgba(22, 33, 28, 0.25);
  --hanzi: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "Noto Serif SC", "STSong", "SimSun", "PMingLiU", serif;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Roboto, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;
  --scale: 1;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1513;
    --surface: #172019;
    --sunken: #0b100e;
    --ink: #e8efe9;
    --ink-2: #b2c0b8;
    --ink-3: #8c9b93;
    --line: #26332c;
    --line-strong: #3a4a41;
    --jade: #5cc2a4;
    --jade-ink: #07130e;
    --jade-soft: #1b3028;
    --seal: #f08272;
    --seal-soft: #3a1f1b;
    --amber: #e2b552;
    --amber-soft: #33290f;
    --blue: #7db4e8;
    --blue-soft: #15283a;
    --focus: #5cc2a4;
    --shadow: 0 6px 20px -12px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f1513;
  --surface: #172019;
  --sunken: #0b100e;
  --ink: #e8efe9;
  --ink-2: #b2c0b8;
  --ink-3: #8c9b93;
  --line: #26332c;
  --line-strong: #3a4a41;
  --jade: #5cc2a4;
  --jade-ink: #07130e;
  --jade-soft: #1b3028;
  --seal: #f08272;
  --seal-soft: #3a1f1b;
  --amber: #e2b552;
  --amber-soft: #33290f;
  --blue: #7db4e8;
  --blue-soft: #15283a;
  --focus: #5cc2a4;
  --shadow: 0 6px 20px -12px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}
:root[data-text="s"] { --scale: 0.92; }
:root[data-text="l"] { --scale: 1.14; }

* { box-sizing: border-box; }
html { font-size: calc(100% * var(--scale)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--jade); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--paper); padding: 10px 14px; z-index: 50; }
.skip:focus { left: 8px; top: 8px; }
.hanzi, .hz { font-family: var(--hanzi); font-weight: 500; }
.muted { color: var(--ink-2); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.seal {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  background: var(--seal); color: #fff; border-radius: 7px;
  font-family: var(--hanzi); font-size: 1.1rem; font-weight: 700;
}
.icon-btn { display: grid; place-items: center; width: var(--tap); height: var(--tap); border: 0; background: transparent; border-radius: 50%; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--sunken); }
main { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(var(--tap) + 44px + env(safe-area-inset-bottom)); outline: none; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 58px; text-decoration: none; color: var(--ink-3); font-size: 0.75rem; font-weight: 550;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--jade); }
.tabbar a[aria-current="page"] span { box-shadow: inset 0 -2px 0 var(--jade); }
body.immersive .tabbar { display: none; }
body.immersive main { padding-bottom: 24px; }

.stack { display: grid; gap: 16px; }
.stack-sm { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.page-head { padding: 8px 0 4px; display: grid; gap: 2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
}
.btn:hover { background: var(--sunken); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--jade); border-color: var(--jade); color: var(--jade-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { min-height: 60px; font-size: 1.15rem; border-radius: var(--radius); width: 100%; }
.btn.block { width: 100%; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--jade); padding-inline: 10px; }
.btn.danger { color: var(--seal); border-color: var(--seal); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface);
  cursor: pointer; font-size: 0.9rem; font-weight: 550;
}
.chip[aria-pressed="true"], .chip[aria-checked="true"] { background: var(--jade-soft); border-color: var(--jade); color: var(--ink); }
.chip[aria-pressed="true"]::before { content: "✓"; color: var(--jade); font-weight: 700; }

/* ---------- today ---------- */
.day-hero { display: grid; gap: 4px; padding: 6px 2px 2px; }
.day-hero .big-n { font-size: 3.4rem; line-height: 1; font-weight: 700; letter-spacing: -0.03em; }
.day-hero .big-n small { font-size: 1rem; font-weight: 550; color: var(--ink-2); letter-spacing: 0; margin-left: 6px; }
.phase { display: inline-flex; gap: 8px; align-items: baseline; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.stats > div { padding: 12px 10px; border-right: 1px solid var(--line); display: grid; gap: 2px; }
.stats > div:last-child { border-right: 0; }
.stats b { font-size: 1.6rem; line-height: 1; font-variant-numeric: tabular-nums; }
.stats span { font-size: 0.8rem; color: var(--ink-2); }
.stats .hot b { color: var(--seal); }
.notice { border-left: 4px solid var(--amber); background: var(--amber-soft); padding: 12px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; display: grid; gap: 8px; }
.notice.info { border-color: var(--blue); background: var(--blue-soft); }
.notice.bad { border-color: var(--seal); background: var(--seal-soft); }
.notice .notice-title { font-weight: 650; }
.meter { height: 8px; background: var(--sunken); border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--jade); border-radius: 99px; }
.progress-line { display: grid; gap: 6px; }

/* ---------- study card ---------- */
.study { display: grid; gap: 14px; min-height: calc(100dvh - 90px); align-content: start; }
.study-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.study-bar { flex: 1; }
.card-face {
  position: relative; display: grid; place-items: center; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  min-height: min(46dvh, 360px); padding: 36px 16px 28px; box-shadow: var(--shadow);
  overflow: hidden;
}
.card-face .guide { position: absolute; inset: 18px; pointer-events: none; opacity: 0.55; }
.card-face .guide::before, .card-face .guide::after { content: ""; position: absolute; }
.card-face .guide::before { left: 0; right: 0; top: 50%; border-top: 1px dashed var(--line-strong); }
.card-face .guide::after { top: 0; bottom: 0; left: 50%; border-left: 1px dashed var(--line-strong); }
.stamp {
  position: absolute; top: 12px; right: 12px; z-index: 1;
  min-width: 52px; padding: 4px 8px; text-align: center; line-height: 1.1;
  border: 2px solid var(--seal); color: var(--seal); border-radius: 6px; font-weight: 700; font-size: 0.8rem;
  background: var(--surface);
}
.stamp b { display: block; font-family: var(--hanzi); font-size: 1.15rem; }
.word {
  position: relative; z-index: 1; font-family: var(--hanzi); font-weight: 500; color: var(--ink);
  font-size: clamp(3.4rem, 22vw, 6.5rem); line-height: 1.15; letter-spacing: 0.12em; padding-left: 0.12em;
  word-break: keep-all; overflow-wrap: anywhere; max-width: 100%;
}
.word.long { font-size: clamp(2.4rem, 15vw, 4.4rem); }
.word.xlong { font-size: clamp(1.8rem, 10.5vw, 3.2rem); letter-spacing: 0.06em; }
.prompt { color: var(--ink-2); text-align: center; }
.study.revealed .card-face { min-height: 26dvh; padding-block: 28px 20px; }
.study.revealed .word { font-size: clamp(3rem, 18vw, 5rem); }
.study.revealed .word.long { font-size: clamp(2.2rem, 12vw, 3.6rem); }
.study.revealed .word.xlong { font-size: clamp(1.7rem, 9vw, 2.8rem); }
.study.revealed .rate { position: sticky; bottom: 0; z-index: 4; background: var(--paper); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 12px -10px var(--paper); }
.answer { display: grid; gap: 6px; text-align: center; padding: 14px 8px; }
.answer .py { font-size: 1.6rem; font-weight: 600; letter-spacing: 0.01em; }
.answer .mean { font-size: 1.05rem; color: var(--ink-2); max-width: 36ch; margin-inline: auto; }
.rate { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rate button {
  min-height: 64px; border-radius: var(--radius); border: 2px solid var(--line-strong); background: var(--surface);
  display: grid; align-content: center; gap: 0; cursor: pointer; font-weight: 650; font-size: 1.05rem;
}
.rate button small { font-weight: 500; font-size: 0.78rem; color: var(--ink-2); }
.rate button kbd { display: none; }
.rate .forgot { border-color: var(--seal); } .rate .forgot b { color: var(--seal); }
.rate .difficult { border-color: var(--amber); } .rate .difficult b { color: var(--amber); }
.rate .good { border-color: var(--jade); } .rate .good b { color: var(--jade); }
.rate .easy { border-color: var(--blue); } .rate .easy b { color: var(--blue); }
.rate button:hover { background: var(--sunken); }
.rate button b::before { margin-right: 6px; font-weight: 700; }
.rate .forgot b::before { content: "✕"; }
.rate .difficult b::before { content: "▲"; font-size: 0.8em; }
.rate .good b::before { content: "✓"; }
.rate .easy b::before { content: "✓✓"; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
details.note summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; color: var(--jade); font-weight: 600; }
textarea, input[type="text"], input[type="search"], input[type="date"], input[type="number"], select {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface);
}
textarea { min-height: 88px; resize: vertical; }
label.field { display: grid; gap: 6px; font-weight: 600; }
label.field .hint { font-weight: 400; color: var(--ink-2); font-size: 0.875rem; }
.kbd-hint { text-align: center; color: var(--ink-3); font-size: 0.8rem; }
@media (hover: none) { .kbd-hint { display: none; } }

/* ---------- library ---------- */
.search { position: sticky; top: 46px; z-index: 5; background: var(--paper); padding: 6px 0; display: grid; gap: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select { width: auto; min-width: 120px; }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { flex: 1; min-height: 44px; border: 0; background: var(--surface); cursor: pointer; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--jade); color: var(--jade-ink); }
.list { display: grid; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 14px; align-items: center;
  padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; width: 100%; min-height: 64px; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--sunken); }
.item .hz { font-size: 1.7rem; min-width: 2.2em; line-height: 1.2; }
.item .pm { font-weight: 600; }
.item .ml { grid-column: 1 / -1; font-size: 0.875rem; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tag {
  display: inline-block; font-size: 0.75rem; font-weight: 650; padding: 2px 8px; border-radius: 99px;
  background: var(--sunken); color: var(--ink-2); white-space: nowrap;
}
.tag.due { background: var(--seal-soft); color: var(--seal); }
.tag.stable { background: var(--jade-soft); color: var(--jade); }
.tag.learning { background: var(--amber-soft); color: var(--amber); }
.tag.lv { background: transparent; border: 1px solid var(--line-strong); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

dialog {
  border: 1px solid var(--line-strong); border-radius: 20px; padding: 0; background: var(--paper); color: var(--ink);
  width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 24px); overflow: auto; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.5);
}
dialog::backdrop { background: rgba(10, 18, 14, 0.55); }
.dlg { padding: 18px; display: grid; gap: 14px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.big-hz { font-family: var(--hanzi); font-size: 3.6rem; line-height: 1.15; letter-spacing: 0.1em; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 0.9rem; }
.facts dt { color: var(--ink-2); } .facts dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ---------- progress ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 2px; }
.tile b { font-size: 1.9rem; line-height: 1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--ink-2); font-size: 0.875rem; }
table.lv { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
table.lv th, table.lv td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.lv th:first-child, table.lv td:first-child { text-align: left; }
table.lv th { font-weight: 600; color: var(--ink-2); font-size: 0.8rem; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding-top: 8px; }
.bars div { flex: 1; display: grid; align-content: end; height: 100%; gap: 4px; justify-items: center; font-size: 0.7rem; color: var(--ink-3); }
.bars i { display: block; width: 100%; background: var(--jade); border-radius: 4px 4px 0 0; min-height: 2px; }
details.why { border-top: 1px solid var(--line); padding-top: 8px; }
details.why summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; font-weight: 600; color: var(--jade); }
details.why p, details.why li { color: var(--ink-2); font-size: 0.9rem; }
.check { display: flex; align-items: center; gap: 12px; min-height: var(--tap); }
.check input { width: 24px; height: 24px; accent-color: var(--jade); }
.phase-card { border-left: 4px solid var(--line-strong); padding-left: 12px; display: grid; gap: 2px; }
.phase-card.now { border-color: var(--seal); }
.err { color: var(--seal); font-weight: 600; }
ul.plain { margin: 0; padding-left: 1.1em; display: grid; gap: 4px; }
hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 0; }

#banners { position: sticky; top: 0; z-index: 20; display: grid; }
#banners .banner { padding: 10px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-size: 0.9rem; background: var(--blue-soft); }
#banners .banner.bad { background: var(--seal-soft); }
.center { text-align: center; }
.empty { text-align: center; padding: 28px 12px; display: grid; gap: 10px; justify-items: center; }
.noscript { padding: 20px; }

@media (min-width: 700px) {
  .rate { grid-template-columns: repeat(4, 1fr); }
  .rate button kbd { display: inline; font-size: 0.7rem; color: var(--ink-3); font-weight: 500; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .btn:active { transform: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .card-face.swap .word { animation: fadein 0.18s ease-out; }
  @keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
}

.top-actions { display: flex; align-items: center; gap: 4px; }
.lang { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.lang button { min-height: 40px; min-width: 44px; border: 0; background: transparent; cursor: pointer; font-weight: 650; font-size: 0.85rem; color: var(--ink-2); }
.lang button[aria-pressed="true"] { background: var(--jade); color: var(--jade-ink); }
.mean-en { font-size: 0.85rem; color: var(--ink-3); max-width: 40ch; margin-inline: auto; }
