/* ======================================================================
   VN Catchup — dark, mobile-first, zero dependencies.
   System font stack (diacritic-friendly), large tap targets,
   subtle CSS-only animations (respects prefers-reduced-motion).
   ====================================================================== */

:root{
  --bg:#0e1120;
  --surface:#181d31;
  --surface-2:#232a4a;
  --line:#2e3560;
  --text:#eef1ff;
  --muted:#9aa3c7;
  --green:#58cc02;  --green-2:#46a302;
  --blue:#1cb0f6;
  --gold:#ffc800;
  --red:#ff4b4b;    --red-2:#d33;
  --orange:#ff9600;
  --radius:16px;
  --shadow:0 8px 24px rgba(0,0,0,.35);
  --font:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,
         "Noto Sans","Segoe UI Emoji","Apple Color Emoji",sans-serif;
}

*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:var(--font);
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
  min-height:100vh;
  min-height:100dvh;
  padding-bottom:calc(24px + env(safe-area-inset-bottom));
}
button{font-family:inherit}
:focus-visible{outline:3px solid var(--blue); outline-offset:2px}

/* ---------- top bar ---------- */
.topbar{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; justify-content:space-between; gap:8px;
  padding:10px 16px;
  background:rgba(14,17,32,.92);
  backdrop-filter:blur(10px);
  border-bottom:1px solid var(--line);
}
.brand{font-weight:800; letter-spacing:.3px}
.top-stats{display:flex; align-items:center; gap:10px; font-size:.9rem}
.top-xp{color:var(--gold); font-weight:700}
.top-streak{white-space:nowrap}
.lvl-badge{
  background:linear-gradient(135deg,var(--gold),var(--orange));
  color:#231a00; font-weight:800; font-size:.8rem;
  padding:2px 10px; border-radius:999px;
}
.lvl-badge.big{font-size:1.05rem; padding:4px 14px}

/* ---------- layout / screens ---------- */
main{max-width:560px; margin:0 auto; padding:16px}
.screen{display:none}
.screen.active{display:block; animation:fadeUp .28s ease both}

.card{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:16px; margin-bottom:14px;
  box-shadow:var(--shadow);
}
.section-title{margin:0 0 10px; font-size:1.05rem}
.chip-heading{
  margin:12px 0 6px; font-size:.8rem; color:var(--muted);
  text-transform:uppercase; letter-spacing:.6px;
}
.muted{color:var(--muted)}
.small{font-size:.85rem}
.center{text-align:center}
.block{display:block}
.row{display:flex; gap:10px; flex-wrap:wrap; align-items:center}
.row.center{justify-content:center}
.visually-hidden{
  position:absolute!important; width:1px; height:1px; overflow:hidden;
  clip:rect(0 0 0 0); white-space:nowrap;
}

/* ---------- home: hero + XP bar ---------- */
.hero .lvl-line{display:flex; align-items:baseline; justify-content:space-between; gap:8px; margin-bottom:10px}
.xpbar{
  height:14px; background:var(--surface-2);
  border:1px solid var(--line); border-radius:999px; overflow:hidden;
}
.xpbar .fill{
  height:100%; width:0%;
  background:linear-gradient(90deg,var(--green),var(--blue));
  border-radius:999px; transition:width .5s ease;
}
#homeXPDetail{margin-top:6px}

/* ---------- home: stat tiles ---------- */
.stat-grid{display:grid; grid-template-columns:repeat(4,1fr); gap:8px; margin-bottom:14px}
.stat{
  background:var(--surface); border:1px solid var(--line);
  border-radius:12px; padding:10px 4px; text-align:center;
}
.stat .num{display:block; font-size:1.4rem; font-weight:800; font-variant-numeric:tabular-nums}
.stat .lbl{font-size:.7rem; color:var(--muted); text-transform:uppercase; letter-spacing:.5px}
.stat.due .num{color:var(--red)}
.stat.learning .num{color:var(--blue)}
.stat.new .num{color:var(--orange)}
.stat.mastered .num{color:var(--green)}

