/* =====================================================================
   Pinyora · Modern UI
   - Inter for UI, Noto Sans SC for hanzi, JetBrains Mono for kbd hints
   - Warm off-white surfaces, slate-tinted ink, single confident red accent
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
  /* Surfaces — warm off-white, not cold grey */
  --bg:               #fafaf9;
  --surface:          #ffffff;
  --surface-2:        #f4f4f2;

  /* Ink — slate-tinted, not pure black */
  --ink:              #0f172a;
  --ink-2:            #1e293b;
  --on-ink:           #ffffff;     /* fg paired with --ink bg */
  --muted:            #64748b;
  --faint:            #94a3b8;

  /* Lines */
  --border:           #e7e5e0;
  --border-strong:    #d6d3ce;

  /* Accent — single confident red, used sparingly */
  --accent:           #e11d48;
  --accent-2:         #be123c;
  --accent-soft:      #fff1f3;
  --accent-border:    #fecdd3;

  /* Level / signal */
  --newbie:           #10b981;
  --beginner:         #3b82f6;
  --intermediate:     #8b5cf6;

  /* HSK palette — keep the rainbow but slightly muted/modern */
  --hsk1: #10b981;
  --hsk2: #3b82f6;
  --hsk3: #8b5cf6;
  --hsk4: #f59e0b;
  --hsk5: #ec4899;
  --hsk6: #64748b;

  /* Word states */
  --word-saved-bg:    #fff1f3;
  --word-saved-fg:    #be123c;
  --word-new-bg:      transparent;
  --word-new-outline: rgba(225, 29, 72, .35);
  --word-hover-bg:    #f4f4f2;

  /* Effects */
  --shadow-xs:    0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:       0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md:    0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg:    0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
  --shadow-xl:    0 20px 25px -5px rgba(15, 23, 42, 0.10), 0 8px 10px -6px rgba(15, 23, 42, 0.06);

  --radius-sm:    8px;
  --radius:       12px;
  --radius-lg:    16px;
  --radius-xl:    20px;
  --radius-pill:  999px;

  --sans:    "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  --sans-cn: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono:    "JetBrains Mono", ui-monospace, "SF Mono", monospace;
}

/* ---------- Dark theme (manual + system) ---------- */
:root[data-theme="dark"],
:root[data-theme="dark"] body {
  --bg:               #0b0b0f;
  --surface:          #16161d;
  --surface-2:        #1f1f29;
  --ink:              #f1f5f9;
  --ink-2:            #e2e8f0;
  --on-ink:           #0b0b0f;     /* dark text on light --ink in dark mode */
  --muted:            #94a3b8;
  --faint:            #64748b;
  --border:           #2a2a36;
  --border-strong:    #3a3a48;
  --accent:           #fb7185;
  --accent-2:         #f43f5e;
  --accent-soft:      #2a1218;
  --accent-border:    #4a1f29;
  --newbie:           #34d399;
  --beginner:         #60a5fa;
  --intermediate:     #a78bfa;
  --hsk1: #34d399; --hsk2: #60a5fa; --hsk3: #a78bfa;
  --hsk4: #fbbf24; --hsk5: #f472b6; --hsk6: #94a3b8;
  --word-saved-bg:    #2a1218;
  --word-saved-fg:    #fb7185;
  --word-new-outline: rgba(251, 113, 133, .45);
  --word-hover-bg:    #1f1f29;
  --shadow-xs:    0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow:       0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md:    0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
  --shadow-lg:    0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
  --shadow-xl:    0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 8px 10px -6px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg:               #0b0b0f;
    --surface:          #16161d;
    --surface-2:        #1f1f29;
    --ink:              #f1f5f9;
    --ink-2:            #e2e8f0;
    --on-ink:           #0b0b0f;
    --muted:            #94a3b8;
    --faint:            #64748b;
    --border:           #2a2a36;
    --border-strong:    #3a3a48;
    --accent:           #fb7185;
    --accent-2:         #f43f5e;
    --accent-soft:      #2a1218;
    --accent-border:    #4a1f29;
    --newbie:           #34d399;
    --beginner:         #60a5fa;
    --intermediate:     #a78bfa;
    --hsk1: #34d399; --hsk2: #60a5fa; --hsk3: #a78bfa;
    --hsk4: #fbbf24; --hsk5: #f472b6; --hsk6: #94a3b8;
    --word-saved-bg:    #2a1218;
    --word-saved-fg:    #fb7185;
    --word-new-outline: rgba(251, 113, 133, .45);
    --word-hover-bg:    #1f1f29;
    --shadow-xs:    0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow:       0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md:    0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg:    0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
    --shadow-xl:    0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 8px 10px -6px rgba(0, 0, 0, 0.6);
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-feature-settings: "cv11", "ss01";
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
:lang(zh), .hz, .hz-line, .w-hz, .ctx-hz, .vocab-context-hz {
  font-family: var(--sans-cn);
}

/* ============== TOPBAR ============== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
  gap: 12px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
  user-select: none;
}
.brand-logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #f43f5e);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--sans-cn);
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(225, 29, 72, 0.35);
}
.brand-text {
  display: flex; align-items: baseline; gap: 8px;
  line-height: 1;
}
.brand-name {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.brand-name-cn {
  font-family: var(--sans-cn);
  font-weight: 500;
  font-size: 14px;
  color: var(--faint);
}

/* Nav: segmented pill group + utility cluster */
.nav {
  display: inline-flex; align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.nav-group {
  display: inline-flex; align-items: center;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: var(--radius-pill);
}
.nav-group button {
  background: transparent;
  border: none;
  padding: 7px 14px;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-pill);
  transition: color .15s, background .15s;
}
.nav-group button:hover { color: var(--ink); background: color-mix(in srgb, var(--surface) 60%, transparent); }

/* Streak chip */
.streak {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  padding: 4px 11px; border-radius: var(--radius-pill);
  cursor: help;
}
.streak.inactive-today {
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
}

/* Icon button (theme toggle) */
#theme-btn, .icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s;
  padding: 0;
}
#theme-btn:hover, .icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--border-strong);
}
.sync-btn {
  font-size: 16px;
  font-weight: 700;
}

#auth-area {
  display: inline-flex; align-items: center; gap: 8px;
}
#auth-status {
  font-size: 12px; color: var(--muted);
}
#auth-status:not(:empty) {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--ink);
}

/* Sign-in button — modern dark pill */
.auth-signin {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--ink);
  color: var(--on-ink);
  border: 1px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 7px 14px 7px 12px;
  font-family: var(--sans);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.auth-signin:hover { background: var(--ink-2); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.auth-signin .g-icon { background: #fff; padding: 2px; border-radius: 3px; flex: 0 0 18px; }

/* Signed-in chip */
.auth-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 4px 12px 4px 4px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.auth-chip:hover { background: var(--surface-2); border-color: var(--border-strong); }
.auth-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #f43f5e); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; line-height: 1;
  overflow: hidden;
}
img.auth-avatar { object-fit: cover; }
.auth-signout-icon {
  font-size: 14px; color: var(--muted);
  padding-left: 6px; border-left: 1px solid var(--border);
}
.auth-chip:hover .auth-signout-icon { color: var(--accent); }

/* ============== MAIN ============== */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 48px 28px 96px;
}

/* ============== HERO ============== */
.hero {
  text-align: center;
  padding: 12px 12px 32px;
}
.hero h1 {
  font-family: var(--sans);
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin: 0 0 14px;
  color: var(--ink);
}
.hero p {
  font-size: 18px;
  color: var(--muted);
  margin: 0 auto;
  max-width: 560px;
  line-height: 1.55;
}
.hero-actions {
  margin-top: 24px;
  display: flex; justify-content: center; gap: 10px;
  flex-wrap: wrap;
}

