/* ============================================================
   Zhongwen Study — styles (sidebar layout, based on Hangul Study)
   ============================================================ */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --text: #1c1e26;
  --muted: #6b7180;
  --border: #e2e5ee;
  --accent: #3b5bdb;
  --accent-soft: #e7ecfd;
  --good: #2b8a3e;
  --good-soft: #e6f4ea;
  --bad: #c92a2a;
  --bad-soft: #fcebec;
  --np: #be185d;
  --np-bg: #fdf2f8;
  --shadow: 0 1px 3px rgba(20, 22, 40, .06), 0 6px 20px rgba(20, 22, 40, .05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --zh-font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --np-font: "Noto Sans Devanagari", "Kohinoor Devanagari", "Nirmala UI", var(--font);
  /* analyzer category colors */
  --c-subj:#2563eb; --c-topic:#0891b2; --c-obj:#d97706; --c-loc:#059669; --c-part:#4d7c0f;
  --c-conn:#e11d48; --c-tense:#ea580c; --c-mod:#c026d3; --c-final:#475569;
  --c-stemv:#7c3aed; --c-stemn:#334155; --c-adv:#0f766e; --c-other:#6b7280;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14151a; --surface: #1e2027; --surface-2: #262933; --text: #e8eaf0;
    --muted: #9aa0ad; --border: #2e313b; --accent: #748ffc; --accent-soft: #28304a;
    --good: #51cf66; --good-soft: #1c3025; --bad: #ff8787; --bad-soft: #3a2326;
    --np: #f9a8d4; --np-bg: #2a1220;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
    --c-subj:#60a5fa; --c-topic:#22d3ee; --c-obj:#fbbf24; --c-loc:#34d399; --c-part:#a3e635;
    --c-conn:#fb7185; --c-tense:#fb923c; --c-mod:#e879f9; --c-final:#94a3b8;
    --c-stemv:#a78bfa; --c-stemn:#cbd5e1; --c-adv:#5eead4; --c-other:#9ca3af;
  }
}
:root[data-theme="dark"] {
  --bg: #14151a; --surface: #1e2027; --surface-2: #262933; --text: #e8eaf0;
  --muted: #9aa0ad; --border: #2e313b; --accent: #748ffc; --accent-soft: #28304a;
  --good: #51cf66; --good-soft: #1c3025; --bad: #ff8787; --bad-soft: #3a2326;
  --np: #f9a8d4; --np-bg: #2a1220;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  --c-subj:#60a5fa; --c-topic:#22d3ee; --c-obj:#fbbf24; --c-loc:#34d399; --c-part:#a3e635;
  --c-conn:#fb7185; --c-tense:#fb923c; --c-mod:#e879f9; --c-final:#94a3b8;
  --c-stemv:#a78bfa; --c-stemn:#cbd5e1; --c-adv:#5eead4; --c-other:#9ca3af;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.np { font-family: var(--np-font); color: var(--np); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 16px 12px 28px;
  z-index: 40;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 1.12rem; letter-spacing: -.01em;
  padding: 6px 8px 14px;
}
.sb-brand .logo {
  font-size: 1.3rem; background: var(--accent-soft); color: var(--accent);
  border-radius: 10px; width: 36px; height: 36px; display: grid; place-items: center; flex: none;
}
.sb-group { margin-top: 14px; }
.sb-group h4 {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); margin: 0 0 6px; padding: 0 10px; font-weight: 700;
}
.sb-link {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: none; background: transparent; color: var(--text);
  font-family: inherit; font-size: .94rem; font-weight: 600;
  padding: 9px 10px; border-radius: 10px; cursor: pointer; text-align: left;
}
.sb-link .ic { width: 20px; text-align: center; flex: none; font-size: 1rem; }
.sb-link:hover { background: var(--surface-2); }
.sb-link.active { background: var(--accent); color: #fff; }
.sb-foot { margin-top: 22px; padding: 0 10px; color: var(--muted); font-size: .75rem; }

/* Main column */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.hamburger {
  display: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); width: 38px; height: 38px; border-radius: 10px;
  font-size: 1.1rem; cursor: pointer; flex: none;
}
.topbar .title { font-weight: 700; margin-right: auto; }
.theme-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; width: 38px; height: 38px; font-size: 1.1rem; cursor: pointer; flex: none;
}
.theme-btn:hover { background: var(--surface-2); }
.topbar { position: sticky; }
.voice-pop {
  position: absolute; top: calc(100% + 6px); right: 12px; z-index: 50;
  width: min(330px, calc(100vw - 24px)); padding: 14px; display: grid; gap: 6px;
}
.voice-pop[hidden] { display: none; }
.vp-h { font-weight: 800; }
.vp-l { font-size: .78rem; font-weight: 700; color: var(--muted); margin-top: 4px; }
.vp-l span { color: var(--accent); }
.vp-sel { width: 100%; text-align: left; }
.voice-pop input[type=range] { width: 100%; accent-color: var(--accent); }
.voice-pop #voiceTest { justify-self: start; margin-top: 2px; }
.vp-more { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.vp-more summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.vp-more ul { padding-left: 18px; margin: 6px 0; }
.vp-more li { margin-bottom: 4px; }
.vp-more p { margin: 0; }

main.content { max-width: 960px; width: 100%; margin: 0 auto; padding: 22px 16px 80px; }
.scrim {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .hamburger { display: grid; place-items: center; }
  .scrim.show { display: block; }
}

/* ---------- Views & typography ---------- */
section.view { display: none; animation: fade .25s ease; }
section.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
h1 { font-size: 1.6rem; margin: .2em 0 .1em; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; margin: 1.6em 0 .6em; }
h3 { font-size: 1rem; }
.lede { color: var(--muted); margin: 0 0 1.2em; }
.hint { color: var(--muted); font-size: .9rem; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}

/* Home */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-top: 18px; }
.home-card { text-align: left; cursor: pointer; font-family: inherit; color: inherit; }
.home-card:hover { border-color: var(--accent); transform: translateY(-2px); transition: .15s; }
.home-card .big { font-size: 1.8rem; }
.home-card h3 { margin: .4em 0 .2em; font-size: 1.05rem; }
.home-card p { margin: 0; color: var(--muted); font-size: .9rem; }