/* ---------- chips & pills ---------- */
.chips{display:flex; flex-wrap:wrap; gap:8px; margin-bottom:8px}
.chip{
  border:1px solid var(--line); background:var(--surface-2); color:var(--text);
  border-radius:999px; padding:9px 14px; font-size:.85rem; cursor:pointer;
  min-height:40px;
}
.chip[aria-pressed="true"]{background:var(--blue); border-color:var(--blue); color:#04263a; font-weight:700}
.pills{display:grid; grid-template-columns:repeat(4,1fr); gap:8px; margin-bottom:12px}
.pill{
  border:1px solid var(--line); background:var(--surface-2); color:var(--text);
  border-radius:12px; padding:10px 0; font-size:1rem; font-weight:700;
  cursor:pointer; min-height:44px;
}
.pill[aria-pressed="true"]{background:var(--green); border-color:var(--green-2); color:#0b2a00}

/* ---------- buttons ---------- */
.btn{
  border:1px solid var(--line); background:var(--surface-2); color:var(--text);
  border-radius:14px; padding:12px 18px; font-size:1rem; font-weight:700;
  cursor:pointer; min-height:48px;
  transition:transform .06s ease, filter .15s ease;
}
.btn:active{transform:scale(.97)}
.btn:disabled{opacity:.45; cursor:default}
.btn.primary{background:var(--green); border-color:var(--green-2); color:#0b2a00}
.btn.good{background:var(--green); border-color:var(--green-2); color:#0b2a00}
.btn.warn{background:var(--gold); border-color:#d9a800; color:#2b2000}
.btn.bad{background:var(--red); border-color:var(--red-2); color:#fff}
.btn.ghost{background:transparent}
.btn.small{min-height:38px; padding:7px 12px; font-size:.85rem; border-radius:10px}
.btn.big{width:100%; padding:16px; font-size:1.1rem}
.danger-text{color:var(--red)}
.startbox .btn.big{margin-bottom:10px}

/* ---------- session ---------- */
.sess-top{display:flex; align-items:center; gap:10px; margin-bottom:14px}
.sess-progress{
  flex:1; height:12px; background:var(--surface-2);
  border:1px solid var(--line); border-radius:999px; overflow:hidden;
}
.sess-progress .fill{height:100%; width:0%; background:var(--blue); transition:width .4s ease}
.sess-timer{
  font-variant-numeric:tabular-nums; font-weight:800; font-size:1.05rem;
  min-width:64px; text-align:right;
}
.sess-timer.low{color:var(--red); animation:pulse 1s infinite}

.combo-badge{
  display:inline-block; margin-bottom:10px;
  background:rgba(255,150,0,.15); border:1px solid var(--orange); color:var(--orange);
  border-radius:999px; padding:4px 12px; font-weight:700;
}
.combo-badge.pop{animation:pop .4s ease}

.xp-toast{
  position:fixed; top:64px; right:18px; z-index:50;
  background:var(--gold); color:#2b2000; font-weight:800;
  padding:8px 14px; border-radius:12px; box-shadow:var(--shadow);
  animation:floatUp 1.2s ease both;
}

.prompt{margin:6px 0 10px; color:var(--muted); font-weight:600}
.ex-card{
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--radius); box-shadow:var(--shadow);
  padding:26px 18px; text-align:center;
  font-size:1.7rem; font-weight:700; margin-bottom:6px;
  overflow-wrap:break-word;
}
.ex-card.long{font-size:1.15rem; padding:20px 16px}
.ex-meta{margin:0 0 14px; text-align:center}

/* multiple choice */
.answers.mc{display:grid; grid-template-columns:1fr; gap:10px}
@media(min-width:430px){.answers.mc{grid-template-columns:1fr 1fr}}
.option{
  display:flex; align-items:center; gap:10px; text-align:left;
  background:var(--surface-2); border:2px solid var(--line); color:var(--text);
  border-radius:14px; padding:14px; font-size:1.05rem; font-weight:600;
  cursor:pointer; min-height:56px;
}
.option .key{
  flex:none; width:26px; height:26px; border-radius:8px;
  background:var(--line); display:grid; place-items:center;
  font-size:.8rem; font-weight:800; color:var(--muted);
}
.option.correct{border-color:var(--green); background:rgba(88,204,2,.16); animation:pop .35s ease}
.option.wrong{border-color:var(--red); background:rgba(255,75,75,.14); animation:shake .35s ease}
.option:disabled{cursor:default; opacity:.5}
.option.correct:disabled{opacity:1}

/* typing */
.answers.typing{display:flex; flex-direction:column; gap:10px}
#typingInput{
  background:var(--surface-2); border:2px solid var(--line); color:var(--text);
  border-radius:14px; padding:14px; font-size:1.2rem; font-family:var(--font);
  min-height:54px;
}
#typingInput:focus{outline:none; border-color:var(--blue)}
#typingInput.wrong{border-color:var(--red); animation:shake .35s ease}
#typingInput:disabled{opacity:.7}
.answers.typing .hint{margin:0}

/* flip */
.flip-reveal{margin-top:12px}
.flip-back{
  background:var(--surface-2); border:2px solid var(--green);
  border-radius:14px; padding:16px; text-align:center;
  font-size:1.25rem; font-weight:700; margin-bottom:8px;
  animation:pop .35s ease; overflow-wrap:break-word;
}
.flip-extra{margin:0 0 12px; text-align:center}
.flip-grades{display:grid; grid-template-columns:repeat(3,1fr); gap:8px}

/* feedback */
.feedback{
  margin-top:14px; padding:14px;
  border:2px solid var(--line); border-radius:14px;
  background:var(--surface); animation:fadeUp .25s ease;
}
.feedback.good{border-color:var(--green)}
.feedback.bad{border-color:var(--red)}
.feedback.warn{border-color:var(--gold)}
.feedback p{margin:0 0 12px; font-weight:700}

.queue-done{text-align:center}
.queue-done .btn.big{margin-bottom:10px}

/* ---------- break overlay ---------- */
#screen-break{
  position:fixed; inset:0; z-index:60;
  display:none; place-items:center; text-align:center; padding:24px;
  background:radial-gradient(1200px 600px at 50% -10%, #1d2440, var(--bg));
}
#screen-break.active{display:grid; animation:fadeUp .3s ease}
.break-emoji{font-size:4rem; margin-bottom:8px}
.break-title{font-size:2rem; margin:0 0 6px}
.break-sub{color:var(--muted); margin:0 0 18px}
.break-timer{
  font-size:4rem; font-weight:800; font-variant-numeric:tabular-nums;
  letter-spacing:2px; margin-bottom:10px;
}
.break-actions{display:flex; gap:10px; justify-content:center; flex-wrap:wrap; margin-top:16px}

/* ---------- summary ---------- */
.summary-title{text-align:center; margin:8px 0 4px}
.summary-hero{text-align:center; margin:10px 0 18px}
.xp-big{font-size:3.4rem; font-weight:800; color:var(--gold); display:block; line-height:1.1}
.summary-hero .lbl{color:var(--muted); text-transform:uppercase; letter-spacing:1px; font-size:.8rem}
.summary-rows{
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--radius); overflow:hidden; margin-bottom:16px;
}
.srow{display:flex; justify-content:space-between; padding:12px 16px; border-bottom:1px solid var(--line)}
.srow:last-child{border-bottom:none}
.srow b{font-variant-numeric:tabular-nums}

/* ---------- toast ---------- */
.toast{
  position:fixed; left:50%; bottom:24px; transform:translateX(-50%);
  background:var(--surface-2); border:1px solid var(--line); color:var(--text);
  padding:12px 18px; border-radius:12px; box-shadow:var(--shadow);
  z-index:70; max-width:90vw; text-align:center;
}

/* ---------- animations ---------- */
@keyframes fadeUp{from{opacity:0; transform:translateY(10px)} to{opacity:1; transform:none}}
@keyframes pop{50%{transform:scale(1.05)}}
@keyframes shake{20%,60%{transform:translateX(-6px)} 40%,80%{transform:translateX(6px)}}
@keyframes pulse{50%{opacity:.45}}
@keyframes floatUp{
  from{opacity:0; transform:translateY(8px)}
  20%{opacity:1}
  to{opacity:0; transform:translateY(-26px)}
}

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