/* 学 — ink on practice paper. One hero per screen: the character in its
   square. Red is the seal: the stamp on an answer, the Again grade, nothing
   else. Source Sans 3 is Adobe's Latin sibling of the Source Han / Noto CJK
   family the phone renders the characters with. */

@font-face { font-family: 'Source Sans 3'; font-weight: 300 700; font-display: swap; src: url(/fonts/source-sans-3-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Source Sans 3'; font-weight: 300 700; font-display: swap; src: url(/fonts/source-sans-3-latin-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

/* Tokens. Paper ground, soft surfaces, ink text. The seal red is the accent:
   primary actions, progress, the active tab. Grade buttons carry muted Anki
   tints so the hand finds them without reading. */
:root {
  --paper: #ECEEE9;
  --surface: #F7F8F5;
  --surface-2: #E0E4DE;
  --ink: #1C1E1D;
  --mist: #666C67;
  --grid: #CAD0CA;
  --accent: #B8321F;
  --on-accent: #FBF7F4;
  --seal: #B8321F;
  --seal-ink: #FBF7F4;
  --again-bg: #F4DCD7; --again-fg: #8E2416;
  --hard-bg: #F3E5C8;  --hard-fg: #7A4E0E;
  --good-bg: #DAE9D6;  --good-fg: #23592A;
  --easy-bg: #D6E4ED;  --easy-fg: #1E4A66;
  --latin: 'Source Sans 3', 'Segoe UI', Roboto, system-ui, sans-serif;
  --cjk: 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Noto Sans SC', 'Source Han Sans SC', 'Microsoft YaHei', 'Droid Sans Fallback', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --paper: #151816; --surface: #1F2320; --surface-2: #2B302C; --ink: #E8EAE5; --mist: #9AA09B; --grid: #353B36; --accent: #D3492F; --seal: #D3492F; --seal-ink: #151816;
    --again-bg: #3B1F1A; --again-fg: #F0A597; --hard-bg: #3A2E16; --hard-fg: #E8C27A; --good-bg: #1E3220; --good-fg: #9FD3A4; --easy-bg: #1B2E3A; --easy-fg: #9CC7E3; color-scheme: dark; }
}
:root[data-theme="dark"] { --paper: #151816; --surface: #1F2320; --surface-2: #2B302C; --ink: #E8EAE5; --mist: #9AA09B; --grid: #353B36; --accent: #D3492F; --seal: #D3492F; --seal-ink: #151816;
  --again-bg: #3B1F1A; --again-fg: #F0A597; --hard-bg: #3A2E16; --hard-fg: #E8C27A; --good-bg: #1E3220; --good-fg: #9FD3A4; --easy-bg: #1B2E3A; --easy-fg: #9CC7E3; color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--latin); font-size: 16px; line-height: 1.45; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 600; margin: 20px 0 8px; }
p { margin: 0 0 10px; }
.mist { color: var(--mist); }
.small { font-size: 13.5px; }
.zh { font-family: var(--cjk); }
.hidden { display: none !important; }
a { color: inherit; }

/* no min-height: in an installed Android PWA 100vh exceeds the visible area and forces a scroll */
#app { max-width: 560px; margin: 0 auto; padding: 12px 14px calc(72px + env(safe-area-inset-bottom)); }

/* ---- tab bar ---- */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--grid); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
#tabs button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 0; color: var(--mist); font-size: 11.5px; }
#tabs button .glyph { font-family: var(--cjk); font-size: 21px; line-height: 1.1; }
#tabs button.on { color: var(--accent); }
#tabs em { font-style: normal; font-size: 10.5px; margin-left: 4px; padding: 0 5px; border-radius: 8px; background: var(--accent); color: var(--on-accent); vertical-align: 1px; }
@media (min-width: 640px) { #tabs { max-width: 560px; margin: 0 auto; border-left: 1px solid var(--grid); border-right: 1px solid var(--grid); } }

/* ---- buttons: one system. 48 primary/secondary, 36 inline ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 18px; border-radius: 12px; border: 0; background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 16px; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.quiet { background: transparent; color: var(--mist); border: 1px solid var(--grid); font-weight: 500; }
.btn.wide { width: 100%; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active { filter: brightness(0.94); }
.btn:focus-visible, .input:focus-visible, .chip:focus-visible, #tabs button:focus-visible, .grade:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.rowbtns { display: flex; gap: 8px; }
.rowbtns .btn { flex: 1; padding: 0 10px; }
.rowbtns.wrap { display: grid; grid-template-columns: 1fr 1fr; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; font-size: 15px; }

/* ---- inputs: same height as buttons ---- */
.input { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--grid); border-radius: 12px; background: var(--surface); font-size: 16px; min-width: 0; }
.input::placeholder { color: var(--mist); }
.input.hanzi-input { font-family: var(--cjk); font-size: 28px; text-align: center; height: 60px; }
textarea.input { height: auto; padding: 10px 14px; resize: vertical; line-height: 1.4; font-family: var(--latin); }
textarea.hanzi-area { font-family: var(--cjk); font-size: 20px; }
label { display: block; font-size: 15px; margin-bottom: 4px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper .btn { width: 48px; padding: 0; font-size: 22px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---- selects, switches, segmented controls, setting rows ---- */
.select { appearance: none; -webkit-appearance: none; width: 100%; height: 44px; padding: 0 36px 0 14px; border-radius: 12px; border: 1px solid var(--grid); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23666C67' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center; font-size: 15px; color: var(--ink); }
:root[data-theme="dark"] .select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%239AA09B' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%239AA09B' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); } }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 6px; }
.switch { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--surface-2); position: relative; flex: none; margin: 0; cursor: pointer; transition: background 0.15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--mist); font-weight: 500; font-size: 15px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); font-weight: 600; }
.group { background: var(--surface); border-radius: 16px; padding: 2px 16px; margin-bottom: 10px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 54px; padding: 6px 0; border-bottom: 1px solid var(--grid); }
.setting:last-child { border-bottom: 0; }
.setting .lbl { flex: 1; font-size: 16px; }
.setting .lbl small { display: block; color: var(--mist); font-size: 13px; }
.setting .seg { width: 210px; flex: none; }
.setting .stepper { gap: 6px; }
.setting .stepper .btn { width: 40px; height: 40px; font-size: 20px; border-radius: 10px; }
.setting .stepper .val { min-width: 32px; text-align: center; font-weight: 600; font-size: 18px; }
.group-title { font-size: 13.5px; font-weight: 600; color: var(--mist); margin: 18px 4px 6px; }
.topbar { display: flex; align-items: center; gap: 8px; height: 44px; margin: -2px 0 6px; }
.topbar .btn { padding: 0 12px 0 6px; }
.topbar svg { width: 20px; height: 20px; }

