/* Lǎoshī — « 朱与墨 » (vermilion & ink) theme.
   Rice-paper ground, ink text, China-red + gold accents. System CJK for hanzi
   (PingFang SC on Mac is beautiful), Inter for UI. Pinyin rendered in red. */

:root {
  --paper: #f7f3ea;
  --paper-2: #fffdf7;
  --paper-3: #efe7d5;
  --ink: #1c1a17;
  --muted: #7c7365;
  --line: #e7ddca;
  --line-soft: #efe8d7;
  --zhu: #c8302a;          /* 朱 vermilion / China red */
  --zhu-deep: #9c241f;
  --zhu-wash: #f8 e9 e7;   /* overwritten below */
  --zhu-wash: #f9eae8;
  --gold: #c1962f;
  --gold-soft: #f2e7c9;
  --verde: #3f7d4e;
  --rojo: #b3362f;
  --cjk: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "Heiti SC", "WenQuanYi Micro Hei", sans-serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --shadow-1: 0 1px 2px rgba(28, 26, 23, .05), 0 6px 18px rgba(28, 26, 23, .06);
  --shadow-2: 0 2px 6px rgba(28, 26, 23, .08), 0 16px 38px rgba(28, 26, 23, .12);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--sans); color: var(--ink); line-height: 1.6; font-size: 16px;
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 88% -12%, rgba(200, 48, 42, .06), transparent 60%),
    radial-gradient(900px 460px at -8% -6%, rgba(193, 150, 47, .07), transparent 58%),
    var(--paper);
}
h1, h2, h3 { font-weight: 700; line-height: 1.2; margin: 0 0 .4em; }
.hz, .cjk { font-family: var(--cjk); }
a { color: var(--zhu); }
button { font-family: inherit; }

/* Layout */
.wrap { max-width: 760px; margin: 0 auto; padding: 0 20px 96px; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; background: rgba(247, 243, 234, .86);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 9px; cursor: pointer; }
.brand .mark { width: 26px; height: 26px; border-radius: 7px; box-shadow: var(--shadow-1); background: #de2910; position: relative; align-self: center; }
.brand .mark::before { content: "★"; position: absolute; color: #ffde00; font-size: 15px; left: 3px; top: -1px; line-height: 26px; }
.brand .zh { font-family: var(--cjk); font-size: 20px; font-weight: 700; }
.brand .lat { font-size: 13px; color: var(--muted); letter-spacing: .3px; }
.spacer { flex: 1; }
.streak { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.streak b { color: var(--zhu); }

/* Bottom nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center; gap: 2px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: rgba(255, 253, 247, .93);
  backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.nav button { border: 0; background: none; cursor: pointer; padding: 6px 10px; border-radius: 10px; color: var(--muted); font-size: 11px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 60px; }
.nav button .ic { font-family: var(--cjk); font-size: 17px; line-height: 1; }
.nav button.on { color: var(--zhu); background: var(--zhu-wash); }

/* Cards */
.section-title { margin: 26px 0 12px; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.card { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 18px 20px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .grid.two { grid-template-columns: 1fr; } }

.hero { margin-top: 22px; padding: 26px 24px; }
.hero h1 { font-size: 30px; margin-bottom: 4px; }
.hero h1 .zh { font-family: var(--cjk); }
.hero p { margin: 0 0 18px; color: var(--muted); max-width: 46ch; }
.statrow { display: flex; gap: 22px; margin: 4px 0 2px; }
.stat b { font-size: 24px; color: var(--zhu); display: block; line-height: 1; }
.stat span { font-size: 12px; color: var(--muted); }

.tile { display: flex; flex-direction: column; gap: 5px; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.tile .k { font-size: 18px; font-weight: 700; }
.tile .k .zh { font-family: var(--cjk); margin-right: 6px; }
.tile .d { font-size: 13px; color: var(--muted); }
.tile .meta { font-size: 12.5px; color: var(--gold); font-weight: 700; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--paper-2); color: var(--ink); padding: 11px 18px; border-radius: 999px; font-size: 15px; font-weight: 600; cursor: pointer; transition: transform .1s ease, box-shadow .12s ease, background .12s ease; }
.btn:hover { box-shadow: var(--shadow-1); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--zhu); border-color: var(--zhu); color: #fff; }
.btn.primary:hover { background: var(--zhu-deep); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.sm { padding: 7px 13px; font-size: 13.5px; }

/* Flashcard */
.reviewwrap { max-width: 620px; margin: 0 auto; }
.progressbar { height: 4px; background: var(--paper-3); border-radius: 4px; overflow: hidden; margin: 10px 0 8px; }
.progressbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--zhu)); }
.count { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.flash { min-height: 240px; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 30px 24px; }
.bighz { font-family: var(--cjk); font-size: 76px; line-height: 1.05; font-weight: 500; }
.flash .pos { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); font-weight: 700; margin-top: 14px; }
.flash .reveal { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 16px; text-align: center; }
.py { font-family: var(--sans); color: var(--zhu); font-weight: 600; }
.flash .reveal .py { font-size: 24px; }
.flash .en { font-size: 18px; margin-top: 6px; }
.flash .measure { display: inline-block; font-size: 13px; color: var(--muted); background: var(--paper); border: 1px solid var(--line-soft); border-radius: 999px; padding: 3px 12px; margin-top: 12px; }
.flash .measure .hz { font-family: var(--cjk); color: var(--ink); }
.flash .ex { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.flash .ex .exhz { font-family: var(--cjk); font-size: 22px; }
.flash .ex .expy { font-size: 14px; margin-top: 3px; }
.flash .ex .exen { font-size: 13.5px; color: var(--muted); margin-top: 2px; }
.speak { border: 0; background: var(--gold-soft); color: var(--gold); width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 14px; vertical-align: middle; }
.speak:hover { filter: brightness(.96); }
.speak.big { width: 44px; height: 44px; font-size: 20px; margin-top: 14px; }

.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; }
.grades button { border: 1px solid var(--line); background: var(--paper-2); border-radius: 12px; padding: 12px 4px; cursor: pointer; font-weight: 700; font-size: 14px; }
.grades button .zh { font-family: var(--cjk); }
.grades button small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); margin-top: 2px; }
.grades .g0:hover { border-color: var(--rojo); color: var(--rojo); }
.grades .g1:hover { border-color: var(--gold); color: var(--gold); }
.grades .g2:hover { border-color: var(--zhu); color: var(--zhu); }
.grades .g3:hover { border-color: var(--verde); color: var(--verde); }