/* Letter grids */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
.letter { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 6px 8px; text-align: center; cursor: pointer; transition: .12s; }
.letter:hover { border-color: var(--accent); background: var(--accent-soft); }
.letter .glyph { font-size: 2rem; line-height: 1.1; font-weight: 600; }
.letter .rom { font-size: .82rem; color: var(--accent); font-weight: 700; }
.letter .name { font-size: .68rem; color: var(--muted); }

/* Flashcards */
.fc-stage { display: grid; place-items: center; gap: 16px; margin-top: 10px; }
.flashcard { width: 100%; max-width: 320px; aspect-ratio: 3 / 2; perspective: 1000px; cursor: pointer; }
.fc-inner { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); display: grid; place-items: center; text-align: center; padding: 10px; }
.fc-face .glyph { font-size: 4.5rem; font-weight: 600; }
.fc-back { transform: rotateY(180deg); }
.fc-back .rom { font-size: 2.2rem; font-weight: 800; color: var(--accent); }
.fc-back .note { color: var(--muted); font-size: .95rem; margin-top: 6px; max-width: 240px; }
.fc-controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.fc-progress { color: var(--muted); font-size: .9rem; }

/* Quiz */
.quiz-prompt { font-size: 3.4rem; text-align: center; font-weight: 600; margin: 8px 0 4px; }
.quiz-sub { text-align: center; color: var(--muted); margin-bottom: 14px; }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { padding: 16px; font-size: 1.3rem; font-weight: 700; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); cursor: pointer; font-family: inherit; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.correct { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.opt:disabled { cursor: default; }
.scorebar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--muted); font-size: .92rem; }