/* ============== BUTTONS ============== */
.ctrl-btn {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--on-ink);
  transition: all .15s;
  display: inline-flex; align-items: center; gap: 6px;
  letter-spacing: -0.005em;
}
.ctrl-btn:hover { background: var(--ink-2); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.ctrl-btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.ctrl-btn.secondary:hover { background: var(--surface-2); border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow); color: var(--ink); }
.ctrl-btn:disabled,
.ctrl-btn.secondary:disabled {
  cursor: not-allowed;
  opacity: .45;
  transform: none;
  box-shadow: none;
}
.ctrl-btn:disabled:hover {
  background: var(--ink); color: var(--on-ink); transform: none; box-shadow: none;
}
.ctrl-btn.secondary:disabled:hover {
  background: var(--surface); color: var(--ink); border-color: var(--border);
}

.back-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all .15s;
  box-shadow: var(--shadow-xs);
}
.back-btn:hover { color: var(--ink); border-color: var(--border-strong); background: var(--surface-2); }

/* ============== ADMIN ANALYTICS ============== */
.admin-view {
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.admin-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.admin-head h1 {
  font-size: 32px;
  line-height: 1.1;
  margin: 4px 0 0;
  letter-spacing: 0;
}
.admin-eyebrow {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.analytics-metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  box-shadow: var(--shadow-xs);
}
.analytics-metric-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.analytics-metric strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.analytics-metric-sub {
  display: block;
  margin-top: 7px;
  font-size: 12px;
  color: var(--faint);
}
.analytics-panel,
.admin-empty,
.admin-alert {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
}
.analytics-panel {
  overflow: hidden;
}
.analytics-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.analytics-panel-head h2 {
  font-size: 18px;
  margin: 0;
  letter-spacing: 0;
}
.analytics-panel-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.analytics-table-wrap {
  overflow-x: auto;
}
.analytics-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: 13px;
}
.analytics-table th,
.analytics-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.analytics-table th {
  color: var(--muted);
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
}
.analytics-table tr:last-child td {
  border-bottom: none;
}
.analytics-table tr.is-active td {
  background: color-mix(in srgb, var(--newbie) 5%, transparent);
}
.analytics-table small {
  display: block;
  color: var(--faint);
  line-height: 1.35;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.analytics-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 230px;
}
.analytics-user img,
.analytics-user > span {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: 0 0 32px;
}
.analytics-user img {
  object-fit: cover;
}
.analytics-user > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent-2);
  border: 1px solid var(--accent-border);
  font-weight: 700;
}
.analytics-user strong {
  display: block;
  color: var(--ink);
  line-height: 1.25;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  background: var(--faint);
}
.status-dot.on {
  background: var(--newbie);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--newbie) 18%, transparent);
}
.analytics-empty-row {
  color: var(--muted);
  text-align: center !important;
  padding: 28px !important;
}
.admin-empty,
.admin-alert {
  padding: 22px;
}
.admin-empty h1 {
  margin: 0 0 8px;
}
.admin-empty p,
.admin-alert span {
  color: var(--muted);
  margin: 0;
}
.admin-alert {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.admin-alert strong {
  color: var(--accent-2);
}

@media (max-width: 860px) {
  .analytics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .analytics-grid { grid-template-columns: 1fr; }
  .admin-head { align-items: stretch; }
  .admin-head .ctrl-btn { justify-content: center; }
}

/* ============== SEARCH ============== */
.library-search,
.vocab-search {
  max-width: 540px;
  margin: 0 auto 24px;
  position: relative;
}
.library-search input,
.vocab-search input {
  width: 100%;
  padding: 12px 44px 12px 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14.5px;
  transition: all .15s;
  box-shadow: var(--shadow-xs);
}
.library-search input::placeholder,
.vocab-search input::placeholder { color: var(--faint); }
.library-search input:focus,
.vocab-search input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ink) 8%, transparent);
}
.library-search::before,
.vocab-search::before {
  content: "";
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px;
  background-color: var(--faint);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>") center / contain no-repeat;
  pointer-events: none;
}
#lib-search-clear,
#vocab-search-clear {
  position: absolute;
  right: 10px; top: 50%; transform: translateY(-50%);
  background: var(--surface-2); border: 1px solid var(--border);
  width: 24px; height: 24px;
  border-radius: 50%;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s;
}
#lib-search-clear:hover,
#vocab-search-clear:hover {
  color: var(--accent); background: var(--accent-soft); border-color: var(--accent-border);
}

/* ============== LEVEL FILTER ============== */
.level-filter {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center;
  margin: 18px auto 32px;
  max-width: 1100px;
}
.lvl-pill {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: all .15s;
  box-shadow: var(--shadow-xs);
}
.lvl-pill:hover { color: var(--ink); border-color: var(--border-strong); }
.lvl-pill.active {
  background: var(--ink);
  color: var(--on-ink);
  border-color: var(--ink);
}
.lvl-pill .lvl-count {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--faint);
}
.lvl-pill.active .lvl-count { background: color-mix(in srgb, var(--on-ink) 18%, transparent); color: var(--on-ink); }

