/* ReadHound — child-first reading UI.
   Eye-care rules (proposal §15): large type, 1.8 line-height, limited
   line length, warm off-white background, low-light night theme. */
:root {
  --bg: #fdf6e9;
  --card: #fffdf7;
  --ink: #33302a;
  --ink-soft: #6f675b;
  --line: #eadfcb;
  --accent: #e07a3f;
  --accent-soft: #fbe3d3;
  --accent-ink: #ffffff;
  --good: #3f8f5a;
  --good-soft: #dcefe2;
  --gold: #c9912b;
  --gold-soft: #fbefd2;
  --blue: #3e74b8;
  --blue-soft: #dfe9f6;
  --new-mark: #fff0a8;
  --shadow: 0 2px 12px rgba(90, 70, 40, 0.09);
  --read-size: 22px;
  --radius: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1b18; --card: #282521; --ink: #d9d2c5; --ink-soft: #a39a8b; --line: #3b3630;
    --accent: #d9864f; --accent-soft: #4a3123; --good: #74b98a; --good-soft: #263b2c;
    --gold: #d6a84c; --gold-soft: #3d3220; --blue: #7ea6d8; --blue-soft: #23303f;
    --new-mark: #4d4422; --shadow: 0 2px 12px rgba(0, 0, 0, 0.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1b18; --card: #282521; --ink: #d9d2c5; --ink-soft: #a39a8b; --line: #3b3630;
  --accent: #d9864f; --accent-soft: #4a3123; --good: #74b98a; --good-soft: #263b2c;
  --gold: #d6a84c; --gold-soft: #3d3220; --blue: #7ea6d8; --blue-soft: #23303f;
  --new-mark: #4d4422; --shadow: 0 2px 12px rgba(0, 0, 0, 0.35); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.shell { max-width: 760px; margin: 0 auto; padding: 20px 16px 48px; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.3; }

/* ------------------------------------------------------------ buttons */
button, .btn {
  font: inherit;
  font-size: 20px;
  min-height: 52px;
  padding: 10px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; }
button.ghost, .btn.ghost { background: transparent; color: var(--ink); border: 2px solid var(--line); }
button.soft { background: var(--accent-soft); color: var(--ink); }
button.small { font-size: 16px; min-height: 40px; padding: 6px 16px; }
button.big { font-size: 24px; min-height: 64px; padding: 12px 40px; }
button.icon { width: 52px; padding: 0; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.spacer { flex: 1; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }

/* ------------------------------------------------------------ cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 22px; }

/* ------------------------------------------------------------ top bar */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.topbar h1 { margin: 0; font-size: 28px; letter-spacing: 2px; }
.topbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border-radius: 999px; padding: 6px 14px;
  box-shadow: var(--shadow); font-size: 18px; font-weight: 600;
}

/* ------------------------------------------------------------ home */
.hero { display: flex; gap: 18px; align-items: center; }
.hero .pup { width: 132px; height: 132px; flex: none; }
.hero .say { font-size: 20px; }
.hero .say b { color: var(--accent); }
.today { text-align: center; padding: 26px 22px; }
.today .title { font-size: 28px; font-weight: 700; margin: 6px 0 4px; }
.today .meta { color: var(--ink-soft); margin-bottom: 18px; }
.done-badge { display: inline-block; background: var(--good-soft); color: var(--good); border-radius: 999px; padding: 4px 14px; font-weight: 600; margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { background: var(--card); border-radius: 16px; padding: 14px 8px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 28px; }
.stat span { color: var(--ink-soft); font-size: 15px; }
.nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.nav button { flex-direction: column; border-radius: 18px; min-height: 88px; background: var(--card); color: var(--ink); box-shadow: var(--shadow); font-size: 17px; gap: 2px; }
.nav button .ico { font-size: 30px; line-height: 1; }

/* quest map strip */
.map-strip { display: flex; align-items: center; gap: 6px; overflow: hidden; margin-top: 8px; padding: 6px; }
.node { width: 26px; height: 26px; border-radius: 50%; background: var(--line); flex: none; display: grid; place-items: center; font-size: 13px; color: var(--ink-soft); }
.node.lit { background: var(--gold); color: #fff; }
.node.here { outline: 3px solid var(--accent); outline-offset: 2px; }
.path { height: 4px; flex: 1; min-width: 6px; background: var(--line); border-radius: 2px; }
.path.lit { background: var(--gold); }
.region { margin-bottom: 18px; }
.region h3 { margin: 0 0 6px; }
.region.locked { opacity: 0.45; }

/* ------------------------------------------------------------ PIN pad */
.pin-wrap { max-width: 360px; margin: 8vh auto 0; text-align: center; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 20px 0; }
.pin-dots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink-soft); }
.pin-dots i.on { background: var(--ink); border-color: var(--ink); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.pad button { font-size: 30px; min-height: 76px; border-radius: 22px; background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.err { color: #c0392b; min-height: 1.6em; }

/* ------------------------------------------------------------ reading */
.reader-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 5; }
.reader-head .t { flex: 1; font-weight: 700; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width 0.3s ease; }
.para {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
  font-size: var(--read-size);
  line-height: 1.8;
  max-width: 34em; /* limit line length: less eye travel */
  box-shadow: var(--shadow);
  opacity: 0.55;
  transition: opacity 0.25s ease;
}
.para.current { opacity: 1; outline: 3px solid var(--accent-soft); }
.para.done { opacity: 0.8; }
.para .no { font-size: 14px; color: var(--ink-soft); display: block; margin-bottom: 2px; }
.para.flash { animation: flash 1.2s ease 2; }
@keyframes flash { 50% { outline: 4px solid var(--accent); } }
/* pinyin: one column per character (native ruby lets syllables collide) */
ruby.hz { display: inline-flex; flex-direction: column-reverse; align-items: center; vertical-align: bottom; min-width: 1em; margin: 0 0.04em; line-height: 1.25; }
ruby.hz rt { display: block; font-size: 0.48em; line-height: 1.2; color: var(--ink-soft); letter-spacing: 0; user-select: none; white-space: nowrap; font-family: -apple-system, "Helvetica Neue", Arial, sans-serif; }
.para.with-py { line-height: 1.5; }
.hz { cursor: pointer; border-radius: 4px; }
.hz.new { background: var(--new-mark); }
.hz.review { box-shadow: inset 0 -3px 0 var(--blue); }
.hz.tapped { background: var(--accent-soft); }
.reader-actions { display: flex; gap: 12px; justify-content: center; margin: 12px 0 24px; flex-wrap: wrap; }
.mode-pick { display: flex; gap: 8px; justify-content: center; }
.mode-pick button { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.mode-pick button.on { background: var(--accent); color: #fff; }
.listen-only { text-align: center; padding: 40px 20px; }
.listen-only .big-play { width: 140px; height: 140px; border-radius: 50%; font-size: 54px; }

/* popover for a tapped character */
.pop {
  position: fixed; z-index: 40; left: 50%; bottom: 24px; transform: translateX(-50%);
  width: min(440px, calc(100vw - 32px));
  background: var(--card); border-radius: 22px; padding: 18px 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.pop .big { font-size: 64px; line-height: 1.1; font-family: "Kaiti SC", "STKaiti", "KaiTi", serif; }
.pop .py { font-size: 26px; color: var(--accent); }

/* ------------------------------------------------------------ char cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ccard { background: var(--card); border-radius: 18px; padding: 16px; text-align: center; box-shadow: var(--shadow); }
.ccard .big { font-size: 60px; line-height: 1.15; font-family: "Kaiti SC", "STKaiti", "KaiTi", serif; }
.ccard .py { color: var(--accent); font-size: 20px; }
.ccard .word { font-size: 18px; }
.ccard .gloss { color: var(--ink-soft); font-size: 15px; }
.warm-card { max-width: 420px; margin: 0 auto; text-align: center; padding: 30px 24px; }
.warm-card .big { font-size: 120px; line-height: 1.1; font-family: "Kaiti SC", "STKaiti", "KaiTi", serif; }
.warm-card .py { font-size: 34px; color: var(--accent); }
.warm-card .word { font-size: 24px; margin-top: 6px; }
.warm-card .gloss { color: var(--ink-soft); margin-top: 8px; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 12px 0; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); }
.tile { border: 3px solid transparent; }
.tile.mastered { border-color: var(--gold); background: var(--gold-soft); }
.tile.familiar { border-color: var(--blue-soft); }
.tile.seen { opacity: 0.7; border-style: dashed; border-color: var(--line); }
.tile .tag { font-size: 13px; color: var(--ink-soft); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 15px; color: var(--ink-soft); margin-bottom: 12px; }

/* ------------------------------------------------------------ quiz */
.task { background: var(--blue-soft); border-radius: var(--radius); padding: 18px 20px; font-size: 21px; }
.task .lbl { font-size: 15px; color: var(--blue); font-weight: 700; }
.q { font-size: 22px; font-weight: 600; margin: 4px 0 16px; }
.opts { display: grid; gap: 12px; }
.opts button { justify-content: flex-start; text-align: left; background: var(--card); color: var(--ink); border: 2px solid var(--line); border-radius: 18px; font-size: 21px; min-height: 60px; box-shadow: none; }
.opts button.right { border-color: var(--good); background: var(--good-soft); }
.opts button.nope { border-color: var(--line); opacity: 0.5; }
.opts.py button { justify-content: center; font-size: 30px; }
.feedback { margin-top: 14px; padding: 14px 16px; border-radius: 16px; font-size: 19px; }
.feedback.ok { background: var(--good-soft); }
.feedback.try { background: var(--accent-soft); }
.ability { display: inline-block; font-size: 14px; border-radius: 999px; padding: 2px 10px; background: var(--accent-soft); margin-bottom: 4px; }

/* ------------------------------------------------------------ celebration */
.celebrate { text-align: center; padding: 30px 20px; }
.celebrate h2 { font-size: 30px; }
.gain { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 19px; }
.chest { font-size: 84px; cursor: pointer; display: inline-block; animation: wobble 1.6s ease infinite; background: none; color: inherit; min-height: 0; padding: 0; }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-8deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(0); } }
.surprise { background: var(--gold-soft); border-radius: 18px; padding: 16px; margin: 12px 0; font-size: 19px; }
.medal { display: inline-flex; align-items: center; gap: 6px; background: var(--gold-soft); border-radius: 999px; padding: 6px 14px; margin: 4px; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall 2.6s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ------------------------------------------------------------ rest page */
.rest {
  position: fixed; inset: 0; z-index: 50; background: #24402f; color: #e9f3ea;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px;
}
.rest h2 { font-size: 34px; margin: 10px 0; }
.rest .count { font-size: 64px; font-variant-numeric: tabular-nums; margin: 16px 0; }
.rest p { font-size: 21px; max-width: 30em; }
.rest button { background: #e9f3ea; color: #24402f; }

/* ------------------------------------------------------------ modal */
.modal { position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, 0.35); display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: var(--bg); width: min(760px, 100vw); max-height: 88vh; overflow: auto; border-radius: 24px 24px 0 0; padding: 20px 16px 30px; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.snippet { color: var(--ink-soft); font-size: 17px; }
.snippet mark { background: var(--new-mark); color: inherit; border-radius: 3px; }

/* ------------------------------------------------------------ skills */
.skill { display: flex; gap: 14px; align-items: center; }
.skill .badge { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; font-size: 28px; background: var(--accent-soft); flex: none; }
.skill.locked .badge { background: var(--line); filter: grayscale(1); }
.skill.locked { opacity: 0.6; }

/* ------------------------------------------------------------ toast */
.toast { position: fixed; left: 50%; top: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 20px; border-radius: 999px; z-index: 60; font-size: 17px; }

.foot { text-align: center; font-size: 14px; color: var(--ink-soft); margin-top: 28px; }
.foot a { color: inherit; }

@media (max-width: 520px) {
  .hero .pup { width: 96px; height: 96px; }
  .stat b { font-size: 24px; }
  .nav button { min-height: 76px; font-size: 15px; }
  .para { padding: 14px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
