/* HSK Hanzi — styles. System fonts, light/dark, translucent chrome, instant press feedback. */

:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #e9e9ef;
  --text: #000000;
  --text-2: rgba(60, 60, 67, 0.62);
  --text-3: rgba(60, 60, 67, 0.36);
  --sep: rgba(60, 60, 67, 0.16);
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.14);
  --good: #248a3d;
  --good-soft: rgba(52, 199, 89, 0.16);
  --bad: #d70015;
  --bad-soft: rgba(255, 59, 48, 0.13);
  --warn: #b25000;
  --warn-soft: rgba(255, 149, 0, 0.16);
  --chrome: rgba(249, 249, 251, 0.72);
  --scrim: rgba(0, 0, 0, 0.22);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 18px rgba(0, 0, 0, 0.05);
  --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, 0.12);
  --grid: rgba(208, 49, 45, 0.22);
  --seg-on: #ffffff;

  --radius: 14px;
  --radius-lg: 20px;
  --gutter: 16px;
  --tabbar-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --font: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", "Helvetica Neue", sans-serif;
  --font-zh: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --font-kai: "Kaiti SC", "STKaiti", "KaiTi", "Kaiti", var(--font-zh);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #ffffff;
    --text-2: rgba(235, 235, 245, 0.62);
    --text-3: rgba(235, 235, 245, 0.32);
    --sep: rgba(84, 84, 88, 0.6);
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.22);
    --good: #30d158;
    --good-soft: rgba(48, 209, 88, 0.18);
    --bad: #ff453a;
    --bad-soft: rgba(255, 69, 58, 0.18);
    --warn: #ff9f0a;
    --warn-soft: rgba(255, 159, 10, 0.18);
    --chrome: rgba(22, 22, 24, 0.72);
    --scrim: rgba(0, 0, 0, 0.5);
    --shadow: none;
    --sheet-shadow: none;
    --grid: rgba(255, 105, 97, 0.22);
    --seg-on: #636366;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --surface: #1c1c1e; --surface-2: #2c2c2e; --text: #ffffff;
  --text-2: rgba(235, 235, 245, 0.62); --text-3: rgba(235, 235, 245, 0.32); --sep: rgba(84, 84, 88, 0.6);
  --accent: #0a84ff; --accent-soft: rgba(10, 132, 255, 0.22); --good: #30d158; --good-soft: rgba(48, 209, 88, 0.18);
  --bad: #ff453a; --bad-soft: rgba(255, 69, 58, 0.18); --warn: #ff9f0a; --warn-soft: rgba(255, 159, 10, 0.18);
  --chrome: rgba(22, 22, 24, 0.72); --scrim: rgba(0, 0, 0, 0.5); --shadow: none; --sheet-shadow: none;
  --grid: rgba(255, 105, 97, 0.22); --seg-on: #636366;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font: 100%/1.45 var(--font); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.zh { font-family: var(--font-zh); }

/* ---------- Layout ---------- */

#app { min-height: 100dvh; }
.screen {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 20px) var(--gutter) calc(var(--tabbar-h) + var(--safe-b) + 32px);
}
.large-title {
  font-size: 2.125rem;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -0.022em;
  margin: 12px 0 4px;
}
.subtitle { color: var(--text-2); margin: 0 0 20px; font-size: 0.95rem; }
.section-label {
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-2);
  margin: 28px 4px 8px;
}
.footnote { font-size: 0.8125rem; color: var(--text-2); margin: 8px 4px 0; line-height: 1.4; }

.group {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 16px;
  position: relative;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0; left: 16px; right: 0;
  height: 0.5px;
  background: var(--sep);
}
.row .label { flex: 1; min-width: 0; }
.row .value { color: var(--text-2); font-variant-numeric: tabular-nums; }
.row.stack { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px 16px; }

