/* ForceLearn styles — mobile-first, dark-mode aware, iOS safe-area aware */
:root {
  --bg: #f5f6fa;
  --bg2: #ffffff;
  --card: #ffffff;
  --text: #1e2230;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #6366f1;
  --primary-d: #4f46e5;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(20, 25, 50, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --bg2: #161a24;
    --card: #1a1f2b;
    --text: #e7e9f0;
    --muted: #9aa3b2;
    --border: #2a3142;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --bg2: #161a24;
  --card: #1a1f2b;
  --text: #e7e9f0;
  --muted: #9aa3b2;
  --border: #2a3142;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
h1, h2, h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
code { background: rgba(127,127,127,0.15); padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }
hr.fc-div { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- splash ---------- */
#splash {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  padding: 24px;
}
.splash-inner { text-align: center; max-width: 420px; }
.splash-bolt, .splash-inner h1 { animation: pop .5s ease; }
.splash-bolt { font-size: 64px; }
.splash-error { color: var(--bad); font-weight: 600; }
.splash-hint { color: var(--muted); font-size: 14px; }
.splash-detail { color: var(--muted); font-size: 12px; opacity: .7; margin-top: 12px; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- layout ---------- */
#main {
  max-width: 640px; margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 14px calc(var(--nav-h) + var(--safe-bottom) + 20px);
}
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.app-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 2px 14px; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.bolt { filter: drop-shadow(0 2px 3px rgba(99,102,241,.4)); }
.streak-chip { background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-weight: 700; box-shadow: var(--shadow); }
.freeze { font-size: 12px; color: #38bdf8; margin-left: 2px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.link { background: none; border: none; color: var(--primary); font-weight: 600; cursor: pointer; font-size: 14px; }

/* ---------- level ---------- */
.level-card { padding: 14px 16px; }
.level-row { display: flex; align-items: center; gap: 10px; }
.level-badge { background: var(--primary); color: #fff; font-weight: 800; border-radius: 10px; padding: 4px 10px; font-size: 14px; white-space: nowrap; }
.level-prog { flex: 1; height: 12px; background: var(--border); border-radius: 999px; overflow: hidden; }
.level-prog-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); transition: width .4s ease; }
.level-xp { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- daily ring ---------- */
.home-top { display: flex; align-items: center; gap: 18px; }
.ring-wrap { position: relative; width: 110px; height: 110px; flex-shrink: 0; }
.ring { width: 110px; height: 110px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--border); stroke-width: 9; }
.ring-fg { fill: none; stroke: url(#g); stroke: var(--primary); stroke-width: 9; stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-val { font-size: 30px; font-weight: 800; line-height: 1; }
.stat-grid { display: flex; gap: 10px; flex: 1; }
.stat-grid.four { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 10px; }
.stat-box { flex: 1; text-align: center; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 4px; }
.stat-val { font-size: 22px; font-weight: 800; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; font-size: 15px; font-weight: 700; cursor: pointer; transition: transform .08s ease, background .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:active { background: var(--primary-d); }
.btn.big { padding: 16px; font-size: 17px; }
.btn.full { width: 100%; margin-top: 8px; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.action-grid .btn:first-child { grid-column: span 2; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.file-btn { position: relative; overflow: hidden; }

/* ---------- mastery ---------- */
.mastery-bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--border); margin: 8px 0 6px; }
.mastery-bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 12px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }

/* ---------- badges ---------- */
.badge-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.badge-mini { font-size: 22px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--bg2); border: 1px solid var(--border); }
.badge-mini.locked { filter: grayscale(1); opacity: .35; }
.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.badge-card { text-align: center; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px 10px; }
.badge-card.locked { opacity: .55; }
.badge-card.got { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99,102,241,.15); }
.badge-icon { font-size: 36px; }
.badge-name { font-weight: 700; margin-top: 6px; }

/* ---------- decks ---------- */
.deck-list { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.deck-item { display: flex; align-items: center; gap: 12px; }
.deck-item.compact { gap: 10px; }
.deck-icon { width: 42px; height: 42px; flex-shrink: 0; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; }
.deck-meta { flex: 1; min-width: 0; }
.deck-name { font-weight: 700; }
.tag { font-size: 10px; background: var(--primary); color: #fff; border-radius: 6px; padding: 1px 6px; vertical-align: middle; }

/* ---------- switch ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .2s; }
.slider:before { content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(18px); }

/* ---------- stage tracker ---------- */
.stage-track { display: flex; align-items: flex-start; justify-content: space-between; margin: 14px 0 12px; }
.stage-node { display: flex; flex-direction: column; align-items: center; gap: 5px; flex: 0 0 auto; width: 64px; text-align: center; }
.stage-dot { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; border: 2px solid var(--border); background: var(--bg2); color: var(--muted); }
.stage-node.done .stage-dot { background: var(--good); border-color: var(--good); color: #fff; }
.stage-node.active .stage-dot { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 0 0 4px rgba(99,102,241,.2); }
.stage-node.locked .stage-dot { opacity: .5; }
.stage-name { font-size: 10px; color: var(--muted); line-height: 1.2; }
.stage-node.active .stage-name { color: var(--primary); font-weight: 700; }
.stage-node.done .stage-name { color: var(--text); }
.stage-sep { flex: 1; height: 3px; border-radius: 2px; background: var(--border); margin: 16px 2px 0; }
.stage-sep.done { background: var(--good); }
.stage-prog { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin: 8px 0 6px; }
.stage-prog-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); transition: width .4s ease; }
.action-grid .btn.span2 { grid-column: span 2; }
.learn-grid { grid-template-columns: 1fr 1fr; }

/* ---------- install hint ---------- */
.install-hint { border-style: dashed; }

/* ---------- nav ---------- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; z-index: 50;
}
.nav-btn { flex: 1; background: none; border: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10px; font-weight: 600; cursor: pointer; padding: 6px 0; }
.nav-ico { font-size: 20px; }
.nav-btn.active { color: var(--primary); }

/* ---------- study ---------- */
.study-wrap { max-width: 640px; margin: 0 auto; min-height: 70vh; display: flex; flex-direction: column; }
.study-top { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.icon-btn { background: var(--card); border: 1px solid var(--border); border-radius: 10px; width: 38px; height: 38px; font-size: 18px; cursor: pointer; color: var(--text); }
.study-progress { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.study-progress-fill { height: 100%; background: var(--good); transition: width .3s; }
.combo { min-width: 56px; text-align: right; font-weight: 800; color: var(--bad); }
.card-chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 4px 10px; }
.chip.ghost { background: var(--bg2); color: var(--muted); border: 1px solid var(--border); }

.flashcard { background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 26px 22px; min-height: 200px; box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: center; }
.fc-q { font-size: 21px; font-weight: 600; line-height: 1.45; }
.fc-a { font-size: 17px; color: var(--text); }
.fc-hint { margin-top: 14px; font-size: 14px; color: var(--warn); }
.cloze-blank { display: inline-block; min-width: 60px; border-bottom: 2px solid var(--primary); color: transparent; }
.cloze-fill { color: var(--primary); font-weight: 800; background: rgba(99,102,241,.12); border-radius: 5px; padding: 0 4px; }

.study-actions { margin-top: 20px; text-align: center; }
.study-actions .btn { width: 100%; }
.kbd-hint { margin-top: 8px; }

.rate-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 20px; }
.rate { flex-direction: column; gap: 2px; padding: 12px 4px; }
.rate-label { font-size: 14px; }
.rate-iv { font-size: 11px; color: var(--muted); font-weight: 600; }
.rate-key { font-size: 10px; opacity: .5; }
.rate-again { border-color: var(--bad); } .rate-again .rate-label { color: var(--bad); }
.rate-hard { border-color: var(--warn); } .rate-hard .rate-label { color: var(--warn); }
.rate-good { border-color: var(--good); } .rate-good .rate-label { color: var(--good); }
.rate-easy { border-color: #38bdf8; } .rate-easy .rate-label { color: #38bdf8; }

/* ---------- MC ---------- */
.mc-options { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.mc-opt { justify-content: flex-start; text-align: left; gap: 10px; padding: 14px; font-weight: 600; }
.mc-key { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.mc-opt.disabled { pointer-events: none; }
.mc-opt.correct { border-color: var(--good); background: rgba(34,197,94,.14); }
.mc-opt.wrong { border-color: var(--bad); background: rgba(239,68,68,.14); }
.mc-after { margin-top: 16px; }
.mc-after .btn { width: 100%; }
.mc-explain { font-size: 15px; margin-bottom: 12px; color: var(--text); }

/* ---------- summary ---------- */
.summary { text-align: center; margin-top: 30px; }
.summary-emoji { font-size: 56px; }
.summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 16px 0; }
.flawless-note { color: var(--good); font-weight: 700; }

/* ---------- sparkline ---------- */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 70px; margin: 10px 0 4px; }
.spark-col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.spark-bar { width: 100%; background: linear-gradient(180deg, #6366f1, #8b5cf6); border-radius: 3px 3px 0 0; min-height: 4px; }

/* ---------- pills ---------- */
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill { background: var(--bg2); border: 1px solid var(--border); color: var(--muted); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 14px; cursor: pointer; }
.pill.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- settings ---------- */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-row input[type="number"] { width: 90px; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg2); color: var(--text); font-size: 15px; text-align: right; }
.set-row select { padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg2); color: var(--text); font-size: 15px; }
.file-input { width: 100%; margin: 8px 0; font-size: 13px; }
.custom-list { margin-top: 8px; }

/* ---------- toast + confetti ---------- */
#toast { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast-item { background: #111827; color: #fff; padding: 11px 18px; border-radius: 999px; font-weight: 700; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.3); opacity: 0; transform: translateY(12px); transition: all .3s ease; max-width: 90vw; }
.toast-item.show { opacity: 1; transform: none; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.confetti-piece { position: absolute; top: -30px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: .2; } }

@media (min-width: 560px) {
  .badge-grid { grid-template-columns: repeat(3, 1fr); }
}