/* Drills (tones / measures) */
.drillq { text-align: center; padding: 8px 0 4px; }
.drillq .bighz { font-size: 60px; }
.drillq .sub { color: var(--muted); font-size: 14px; margin-top: 8px; }
.opts { display: grid; gap: 10px; margin: 18px 0; }
.opts.tones { grid-template-columns: 1fr 1fr; }
.opts button { text-align: center; border: 1px solid var(--line); background: var(--paper-2); border-radius: 12px; padding: 14px 12px; cursor: pointer; font-size: 20px; }
.opts button .py { font-size: 20px; }
.opts button .hz { font-family: var(--cjk); font-size: 26px; display: block; }
.opts button .mpy { display: block; font-size: 13px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.opts button:hover { border-color: var(--zhu); }
.opts button.right { border-color: var(--verde); background: #eef6ef; }
.opts button.wrong { border-color: var(--rojo); background: #f8ecea; }
.opts button:disabled { cursor: default; }
.explain { border-left: 3px solid var(--gold); padding: 4px 0 4px 14px; margin-top: 6px; color: var(--muted); font-size: 14.5px; }
.explain .hz { font-family: var(--cjk); color: var(--ink); }
.cat { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.subtabs { display: flex; gap: 8px; margin-bottom: 12px; }
.subtabs button { border: 1px solid var(--line); background: var(--paper-2); border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.subtabs button.on { background: var(--zhu-wash); color: var(--zhu); border-color: var(--zhu); }

/* Rules list */
.rule { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--paper-2); }
.rule .rh { display: flex; align-items: baseline; gap: 10px; }
.rule .rh .hz { font-family: var(--cjk); font-size: 22px; }
.rule .rh .py { font-size: 15px; }
.rule .rh .en { color: var(--muted); font-size: 13.5px; }
.rule .foc { font-size: 12px; color: var(--gold); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin: 4px 0; }
.rule .exp { font-size: 14px; color: var(--muted); }

/* Reader */
.reader .ex { margin: 0 0 16px; }
.reader .who { font-size: 12px; font-weight: 700; color: var(--zhu); margin-bottom: 4px; }
.line { display: flex; flex-wrap: wrap; gap: 2px 4px; align-items: flex-end; }
.tok { display: inline-flex; flex-direction: column; align-items: center; cursor: pointer; padding: 1px 2px; border-radius: 6px; }
.tok:hover { background: var(--gold-soft); }
.tok .py { font-size: 12px; height: 15px; line-height: 15px; }
.tok .hz { font-family: var(--cjk); font-size: 27px; line-height: 1.25; }
.reader.no-py .tok .py { display: none; }
.reader .trans { color: var(--muted); font-size: 14px; margin-top: 4px; }
.reader .trans.hidden { filter: blur(5px); cursor: pointer; }
.pop { position: fixed; z-index: 50; max-width: 260px; background: var(--ink); color: #fbf7ee; padding: 10px 13px; border-radius: 10px; box-shadow: var(--shadow-2); font-family: var(--sans); font-size: 13.5px; line-height: 1.5; }
.pop .p-hz { font-family: var(--cjk); font-size: 20px; }
.pop .p-py { color: #ffd9a8; font-weight: 600; }
.pop .p-en { color: #ded3c2; }

/* Forms / Ajustes */
.field { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.field:last-child { border-bottom: 0; }
.field label { font-weight: 600; }
.field .sub { font-size: 12.5px; color: var(--muted); font-weight: 400; }
select, input[type=number] { font-family: var(--sans); font-size: 15px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper-2); color: var(--ink); }
input[type=range] { accent-color: var(--zhu); }
.hint { font-size: 13px; color: var(--muted); }
.warn { background: var(--zhu-wash); border: 1px solid #e8c6c2; color: var(--zhu-deep); border-radius: 10px; padding: 10px 13px; font-size: 13.5px; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.mt { margin-top: 16px; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: #fbf7ee; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-2); z-index: 60; }