/* ---------- Buttons: feedback on press, not release ---------- */

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  min-height: 48px;
  font-weight: 600;
  font-size: 1.0625rem;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  transition: transform 100ms ease-out, opacity 100ms ease-out, background-color 150ms ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active, .btn.pressed { transform: scale(0.97); opacity: 0.85; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.plain { background: transparent; padding: 0 8px; min-height: 44px; font-weight: 500; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn:focus-visible, .seg button:focus-visible, .choice:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

.icon-btn {
  appearance: none; border: 0; background: var(--surface-2); color: var(--text-2);
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  transition: transform 100ms ease-out;
}
.icon-btn:active { transform: scale(0.92); }

/* Segmented control */
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.seg button {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 7px;
  min-height: 32px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: background-color 150ms ease, transform 100ms ease-out;
}
.seg button:active { transform: scale(0.96); }
.seg button[aria-pressed="true"] {
  background: var(--seg-on);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  font-weight: 600;
}

/* Inputs */
.field {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  padding: 0 14px;
  min-height: 50px;
  font-size: 1.125rem; /* ≥16px so iOS doesn't zoom */
  outline: none;
  transition: box-shadow 150ms ease;
}
.field:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
.field.zh { font-size: 1.25rem; }
input[type="date"].field { min-height: 44px; font-size: 1rem; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }

/* Pills */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.8125rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.notice {
  border-radius: 12px; padding: 12px 14px; font-size: 0.9375rem; line-height: 1.4;
  background: var(--warn-soft); color: var(--text);
}
.notice.good { background: var(--good-soft); }
.notice b { color: var(--warn); }
.notice.good b { color: var(--good); }

/* ---------- Tab bar: translucent material, content scrolls under ---------- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding-bottom: var(--safe-b);
  background: var(--chrome);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 -0.5px 0 var(--sep);
}
.tabbar nav { display: flex; width: 100%; max-width: 680px; }
.tab {
  flex: 1;
  appearance: none; border: 0; background: none;
  height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.6875rem; font-weight: 500; letter-spacing: 0.01em;
  color: var(--text-3);
  cursor: pointer;
  transition: color 150ms ease, transform 100ms ease-out;
}
.tab:active { transform: scale(0.94); }
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- Today ---------- */

.hero {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px 20px 20px;
}
.hero .big {
  font-size: 3.25rem; font-weight: 700; line-height: 1; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.hero .big small { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; color: var(--text-2); margin-left: 4px; }
.hero .caption { color: var(--text-2); margin: 6px 0 18px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.375rem; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { font-size: 0.75rem; color: var(--text-2); }

/* ---------- Progress bars ---------- */

.levels .row { align-items: flex-start; }
.level-badge {
  flex: none;
  width: 44px; height: 44px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 0.9375rem; letter-spacing: -0.01em;
}
.level-badge.muted { background: var(--surface-2); color: var(--text-3); }
.bar {
  display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-2); margin: 8px 0 6px;
}
.bar i { display: block; height: 100%; }
.bar .known { background: var(--accent); }
.bar .learning { background: color-mix(in srgb, var(--accent) 40%, transparent); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8125rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.legend .k { background: var(--accent); }
.legend .l { background: color-mix(in srgb, var(--accent) 40%, transparent); }
.legend .n { background: var(--surface-2); }
.row-title { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.row-title span { font-weight: 400; color: var(--text-2); font-size: 0.875rem; }

/* ---------- Plan ---------- */

.slider-value {
  display: flex; align-items: baseline; justify-content: space-between;
}
.slider-value b { font-size: 2rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.slider-value b small { font-size: 0.9375rem; font-weight: 500; color: var(--text-2); letter-spacing: 0; margin-left: 4px; }
.proj { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.9375rem; }
.proj th { text-align: left; font-weight: 500; color: var(--text-2); font-size: 0.8125rem; padding: 8px 16px 6px; }
.proj td { padding: 10px 16px; border-top: 0.5px solid var(--sep); }
.proj td:first-child { font-weight: 600; }
.proj .target td { background: var(--accent-soft); }
.minutes-chart { display: flex; align-items: flex-end; gap: 2px; height: 64px; margin-top: 6px; position: relative; }
.minutes-chart i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 1px; opacity: 0.85; }
.minutes-chart i.over { background: var(--warn); }
.minutes-chart .budget { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--text-3); }

/* ---------- Sheet (study session) ---------- */

.scrim {
  position: fixed; inset: 0; z-index: 20; background: var(--scrim); opacity: 0;
  will-change: opacity;
}
.sheet {
  position: fixed;
  inset: 0;
  top: calc(var(--safe-t) + 10px);
  z-index: 21;
  background: var(--bg);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--sheet-shadow);
  display: flex;
  flex-direction: column;
  will-change: transform;
  transform: translateY(100%);
}
.sheet-head {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 10px var(--gutter) 8px;
  touch-action: none;
  cursor: grab;
}
.sheet-head .grabber {
  position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; margin-left: -18px;
  border-radius: 3px; background: var(--text-3);
}
.progress-track { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress-track i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 300ms cubic-bezier(.2,.8,.2,1); }
.sheet-head .time { font-size: 0.8125rem; color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px var(--gutter) calc(var(--safe-b) + 24px);
}
.card {
  max-width: 560px;
  margin: 0 auto;
  display: flex; flex-direction: column; gap: 16px;
}
.card-kind { text-align: center; font-size: 0.8125rem; color: var(--text-2); font-weight: 500; letter-spacing: 0.01em; margin-top: 6px; }
.prompt-hanzi {
  font-family: var(--font-zh);
  font-size: clamp(4rem, 22vw, 6.5rem);
  line-height: 1.1;
  text-align: center;
  font-weight: 400;
  margin: 8px 0 0;
  letter-spacing: 0.02em;
}
.prompt-hanzi.long { font-size: clamp(2.75rem, 13vw, 4.25rem); }
.prompt-text { text-align: center; font-size: 1.375rem; line-height: 1.3; letter-spacing: -0.01em; font-weight: 600; margin: 8px 0 0; }
.prompt-pinyin { text-align: center; font-size: 2.25rem; letter-spacing: -0.01em; font-weight: 500; margin: 8px 0 0; }
.prompt-hint { text-align: center; color: var(--text-2); margin: -6px 0 0; }
.meanings { margin: 0; padding: 0; list-style: none; text-align: center; color: var(--text); font-size: 1.0625rem; }
.meanings li + li { color: var(--text-2); font-size: 0.9375rem; margin-top: 2px; }
.answer-reveal {
  border-radius: var(--radius); padding: 14px 16px; background: var(--surface);
  display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center;
}
.answer-reveal .zh { font-size: 2rem; line-height: 1.2; }
.answer-reveal .py { font-size: 1.125rem; font-weight: 500; }
.answer-reveal .mn { color: var(--text-2); font-size: 0.9375rem; }
.verdict { text-align: center; font-weight: 600; font-size: 1.0625rem; display: flex; justify-content: center; align-items: center; gap: 6px; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }
.verdict.warn { color: var(--warn); }
.your-answer { text-align: center; color: var(--text-2); font-size: 0.9375rem; margin-top: -10px; }
.your-answer s { color: var(--bad); text-decoration-thickness: 1.5px; }

.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rating {
  appearance: none; border: 0; border-radius: 12px; padding: 8px 4px; min-height: 58px;
  background: var(--surface); color: var(--text); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-weight: 600; font-size: 0.9375rem;
  transition: transform 100ms ease-out, box-shadow 150ms ease, background-color 150ms ease;
  box-shadow: var(--shadow);
}
.rating small { font-weight: 400; font-size: 0.75rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.rating:active { transform: scale(0.95); }
.rating[data-r="1"] { color: var(--bad); }
.rating[data-r="2"] { color: var(--warn); }
.rating[data-r="3"] { color: var(--good); }
.rating[data-r="4"] { color: var(--accent); }
.rating.suggested { box-shadow: 0 0 0 2px currentColor inset; }
.rating-hint { text-align: center; font-size: 0.8125rem; color: var(--text-2); margin-top: -8px; }

.tone-pad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.tone-pad button {
  appearance: none; border: 0; border-radius: 10px; min-height: 44px; background: var(--surface);
  font-size: 1.25rem; cursor: pointer; box-shadow: var(--shadow); transition: transform 100ms ease-out;
}
.tone-pad button:active { transform: scale(0.92); background: var(--surface-2); }

/* Writing pad */
.write-slots { display: flex; justify-content: center; gap: 8px; }
.write-slot {
  width: 44px; height: 44px; border-radius: 10px; background: var(--surface);
  display: grid; place-items: center; font-family: var(--font-kai); font-size: 1.75rem; color: var(--text-3);
  box-shadow: var(--shadow);
}
.write-slot.current { box-shadow: 0 0 0 2px var(--accent) inset; color: transparent; }
.write-slot.done { color: var(--text); }
.write-slot.missed { color: var(--bad); }
.pad-wrap { display: flex; justify-content: center; }
.pad {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.pad svg.grid, .pad .writer { position: absolute; inset: 0; }
.pad-status { text-align: center; font-size: 0.875rem; color: var(--text-2); min-height: 1.3em; }

/* Intro card */
.intro-anim { display: flex; justify-content: center; gap: 6px; }
.intro-anim > div { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); }

/* Multiple choice */
.choices { display: grid; gap: 10px; }
.choices.grid2 { grid-template-columns: 1fr 1fr; }
.choice {
  appearance: none; border: 0; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  min-height: 60px; padding: 12px 16px; font-size: 1.0625rem; text-align: center; cursor: pointer;
  transition: transform 100ms ease-out, background-color 150ms ease, color 150ms ease;
}
.choice.zh { font-size: 2rem; min-height: 84px; }
.choice:active { transform: scale(0.97); }
.choice.right { background: var(--good-soft); color: var(--good); box-shadow: 0 0 0 2px var(--good) inset; }
.choice.wrong { background: var(--bad-soft); color: var(--bad); }
.choice:disabled { cursor: default; }

/* Setup */
.setup-hero { text-align: center; margin: 40px 0 8px; }
.setup-hero .mark { font-family: var(--font-kai); font-size: 4.5rem; line-height: 1; }

.done-mark {
  width: 72px; height: 72px; border-radius: 50%; margin: 24px auto 4px; display: grid; place-items: center;
  background: var(--good-soft); color: var(--good);
}
.center { text-align: center; }
.muted { color: var(--text-2); }
.spacer { height: 12px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); transform: translateX(-50%);
  background: var(--chrome); backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--text); padding: 10px 16px; border-radius: 999px; font-size: 0.9375rem; font-weight: 500; z-index: 40;
  box-shadow: 0 4px 20px rgba(0,0,0,.12), 0 0 0 0.5px var(--sep);
  transition: opacity 200ms ease, transform 250ms cubic-bezier(.2,.8,.2,1);
}
.toast.hide { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* ---------- Accessibility preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
  .btn:active, .rating:active, .choice:active, .tab:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .tabbar, .toast { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --sep: rgba(0, 0, 0, 0.5); --text-2: rgba(0, 0, 0, 0.8); }
  .tabbar { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .group, .hero, .rating, .choice { box-shadow: 0 0 0 1px var(--sep); }
}

@media (min-width: 720px) {
  .large-title { font-size: 2.5rem; }
  .sheet { left: 50%; right: auto; width: 680px; margin-left: -340px; top: calc(var(--safe-t) + 24px); bottom: 24px; border-radius: 16px; }
}