/* Reading */
.word-list { display: grid; gap: 12px; }
.word { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.word .ko { font-size: 2.1rem; font-weight: 600; cursor: pointer; }
.word .meta { flex: 1; min-width: 160px; }
.word .meta .rom { color: var(--accent); font-weight: 700; }
.word .meta .mean { color: var(--muted); }
.syllables { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; width: 100%; }
.syl { background: var(--surface-2); border-radius: 10px; padding: 6px 10px; text-align: center; font-size: .85rem; }
.syl .block { font-size: 1.5rem; font-weight: 600; }
.syl .parts { color: var(--muted); letter-spacing: .05em; }

/* Buttons */
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); font-family: inherit; font-weight: 600; font-size: .92rem; padding: 9px 16px; border-radius: 10px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding: 6px 11px; font-size: .84rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: var(--surface); color: var(--muted); padding: 8px 14px; font-family: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; }
.seg button.active { background: var(--accent); color: #fff; }

.chip {
  --c: var(--c-other);
  display: inline-flex; align-items: center; gap: 4px; border-radius: 6px;
  padding: 1px 8px; font-size: .78rem; font-weight: 700; color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 38%, transparent); white-space: nowrap; line-height: 1.6;
}
.cat-subj{--c:var(--c-subj)} .cat-topic{--c:var(--c-topic)} .cat-obj{--c:var(--c-obj)} .cat-loc{--c:var(--c-loc)}
.cat-part{--c:var(--c-part)} .cat-conn{--c:var(--c-conn)} .cat-tense{--c:var(--c-tense)} .cat-mod{--c:var(--c-mod)}
.cat-final{--c:var(--c-final)} .cat-stemv{--c:var(--c-stemv)} .cat-stemn{--c:var(--c-stemn)} .cat-adv{--c:var(--c-adv)} .cat-other{--c:var(--c-other)}
/* ---------- Grammar section ---------- */
.gr-toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 18px; }
.gr-toc button { font-size: .82rem; }
.gr-sec { margin-bottom: 14px; }
.gr-sec > summary {
  cursor: pointer; list-style: none; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-weight: 700; display: flex; align-items: center; gap: 10px;
}
.gr-sec > summary::-webkit-details-marker { display: none; }
.gr-sec > summary::before { content: "▸"; color: var(--accent); transition: transform .2s; }
.gr-sec[open] > summary::before { transform: rotate(90deg); }
.gr-sec > summary .gr-np { color: var(--np); font-weight: 600; font-size: .9rem; }
.gr-body { padding: 10px 2px 4px; }
.gr-formula { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 10px 14px; margin: 10px 0; font-size: .92rem; }
.gr-formula .np { display: block; margin-top: 3px; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; margin: 10px 0; }
table.gr-tbl { border-collapse: collapse; width: 100%; font-size: .88rem; min-width: 420px; }
table.gr-tbl th { background: var(--surface-2); text-align: left; padding: 8px 10px; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border); }
table.gr-tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.gr-tbl td.ko { font-size: 1.05rem; font-weight: 600; }
table.gr-tbl .np { font-weight: 600; }

.ex { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 12px 0; background: var(--surface); }
.ex-title { font-weight: 700; margin-bottom: 8px; }
.ex-row { display: grid; grid-template-columns: 92px 1fr; gap: 3px 10px; font-size: .92rem; align-items: baseline; }
.ex-row dt { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; }
.ex-row dd { margin: 0; }
.ex-row dd.ko { font-size: 1.15rem; font-weight: 600; }
.ex-row dd.np { font-weight: 600; }
.ex-break { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; margin-top: 8px; font-size: .88rem; }

.tip { border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; padding: 10px 14px; margin: 12px 0; font-size: .9rem; }

