:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #16191f;
  --muted: #5f6773;
  --line: #dde1e8;
  --accent: #2f6df6;
  --accent-soft: #e6edfe;
  --good: #17864a;
  --good-soft: #e2f4ea;
  --bad: #c0392f;
  --bad-soft: #fdeae8;
  --warn: #9a6700;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 20, 28, .06), 0 4px 16px rgba(16, 20, 28, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --surface: #1b1f26;
    --surface-2: #232832;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --line: #2e3440;
    --accent: #6c9bff;
    --accent-soft: #1e2a45;
    --good: #56c88a;
    --good-soft: #16301f;
    --bad: #ff8478;
    --bad-soft: #35191a;
    --warn: #e0b341;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px 96px; }

/* ---------- header ---------- */
header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar { max-width: 720px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 650; letter-spacing: -.01em; margin-right: auto; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
select, .btn, button { font: inherit; color: inherit; }
select {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; max-width: 190px;
}
nav { display: flex; gap: 4px; max-width: 720px; margin: 0 auto; padding: 0 12px 8px; overflow-x: auto; }
nav button {
  flex: 1; min-width: 74px; background: none; border: 0; cursor: pointer;
  padding: 7px 10px; border-radius: 8px; color: var(--muted); font-weight: 550; white-space: nowrap;
}
nav button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 5px;
  border-radius: 9px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
nav button[aria-selected="true"] .badge { background: var(--accent); }

/* ---------- generic ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-top: 14px;
}
.btn {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  border-radius: 9px; padding: 9px 14px; font-weight: 550;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { border: 0; background: none; color: var(--muted); padding: 6px 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
h2 { font-size: 17px; margin: 22px 0 0; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }

/* ---------- study ---------- */
.progress { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 14px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.kind {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--accent); background: var(--accent-soft);
  padding: 3px 8px; border-radius: 6px;
}
.prompt { font-size: 21px; line-height: 1.4; margin: 14px 0 4px; letter-spacing: -.01em; }
.prompt .gap { color: var(--accent); font-weight: 700; letter-spacing: .06em; }
.ipa { color: var(--muted); font-size: 15px; }
.answer {
  width: 100%; padding: 12px 14px; font-size: 17px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface-2); color: var(--text); margin-top: 14px;
}
.answer:focus { outline: none; border-color: var(--accent); }
.reveal { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.reveal .term { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.verdict { border-radius: 9px; padding: 10px 12px; margin-top: 12px; font-weight: 550; }
.verdict.ok { background: var(--good-soft); color: var(--good); }
.verdict.no { background: var(--bad-soft); color: var(--bad); }
.verdict.close { background: var(--accent-soft); color: var(--accent); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.grades button { padding: 11px 4px; text-align: center; }
.grades b { display: block; font-size: 14px; }
.grades span { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: 4px 11px; font-size: 12.5px; cursor: pointer;
}
.chip.on { background: var(--good-soft); border-color: var(--good); color: var(--good); text-decoration: line-through; }
.speak-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  cursor: pointer; padding: 4px 9px; font-size: 14px; line-height: 1.4;
}

/* ---------- browse ---------- */
.term-row { border-top: 1px solid var(--line); padding: 12px 0; }
.term-row:first-of-type { border-top: 0; }
.term-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.term-head b { font-size: 16px; letter-spacing: -.01em; }
.pill {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-2); color: var(--muted); border-radius: 5px; padding: 2px 6px;
}
.eg { color: var(--muted); font-size: 13.5px; margin-top: 4px; font-style: italic; }
.vi {
  color: var(--accent); font-size: 14px; margin-top: 4px;
  padding-left: 9px; border-left: 2px solid var(--accent-soft);
}
.prompt + .vi { font-size: 16px; margin-top: 8px; }
input.num {
  width: 82px; padding: 7px 9px; font: inherit; text-align: right;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
}
input.num:focus { outline: none; border-color: var(--accent); }
.setting { margin: 14px 0; }
.setting label { align-items: center; }
.setting .small { margin-top: 3px; }
input[type="checkbox"] { width: 17px; height: 17px; margin-left: auto; accent-color: var(--accent); }
.opp { font-size: 12.5px; margin-top: 5px; }
.opp b { color: var(--accent); font-style: normal; }
.mastery { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: flex; }
.mastery i { display: block; height: 100%; }
.mastery .m-new { background: var(--line); }
.mastery .m-learn { background: var(--warn); }
.mastery .m-known { background: var(--good); }
.lesson-head { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.lesson-head h2 { margin: 0; flex: 1; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 26px; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12.5px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 40px; }
kbd {
  font: 600 11px ui-monospace, Menlo, monospace; background: var(--surface-2);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px;
}

/* ---------- speaking recorder ---------- */
.rec-live {
  display: flex; align-items: center; gap: 7px; margin-left: auto;
  color: var(--bad); font-size: 13px; font-weight: 600;
}
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--bad);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }
.take { border-top: 1px solid var(--line); padding: 10px 0; }
.take audio { width: 100%; height: 36px; display: block; }
.take .row { margin-top: 6px; }
.take a.btn { margin-left: auto; text-decoration: none; }
textarea.ta { min-height: 96px; resize: vertical; font-size: 15px; line-height: 1.5; }
.report { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.report h3 { margin-top: 16px; }
.report .stat b { font-size: 21px; }
.chip.off { opacity: .5; }

/* ---------- phone: notches, home-screen mode, no zoom-on-focus ---------- */
header { padding-top: env(safe-area-inset-top); }
.wrap {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
@media (max-width: 560px) {
  /* iOS zooms the page when a focused control is under 16px */
  select, input, textarea, .answer { font-size: 16px; }
  .prompt { font-size: 19px; }
  .grades { gap: 6px; }
  .grades button { padding: 12px 2px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