/* ============== LEVEL SECTION ============== */
.level-section { margin-top: 48px; }
.level-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.level-title {
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--ink);
}
.level-badge {
  font-family: var(--sans);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
}
.level-badge.newbie       { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.level-badge.beginner     { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.level-badge.intermediate { background: #ede9fe; color: #5b21b6; border: 1px solid #ddd6fe; }
.level-badge.upper        { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.level-badge.advanced     { background: #ffedd5; color: #9a3412; border: 1px solid #fed7aa; }
.level-badge.native       { background: #fce7f3; color: #9d174d; border: 1px solid #fbcfe8; }
.level-badge.paste        { background: var(--accent-soft); color: var(--accent-2); border: 1px solid var(--accent-border); }
:root[data-theme="dark"] .level-badge.newbie       { background: rgba(52, 211, 153, .15); color: #34d399; border-color: rgba(52, 211, 153, .3); }
:root[data-theme="dark"] .level-badge.beginner     { background: rgba(96, 165, 250, .15); color: #60a5fa; border-color: rgba(96, 165, 250, .3); }
:root[data-theme="dark"] .level-badge.intermediate { background: rgba(167, 139, 250, .15); color: #a78bfa; border-color: rgba(167, 139, 250, .3); }
:root[data-theme="dark"] .level-badge.upper        { background: rgba(251, 191, 36, .15); color: #fbbf24; border-color: rgba(251, 191, 36, .3); }
:root[data-theme="dark"] .level-badge.advanced     { background: rgba(251, 146, 60, .15); color: #fb923c; border-color: rgba(251, 146, 60, .3); }
:root[data-theme="dark"] .level-badge.native       { background: rgba(244, 114, 182, .15); color: #f472b6; border-color: rgba(244, 114, 182, .3); }
.level-desc {
  margin-left: auto;
  font-size: 13px;
  color: var(--faint);
  font-weight: 500;
}

/* ============== STORY CARDS ============== */
.story-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.story-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px 20px;
  cursor: pointer;
  position: relative;
  display: flex; flex-direction: column;
  transition: transform .2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow .2s, border-color .2s;
  box-shadow: var(--shadow-xs);
}
.story-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}
.story-card > .hz {
  font-family: var(--sans-cn);
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: 0;
  color: var(--ink);
  line-height: 1.2;
}
.story-card > .py {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--faint);
  margin-top: 0;
}
.story-card > .en {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 8px;
}
.story-card > .desc {
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--muted);
  margin: 12px 0 14px;
  flex: 1;
  line-height: 1.55;
}
.story-card.done { border-color: rgba(16, 185, 129, .35); }
.story-card.in-progress { border-color: rgba(59, 130, 246, .35); }
.story-card .done-badge {
  position: absolute; top: 12px; right: 12px;
  background: var(--newbie); color: #fff;
  font-size: 10px; padding: 3px 9px; border-radius: var(--radius-pill);
  font-weight: 600; letter-spacing: .3px;
}
.story-card .done-badge.in-progress { background: var(--beginner); }

/* Coverage meter on cards */
.story-card .coverage { margin-top: auto; }
.coverage-bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.coverage-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--newbie), var(--beginner));
  border-radius: var(--radius-pill);
  transition: width .3s ease;
}
.coverage-label {
  font-size: 11px;
  color: var(--faint);
  margin-top: 5px;
  letter-spacing: 0.2px;
  font-weight: 500;
}

/* ============== RESUME / CONTINUE READING ============== */
.resume-section { margin-bottom: 32px; }
.resume-card {
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s, border-color .2s;
  box-shadow: var(--shadow-xs);
}
.resume-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.resume-label {
  font-size: 11px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 1.2px; margin-bottom: 6px;
}
.resume-title .hz {
  font-family: var(--sans-cn);
  font-size: 22px; font-weight: 600; margin-right: 10px;
  color: var(--ink);
}
.resume-title .py { font-size: 13px; color: var(--muted); }
.resume-progress {
  margin-top: 10px; height: 6px; background: var(--border);
  border-radius: var(--radius-pill); overflow: hidden;
}
.resume-progress > div {
  height: 100%; background: var(--accent); transition: width .3s ease;
}
.resume-meta { font-size: 12px; color: var(--faint); margin-top: 6px; font-weight: 500; }

/* ============== READER ============== */
.reader-progress-sticky {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 3px;
  background: var(--surface-2);
  z-index: 100;
  pointer-events: none;
}
.reader-progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.reader-top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.reader-title {
  font-family: var(--sans);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  flex: 1;
  color: var(--ink);
}
.reader-title .py {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  display: block;
  letter-spacing: 0;
  margin-top: 4px;
}
.reader-coverage {
  font-size: 12px; color: var(--muted);
  padding: 5px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-pill);
  font-weight: 500;
}

.story-sources {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin: -8px 0 16px;
  font-size: 12px; color: var(--faint);
}
.story-sources-label { font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.story-source-link {
  max-width: min(280px, 70vw);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--ink); text-decoration: none;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 4px 10px; background: var(--surface);
  font-weight: 500;
  transition: all .15s;
}
.story-source-link:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-2);
}
.source-link {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px; font-weight: 500;
  text-decoration: none;
  vertical-align: middle;
}
.source-link:hover { color: var(--accent); border-color: var(--accent); }

/* Controls bar */
.controls {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: var(--shadow-xs);
}
.toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13.5px; cursor: pointer; user-select: none;
  color: var(--ink);
  font-weight: 500;
}
.toggle input { margin: 0; accent-color: var(--accent); }

.voice-picker, .rate-picker, .zoom-picker {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--muted);
  font-weight: 500;
}
.rate-picker input[type="range"], .zoom-picker input[type="range"] {
  width: 100px;
  accent-color: var(--accent);
}
.voice-picker select {
  font-family: var(--sans);
  font-size: 13px; padding: 5px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); max-width: 240px;
}
.zoom-btn {
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border);
  padding: 4px 9px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; cursor: pointer;
  min-width: 30px;
  transition: all .15s;
}
.zoom-btn:hover { border-color: var(--border-strong); color: var(--ink); background: var(--surface-2); }
#zoom-val { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; font-weight: 600; }
.controls .spacer { flex: 1; }

.voice-warning {
  font-size: 13px; color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-weight: 500;
}

/* Reader sentences */
.sentence {
  padding: 14px 16px;
  margin: 6px 0;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  border: 1px solid transparent;
}
.sentence:hover { background: var(--surface-2); }
.sentence.active {
  background: var(--surface-2);
  border-color: var(--border);
  box-shadow: inset 3px 0 0 var(--accent);
}
#sentences { --reader-scale: 1; }
.sentence .hz-line {
  font-family: var(--sans-cn);
  font-size: calc(22px * var(--reader-scale));
  line-height: 2.2;
  letter-spacing: 0;
  color: var(--ink);
}
.word {
  display: inline-flex; flex-direction: column; align-items: center;
  margin: 0 1px; padding: 0 3px; border-radius: 4px;
  cursor: pointer; vertical-align: bottom;
  transition: background .12s;
}
.word:hover { background: var(--word-hover-bg); }
.word .w-py {
  font-family: var(--sans);
  font-size: calc(11px * var(--reader-scale));
  color: var(--faint);
  line-height: 1;
  font-weight: 500;
  min-height: 0; opacity: 0;
  transition: opacity .15s;
}
.show-pinyin .word .w-py { opacity: 1; min-height: calc(14px * var(--reader-scale)); }
.sentence .en-line {
  font-family: var(--sans);
  font-size: calc(14px * var(--reader-scale));
  color: var(--muted);
  margin-top: 8px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  display: none;
}
.show-translation .sentence .en-line { display: block; }
.sentence.show-en .en-line { display: block !important; color: var(--ink); }

/* Word states */
.word.new {
  background: var(--word-new-bg);
  box-shadow: inset 0 -2px 0 var(--word-new-outline);
}
.word.saved {
  background: var(--word-saved-bg);
  color: var(--word-saved-fg);
  box-shadow: none;
}
.word.saved .w-py { color: var(--word-saved-fg); opacity: 1 !important; }
.word.unknown { opacity: .55; }
.word.known { background: transparent; box-shadow: none; opacity: 1; }
.word.known:hover { background: var(--word-hover-bg); }