/* ---- sections as soft surfaces ---- */
.block { background: var(--surface); border-radius: 16px; padding: 16px; margin-bottom: 10px; }
.block .block { padding: 0; margin: 0; background: none; }
.block > h1:first-child, .block > h2:first-child { margin-top: 0; }
.block .input { background: var(--paper); }
.block .btn:not(.primary) { background: var(--surface-2); }

/* ---- the practice squares ---- */
.hanzi { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0; --sq: 150px; }
.tian { width: var(--sq); height: var(--sq); display: flex; align-items: center; justify-content: center; border: 1.5px solid var(--grid); border-radius: 8px; background: var(--surface); font-family: var(--cjk); font-size: calc(var(--sq) * 0.66); line-height: 1; color: var(--ink);
  background-image:
    linear-gradient(to right, transparent calc(50% - 0.5px), color-mix(in srgb, var(--grid) 60%, transparent) calc(50% - 0.5px), color-mix(in srgb, var(--grid) 60%, transparent) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), color-mix(in srgb, var(--grid) 60%, transparent) calc(50% - 0.5px), color-mix(in srgb, var(--grid) 60%, transparent) calc(50% + 0.5px), transparent calc(50% + 0.5px)); }
.hanzi.wrong .tian { border-color: var(--seal); }

.card { text-align: center; padding-top: 8px; }
.card .py { font-size: 24px; margin: 2px 0 4px; letter-spacing: 0.01em; }
.card .m { font-size: 18px; margin: 0 0 6px; }
.card .alt { font-size: 14px; color: var(--mist); }
.card .prompt { font-size: 22px; margin: 18px 0 16px; font-weight: 600; }
.card .hint { font-size: 14px; color: var(--mist); margin-bottom: 8px; }
.card .meta { font-size: 13px; color: var(--mist); margin-top: 14px; }
.ex { display: flex; flex-direction: column; gap: 1px; font-size: 14.5px; margin: 6px 0 4px; }
.ex .zh { font-size: 19px; }
.card .ex { align-items: center; }

