/* ---------- theme tokens ---------- */
:root {
  --bg: #ffffff;
  --bg-raised: #f6f6f4;
  --fg: #1c1c1e;
  --fg-soft: #6b6b70;
  --line: #e3e3e0;
  --accent: #b3542e;
  --accent-soft: #f6e8e1;
  --rt: #8a8a8e;
  --tip-bg: #ffffff;
  --tip-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
  --t1: #c0392b;
  --t2: #1e8449;
  --t3: #1a5fb4;
  --t4: #7d3c98;
  --t0: #8a8a8e;
  --good: #1e8449;
  --bad: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1e;
    --bg-raised: #242428;
    --fg: #e8e8ea;
    --fg-soft: #9a9aa2;
    --line: #38383e;
    --accent: #e0906a;
    --accent-soft: #3a2c24;
    --rt: #85858d;
    --tip-bg: #26262b;
    --tip-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
    --t1: #ff7b6e;
    --t2: #5dd39e;
    --t3: #6fa8ff;
    --t4: #c39bd3;
    --t0: #9aa0a6;
    --good: #5dd39e;
    --bad: #ff7b6e;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei",
    sans-serif;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
main { max-width: 42rem; margin: 0 auto; padding: 1rem 1.1rem 6rem; }

/* ---------- toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.toolbar .home { font-size: 0.95rem; white-space: nowrap; }
.toolbar .title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.toolbar .title .pinyin { color: var(--fg-soft); font-weight: 400; font-size: 0.85em; }
.pill {
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--fg-soft);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.pill.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pill.badge { text-decoration: none; }

/* ---------- reading view ---------- */
.story-head { margin: 1.4rem 0 0.4rem; }
.story-head h1 { font-size: 1.9rem; margin: 0 0 0.1rem; }
.story-head .reading { color: var(--fg-soft); margin: 0 0 0.35rem; }
.story-head .meaning { color: var(--fg-soft); font-style: italic; margin: 0; }
.callout {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  margin: 1rem 0;
  font-size: 0.92rem;
  color: var(--fg-soft);
}
.callout b { color: var(--fg); }
.callout ul { margin: 0.25rem 0 0; padding-left: 1.2rem; }

p.zh {
  font-size: 1.35rem;
  line-height: 2;
  margin: 1.1rem 0;
}
body.show-pinyin p.zh { line-height: 2.35; }
.w { white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.w.saved { border-bottom: 2px dotted var(--accent); }
.w.active { background: var(--accent-soft); border-radius: 4px; }
ruby { ruby-align: center; }
rt {
  font-size: 0.5em;
  color: var(--rt);
  font-weight: 400;
  letter-spacing: 0;
}
body:not(.show-pinyin) rt { display: none; }
body.show-tones .t1 { color: var(--t1); }
body.show-tones .t2 { color: var(--t2); }
body.show-tones .t3 { color: var(--t3); }
body.show-tones .t4 { color: var(--t4); }
body.show-tones .t0 { color: var(--t0); }

p.en-block { display: none; }
body.show-en p.en-block {
  display: block;
  color: var(--fg-soft);
  font-size: 0.98rem;
  margin: -0.4rem 0 1.2rem;
}
.en-text { filter: blur(6px); cursor: pointer; transition: filter 0.25s; }
.en-text.revealed { filter: none; cursor: auto; }

.story-nav { display: flex; justify-content: space-between; margin: 2.5rem 0 1rem; gap: 1rem; }

/* ---------- tooltip ---------- */
#tip {
  position: fixed;
  z-index: 50;
  max-width: 20rem;
  background: var(--tip-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--tip-shadow);
  padding: 0.8rem 1rem;
  display: none;
}
#tip.open { display: block; }
#tip .tip-word { font-size: 1.6rem; line-height: 1.3; }
#tip .tip-pinyin { color: var(--fg-soft); margin: 0.1rem 0 0.4rem; }
#tip .tip-tag {
  display: inline-block;
  font-size: 0.7rem;
  border: 1px solid var(--line);
  color: var(--fg-soft);
  border-radius: 4px;
  padding: 0 0.3rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}