/* Inline EN chip */
.en-chip {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px; padding: 2px 9px;
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  cursor: pointer; vertical-align: middle;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.sentence:hover .en-chip,
.sentence.show-en .en-chip { opacity: 1; }
.en-chip:hover { color: var(--accent); border-color: var(--accent); }

/* ============== POPUP ============== */
.popup {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  min-width: 280px; max-width: 92vw;
  z-index: 20;
}
.popup.hidden { display: none; }
.popup-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.popup-hz {
  font-family: var(--sans-cn);
  font-size: 28px; font-weight: 600;
  letter-spacing: 0;
  color: var(--ink);
}
.popup-py {
  font-family: var(--sans);
  font-size: 15px; color: var(--accent);
  font-weight: 500;
  margin: 2px 0;
}
.popup-en {
  font-family: var(--sans);
  font-size: 14px; color: var(--muted);
  margin-bottom: 12px;
}
.popup-actions { display: flex; gap: 8px; }
.popup-actions button {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px; font-weight: 500;
  color: var(--ink);
  transition: all .15s;
  display: inline-flex; align-items: center; gap: 5px;
}
.popup-actions button:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.popup-hsk {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  color: white; padding: 3px 9px; border-radius: var(--radius-pill);
}
.popup-hsk.hsk-1 { background: var(--hsk1); }
.popup-hsk.hsk-2 { background: var(--hsk2); }
.popup-hsk.hsk-3 { background: var(--hsk3); }
.popup-hsk.hsk-4 { background: var(--hsk4); }
.popup-hsk.hsk-5 { background: var(--hsk5); }
.popup-hsk.hsk-6 { background: var(--hsk6); }
.popup-examples {
  margin: 12px 0 14px; padding-top: 12px;
  border-top: 1px dashed var(--border);
  max-height: 220px; overflow-y: auto;
}
.popup-examples .ex { margin-bottom: 10px; }
.popup-examples .ex:last-child { margin-bottom: 0; }
.popup-examples .ex-c { font-family: var(--sans-cn); font-size: 15px; color: var(--ink); }
.popup-examples .ex-p { font-size: 12px; color: var(--accent); margin-top: 1px; font-weight: 500; }
.popup-examples .ex-e { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ============== VOCAB ============== */
.vocab-list {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.vocab-item {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: var(--radius);
  position: relative;
  box-shadow: var(--shadow-xs);
  transition: all .15s;
}
.vocab-item:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.vocab-item .hz {
  font-family: var(--sans-cn);
  font-size: 22px; font-weight: 600;
  color: var(--ink);
  letter-spacing: 0;
}
.vocab-item .py {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  margin-top: 2px;
}
.vocab-item .en {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}
.vocab-item .remove {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none;
  color: var(--faint);
  cursor: pointer; font-size: 16px;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.vocab-item .remove:hover { background: var(--accent-soft); color: var(--accent); }

.empty-state {
  text-align: center; color: var(--muted);
  padding: 60px 20px;
  font-size: 15px;
}

/* Vocab filters & sort */
.vocab-filters {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px;
}
.vocab-filters .pill {
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 13px; border-radius: var(--radius-pill); cursor: pointer;
  font-family: var(--sans);
  font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
  box-shadow: var(--shadow-xs);
}
.vocab-filters .pill:hover { color: var(--ink); border-color: var(--border-strong); }
.vocab-filters .pill.active {
  background: var(--ink); color: var(--on-ink); border-color: var(--ink);
}
.vocab-filters .pill .count {
  font-size: 11px; font-weight: 600; opacity: .8;
  padding: 1px 6px; background: var(--surface-2); color: var(--faint);
  border-radius: var(--radius-pill);
}
.vocab-filters .pill.active .count { background: color-mix(in srgb, var(--on-ink) 18%, transparent); color: var(--on-ink); opacity: 1; }
.vocab-sort {
  display: flex; align-items: center; gap: 8px;
  margin: -4px 0 16px; font-size: 13px; color: var(--muted);
  font-weight: 500;
}
.vocab-sort label { font-weight: 600; }
.vocab-sort select {
  font-family: var(--sans);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border);
  padding: 6px 28px 6px 12px; border-radius: var(--radius-sm);
  font-size: 13px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 12px top 50%, right 8px top 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.vocab-sort select:hover { border-color: var(--border-strong); }
.vocab-sort select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 8%, transparent); }

.vocab-context {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.vocab-context-hz {
  font-family: var(--sans-cn);
  font-size: 14px; color: var(--ink); line-height: 1.5;
}
.vocab-context-hz mark {
  background: var(--word-saved-bg); color: var(--word-saved-fg);
  padding: 0 3px; border-radius: 3px;
}
.vocab-context-en {
  font-size: 12px; color: var(--muted); margin-top: 4px;
}

/* ============== ADD-A-WORD ============== */
.add-word { margin: 8px 0 18px; }
.add-word-toggle {
  background: var(--surface); color: var(--muted);
  border: 1px dashed var(--border);
  padding: 11px 16px; border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 8px;
  transition: all .15s;
}
.add-word-toggle:hover {
  border-color: var(--ink); color: var(--ink); background: var(--surface-2);
}
.add-word-toggle .add-word-plus {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: var(--radius-pill);
  background: var(--ink); color: var(--on-ink);
  font-weight: 700; font-size: 14px; line-height: 1;
}
.add-word-form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow);
}
.add-word-form.hidden, .add-word-toggle.hidden { display: none; }
.add-word-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 14px;
  font-weight: 500;
}

.aw-suggestions {
  margin: 12px 0 0;
  display: flex; flex-direction: column; gap: 6px;
}
.aw-suggestions.hidden { display: none; }
.aw-suggestions-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  font-weight: 600;
  margin-bottom: 4px;
}
.aw-suggestion {
  display: grid;
  grid-template-columns: auto 1fr 2fr auto;
  align-items: baseline;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-family: var(--sans);
  transition: all .12s;
}
.aw-suggestion:hover {
  border-color: var(--ink);
  background: var(--surface-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}
.aw-sg-hz {
  font-family: var(--sans-cn);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}
.aw-sg-py { color: var(--accent); font-size: 13px; font-weight: 500; }
.aw-sg-en {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aw-suggestion .hsk-badge { margin: 0; }
@media (max-width: 600px) {
  .aw-suggestion {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "hz py hsk"
      "en en en";
    row-gap: 4px;
  }
  .aw-sg-hz  { grid-area: hz; }
  .aw-sg-py  { grid-area: py; }
  .aw-sg-en  { grid-area: en; white-space: normal; }
  .aw-suggestion .hsk-badge { grid-area: hsk; }
}
.add-word-row {
  display: grid; gap: 12px;
  grid-template-columns: 1fr 1fr 1fr;
}
@media (max-width: 600px) {
  .add-word-row { grid-template-columns: 1fr; }
}
.add-word-row label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; color: var(--muted); font-weight: 600;
  letter-spacing: 0.02em;
}
.add-word-row input {
  font-family: var(--sans);
  font-size: 14.5px; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg); color: var(--ink);
  transition: all .15s;
}
.add-word-row input:focus {
  outline: none; border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 8%, transparent);
}
.add-word-hint {
  font-size: 12px; color: var(--muted); margin: 12px 0 0; min-height: 16px;
}
.add-word-hint.ok { color: var(--newbie); }
.add-word-hint.warn { color: var(--accent); }
.add-word-actions {
  display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end;
}
.aw-save, .aw-cancel {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 8px 16px; border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--sans);
  font-size: 13px; font-weight: 600;
  transition: all .15s;
}
.aw-save {
  background: var(--ink); color: var(--on-ink); border-color: var(--ink);
}
.aw-save:hover { background: var(--ink-2); }
.aw-cancel:hover { border-color: var(--border-strong); background: var(--surface-2); }

/* ============== HSK BADGES ============== */
.hsk-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  color: white; padding: 2px 8px; border-radius: var(--radius-pill);
  margin-bottom: 6px; letter-spacing: .4px;
}
.hsk-badge.hsk-1 { background: var(--hsk1); }
.hsk-badge.hsk-2 { background: var(--hsk2); }
.hsk-badge.hsk-3 { background: var(--hsk3); }
.hsk-badge.hsk-4 { background: var(--hsk4); }
.hsk-badge.hsk-5 { background: var(--hsk5); }
.hsk-badge.hsk-6 { background: var(--hsk6); }