.seal { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 6px; background: var(--seal); color: var(--seal-ink); font-family: var(--cjk); font-size: 20px; line-height: 1; vertical-align: middle; margin-left: 10px; animation: stamp 140ms ease-out; }
@keyframes stamp { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .seal { animation: none; } }

/* ---- grades ---- */
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; }
.grade { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 62px; padding: 8px 4px; border: 0; border-radius: 12px; background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 15px; }
.grade small { font-weight: 500; font-size: 12.5px; opacity: 0.75; }
.grade[data-r="1"] { background: var(--again-bg); color: var(--again-fg); }
.grade[data-r="2"] { background: var(--hard-bg); color: var(--hard-fg); }
.grade[data-r="3"] { background: var(--good-bg); color: var(--good-fg); }
.grade[data-r="4"] { background: var(--easy-bg); color: var(--easy-fg); }
.grade.suggested { box-shadow: inset 0 0 0 2px currentColor; }
.grade:active { filter: brightness(0.94); }

.progress { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--mist); margin-bottom: 4px; }
.bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-bottom: 14px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* ---- lists ---- */
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--grid); text-align: left; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; }
.row:last-child { border-bottom: 0; }
.row .zh { font-size: 23px; min-width: 2.2em; }
.row .body { flex: 1; min-width: 0; }
.row .body .py { color: var(--mist); font-size: 14px; }
.row .body .m { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.row .tail { font-size: 13px; color: var(--mist); text-align: right; white-space: nowrap; }
.row .btn { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.chip { height: 34px; padding: 0 13px; border-radius: 17px; border: 0; background: var(--surface-2); font-size: 14px; color: var(--ink); }
.chip.on { background: var(--accent); color: var(--on-accent); }

table.plain { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.plain th { text-align: left; font-weight: 600; color: var(--mist); padding: 6px 0; border-bottom: 1px solid var(--grid); }
table.plain td { padding: 7px 0; border-bottom: 1px solid var(--grid); }
table.plain td.num, table.plain th.num { text-align: right; }

.big { font-size: 40px; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.figures { display: flex; gap: 20px; flex-wrap: wrap; }
.figures div span { display: block; font-size: 26px; font-weight: 600; line-height: 1.1; color: var(--ink); }
.figures div span.hot { color: var(--accent); }
.figures div { font-size: 13.5px; color: var(--mist); }

/* ---- reader ---- */
.reader { font-size: 24px; line-height: 1.9; margin: 8px 0 4px; letter-spacing: 0.02em; }
.reader .tok { cursor: pointer; border-bottom: 1.5px solid transparent; padding: 0 1px 1px; border-radius: 4px; }
.reader .tok.tapped { border-bottom-color: var(--seal); }
.reader .tok.open { background: var(--surface-2); border-bottom-color: transparent; }
.gloss-box { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 6px 0 10px; border-radius: 12px; background: var(--surface-2); font-size: 15px; }
.gloss-box .big { font-size: 26px; }
.gloss-box .py { color: var(--mist); }
.gloss-box .tail { margin-left: auto; color: var(--mist); font-size: 13px; }
.gloss-box .btn { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.gloss-box .close { background: none; border: 0; color: var(--mist); font-size: 22px; line-height: 1; padding: 0 2px 2px; }

.login { padding-top: 18vh; display: flex; flex-direction: column; gap: 14px; }
.login .mark { font-family: var(--cjk); font-size: 96px; line-height: 1; margin-bottom: 8px; color: var(--accent); text-align: center; }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 9px 14px; border-radius: 10px; font-size: 14px; max-width: 90vw; z-index: 5; }
.note { font-size: 14px; color: var(--mist); }
.done { text-align: center; padding: 40px 0; }
.done .zh { font-size: 64px; line-height: 1; margin-bottom: 14px; color: var(--accent); }