#tip ol { margin: 0.2rem 0 0.6rem; padding-left: 1.25rem; font-size: 0.92rem; }
#tip ol li { margin: 0.1rem 0; }
#tip .tip-sub { margin: 0.3rem 0 0.5rem; }
#tip .tip-sub .sub-head { font-weight: 600; }
#tip button {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 0.55rem;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
#tip button.saved { background: var(--bg-raised); color: var(--accent); border: 1px solid var(--accent); }
@media (max-width: 600px) {
  #tip {
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    max-width: none;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    max-height: 55vh;
    overflow-y: auto;
  }
}

/* ---------- index ---------- */
.site-head { margin: 2rem 0 1rem; }
.site-head h1 { font-size: 2.1rem; margin: 0; }
.site-head p { color: var(--fg-soft); margin: 0.3rem 0 0; }
.tier-head { margin: 1.8rem 0 0.6rem; font-size: 1.05rem; color: var(--fg-soft); }
.story-card {
  display: block;
  color: inherit;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  margin: 0.6rem 0;
}
.story-card:hover { text-decoration: none; border-color: var(--accent); }
.story-card .row1 { display: flex; align-items: baseline; gap: 0.6rem; }
.story-card .hanzi { font-size: 1.3rem; font-weight: 600; }
.story-card .pinyin { color: var(--fg-soft); font-size: 0.9rem; }
.story-card .dots { margin-left: auto; color: var(--accent); letter-spacing: 2px; font-size: 0.8rem; }
.story-card .gloss { color: var(--fg-soft); font-size: 0.92rem; margin-top: 0.15rem; }
.story-card .meta { color: var(--fg-soft); font-size: 0.8rem; margin-top: 0.3rem; }
footer { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--line); font-size: 0.8rem; color: var(--fg-soft); }

/* ---------- review ---------- */
.tabs { display: flex; gap: 0.5rem; margin: 1.2rem 0; }
.review-progress { color: var(--fg-soft); font-size: 0.9rem; margin: 0.5rem 0 1.5rem; }
#card {
  border: 1px solid var(--line);
  background: var(--bg-raised);
  border-radius: 16px;
  padding: 2rem 1.4rem;
  min-height: 16rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#card .big { font-size: 2.6rem; line-height: 1.4; }
#card .ctx { font-size: 1.15rem; color: var(--fg-soft); margin-top: 1rem; line-height: 1.8; }
#card .ctx .hl { color: var(--accent); font-weight: 600; }
#card .back-pinyin { font-size: 1.4rem; margin-top: 0.6rem; }
#card .back-defs { margin-top: 0.7rem; text-align: left; }
#card .back-defs ol { margin: 0; padding-left: 1.3rem; }
#card .src { margin-top: 1rem; font-size: 0.85rem; }
#card .hint { color: var(--fg-soft); font-size: 0.85rem; margin-top: 1.4rem; }
.grades {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 1.1rem max(0.7rem, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
  max-width: 42rem;
  margin: 0 auto;
}
.grades button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--fg);
  border-radius: 10px;
  padding: 0.55rem 0;
  font-size: 0.95rem;
  cursor: pointer;
}
.grades button small { display: block; color: var(--fg-soft); font-size: 0.72rem; }
.grades button.again { color: var(--bad); }
.grades button.easy { color: var(--good); }
.done-msg { text-align: center; color: var(--fg-soft); margin: 3rem 0; }

/* ---------- deck tab ---------- */
#deck-search {
  width: 100%;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-raised);
  color: var(--fg);
  font-size: 1rem;
  margin: 0.4rem 0 1rem;
}
.deck-row {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  padding: 0.5rem 0.2rem;
  border-bottom: 1px solid var(--line);
}
.deck-row .word { font-size: 1.15rem; min-width: 5.5rem; }
.deck-row .pinyin { color: var(--fg-soft); min-width: 6rem; }
.deck-row .state { color: var(--fg-soft); font-size: 0.8rem; margin-left: auto; white-space: nowrap; }
.deck-row .del {
  border: none;
  background: none;
  color: var(--bad);
  cursor: pointer;
  font-size: 0.9rem;
}
.deck-actions { display: flex; gap: 0.6rem; margin: 1.2rem 0; flex-wrap: wrap; }
.deck-actions .pill { text-decoration: none; }
.deck-stats { color: var(--fg-soft); font-size: 0.9rem; margin: 0.8rem 0; }