/* ============== HSK DASHBOARD ============== */
.hsk-grid {
  display: flex; flex-direction: column; gap: 10px;
  max-width: 720px; margin: 0 auto;
}
.hsk-row {
  display: grid;
  grid-template-columns: 70px 1fr auto auto;
  align-items: center; gap: 14px;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition: all .15s;
}
.hsk-row:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow); }
.hsk-row-badge { margin: 0; }
.hsk-row-bar {
  height: 8px; background: var(--surface-2);
  border-radius: var(--radius-pill); overflow: hidden;
}
.hsk-row-bar > div { height: 100%; transition: width .4s ease; border-radius: var(--radius-pill); }
.hsk-row-bar > div.hsk-1 { background: var(--hsk1); }
.hsk-row-bar > div.hsk-2 { background: var(--hsk2); }
.hsk-row-bar > div.hsk-3 { background: var(--hsk3); }
.hsk-row-bar > div.hsk-4 { background: var(--hsk4); }
.hsk-row-bar > div.hsk-5 { background: var(--hsk5); }
.hsk-row-bar > div.hsk-6 { background: var(--hsk6); }
.hsk-row-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; }
.hsk-row-pct { font-size: 14px; font-weight: 700; color: var(--ink); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.hsk-other-note { text-align: center; color: var(--muted); font-size: 13px; margin-top: 16px; }
.hsk-breakdown {
  font-size: 13px; color: var(--muted);
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
  margin-top: 6px;
}

/* ============== FLASHCARDS ============== */
.flashcard-view {
  max-width: 600px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 24px;
}
.flashcard-top {
  display: flex; justify-content: space-between; align-items: center;
}
.fc-progress {
  font-size: 13px; color: var(--muted); font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.flashcard-container {
  height: 400px; perspective: 1000px;
  cursor: pointer; position: relative;
}
.fc-front, .fc-back {
  position: absolute;
  width: 100%; height: 100%;
  backface-visibility: hidden;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 40px 48px;
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform .6s cubic-bezier(0.4, 0, 0.2, 1), box-shadow .3s;
}
.fc-back {
  transform: rotateY(180deg);
  overflow-y: auto;
  /* Stack content from top so the bottom hint never overlaps a long example. */
  justify-content: flex-start;
  padding-top: 32px;
}
.flashcard-container.flipped .fc-front { transform: rotateY(-180deg); }
.flashcard-container.flipped .fc-back  { transform: rotateY(0deg); }
.flashcard-container:hover .fc-front,
.flashcard-container:hover .fc-back { box-shadow: var(--shadow-lg); }
.flashcard-view .hz {
  font-family: var(--sans-cn);
  font-size: 80px; font-weight: 600; margin-bottom: 18px;
  color: var(--ink);
}
.flashcard-view .py {
  font-size: 22px; color: var(--accent); font-weight: 500; margin-bottom: 12px;
}
.flashcard-view .en {
  font-size: 19px; color: var(--ink); text-align: center; margin-bottom: 18px;
}
.fc-context {
  margin-top: 24px; padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius);
  width: 100%; font-size: 14.5px;
}
.ctx-hz { margin-bottom: 4px; line-height: 1.4; font-family: var(--sans-cn); }
.ctx-hz mark { background: var(--word-saved-bg); color: var(--word-saved-fg); border-radius: 3px; padding: 0 3px; }
.ctx-en { color: var(--muted); font-size: 13px; }
.fc-hint {
  position: absolute; bottom: 18px;
  font-size: 11px; color: var(--faint);
  text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600;
  background: var(--surface);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  pointer-events: none;
}
/* On the back face the content can be tall — pin the hint in flow at the
   bottom (margin-top:auto) instead of absolutely, so it's pushed below the
   example sentence rather than overlapping it. */
.fc-back .fc-hint {
  position: static;
  bottom: auto;
  margin-top: auto;
  padding-top: 14px;
  background: transparent;
}
.flashcard-actions {
  display: flex; justify-content: center; gap: 12px;
}
.flashcard-actions button { min-width: 120px; }

/* ============== SESSION STATS ============== */
.session-stats {
  max-width: 760px; margin: 24px auto 40px;
  padding: 22px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}
.session-stats h2 {
  margin: 0 0 14px; font-size: 18px; font-weight: 700;
  letter-spacing: -0.01em;
}
.session-stats h3 {
  margin: 22px 0 10px; font-size: 11px;
  color: var(--faint); font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
}
.session-stats.empty p { color: var(--muted); margin: 0; }
.sess-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.sess-card {
  display: flex; flex-direction: column;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.sess-card .num {
  font-size: 22px; font-weight: 700; color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.sess-card .lbl {
  font-size: 11px; color: var(--faint);
  text-transform: uppercase; letter-spacing: .05em;
  font-weight: 600;
  margin-top: 2px;
}
.sess-spark {
  display: flex; align-items: flex-end;
  gap: 4px; height: 52px;
  padding: 6px 2px 0;
  border-bottom: 1px solid var(--border);
}
.sess-spark .bar {
  flex: 1 1 0; min-width: 4px;
  background: var(--surface-2);
  border-radius: 3px 3px 0 0;
}
.sess-spark .bar.has { background: var(--accent); }
.sess-spark-labels {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--faint);
  margin-top: 6px;
  font-weight: 500;
}
.sess-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.sess-row {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 13px;
  align-items: center;
}
.sess-when { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; }
.sess-title {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--ink); font-weight: 500;
}
.sess-metric { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12px; }
@media (max-width: 560px) {
  .sess-row { grid-template-columns: 1fr; gap: 2px; }
  .sess-metric { text-align: left; }
}

/* ============== GRAMMAR CHIPS ============== */
.grammar-chips {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px;
}
.grammar-chip {
  font-size: 11px; font-weight: 600;
  color: var(--intermediate);
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--intermediate) 35%, transparent);
  padding: 2px 9px; border-radius: var(--radius-pill);
  letter-spacing: .2px; cursor: help;
  transition: all .15s;
}
.grammar-chip:hover {
  background: color-mix(in srgb, var(--intermediate) 10%, transparent);
  border-color: var(--intermediate);
}

/* ============== PRONUNCIATION ============== */
.mic-chip {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px; padding: 2px 9px;
  font-size: 11px; line-height: 1;
  background: transparent;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  cursor: pointer; vertical-align: middle;
  opacity: 0; transition: all .15s;
}
.sentence:hover .mic-chip,
.sentence .pronun-check ~ .hz-line .mic-chip { opacity: 1; }
.mic-chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.pronun-check {
  margin-top: 12px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px;
  animation: pronun-in .18s ease;
  box-shadow: var(--shadow-xs);
}
@keyframes pronun-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.pronun-check.shadow { border-left: 3px solid var(--accent); }
.pronun-check.shadow .pronun-skip {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); padding: 4px 11px;
  border-radius: var(--radius-pill); font-size: 12px; cursor: pointer;
  font-weight: 500;
}
.pronun-check.shadow .pronun-skip:hover { color: var(--ink); border-color: var(--border-strong); }

.pronun-check .pronun-row { display: flex; align-items: center; gap: 10px; }
.pronun-check .pronun-status { flex: 1; color: var(--ink); font-size: 13px; font-weight: 500; }
.pronun-check .pronun-status.error { color: var(--accent); }
.pronun-check .pronun-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; vertical-align: middle;
  animation: pronun-pulse 1s ease-in-out infinite;
}
@keyframes pronun-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.5); opacity: .4; }
}
.pronun-check .pronun-interim {
  font-family: var(--sans-cn);
  font-size: 20px; color: var(--muted); margin-top: 6px; min-height: 24px;
  letter-spacing: 1px;
}
.pronun-check .pronun-stop,
.pronun-check .pronun-retry,
.pronun-check .pronun-play,
.pronun-check .pronun-close {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 13px; font-size: 13px; cursor: pointer; font-weight: 500;
  transition: all .15s;
}
.pronun-check .pronun-stop:hover,
.pronun-check .pronun-retry:hover,
.pronun-check .pronun-play:hover {
  background: var(--surface-2); border-color: var(--border-strong);
}
.pronun-check .pronun-close { padding: 6px 11px; font-size: 16px; line-height: 1; }

