/* ==========================================================================
   中文 — app stylesheet. Mobile first; side navigation from 900px up.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  color-scheme: light;

  --bg: #f6f4f1;
  --surface: #ffffff;
  --surface-2: #efebe6;
  --border: #e0dad3;
  --text: #1d1b19;
  --text-2: #5f5852;
  --accent: #b3122b;        /* 中国红, darkened for contrast */
  --accent-text: #ffffff;
  --accent-soft: #fbe7ea;
  --focus: #2563eb;
  --ok: #17803d;
  --warn: #a15c00;

  /* Tone colours (same scheme as Pleco): 1 red, 2 green, 3 blue, 4 purple, neutral grey */
  --tone1: #d0021b;
  --tone2: #1a8a2e;
  --tone3: #1f5fd1;
  --tone4: #8b2fc9;
  --tone5: #6b6b6b;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .05);
  --tap: 48px;
  --tabbar-h: 64px;
  --sidenav-w: 248px;
  --content-max: 760px;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC",
    "Source Han Sans SC", sans-serif;
  /* Simplified-Chinese faces first so mainland glyph shapes are used, not Japanese ones. */
  --font-hanzi-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
    "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", sans-serif;
  /* 楷体: handwriting-like strokes, best for learning to write. Falls back to serif (宋体) on Android. */
  --font-hanzi-kai: "Kaiti SC", "STKaiti", "KaiTi", "AR PL UKai CN", "Noto Serif SC",
    "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --font-hanzi: var(--font-hanzi-sans);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141416;
  --surface: #1e1e21;
  --surface-2: #2a2a2e;
  --border: #36363b;
  --text: #ecebea;
  --text-2: #a8a5a1;
  --accent: #ff5a6e;
  --accent-text: #1a0a0d;
  --accent-soft: #3a1c22;
  --focus: #7aa7ff;
  --ok: #4ade80;
  --warn: #fbbf24;

  --tone1: #ff6b6b;
  --tone2: #5fd47a;
  --tone3: #6ea8ff;
  --tone4: #c98bff;
  --tone5: #a0a0a0;

  --shadow: 0 1px 2px rgb(0 0 0 / .4);
}

:root[data-hanzi-font="kai"] { --font-hanzi: var(--font-hanzi-kai); }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); }
small, .muted { color: var(--text-2); }
img, svg { max-width: 100%; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--surface); padding: 10px 14px; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

/* Chinese text. Always set lang="zh-CN" on these elements as well. */
.hanzi { font-family: var(--font-hanzi); font-weight: 400; letter-spacing: .02em; }
.hanzi-xl { font-size: clamp(4rem, 22vw, 7.5rem); line-height: 1.1; }
.hanzi-lg { font-size: 2.6rem; line-height: 1.2; }
.pinyin { font-family: var(--font-ui); letter-spacing: .01em; }
.t1 { color: var(--tone1); } .t2 { color: var(--tone2); } .t3 { color: var(--tone3); }
.t4 { color: var(--tone4); } .t5 { color: var(--tone5); }

/* ---------- App layout ---------- */
.app { min-height: 100dvh; }

.content {
  padding: max(16px, env(safe-area-inset-top)) 16px
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

main { max-width: var(--content-max); margin: 0 auto; outline: none; }

/* Bottom tab bar (phones) */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-2); text-decoration: none; font-size: .72rem; font-weight: 500;
  min-height: var(--tap);
}
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a[aria-current="page"] { color: var(--accent); }

/* Side navigation (PC) */
.sidenav { display: none; }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .sidenav {
    display: flex; flex-direction: column; gap: 2px;
    position: fixed; inset: 0 auto 0 0; width: var(--sidenav-w); z-index: 20;
    padding: 20px 12px; overflow-y: auto;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .content { margin-left: var(--sidenav-w); padding: 32px 40px 48px; }
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 18px; color: var(--text); text-decoration: none; font-weight: 700;
}
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text);
  font-family: var(--font-hanzi); font-size: 22px; font-weight: 700;
}
.nav-group {
  margin: 14px 10px 4px; font-size: .72rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-2);
}
.sidenav a.nav-link {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px;
  border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 500;
}
.sidenav a.nav-link svg { width: 22px; height: 22px; color: var(--text-2); flex: none; }
.sidenav a.nav-link:hover { background: var(--surface-2); }
.sidenav a.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.sidenav a.nav-link[aria-current="page"] svg { color: var(--accent); }

.offline-banner {
  max-width: var(--content-max); margin: 0 auto 12px; padding: 8px 14px;
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2);
  font-size: .9rem; text-align: center;
}

/* ---------- Components ---------- */
.page-header { margin: 4px 0 20px; }
.page-header p { color: var(--text-2); margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.card > :last-child { margin-bottom: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation; user-select: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-block { display: flex; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.stats-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { margin: 0; }
.stat .value { font-size: 2.4rem; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--text-2); font-size: .9rem; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 6px; min-height: 96px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.tile:hover { border-color: var(--accent); }
.tile svg { width: 26px; height: 26px; color: var(--accent); }
.tile strong { font-size: 1rem; }
.tile span { font-size: .85rem; color: var(--text-2); line-height: 1.35; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-2);
}
.badge-accent { background: var(--accent-soft); color: var(--accent); }

ul.clean { list-style: none; margin: 0; padding: 0; }
ul.checklist li { padding: 6px 0 6px 28px; position: relative; }
ul.checklist li::before {
  content: ""; position: absolute; left: 4px; top: 14px; width: 10px; height: 10px;
  border-radius: 3px; border: 2px solid var(--border);
}

/* Settings */
.setting { padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting:last-child { border-bottom: 0; padding-bottom: 0; }
.setting:first-child { padding-top: 0; }
.setting-label { display: block; font-weight: 600; margin-bottom: 4px; }
.setting-help { display: block; color: var(--text-2); font-size: .88rem; margin-bottom: 10px; }

.segmented {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; max-width: 100%;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  display: grid; place-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px;
  font-weight: 600; font-size: .92rem; cursor: pointer; color: var(--text-2); white-space: nowrap;
}
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + label { outline: 3px solid var(--focus); }

/* Resources */
.resource { display: block; padding: 12px 0; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.resource:last-child { border-bottom: 0; padding-bottom: 0; }
.resource:first-of-type { padding-top: 0; }
.resource strong { color: var(--accent); }
.resource span { display: block; color: var(--text-2); font-size: .92rem; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 24px);
  padding: 10px 10px 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); box-shadow: 0 4px 20px rgb(0 0 0 / .25);
}
.toast .btn { min-height: 38px; padding: 0 14px; background: var(--bg); color: var(--text); border: 0; }
@media (min-width: 900px) { .toast { bottom: 24px; left: calc(50% + var(--sidenav-w) / 2); } }

.site-footer { margin-top: 32px; color: var(--text-2); font-size: .82rem; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
