:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1c2333;
  --muted: #6b7280;
  --primary: #3b4cca;
  --primary-ink: #ffffff;
  --ok: #167c4a;
  --ok-bg: #e4f6ec;
  --bad: #b02a37;
  --bad-bg: #fceced;
  --line: #e6e9f2;
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
}
#app { max-width: 560px; margin: 0 auto; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px; margin: 10px 0; box-shadow: 0 2px 14px rgba(28,35,51,.06);
}
.center { text-align: center; }
h1 { font-size: 1.7rem; margin: .2em 0; }
h2 { font-size: 1.3rem; margin: 0; }
.muted { color: var(--muted); }
.warn { color: #8a5a00; background: #fff7e6; border-radius: 10px; padding: 8px 12px; font-size: .85rem; margin-top: 14px; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.link { background: none; border: none; color: var(--primary); font-size: .95rem; cursor: pointer; }

.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

button.big {
  display: block; width: 100%; padding: 15px 18px; font-size: 1.05rem; font-weight: 600;
  border: 1.5px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink);
  cursor: pointer; margin: 10px 0;
}
button.big:active { transform: translateY(1px); }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
button.ghost { background: transparent; }
.row button.big { width: auto; min-width: 130px; }

.stats { display: flex; gap: 10px; margin: 6px 0 12px; }
.stat { flex: 1; background: var(--bg); border-radius: 12px; padding: 12px 8px; text-align: center; }
.stat-ic { font-size: 1.3rem; }
.stat-v { font-size: 1.4rem; font-weight: 700; }
.stat-l { font-size: .72rem; color: var(--muted); }
.levelbar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 6px; }
.levelfill { height: 100%; background: var(--primary); transition: width .3s; }