.pronun-header {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius);
  margin: -14px -16px 12px;
}
.pronun-header .pronun-score { font-size: 28px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.pronun-header .pronun-label { font-size: 14px; font-weight: 600; opacity: .9; }
.pronun-header.great { background: rgba(16, 185, 129, .14); color: #047857; }
.pronun-header.ok    { background: rgba(245, 158, 11, .14); color: #b45309; }
.pronun-header.low   { background: rgba(225, 29, 72, .12);  color: var(--accent-2); }
:root[data-theme="dark"] .pronun-header.great { color: #34d399; }
:root[data-theme="dark"] .pronun-header.ok    { color: #fbbf24; }
:root[data-theme="dark"] .pronun-header.low   { color: var(--accent); }

.pronun-detail { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.pronun-line { display: flex; gap: 10px; align-items: baseline; }
.pronun-line .pronun-key {
  font-size: 11px; font-weight: 700; color: var(--faint);
  letter-spacing: .6px; text-transform: uppercase; min-width: 48px;
}
.pronun-line .pronun-text {
  font-size: 22px; letter-spacing: 1.5px; line-height: 1.4;
  font-family: var(--sans-cn);
}
.pronun-text .ok { color: var(--ink); }
.pronun-text .miss { color: var(--accent); text-decoration: underline wavy var(--accent); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.pronun-text .missed-target { color: var(--muted); opacity: .55; }
.pronun-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============== TRANSLATE STATUS ============== */
.translate-status {
  display: inline-block;
  font-size: 12px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 6px 14px;
  margin: 0 0 14px;
  font-weight: 500;
}
.translate-status::before {
  content: ""; display: inline-block;
  width: 10px; height: 10px; margin-right: 8px;
  border: 2px solid var(--accent); border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============== PASTE ============== */
.paste-wrap { max-width: 720px; margin: 0 auto; }
.paste-input {
  width: 100%; resize: vertical;
  font-family: var(--sans-cn);
  font-size: 17px; line-height: 1.7;
  padding: 16px 18px; border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--ink);
  outline: none;
  box-shadow: var(--shadow-xs);
  transition: all .15s;
}
.paste-input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 8%, transparent); }
.paste-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  align-items: center; margin-top: 14px;
}
.paste-hint {
  font-size: 12px; color: var(--faint); margin-left: auto;
  font-weight: 500;
}
.paste-status {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px; line-height: 1.4;
  display: flex; align-items: center; gap: 10px;
  font-weight: 500;
}
.paste-status.loading {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-2);
}
.paste-status.loading::before {
  content: "";
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}
.paste-status.ok {
  border-color: rgba(16, 185, 129, .35);
  background: rgba(16, 185, 129, .08);
  color: #047857;
}
.paste-status.error {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-2);
}
.paste-drop {
  margin-top: 12px;
  padding: 24px;
  border-radius: var(--radius);
  border: 2px dashed var(--accent);
  background: var(--accent-soft);
  color: var(--accent-2);
  text-align: center;
  font-size: 14px; font-weight: 500;
}

/* Paste library on Library page */
.paste-library .paste-cat { margin-top: 18px; }
.paste-cat-head {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--sans);
  font-size: 16px; font-weight: 600; margin: 14px 0 12px; color: var(--ink);
  letter-spacing: -0.01em;
}
.paste-cat-emoji { font-size: 18px; }
.paste-cat-count {
  font-size: 11px; font-weight: 700; color: var(--faint);
  padding: 2px 8px; background: var(--surface-2);
  border-radius: var(--radius-pill); margin-left: 4px;
}
.paste-card .paste-card-remove {
  position: absolute; top: 8px; left: 8px;
  background: transparent; border: none; color: var(--faint);
  font-size: 16px; line-height: 1; cursor: pointer;
  padding: 3px 7px; border-radius: 4px;
  opacity: 0; transition: all .15s;
}
.paste-card:hover .paste-card-remove { opacity: 1; }
.paste-card .paste-card-remove:hover { color: var(--accent); background: var(--accent-soft); }

/* ============== DIALOG ============== */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.dialog {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 24px; width: 100%; max-width: 440px;
  box-shadow: var(--shadow-xl);
}
.dialog h3 { margin: 0 0 16px; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.dialog-row {
  display: block; margin-bottom: 16px;
  font-size: 13px; color: var(--muted); font-weight: 500;
}
.dialog-row > span { display: block; margin-bottom: 6px; }
.dialog-row input[type="text"] {
  width: 100%; padding: 9px 12px; font-size: 14.5px;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none; font-family: var(--sans);
  transition: all .15s;
}
.dialog-row input[type="text"]:focus {
  border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 8%, transparent);
}
.dialog-cats { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-pill {
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 6px 13px; font-size: 13px; cursor: pointer; font-weight: 500;
  transition: all .15s;
}
.cat-pill:hover { color: var(--ink); border-color: var(--border-strong); }
.cat-pill.active { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.dialog-actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px;
}

/* ============== PWA BANNERS ============== */
.pwa-install, .pwa-update {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 8px 10px 8px 18px;
  box-shadow: var(--shadow-lg); z-index: 30;
  font-size: 13px; max-width: 92vw;
  font-weight: 500;
}
.pwa-install.hidden, .pwa-update.hidden, .pwa-offline.hidden { display: none; }
.pwa-install button, .pwa-update button {
  background: var(--ink); color: var(--on-ink); border: none;
  padding: 6px 14px; border-radius: var(--radius-pill);
  cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all .15s;
}
.pwa-install button:hover, .pwa-update button:hover { background: var(--ink-2); }
.pwa-install #pwa-install-dismiss {
  background: transparent; color: var(--faint); padding: 4px 8px; font-size: 16px;
}
.pwa-install #pwa-install-dismiss:hover { color: var(--accent); }
.pwa-offline {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--ink); color: var(--on-ink);
  text-align: center; padding: 7px 12px;
  font-size: 12px; z-index: 40; letter-spacing: .3px;
  font-weight: 500;
}

/* ============== UTIL ============== */
.hidden { display: none !important; }

/* ============== RESPONSIVE ============== */
@media (max-width: 768px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
  .nav { width: 100%; justify-content: center; gap: 6px; }
  .nav-group { padding: 3px; }
  .nav-group button { padding: 6px 12px; font-size: 13px; }
  main { padding: 32px 16px 64px; }
  .hero h1 { font-size: 36px; }
  .hero p { font-size: 16px; }
  .reader-title { font-size: 20px; }
  .flashcard-view .hz { font-size: 64px; }
  .flashcard-container { height: 360px; }
}

/* ============== TONE DRILL ============== */
.tone-drill-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: tone-fade-in .15s ease;
}
@keyframes tone-fade-in { from { opacity: 0; } to { opacity: 1; } }