/* ---------- Daily practice ---------- */
.daily-tabs { display: flex; flex-wrap: wrap; gap: 6px; border: none; margin: 10px 0 4px; }
.daily-tab {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-family: inherit; font-weight: 600;
  font-size: .9rem; padding: 8px 14px; border-radius: 999px; cursor: pointer; position: relative;
}
.daily-tab:hover { color: var(--text); }
.daily-tab .ko { font-weight: 700; }
.daily-tab.active { background: var(--accent); color: #fff; border-color: transparent; }
.daily-tab.now::after {
  content: "now"; position: absolute; top: -7px; right: -4px; font-size: .58rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em; background: var(--good); color: #fff;
  padding: 1px 6px; border-radius: 999px;
}
.daily-h { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; margin: 18px 0 8px; }
.daily-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.daily-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; cursor: pointer; transition: border-color .12s;
}
.daily-item:hover { border-color: var(--accent); }
.daily-item .ko { font-size: 1.25rem; font-weight: 600; }
.daily-item .rom { font-size: .76rem; color: var(--muted); font-style: italic; }
.daily-item .np { font-size: .86rem; color: var(--np); font-weight: 600; }
.daily-item .en { font-size: .86rem; color: var(--muted); }
.phrase-list { display: grid; gap: 8px; }