.menu { margin-top: 8px; }
.chapters { margin: 10px 0; }
.chapter { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.chapter input { width: 20px; height: 20px; }

.drillhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.stopbtn { background: var(--bg); border: none; width: 34px; height: 34px; border-radius: 10px; font-size: 1rem; color: var(--muted); cursor: pointer; }
.stopbtn:active { transform: translateY(1px); }
.progress { color: var(--muted); font-size: .85rem; }
.lemma { font-size: 2.4rem; font-weight: 700; text-align: center; margin: 12px 0 4px; letter-spacing: .5px; }
.badge { display: inline-block; margin: 0 auto 16px; padding: 3px 12px; border-radius: 99px; background: var(--bg); color: var(--muted); font-size: .8rem; }
.card > .badge { display: table; margin-left: auto; margin-right: auto; }

.field { margin: 12px 0; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 5px; }
.in {
  width: 100%; padding: 13px 14px; font-size: 1.1rem; border: 1.5px solid var(--line);
  border-radius: 12px; background: #fff; color: var(--ink);
}
.in:focus { outline: none; border-color: var(--primary); }
select.in { appearance: none; }

.feedback { margin: 14px 0; border-radius: 12px; padding: 0; }
.feedback.ok { background: var(--ok-bg); padding: 12px 14px; }
.feedback.bad { background: var(--bad-bg); padding: 12px 14px; }
.verdict { font-weight: 700; }
.feedback.ok .verdict { color: var(--ok); }
.feedback.bad .verdict { color: var(--bad); }
.correction { font-size: .95rem; margin-top: 6px; }

.big-num { font-size: 2.6rem; font-weight: 800; margin: 8px 0; }

/* Roman-themed gamification */
.rankbanner {
  background: linear-gradient(135deg, #3b4cca, #2a3699);
  color: #fff; border-radius: 14px; padding: 14px 16px; margin: 6px 0 10px;
  display: flex; justify-content: space-between; align-items: baseline;
}
.rankbanner.small { margin: 14px 0; }
.rank-name { font-weight: 700; font-size: 1.15rem; }
.rank-grade { font-variant: small-caps; letter-spacing: .5px; opacity: .92; font-weight: 600; }
.nextrank { text-align: center; font-size: .78rem; color: var(--muted); margin-bottom: 12px; }
.promo {
  margin-top: 10px; background: #fff4d6; color: #7a5200; border: 1px solid #f0d493;
  border-radius: 10px; padding: 10px 12px; font-weight: 700;
}

/* profiles */
.profile-list { margin: 14px 0; }
.profile-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.profile-row .big { flex: 1; margin: 0; }
.del { background: var(--bg); border: none; width: 46px; border-radius: 12px; font-size: 1.1rem; cursor: pointer; align-self: stretch; }
.addrow { display: flex; gap: 8px; margin-top: 16px; }
.addrow .in { flex: 1; }
.addrow .big { width: auto; margin: 0; white-space: nowrap; }

/* case table trainer */
.casetable { width: 100%; border-collapse: collapse; margin: 8px 0; }
.casetable th { font-size: .78rem; color: var(--muted); font-weight: 600; text-align: left; padding: 4px 6px; }
.casetable td { padding: 3px; }
.casetable td:first-child, .casetable th:first-child { width: 42px; }
.cellin { width: 100%; padding: 9px 8px; font-size: 1rem; border: 1.5px solid var(--line); border-radius: 9px; }
.cellin:focus { outline: none; border-color: var(--primary); }
.cellin.cell-ok { border-color: var(--ok); background: var(--ok-bg); }
.cellin.cell-bad { border-color: var(--bad); background: var(--bad-bg); }
.cellin::placeholder { color: #9aa1ad; font-style: italic; }
.anchor { display: inline-block; padding: 9px 8px; font-weight: 700; color: var(--primary); }
.cellcorrect { display: block; font-size: .72rem; color: var(--ok); font-weight: 600; margin-top: 2px; padding-left: 4px; }

/* mistakes / weighted repetition */
button.big.weak { border-color: #c9922a; color: #7a5200; background: #fff8e8; }
.comeback { background: var(--ok-bg); color: var(--ok); border-radius: 10px; padding: 10px 12px; font-weight: 700; margin: 10px 0; }
.conquer-h { font-size: 1.05rem; margin: 16px 0 8px; text-align: left; }
.misslist { text-align: left; }
.missrow { padding: 8px 0; border-bottom: 1px solid var(--line); }
.missword { display: block; font-weight: 700; color: var(--primary); }
.misscorr { display: block; font-size: .85rem; color: var(--muted); }
.muted.small { font-size: .78rem; margin-top: 8px; }

/* complete per-word overview */
.reviewrow { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line); }
.rev-ic { flex: 0 0 auto; font-size: 1rem; line-height: 1.4; }
.rev-body { display: flex; flex-direction: column; min-width: 0; }
.rev-word { font-weight: 700; }
.rev-ans { font-size: .82rem; color: var(--muted); }
.reviewrow.rev-bad .rev-word { color: var(--bad); }
.reviewrow.rev-ok .rev-word { color: var(--ink); }

/* learn mode */
.hidden { display: none !important; }
.learn-answer { background: var(--bg); border-radius: 12px; padding: 14px; font-size: 1.05rem; margin: 8px 0 14px; text-align: center; }

/* assignments */
.home-assignments { margin: 6px 0 4px; }
.assignment { background: var(--bg); border-radius: 12px; padding: 12px 14px; margin: 8px 0; }
.assign-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.assign-title { font-weight: 700; }
.assign-due { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.assign-due.due-soon { color: #8a5a00; font-weight: 700; }
.assign-due.due-late { color: var(--bad); font-weight: 700; }
.assign-prog { font-size: .8rem; color: var(--muted); margin: 4px 0 8px; }
.assignment .row { gap: 8px; }
.assignment .row .big { margin: 0; padding: 11px 12px; font-size: .95rem; }
.tworow { display: flex; gap: 10px; }
.tworow .field { flex: 1; }

/* parent dashboard */
.parent-card { border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; margin: 12px 0; }
.parent-card .stats { margin: 10px 0 4px; }
