/* ===== Mandarin — mobile-first plain CSS ===== */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --text-2: #6b7280;
  --line: #e3e5ea;
  --accent: #b3261e;
  --accent-soft: #fdeceb;
  --again: #c0392b;
  --hard: #b7791f;
  --good: #2f6f4f;
  --easy: #2b5fa8;
  --shadow: 0 1px 2px rgba(16,18,29,.05), 0 6px 18px rgba(16,18,29,.06);
  --grid: rgba(120,130,150,.28);
  --ink: #16181d;
  --g1: #c8871a;
  --g2: #2f9e6e;
  --g3: #1f7a55;
  --g3-soft: #e8f5ee;
  --nav-h: 62px;
  --r: 16px;
}

html[data-theme="dark"] {
  --bg: #101114;
  --card: #191b1f;
  --text: #f1f2f4;
  --text-2: #9aa0a9;
  --line: #2a2d33;
  --accent: #e8695f;
  --accent-soft: #2a1a19;
  --again: #e05c4c;
  --hard: #d9a63a;
  --good: #5cb98a;
  --easy: #6ea6e8;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --grid: rgba(160,170,190,.24);
  --ink: #f1f2f4;
  --g1: #e0a63a;
  --g2: #4fd1a0;
  --g3: #35c98f;
  --g3-soft: #14251e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* ---------- layout ---------- */
#app { height: 100%; }

.screen {
  position: fixed;
  inset: 0 0 0 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.screen.active { display: flex; }

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: .2px; }

.scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 0 calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}
.pad { padding: 0 16px; }
.pad-x { padding: 0 16px; }

.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 14px; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 16px 14px;
}
.card-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-2);
}

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 10px; }
.stat { display: flex; flex-direction: column; }
.stat-num { font-size: 26px; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 13px; color: var(--text-2); }

.big-num { font-size: 44px; font-weight: 650; margin: 6px 0 0; }