.convo { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.turn { max-width: 80%; padding: 9px 13px; border-radius: 14px; cursor: pointer; }
.turn.a { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.turn.b { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.turn .ko { font-size: 1.1rem; font-weight: 600; }
.turn .rom { font-size: .74rem; color: var(--muted); font-style: italic; }
.turn .np { font-size: .84rem; color: var(--np); font-weight: 600; }
.turn .en { font-size: .82rem; color: var(--muted); }
body.hide-rom .daily-item .rom, body.hide-rom .turn .rom { display: none; }


footer { max-width: 960px; margin: 0 auto; padding: 24px 16px 40px; color: var(--muted); font-size: .85rem; text-align: center; }

@media (max-width: 480px) {
  .fc-face .glyph { font-size: 3.6rem; }
  .quiz-prompt { font-size: 2.8rem; }
  .ex-row { grid-template-columns: 1fr; }
  .ex-row dt { margin-top: 4px; }
}

/* ---------- Sentence Builder ---------- */
.sb-controls { margin: 10px 0; }
.sb-select { max-width: 100%; flex: 1 1 220px; min-width: 0; text-overflow: ellipsis; }
#sbMode { flex-wrap: wrap; }
.sb-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.sb-leg { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--border); border-left: 4px solid var(--c); border-radius: 10px; padding: 8px 10px; background: var(--surface); }
.sb-leg > b { font-size: 1.3rem; color: var(--c); line-height: 1.2; }
.sb-leg .nm { font-weight: 700; font-size: .92rem; }
.sb-leg .hint { font-size: .82rem; word-break: keep-all; overflow-wrap: break-word; }
.sb-legend-note { margin: 10px 2px 0; word-break: keep-all; }

.sb-en { font-size: 1.25rem; font-weight: 600; line-height: 2.1; margin: 4px 0 14px; }
.sb-en.plain { color: var(--muted); font-size: 1.05rem; line-height: 1.5; }
.sb-chunk { display: inline; padding: 2px 6px; border-radius: 6px; transition: background .2s, box-shadow .2s; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.sb-chunk.lit { background: color-mix(in srgb, var(--c) 16%, transparent); box-shadow: inset 0 -3px 0 var(--c); }
.sb-chunk sub { font-size: .62rem; font-weight: 800; color: var(--c); margin-left: 3px; vertical-align: baseline; }
.sb-chunk.focus { background: color-mix(in srgb, var(--c) 32%, transparent); }

.sb-board { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.sb-col { display: flex; flex-direction: column; border-left: 1px solid var(--border); min-width: 0; transition: box-shadow .2s, background .2s; }
.sb-col:first-child { border-left: 0; }
.sb-head { background: color-mix(in srgb, var(--c) 16%, var(--surface)); border-bottom: 3px solid var(--c); padding: 8px 8px 6px; text-align: center; }
.sb-head b { display: block; font-size: 1.3rem; color: var(--c); line-height: 1.1; }
.sb-head .nm { display: block; font-size: .74rem; font-weight: 700; }
.sb-head small { display: block; font-size: .7rem; color: var(--muted); }
.sb-cell { flex: 1; min-height: 116px; padding: 12px 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px; word-break: keep-all; overflow-wrap: anywhere; }
.sb-col.focus, .sb-col[data-asking] { background: color-mix(in srgb, var(--c) 9%, transparent); box-shadow: inset 0 0 0 2px var(--c); }
.sb-ko { font-size: 1.35rem; font-weight: 700; line-height: 1.3; }
.sb-hear { cursor: pointer; border-radius: 8px; padding: 2px 6px; transition: background .15s; }
.sb-hear:hover, .sb-hear:focus-visible { background: color-mix(in srgb, var(--c, var(--accent)) 12%, transparent); outline: none; }
.sb-hear:active { transform: scale(.97); }
.sb-spk { font-size: .62em; margin-left: 5px; opacity: .45; vertical-align: middle; }
.sb-hear:hover .sb-spk { opacity: .9; }
.sb-rom { font-size: .76rem; color: var(--muted); font-style: italic; }
.sb-np { font-size: .84rem; font-weight: 600; }
.sb-q { font-size: 1.8rem; color: var(--border); font-weight: 800; }
.sb-x { font-size: 2.6rem; line-height: 1; color: var(--muted); font-weight: 300; }
.sb-note { font-size: .76rem; color: var(--muted); }
.sb-note .ko { font-weight: 700; color: var(--text); }
.sb-adv { display: flex; flex-direction: column; align-items: center; gap: 1px; padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px dashed var(--border); }
.sb-adv .sb-ko { font-size: 1.05rem; color: var(--c-adv); }
.sb-placed { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-bottom: 4px; }
.sb-placed .sb-chunk { font-size: .85rem; font-weight: 600; }

.sb-say { margin-top: 14px; padding: 10px 14px; border-radius: 0 10px 10px 0; border-left: 3px solid var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 9%, var(--surface)); font-size: .95rem; }
.sb-say .ko, .sb-ask .ko, .sb-feed .ko { font-size: 1.05em; }
.sb-step { display: block; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--c, var(--accent)); }
.sb-nav { margin-top: 12px; }
.btn:disabled { opacity: .45; cursor: default; }

.sb-info { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin-top: 14px; }
.sb-pattern, .sb-dict { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; background: var(--surface); }
.sb-pattern { border: 2px solid var(--c-stemv); }
.sb-tag { display: inline-block; font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sb-pattern .sb-tag { background: color-mix(in srgb, var(--c-stemv) 15%, transparent); color: var(--c-stemv); border-radius: 4px; padding: 0 6px; }
.sb-pattern .form, .sb-dict .form { font-size: 1.3rem; font-weight: 800; }
.sb-pattern .mean, .sb-dict .mean { font-weight: 600; }
.sb-pattern .how { color: var(--muted); font-size: .86rem; margin-top: 4px; }
.sb-full { margin-top: 12px; box-shadow: none; }
.sb-full-ko { font-size: 1.45rem; font-weight: 700; }
.sb-full-np { display: inline-block; font-weight: 600; background: var(--np-bg); border-radius: 8px; padding: 2px 10px; margin: 2px 0; }
.sb-full-en { color: var(--muted); }

.sb-instr { margin: 0 0 6px; }
.sb-pool { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; min-height: 44px; }
.sb-pick { font-family: inherit; font-size: 1rem; font-weight: 600; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: grab; touch-action: manipulation; }
.sb-pick:hover { border-color: var(--accent); }
.sb-pick.sel { background: var(--accent); color: #fff; border-color: transparent; box-shadow: 0 0 0 3px var(--accent-soft); }
.sb-board.clickable .sb-col { cursor: pointer; }
.sb-board.clickable .sb-col:hover, .sb-col.over { background: color-mix(in srgb, var(--c) 10%, transparent); }
.sb-col.shake { animation: sbShake .35s; box-shadow: inset 0 0 0 2px var(--bad); }
@keyframes sbShake { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.sb-feed { min-height: 1.6em; margin: 10px 0; font-size: .95rem; }
.sb-feed.good { color: var(--good); }
.sb-feed.bad { color: var(--bad); }

.sb-ask { margin: 14px 0 8px; font-weight: 600; }
.sb-key { color: var(--c); font-size: 1.15rem; }
.sb-opts .opt { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 1.15rem; padding: 12px 10px; }
.sb-opts .opt .sb-rom { font-size: .74rem; font-weight: 400; }
.sb-opts .opt.wrong .sb-rom { color: inherit; }
.sb-opts { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* Longer sentences: a numbered row of slots that wraps */
.sb-slots { display: flex; flex-wrap: wrap; gap: 8px; }
.sb-slot { flex: 1 1 118px; min-width: 0; border: 1px solid var(--border); border-top: 3px solid var(--c); border-radius: 10px; background: var(--surface); overflow: hidden; transition: box-shadow .2s; }
.sb-slot.focus { box-shadow: 0 0 0 2px var(--c); }
.sb-slot-h { display: flex; align-items: baseline; gap: 5px; padding: 5px 8px; background: color-mix(in srgb, var(--c) 14%, var(--surface)); font-size: .74rem; }
.sb-slot-h .n { font-weight: 800; color: var(--muted); font-size: .68rem; }
.sb-slot-h b { color: var(--c); font-size: .9rem; }
.sb-slot-h .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-slot-b { padding: 8px 6px 10px; min-height: 84px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; word-break: keep-all; overflow-wrap: anywhere; }
.sb-slot-b .sb-ko { font-size: 1.15rem; }

/* Phones: columns become rows, still read top → bottom in S · W · O · V order */
@media (max-width: 640px) {
  .sb-board { grid-template-columns: 1fr; }
  .sb-col { flex-direction: row; border-left: 0; border-top: 1px solid var(--border); }
  .sb-col:first-child { border-top: 0; }
  .sb-head { width: 92px; flex: none; border-bottom: 0; border-right: 3px solid var(--c); display: flex; flex-direction: column; justify-content: center; }
  .sb-cell { min-height: 72px; align-items: flex-start; text-align: left; padding: 10px 12px; }
  .sb-adv { align-items: flex-start; }
  .sb-placed { justify-content: flex-start; }
  .sb-x { font-size: 1.8rem; }
  .sb-info { grid-template-columns: 1fr; }
  .sb-en { font-size: 1.1rem; }
  .sb-head { width: 96px; padding: 8px 6px; }
  .sb-head small { display: none; }
  .sb-head .nm { font-size: .7rem; line-height: 1.3; }
  #sbMode { display: flex; width: 100%; }
  #sbMode { flex-wrap: wrap; }
  #sbMode button { flex: 1 1 45%; padding: 8px 6px; font-size: .82rem; }
  .sb-slot { flex-basis: 140px; }
  .sb-select { flex-basis: 150px; }
  #sbStage { padding: 14px; }
}

/* ============================================================
   Zhongwen Study additions
   ============================================================ */
/* Tone colours (1 red · 2 green · 3 blue · 4 purple · neutral grey) */
:root { --t1: #e03131; --t2: #2f9e44; --t3: #1c7ed6; --t4: #9c36b5; --t5: #868e96;
  --py-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
:root[data-theme="dark"] { --t1: #ff8787; --t2: #69db7c; --t3: #74c0fc; --t4: #e599f7; --t5: #adb5bd; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --t1: #ff8787; --t2: #69db7c; --t3: #74c0fc; --t4: #e599f7; --t5: #adb5bd; } }
.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); } .t4 { color: var(--t4); } .t5 { color: var(--t5); }
body.no-tone-colors .t1, body.no-tone-colors .t2, body.no-tone-colors .t3, body.no-tone-colors .t4, body.no-tone-colors .t5 { color: inherit; }
body.hide-np .np-line, body.hide-np .sb-np, body.hide-np .sb-full-np { display: none; }
.zh, .ch-card .ch, .fc-front .glyph, .sb-ko, .sb-full-ko { font-family: var(--zh-font); }
/* Pinyin uses a Latin system font so tone marks (ā á ǎ à) sit right on the letters. */
.pyw, .tc-py, .py-k, .fc-back .rom, .opt { font-family: var(--py-font); }
.opt .zh { font-family: var(--zh-font); }

.toggles { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 10px; }

/* Tones */
.tone-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.tone-card { cursor: pointer; text-align: center; padding: 14px 10px; border-top: 4px solid currentColor; }
.tone-card:hover { border-color: currentColor; background: var(--accent-soft); }
.tone-card .tc-py { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.tone-card .tc-zh { font-size: 1.4rem; font-weight: 600; color: var(--text); }
.tone-card .tc-name { font-weight: 700; color: var(--text); margin-top: 4px; }
.tone-card .tc-how { font-size: .84rem; color: var(--muted); }
.tone-card svg { display: block; margin: 4px auto 0; }

/* Pinyin sound grids */
.py-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.py-cell { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; cursor: pointer; transition: .12s; }
.py-cell:hover { border-color: var(--accent); background: var(--accent-soft); }
.py-cell .py-k { font-size: 1.5rem; font-weight: 800; color: var(--accent); line-height: 1.2; }
.py-cell .py-k .np { font-size: .9rem; font-weight: 600; margin-left: 6px; }
.py-cell .py-n { font-size: .8rem; color: var(--muted); }
.py-cell .py-ex { font-size: .92rem; margin-top: 3px; }
.py-cell .py-ex .zh { font-size: 1.15rem; font-weight: 600; margin-right: 4px; }
.rule-ex { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.rule-ex .py-cell { flex: 1 1 140px; }

/* Character grid */
.ch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.ch-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 8px 8px; text-align: center; cursor: pointer; transition: .12s; }
.ch-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.ch-card .ch { font-size: 2.4rem; line-height: 1.15; font-weight: 600; }
.ch-card .py { font-weight: 700; }
.ch-card .np { font-size: .8rem; font-weight: 600; }
.ch-card .en { font-size: .78rem; color: var(--muted); line-height: 1.3; }
.ch-card .meta { display: flex; justify-content: center; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.ch-card .meta span { font-size: .68rem; background: var(--surface-2); border-radius: 6px; padding: 0 6px; color: var(--muted); }
.ch-card .meta b { color: var(--text); font-weight: 700; }
.ch-filter { margin: 8px 0 14px; }
.seg.wrap { display: flex; flex-wrap: wrap; gap: 6px; border: none; overflow: visible; }
.seg.wrap button { border: 1px solid var(--border); border-radius: 999px; }
.seg.wrap button:hover:not(.active) { color: var(--text); }

/* Flashcard back for characters */
.fc-back .np { font-size: 1rem; font-weight: 600; }
.fc-back .en { font-size: 1.05rem; margin-top: 4px; }
.fc-back .meta { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.quiz-prompt .small { display: block; font-size: 1rem; color: var(--muted); font-weight: 400; }
.opt .zh { font-size: 1.6rem; }
.opt.small-text { font-size: 1rem; font-weight: 600; }

/* Daily practice: Chinese lines */
.daily-item .zh, .turn .zh { font-size: 1.25rem; font-weight: 600; }
.daily-item .py, .turn .py { font-size: .84rem; font-weight: 600; }
body.hide-py .daily-item .py, body.hide-py .turn .py { display: none; }

.credits { font-size: .8rem; }
.credits a { color: inherit; }

/* Phones: 5 builder columns become rows */
@media (max-width: 640px) {
  .sb-board { grid-template-columns: 1fr; }
  .ch-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .py-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .seg.wrap button { padding: 7px 10px; font-size: .84rem; }
}

/* ▶ Play all */
.playall-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 6px 0 12px; }
.playall-row .hint { font-size: .84rem; }
.playing { outline: 3px solid var(--accent); outline-offset: 2px; background: var(--accent-soft) !important; transition: outline-color .15s; }
