:root {
  --bg: #0f172a; --card: #1e293b; --card2: #273449; --line: #334155;
  --text: #e2e8f0; --muted: #94a3b8; --accent: #38bdf8; --accent-ink: #082f49;
  --again: #ef4444; --hard: #f59e0b; --good: #22c55e; --easy: #3b82f6;
  --rwkv: #a78bfa; --new: #38bdf8;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.4 var(--font); }
body { overscroll-behavior: none; }
#app { max-width: 480px; margin: 0 auto; height: 100%; }
[hidden] { display: none !important; }
.view { min-height: 100%; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.view.center { display: flex; align-items: center; justify-content: center; padding-inline: 16px; }
.panel { background: var(--card); border-radius: 18px; padding: 24px 20px; width: 100%; }
.narrow { max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.logo { width: 52px; height: 52px; margin: 0 auto; border-radius: 14px; display: grid; place-items: center;
  font-weight: 800; font-size: 26px; background: linear-gradient(135deg, var(--rwkv), var(--accent)); color: var(--bg); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 4px 0 12px; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.center-text { text-align: center; padding: 24px; }
.err { color: var(--again); font-size: 13px; min-height: 1em; margin: 0; }
input[type=password], input[type=email], input[type=url], input[type=text], select {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
details.adv { text-align: left; color: var(--muted); font-size: 13px; }
details.adv summary { cursor: pointer; padding: 4px 0; }
details.adv input { margin-top: 8px; }

.btn { font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px; color: var(--text);
  background: var(--card2); cursor: pointer; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.warn { color: #fca5a5; }
.btn.block { display: block; width: 100%; }
.btn.big { padding: 15px; font-size: 17px; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; color: var(--text); border-radius: 10px;
  display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:active { background: var(--card); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px 16px;
  position: sticky; top: 0; background: var(--bg); z-index: 2; }
.bar .title { font-size: 26px; font-weight: 800; }
.bar-actions { display: flex; gap: 2px; }
.sync-line { color: var(--muted); font-size: 12px; padding: 0 16px 6px; }
.legend { display: flex; gap: 14px; padding: 0 16px 10px; font-size: 12px; color: var(--muted); align-items: center; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.dot.rwkv { background: var(--rwkv); } .dot.new { background: var(--new); }

.decks { list-style: none; margin: 0 12px 24px; padding: 0; background: var(--card); border-radius: 16px; overflow: hidden; }
.deck { display: flex; align-items: center; min-height: 52px; border-top: 1px solid var(--line); }
.deck:first-child { border-top: 0; }
.deck .tog { width: 32px; height: 52px; border: 0; background: none; color: var(--muted); font-size: 12px; flex: none; cursor: pointer; }
.deck .tog.none { visibility: hidden; }
.deck .nm { flex: 1; min-width: 0; padding: 14px 6px 14px 0; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck .ct { display: flex; gap: 6px; padding-right: 14px; align-items: center; font-variant-numeric: tabular-nums; }
.pill { min-width: 30px; text-align: center; border-radius: 999px; padding: 2px 8px; font-size: 13px; font-weight: 700; }
.pill.rwkv { background: rgba(167,139,250,.18); color: var(--rwkv); }
.pill.new { background: rgba(56,189,248,.14); color: var(--new); }
.pill.zero { background: transparent; color: #475569; font-weight: 500; }
.anki-ct { color: var(--muted); font-size: 11px; min-width: 34px; text-align: right; }
.deck:active { background: var(--card2); }

/* review */
.review { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.bar.compact { padding: 6px 6px 4px; gap: 4px; }
.rv-head { flex: 1; min-width: 0; text-align: center; }
.rv-deck { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rv-counts { display: flex; gap: 14px; justify-content: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.c-rwkv { color: var(--rwkv); } .c-new { color: var(--new); } .c-done { color: var(--muted); font-weight: 500; }
.c-done::before { content: "✓ "; }
.rv-meta { text-align: center; font-size: 12px; color: var(--muted); min-height: 18px; padding: 0 12px 4px; }
.rv-meta b { color: var(--text); font-weight: 600; }
.card-wrap { flex: 1; min-height: 0; margin: 0 8px; border-radius: 16px; overflow: hidden; background: var(--card); position: relative; }
#card-frame { width: 100%; height: 100%; border: 0; display: block; background: transparent; }
.answer-bar { padding: 10px 8px calc(10px + env(safe-area-inset-bottom)); }
.ease { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ease-btn { border: 0; border-radius: 12px; padding: 10px 2px 9px; font: inherit; font-weight: 700; color: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px; }
.ease-btn .ivl { font-size: 11px; font-weight: 500; opacity: .85; }
.ease-btn:active { filter: brightness(1.15); transform: scale(.97); }
.ease-btn.again { background: #b91c1c; } .ease-btn.hard { background: #b45309; }
.ease-btn.good { background: #15803d; } .ease-btn.easy { background: #1d4ed8; }

/* done */
.done-mark { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center;
  background: rgba(34,197,94,.15); color: var(--good); font-size: 28px; font-weight: 800; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0 8px; }
.stats div { background: var(--bg); border-radius: 10px; padding: 8px 2px; }
.stats b { display: block; font-size: 18px; }
.stats span { font-size: 11px; color: var(--muted); }

/* sheets */
.sheet-bg { position: fixed; inset: 0; background: rgba(2,6,23,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: var(--card); width: 100%; max-width: 480px; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
  max-height: 90vh; overflow: auto; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 6px; }
.big-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.big-stats div { background: var(--bg); border-radius: 12px; padding: 10px 4px; text-align: center; }
.big-stats b { display: block; font-size: 24px; }
.big-stats div:first-child b { color: var(--rwkv); }
.big-stats div:nth-child(2) b { color: var(--new); }
.big-stats span { font-size: 12px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); padding: 4px 0; }
.field.row { flex-direction: row; align-items: center; justify-content: space-between; }
.field.row select { width: auto; padding: 8px 10px; }
.field output { color: var(--text); font-weight: 700; margin-left: 6px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 0 0 6px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #f8fafc; color: #0f172a; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  max-width: calc(100% - 32px); z-index: 30; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.toast.bad { background: #fecaca; color: #7f1d1d; }
.busy { position: fixed; inset: 0; background: rgba(15,23,42,.82); z-index: 20; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: var(--muted); padding: 24px; text-align: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }

.tap-flash { position: absolute; top: 0; bottom: 0; width: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 800; color: #fff; pointer-events: none; animation: flash .35s ease-out forwards; }
.tap-flash.left { left: 0; } .tap-flash.right { right: 0; }
.tap-flash.again { background: rgba(185,28,28,.55); } .tap-flash.good { background: rgba(21,128,61,.55); }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