.kv { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.kv-row span:first-child { color: var(--text-2); }
.kv-row span:last-child { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 14px 16px;
  min-height: 50px;
  cursor: pointer;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-big { display: block; width: 100%; margin: 0 0 12px; }
.pad .btn-big, .pad-x .btn-big { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-ghost { background: var(--card); border-color: var(--line); box-shadow: var(--shadow); }
.btn-warn { background: transparent; border-color: var(--hard); color: var(--hard); }
.btn-danger { background: transparent; border-color: var(--again); color: var(--again); }
.btn-link {
  background: none; border: 0; color: var(--accent);
  font: inherit; font-weight: 600; padding: 8px; cursor: pointer;
}
.back { margin-left: -8px; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.btn-grid .btn { background: var(--card); border-color: var(--line); box-shadow: var(--shadow); }

/* ---------- segmented + inputs ---------- */
.seg {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  margin: 0 0 14px;
}
.card .seg { margin-bottom: 0; }
.seg-btn {
  flex: 1;
  appearance: none; border: 0; border-radius: 9px;
  background: transparent; color: var(--text-2);
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 9px 4px; min-height: 42px; cursor: pointer;
}
.seg-btn.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
  margin-bottom: 12px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.cn-input { font-size: 20px; }
textarea.input { resize: vertical; min-height: 62px; }

.field { display: block; margin-bottom: 4px; }
.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }

.row-check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 15px; }
.row-check input { width: 22px; height: 22px; accent-color: var(--accent); }

.err { color: var(--again); font-size: 14px; margin: 0; }

/* ---------- list ---------- */
.list { padding: 0 16px; }
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.item:active { transform: scale(.995); }
.item-cn { font-size: 26px; line-height: 1.2; min-width: 0; }
.item-cn.sentence { font-size: 19px; }
.item-mid { flex: 1; min-width: 0; }
.item-py { font-size: 15px; color: var(--text); }
.item-en { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  display: inline-block;
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px;
  background: var(--bg); color: var(--text-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.new { color: var(--easy); border-color: var(--easy); }
.pill.learning { color: var(--hard); border-color: var(--hard); }
.pill.mastered { color: var(--good); border-color: var(--good); }
.empty { text-align: center; color: var(--text-2); padding: 32px 16px; }

/* ---------- study one character ---------- */
.study-wrap { padding-bottom: 4px; }

.study-hero { text-align: center; padding: 6px 16px 18px; }
.hero-glyph {
  appearance: none; border: 0; background: none;
  color: var(--text);
  font-size: 108px; line-height: 1.1;
  padding: 0 12px; margin: 0 0 6px;
  cursor: pointer;
  transition: transform .12s ease;
}
.hero-glyph:active { transform: scale(.96); }
.hero-glyph.speaking { color: var(--accent); }
.hero-py { font-size: 26px; font-weight: 650; margin: 0; }
.hero-en { font-size: 17px; color: var(--text-2); margin: 4px 0 12px; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin-bottom: 10px; }
.chip {
  font-size: 12px; font-weight: 650;
  padding: 5px 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); color: var(--text-2);
}
.chip.hsk { color: var(--accent); border-color: var(--accent); }

.stroke-demo {
  width: 100%; max-width: 260px;
  aspect-ratio: 1 / 1;
  margin: 0 auto 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
#st-canvas { display: block; width: 100%; height: 100%; }

.seg-tight { max-width: 280px; margin: 8px auto 0; }
.seg-tight .seg-btn { font-size: 13px; min-height: 36px; padding: 6px 4px; }

.made-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 10px; margin-bottom: 14px;
}
.made-part { text-align: center; cursor: pointer; }
.made-part .mp-cn {
  display: block;
  width: 62px; height: 62px; line-height: 62px;
  font-size: 32px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
}
.made-part .mp-role { display: block; font-size: 11px; color: var(--text-2); margin-top: 4px; }
.made-plus { font-size: 22px; color: var(--text-2); }

.roles { display: flex; flex-direction: column; gap: 6px; }
.role-line { font-size: 14px; }
.role-line b { font-size: 17px; font-weight: 500; margin-right: 6px; }
.role-tag {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-2); margin-right: 6px;
}
.made-note { font-size: 15px; line-height: 1.5; margin: 14px 0 0; }

.mnemo { font-size: 16px; line-height: 1.5; margin: 0 0 12px; }
.mnemo.empty { color: var(--text-2); }

.study-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.study-row:last-child { border-bottom: 0; }
.sr-cn { font-size: 22px; }
.sr-cn.sentence { font-size: 19px; flex: 1 0 100%; line-height: 1.5; }
.sr-mid { flex: 1; min-width: 120px; }
.sr-py { font-size: 14px; }
.sr-en { font-size: 13px; color: var(--text-2); }
.speak {
  appearance: none; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); font-size: 15px; padding: 7px 9px; cursor: pointer;
}

/* ---------- compose ---------- */
.compose-wrap { padding: 6px 16px; text-align: center; position: relative; }

/* hover / long-press overlay describing one building block */
.tip {
  position: absolute;
  z-index: 30;
  transform: translate(-50%, -100%);
  background: var(--ink); color: var(--bg);
  border-radius: 12px;
  padding: 9px 13px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.28);
  animation: fade .12s ease;
  max-width: 78vw;
}
.tip .tip-py { font-size: 17px; font-weight: 650; line-height: 1.2; }
.tip .tip-en { font-size: 13px; opacity: .82; }
.tip::after {
  content: '';
  position: absolute;
  left: 50%; bottom: -5px;
  width: 10px; height: 10px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--ink);
  border-radius: 2px;
}
.k-mean { font-size: 30px; font-weight: 650; margin: 10px 0 2px; }
.k-py { font-size: 20px; color: var(--text-2); margin: 0 0 18px; }

.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 66px; }
.slot {
  width: 60px; height: 60px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  border-radius: 14px;
  border: 1px dashed var(--line);
  background: var(--card);
  cursor: pointer;
}
.slot.empty { color: transparent; }
.slot.filled { border-style: solid; }
.slots.ok .slot.filled { border-color: var(--g2); color: var(--g2); }
.slots.no .slot.filled { border-color: var(--again); color: var(--again); animation: shake .3s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.k-feedback { min-height: 30px; margin: 12px 0; font-size: 15px; font-weight: 600; }
.k-feedback.ok { color: var(--g2); }
.k-feedback.no { color: var(--again); }
.k-feedback .solved { font-size: 34px; font-weight: 500; }

.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 14px; }
.tile {
  appearance: none;
  width: 66px; height: 66px;
  font-size: 32px; line-height: 1;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .08s ease, opacity .15s ease;
}
.tile:active { transform: scale(.94); }
.tile.used { opacity: .28; }

/* ---------- garden ---------- */
.garden-head { padding: 4px 16px 10px; }
.garden-title { margin: 0; font-size: 22px; font-weight: 650; }
.garden-title.small-title { font-size: 17px; margin-top: 8px; }
.garden-sub { margin: 4px 0 0; font-size: 13px; color: var(--text-2); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; }
.lg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.s0 { background: var(--text-2); opacity: .5; }
.dot.s1 { background: var(--g1); }
.dot.s2 { background: var(--g2); }
.dot.s3 { background: var(--g3); }