.tone-drill {
  position: relative;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px 28px 24px;
  width: 100%; max-width: 640px;
  box-shadow: var(--shadow-xl);
  animation: tone-pop-in .18s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes tone-pop-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.tone-drill-close {
  position: absolute; top: 12px; right: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 18px; line-height: 1;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.tone-drill-close:hover { color: var(--ink); border-color: var(--border-strong); background: var(--surface); }

/* Header */
.tone-drill-head {
  text-align: center;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tone-drill-hz {
  font-family: var(--sans-cn);
  font-size: 56px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 2px;
  color: var(--ink);
  margin-bottom: 10px;
}
.tone-drill-py {
  display: flex; flex-wrap: wrap; gap: 12px;
  justify-content: center;
}
.tone-drill-syll {
  display: inline-flex; align-items: baseline; gap: 4px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  font-feature-settings: "lnum";
}
.tone-drill-tonenum {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  margin-left: 2px;
  font-variant-numeric: tabular-nums;
}
.tone-drill-syll[data-tone="1"] .tone-drill-tonenum { color: #be123c; border-color: #fecdd3; background: #fff1f3; }
.tone-drill-syll[data-tone="2"] .tone-drill-tonenum { color: #1e40af; border-color: #bfdbfe; background: #dbeafe; }
.tone-drill-syll[data-tone="3"] .tone-drill-tonenum { color: #166534; border-color: #bbf7d0; background: #dcfce7; }
.tone-drill-syll[data-tone="4"] .tone-drill-tonenum { color: #b45309; border-color: #fde68a; background: #fef3c7; }
.tone-drill-syll[data-tone="5"] .tone-drill-tonenum { color: var(--muted); }
:root[data-theme="dark"] .tone-drill-syll[data-tone="1"] .tone-drill-tonenum { color: #fb7185; background: rgba(251, 113, 133, .15); border-color: rgba(251, 113, 133, .3); }
:root[data-theme="dark"] .tone-drill-syll[data-tone="2"] .tone-drill-tonenum { color: #60a5fa; background: rgba(96, 165, 250, .15); border-color: rgba(96, 165, 250, .3); }
:root[data-theme="dark"] .tone-drill-syll[data-tone="3"] .tone-drill-tonenum { color: #34d399; background: rgba(52, 211, 153, .15); border-color: rgba(52, 211, 153, .3); }
:root[data-theme="dark"] .tone-drill-syll[data-tone="4"] .tone-drill-tonenum { color: #fbbf24; background: rgba(251, 191, 36, .15); border-color: rgba(251, 191, 36, .3); }

/* Body — mic */
.tone-drill-body { min-height: 160px; }
.tone-drill-mic-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 12px 0 4px;
}
.tone-drill-mic {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 14px 26px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: var(--shadow-xs);
  transition: all .15s;
}
.tone-drill-mic:hover { border-color: var(--border-strong); background: var(--surface-2); }
.tone-drill-mic:focus { outline: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--ink) 8%, transparent); }
.tone-drill-mic.recording {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 6px var(--accent-soft), 0 6px 18px rgba(225, 29, 72, .35);
  animation: tone-pulse 1.2s ease-in-out infinite;
}
:root[data-theme="dark"] .tone-drill-mic.recording { color: #0b0b0f; }
@keyframes tone-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}
.tone-drill-mic-icon {
  font-size: 22px;
  line-height: 1;
}
.tone-drill-level {
  width: 200px; height: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.tone-drill-level > div {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width 0.05s linear;
}
.tone-drill-hint {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  font-weight: 500;
  min-height: 18px;
}
.tone-drill-unsupported {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent-2);
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

/* Result */
.tone-drill-result { margin-top: 22px; }
.tone-drill-result.hidden { display: none; }

.tone-drill-overall {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.tone-drill-overall.tier-great { background: rgba(16, 185, 129, .12); color: #047857; border: 1px solid rgba(16, 185, 129, .3); }
.tone-drill-overall.tier-ok    { background: rgba(245, 158, 11, .12); color: #b45309; border: 1px solid rgba(245, 158, 11, .3); }
.tone-drill-overall.tier-low   { background: var(--accent-soft); color: var(--accent-2); border: 1px solid var(--accent-border); }
:root[data-theme="dark"] .tone-drill-overall.tier-great { color: #34d399; }
:root[data-theme="dark"] .tone-drill-overall.tier-ok    { color: #fbbf24; }
:root[data-theme="dark"] .tone-drill-overall.tier-low   { color: var(--accent); }
.tone-drill-overall-score {
  font-family: var(--sans);
  font-size: 38px;
  font-weight: 800;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.tone-drill-overall-label {
  font-size: 14.5px;
  font-weight: 600;
  flex: 1;
}

/* Pitch viz */
.tone-drill-pitch {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.tone-drill-pitch svg.tone-pitch {
  display: block;
  width: 100%;
  height: 130px;
}
.tone-drill-pitch .tone-axis {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}
.tone-drill-pitch .tone-syll-band {
  fill: color-mix(in srgb, var(--ink) 4%, transparent);
}
.tone-drill-pitch .tone-recorded polyline {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tone-drill-pitch .tone-target {
  fill: none;
  stroke-width: 2;
  stroke-dasharray: 6 4;
  stroke-linecap: round;
  opacity: .65;
}
.tone-drill-pitch .tone-target-1 { stroke: #e11d48; }
.tone-drill-pitch .tone-target-2 { stroke: #3b82f6; }
.tone-drill-pitch .tone-target-3 { stroke: #10b981; }
.tone-drill-pitch .tone-target-4 { stroke: #f59e0b; }
.tone-drill-pitch .tone-target-5 { stroke: var(--muted); }
.tone-drill-pitch svg.tone-pitch-empty {
  fill: var(--muted);
  font-size: 13px;
  font-family: var(--sans);
}
.tone-drill-pitch-legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.tone-drill-pitch-legend .legend.recorded { color: var(--ink); }
.tone-drill-pitch-legend .legend.target   { color: var(--accent); }
.tone-drill-pitch-legend .legend.median   { color: var(--faint); }

/* Per-syllable result cards */
.tone-drill-sylls {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.tone-syll-result {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.tone-syll-result.tier-great { border-color: rgba(16, 185, 129, .4); background: rgba(16, 185, 129, .06); }
.tone-syll-result.tier-ok    { border-color: rgba(245, 158, 11, .4); background: rgba(245, 158, 11, .06); }
.tone-syll-result.tier-low   { border-color: var(--accent-border); background: var(--accent-soft); }
:root[data-theme="dark"] .tone-syll-result.tier-great { background: rgba(52, 211, 153, .08); border-color: rgba(52, 211, 153, .3); }
:root[data-theme="dark"] .tone-syll-result.tier-ok    { background: rgba(251, 191, 36, .08); border-color: rgba(251, 191, 36, .3); }
:root[data-theme="dark"] .tone-syll-result.tier-low   { background: rgba(251, 113, 133, .08); border-color: rgba(251, 113, 133, .3); }

.tone-syll-result-top {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px;
}
.tone-syll-result-syll {
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.tone-syll-result-score {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.tone-syll-result.tier-great .tone-syll-result-score { color: #047857; }
.tone-syll-result.tier-ok    .tone-syll-result-score { color: #b45309; }
.tone-syll-result.tier-low   .tone-syll-result-score { color: var(--accent-2); }
:root[data-theme="dark"] .tone-syll-result.tier-great .tone-syll-result-score { color: #34d399; }
:root[data-theme="dark"] .tone-syll-result.tier-ok    .tone-syll-result-score { color: #fbbf24; }
:root[data-theme="dark"] .tone-syll-result.tier-low   .tone-syll-result-score { color: var(--accent); }

.tone-syll-result-row {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.tone-syll-tag {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}
.tone-syll-tag.expected.tone-1 { background: #fff1f3; color: #be123c; border-color: #fecdd3; }
.tone-syll-tag.expected.tone-2 { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.tone-syll-tag.expected.tone-3 { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.tone-syll-tag.expected.tone-4 { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.tone-syll-tag.expected.tone-5 { background: var(--surface-2); color: var(--muted); }
.tone-syll-tag.heard.match    { background: rgba(16, 185, 129, .12); color: #047857; border-color: rgba(16, 185, 129, .35); }
.tone-syll-tag.heard.mismatch { background: var(--accent-soft); color: var(--accent-2); border-color: var(--accent-border); }
:root[data-theme="dark"] .tone-syll-tag.expected.tone-1 { background: rgba(251, 113, 133, .15); color: #fb7185; border-color: rgba(251, 113, 133, .3); }
:root[data-theme="dark"] .tone-syll-tag.expected.tone-2 { background: rgba(96, 165, 250, .15); color: #60a5fa; border-color: rgba(96, 165, 250, .3); }
:root[data-theme="dark"] .tone-syll-tag.expected.tone-3 { background: rgba(52, 211, 153, .15); color: #34d399; border-color: rgba(52, 211, 153, .3); }
:root[data-theme="dark"] .tone-syll-tag.expected.tone-4 { background: rgba(251, 191, 36, .15); color: #fbbf24; border-color: rgba(251, 191, 36, .3); }
:root[data-theme="dark"] .tone-syll-tag.heard.match    { background: rgba(52, 211, 153, .12); color: #34d399; border-color: rgba(52, 211, 153, .3); }

.tone-drill-empty {
  padding: 16px; text-align: center;
  color: var(--muted); font-size: 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

/* Actions */
.tone-drill-actions {
  display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

@media (max-width: 600px) {
  .tone-drill { padding: 24px 20px 20px; }
  .tone-drill-hz { font-size: 44px; }
  .tone-drill-overall-score { font-size: 30px; }
  .tone-drill-actions { justify-content: center; }
  .tone-drill-actions .ctrl-btn { flex: 1 1 calc(50% - 6px); justify-content: center; }
}

/* ============== PRACTICE / EXERCISES ============== */
.practice-landing {
  max-width: 720px; margin: 0 auto;
}
.practice-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}
.practice-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  box-shadow: var(--shadow-xs);
}
.practice-stat-num {
  font-family: var(--sans);
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.practice-stat-lbl {
  font-size: 11px;
  color: var(--faint);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.practice-modes {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
.practice-mode-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  box-shadow: var(--shadow-xs);
  position: relative;
}
.practice-mode-emoji {
  font-size: 32px;
  margin-bottom: 6px;
}
.practice-mode-card h3 {
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  color: var(--ink);
}
.practice-mode-card p {
  font-size: 14.5px;
  color: var(--muted);
  margin: 0 0 18px;
  line-height: 1.55;
}
.practice-mode-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.practice-len-label {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.practice-len-label select {
  font-family: var(--sans);
  font-size: 13.5px;
  padding: 7px 28px 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 12px top 50%, right 8px top 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.practice-len-label select:hover { border-color: var(--border-strong); }
.practice-warning {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}

/* Active question */
.practice-progress {
  max-width: 720px; margin: 0 auto 24px;
}
.practice-progress-bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: 8px;
}
.practice-progress-bar > div {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width 0.25s ease;
}
.practice-progress-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.practice-quit {
  background: transparent;
  border: none;
  color: var(--faint);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: all .15s;
}
.practice-quit:hover { color: var(--accent); background: var(--accent-soft); }

.practice-question {
  max-width: 720px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-sm);
}
.practice-question-stem {
  text-align: center;
  margin-bottom: 28px;
  position: relative;
}
.practice-question-hz {
  font-family: var(--sans-cn);
  font-size: 60px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: 2px;
}
.practice-question-py {
  font-family: var(--sans);
  font-size: 18px;
  color: var(--accent);
  font-weight: 500;
  margin-top: 8px;
}
.practice-question-en {
  font-family: var(--sans);
  font-size: 18px;
  color: var(--muted);
  font-weight: 500;
  margin-top: 8px;
}
.practice-speak {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
  display: inline-flex; align-items: center; justify-content: center;
}
.practice-speak:hover { color: var(--ink); border-color: var(--border-strong); }

.practice-question-prompt {
  font-size: 13px;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  text-align: center;
  margin-bottom: 16px;
}
.practice-question-prompt code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  border: 1px solid var(--border);
}

/* MC options */
.practice-mc-options {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 560px) {
  .practice-mc-options { grid-template-columns: 1fr; }
}
.practice-mc-opt {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 500;
  padding: 14px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .15s;
  text-align: left;
  box-shadow: var(--shadow-xs);
}
.practice-mc-opt:hover:not(.locked) {
  border-color: var(--ink);
  background: var(--surface-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.practice-mc-opt.locked { cursor: default; transform: none; box-shadow: none; }
.practice-mc-opt.correct {
  background: rgba(16, 185, 129, .12);
  border-color: rgba(16, 185, 129, .5);
  color: #047857;
  font-weight: 600;
}
.practice-mc-opt.wrong {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-2);
  font-weight: 600;
  text-decoration: line-through;
  text-decoration-color: var(--accent);
}
:root[data-theme="dark"] .practice-mc-opt.correct { color: #34d399; background: rgba(52, 211, 153, .1); border-color: rgba(52, 211, 153, .35); }
:root[data-theme="dark"] .practice-mc-opt.wrong   { color: var(--accent); }

/* Pinyin form */
.practice-pinyin-form {
  display: flex; gap: 10px;
  max-width: 480px;
  margin: 0 auto;
}
.practice-pinyin-form input {
  flex: 1;
  font-family: var(--sans);
  font-size: 18px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: all .15s;
  letter-spacing: 0.5px;
}
.practice-pinyin-form input:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ink) 8%, transparent);
}
.practice-pinyin-form input:disabled {
  opacity: 0.7;
}
.practice-pinyin-feedback {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  font-weight: 500;
  text-align: center;
}
.practice-pinyin-feedback.ok {
  background: rgba(16, 185, 129, .12);
  border: 1px solid rgba(16, 185, 129, .35);
  color: #047857;
}
.practice-pinyin-feedback.miss {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent-2);
}
:root[data-theme="dark"] .practice-pinyin-feedback.ok   { color: #34d399; }
:root[data-theme="dark"] .practice-pinyin-feedback.miss { color: var(--accent); }

.practice-actions {
  max-width: 720px;
  margin: 18px auto 0;
  display: flex;
  justify-content: flex-end;
}

/* End-of-session result */
.practice-result {
  display: flex; align-items: center; gap: 20px;
  max-width: 720px; margin: 0 auto 28px;
  padding: 22px 26px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.practice-result.tier-great { background: rgba(16, 185, 129, .1); color: #047857; border-color: rgba(16, 185, 129, .35); }
.practice-result.tier-ok    { background: rgba(245, 158, 11, .1); color: #b45309; border-color: rgba(245, 158, 11, .35); }
.practice-result.tier-low   { background: var(--accent-soft); color: var(--accent-2); border-color: var(--accent-border); }
:root[data-theme="dark"] .practice-result.tier-great { color: #34d399; }
:root[data-theme="dark"] .practice-result.tier-ok    { color: #fbbf24; }
:root[data-theme="dark"] .practice-result.tier-low   { color: var(--accent); }
.practice-result-score {
  font-family: var(--sans);
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.practice-result-detail { flex: 1; }
.practice-result-label {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 4px;
}
.practice-result-meta {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
:root[data-theme="dark"] .practice-result.tier-great .practice-result-meta,
:root[data-theme="dark"] .practice-result.tier-ok    .practice-result-meta,
:root[data-theme="dark"] .practice-result.tier-low   .practice-result-meta { color: var(--faint); }

.practice-summary {
  list-style: none;
  padding: 0;
  margin: 0 auto 24px;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.practice-summary-row {
  display: grid;
  grid-template-columns: 24px 1fr 1fr 2fr;
  gap: 10px;
  align-items: baseline;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  flex-wrap: wrap;
}
.practice-summary-row.ok    { border-left: 3px solid var(--newbie); }
.practice-summary-row.miss  { border-left: 3px solid var(--accent); }
.practice-summary-mark {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.practice-summary-row.ok   .practice-summary-mark { color: var(--newbie); }
.practice-summary-row.miss .practice-summary-mark { color: var(--accent); }
.practice-summary-hz {
  font-family: var(--sans-cn);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}
.practice-summary-py {
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
}
.practice-summary-en {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.practice-summary-given {
  grid-column: 2 / -1;
  font-size: 12px;
  color: var(--accent-2);
  font-style: italic;
}
@media (max-width: 600px) {
  .practice-summary-row {
    grid-template-columns: 24px 1fr;
    grid-template-areas:
      "mark hz"
      ".    py"
      ".    en"
      ".    given";
  }
  .practice-summary-mark { grid-area: mark; }
  .practice-summary-hz   { grid-area: hz; }
  .practice-summary-py   { grid-area: py; }
  .practice-summary-en   { grid-area: en; white-space: normal; }
  .practice-summary-given{ grid-area: given; }
}
.practice-summary-actions {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  max-width: 720px; margin: 0 auto;
}
