:root {
  --bg: #faf7f2; --card: #ffffff; --ink: #1f1b16; --muted: #7a7166; --line: #e8e1d6;
  --accent: #c43226; --accent-ink: #fff; --good: #2f7d4f; --bad: #c43226; --warn: #b7791f;
  --soft: #f3ede4; --chip: #efe7dc;
  --zh: "Noto Sans SC", "Noto Sans CJK SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171512; --card: #221f1b; --ink: #f1ebe2; --muted: #a39a8e; --line: #3a352e;
    --accent: #e0574a; --soft: #2b2722; --chip: #332e28; --good: #5fbf85; --bad: #ef6b5e; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); min-height: 100vh; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.zh { font-family: var(--zh); }

#top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
#top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: none; font-size: 24px; width: 40px; height: 40px; border-radius: 10px; }
.icon-btn:active { background: var(--soft); }
#back { font-size: 34px; line-height: 1; }

#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs a { flex: 1; text-align: center; padding: 6px 0 8px; font-size: 11px; color: var(--muted); }
#tabs a span { display: block; font-family: var(--zh); font-size: 20px; line-height: 1.2; }
#tabs a.on { color: var(--accent); font-weight: 600; }
body.focus #tabs { display: none; }
body.focus { padding-bottom: 0; }

#view { padding: 12px 14px 24px; max-width: 640px; margin: 0 auto; }
.loading { text-align: center; padding: 60px 0; font-family: var(--zh); color: var(--muted); font-size: 22px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card h2, .card h3 { margin: 0 0 8px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px;
  padding: 12px 16px; background: var(--chip); font-weight: 600; min-height: 46px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; }
.btn:active { transform: scale(.98); }

.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-height: 104px;
  display: flex; flex-direction: column; justify-content: space-between; cursor: pointer; }
.tile .k { font-family: var(--zh); font-size: 26px; color: var(--accent); line-height: 1; }
.tile .t { font-weight: 650; }
.tile .s { font-size: 13px; color: var(--muted); }
.tile.main { grid-column: span 2; background: var(--accent); color: var(--accent-ink); border: 0; }
.tile.main .k, .tile.main .s { color: var(--accent-ink); }
.tile.dim { opacity: .55; }

.stats { display: flex; gap: 8px; margin-bottom: 12px; }
.stat { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 11px; color: var(--muted); }

.bar { height: 6px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--good); border-radius: 4px; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; cursor: pointer; }
.list-item .num { font-family: var(--zh); width: 38px; height: 38px; border-radius: 10px; background: var(--soft);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.list-item .num.done { background: var(--good); color: #fff; }
.chev { color: var(--muted); font-size: 22px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--chip); border-radius: 999px; padding: 4px 10px; font-size: 13px; border: 0; }
.chip.on { background: var(--accent); color: #fff; }

/* слово */
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.dot.l { background: var(--warn); }
.dot.k { background: var(--good); }
.word-row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.word-row .h { font-family: var(--zh); font-size: 22px; min-width: 64px; }
.word-row .p { color: var(--accent); font-size: 14px; }
.word-row .r { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
input[type=search], input[type=text], select { width: 100%; font: inherit; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); }

/* карточки упражнений */
.stage { min-height: calc(100vh - 140px); display: flex; flex-direction: column; }
.progress { height: 5px; background: var(--soft); border-radius: 3px; overflow: hidden; margin: 2px 0 14px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.prompt { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 10px 0; }
.hz-big { font-family: var(--zh); font-size: 76px; line-height: 1.1; font-weight: 500; }
.hz-big.len3 { font-size: 60px; } .hz-big.len4 { font-size: 50px; } .hz-big.len5 { font-size: 40px; }
.py-big { font-size: 24px; color: var(--accent); }
.ru-big { font-size: 19px; max-width: 34em; }
.kind { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.options { display: grid; gap: 8px; margin-top: 10px; }
.opt { text-align: left; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  font-size: 16px; min-height: 52px; cursor: pointer; }
.opt.zh-opt { font-family: var(--zh); font-size: 24px; text-align: center; }
.opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 15%, var(--card)); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 15%, var(--card)); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.grades .btn { flex-direction: column; gap: 0; font-size: 14px; padding: 8px 4px; }
.grades .btn small { font-weight: 400; font-size: 11px; opacity: .75; }
.g0 { background: color-mix(in srgb, var(--bad) 22%, var(--card)) !important; }
.g1 { background: color-mix(in srgb, var(--warn) 22%, var(--card)) !important; }
.g2 { background: color-mix(in srgb, var(--good) 22%, var(--card)) !important; }
.g3 { background: color-mix(in srgb, #3b82f6 22%, var(--card)) !important; }
.feedback { border-radius: 12px; padding: 12px; margin-top: 12px; }
.feedback.ok { background: color-mix(in srgb, var(--good) 14%, var(--card)); }
.feedback.no { background: color-mix(in srgb, var(--bad) 14%, var(--card)); }
.play { border: 0; background: var(--soft); border-radius: 50%; width: 52px; height: 52px; font-size: 22px; cursor: pointer; }
.play.sm { width: 34px; height: 34px; font-size: 15px; }
.play.huge { width: 96px; height: 96px; font-size: 40px; background: var(--accent); color: #fff; }
.examples { width: 100%; text-align: left; margin-top: 6px; }
.ex { padding: 8px 0; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: flex-start; }
.ex .zh { font-size: 18px; }
.mark { color: var(--accent); font-weight: 700; }

/* ruby-текст */
.tline { padding: 10px 2px; border-bottom: 1px solid var(--line); }
.tline .sp { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.tline .zhl { font-family: var(--zh); font-size: 22px; line-height: 2.1; }
.tline.active { background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 8px; }
.tok { cursor: pointer; border-radius: 4px; }
.tok:active, .tok.sel { background: color-mix(in srgb, var(--accent) 22%, transparent); }
ruby { ruby-align: center; }
rt { font-family: system-ui, sans-serif; font-size: 11px; color: var(--muted); }
.nopy rt { visibility: hidden; }
.tline .ru { font-size: 14px; color: var(--muted); margin-top: 2px; }
.tline .tools { display: flex; gap: 6px; margin-top: 4px; }
.tline .tools button { border: 0; background: var(--soft); border-radius: 8px; padding: 4px 9px; font-size: 13px; }
.reader-bar { position: sticky; top: 57px; z-index: 4; background: var(--bg); padding: 6px 0; display: flex; gap: 6px; flex-wrap: wrap; }

/* сборка фразы */
.slots { min-height: 64px; border-bottom: 2px dashed var(--line); display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0; align-content: flex-start; }
.bank { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; justify-content: center; }
.piece { font-family: var(--zh); font-size: 21px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 7px 11px; cursor: pointer; }
.piece.used { visibility: hidden; }
.blank { display: inline-block; min-width: 2.2em; border-bottom: 2px solid var(--accent); text-align: center; color: var(--accent); }

/* голос */
.mic { width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 34px; cursor: pointer; }
.mic.rec { animation: pulse 1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(196,50,38,.5); } 70% { box-shadow: 0 0 0 18px rgba(196,50,38,0); } 100% { box-shadow: 0 0 0 0 rgba(196,50,38,0); } }
.sc-ok { color: var(--good); } .sc-no { color: var(--bad); text-decoration: underline wavy; }

/* шторка */
#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 80vh; overflow: auto; max-width: 640px; margin: 0 auto;
  box-shadow: 0 -6px 30px rgba(0,0,0,.2); }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; }
.gram { border-left: 3px solid var(--accent); padding-left: 10px; }
.gram h3 { font-family: var(--zh); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting select { width: auto; max-width: 55%; }
.toggle { appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; flex: none; cursor: pointer; }
.toggle:checked { background: var(--accent); }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle:checked::after { left: 21px; }
.done-big { font-size: 64px; text-align: center; }
.center { text-align: center; }
.banner { background: color-mix(in srgb, var(--warn) 18%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line)); }
ruby.tok { margin: 0 1px; }
rt { padding: 0 1px; letter-spacing: -0.01em; }

.schema { background: var(--soft); border-radius: 10px; padding: 8px 10px; margin: 6px 0 8px; display: grid; gap: 6px; }
.sch-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.sch-part { padding: 2px 8px; border-radius: 7px; font-size: 15px; }
.sch-part.zh { background: var(--card); border: 1px solid var(--line); font-family: var(--zh); font-weight: 600; color: var(--accent); font-size: 17px; }
.sch-part.ph { color: var(--muted); font-style: italic; }
.sch-plus { color: var(--muted); font-weight: 700; }