.garden-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 7px;
  padding: 4px 16px 8px;
}
.glyph {
  appearance: none;
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 27px; line-height: 1;
  background: var(--card);
  color: var(--text-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  padding: 0;
  transition: transform .08s ease;
}
.glyph:active { transform: scale(.94); }
.glyph.s1 { color: var(--g1); border-color: var(--g1); }
.glyph.s2 { color: var(--g2); border-color: var(--g2); }
.glyph.s3 { color: var(--g3); border-color: var(--g3); background: var(--g3-soft); }

.prim-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 8px; }
.prim {
  appearance: none;
  display: inline-flex; align-items: baseline; gap: 7px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 13px;
  color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer;
}
.prim b { font-size: 19px; font-weight: 500; }
.prim.on { color: var(--g2); border-color: var(--g2); }

#gl-words .item { margin-bottom: 8px; }
#gl-words .item:last-child { margin-bottom: 0; }

/* ---------- review ---------- */
.review-wrap { display: flex; flex-direction: column; min-height: 100%; padding: 0 16px; }
.rv-head { display: flex; justify-content: space-between; align-items: center; }
.rv-bar { height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; margin-bottom: 8px; }
.rv-bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }

.rv-card {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  padding: 28px 4px;
  gap: 10px;
  min-height: 46vh;
}
.rv-prompt {
  font-size: 12px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-2); margin: 0;
}
.q-cn { font-size: 68px; line-height: 1.25; margin: 6px 0; font-weight: 500; }
.q-cn.sentence { font-size: 34px; line-height: 1.5; }
.q-py { font-size: 30px; margin: 4px 0; }
.q-py.sentence { font-size: 20px; color: var(--text-2); }
.q-en { font-size: 22px; margin: 4px 0; }
.q-en.sentence { font-size: 24px; line-height: 1.4; }
.a-block {
  border-top: 1px solid var(--line);
  margin-top: 14px; padding-top: 16px; width: 100%;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.a-note { font-size: 14px; color: var(--text-2); margin: 8px 0 0; }

.rv-actions { padding-bottom: 10px; }
.rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate { padding: 14px 4px; font-size: 14px; border-width: 1px; border-style: solid; background: var(--card); }
.rate.again { color: var(--again); border-color: var(--again); }
.rate.hard { color: var(--hard); border-color: var(--hard); }
.rate.good { color: var(--good); border-color: var(--good); }
.rate.easy { color: var(--easy); border-color: var(--easy); }

/* ---------- writing ---------- */
.write-wrap { padding: 0 16px; text-align: center; }
.write-cue { font-size: 32px; font-weight: 600; margin: 6px 0 0; }
.write-sub { font-size: 15px; color: var(--text-2); margin: 2px 0 12px; }

.canvas-box {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 12px;
  touch-action: none;
}
#w-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.ghost-char {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 62vw; line-height: 1;
  color: var(--ink); opacity: .10;
  pointer-events: none; user-select: none;
}
.ghost-char.multi { font-size: 30vw; }
.write-reveal { font-size: 46px; margin: 0 0 12px; }

.w-charnav { font-size: 13px; color: var(--text-2); margin: 0 0 8px; }
.w-status { min-height: 26px; margin: 10px 0; font-size: 15px; font-weight: 600; }
.w-status.ok { color: var(--g2); }
.w-status.no { color: var(--again); }
.btn-grid.four { grid-template-columns: repeat(2, 1fr); }
#w-credit { margin: 4px 0 0; opacity: .65; }

/* ---------- detail ---------- */
.detail-cn { font-size: 76px; line-height: 1.2; margin: 4px 0 8px; font-weight: 500; }
.detail-cn.sentence { font-size: 34px; line-height: 1.5; }
.detail-py { font-size: 24px; margin: 0 0 6px; }
.detail-en { font-size: 18px; margin: 0 0 4px; }
.detail-it { font-size: 15px; margin: 0 0 10px; }

/* ---------- nav ---------- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  appearance: none; border: 0; background: none;
  color: var(--text-2);
  font: inherit; font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px 8px;
  min-height: var(--nav-h);
  cursor: pointer;
}
.nav-btn .ico { font-size: 21px; line-height: 1.1; }
.nav-btn.active { color: var(--accent); }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  z-index: 50; max-width: 88%; text-align: center;
  animation: fade .18s ease;
}

/* ---------- larger screens ---------- */
@media (min-width: 620px) {
  .card, .list, .pad, .pad-x, .review-wrap, .write-wrap {
    max-width: 560px; margin-left: auto; margin-right: auto;
  }
  .card { margin-bottom: 14px; }
  .ghost-char { font-size: 340px; }
  .ghost-char.multi { font-size: 170px; }
  #nav > .nav-btn { max-width: 130px; }
  #nav { justify-content: center; }
}
