:root {
  --bg: #f2f2f7; --surface: #fff; --text: #1c1c1e; --muted: #6e6e73; --line: #d8d8de;
  --accent: #0a7aff; --danger: #e5342f; --new: #0a66d8; --learn: #d33b2c; --review: #1d8a3a;
  --again: #e5342f; --hard: #8e8e93; --good: #1d8a3a; --easy: #0a7aff;
  --radius: 12px; --bar: 52px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --surface: #1c1c1e; --text: #f2f2f7; --muted: #98989f; --line: #38383a;
    --accent: #0a84ff; --new: #4aa3ff; --learn: #ff6b5b; --review: #4cd964; --hard: #8e8e93; --good: #34c759; --easy: #0a84ff; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
#app { min-height: 100%; display: flex; flex-direction: column; }
button { font: inherit; color: var(--accent); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; min-height: 44px; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.big { display: block; width: 100%; margin: 10px 0; font-size: 18px; }
button.text, button.icon, button.plain { background: none; border: none; padding: 8px 10px; }
button.icon { font-size: 26px; line-height: 1; min-width: 44px; }
button.small { font-size: 14px; min-height: 32px; padding: 4px 8px; }
a { color: var(--accent); }

header.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px; min-height: var(--bar);
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
header.bar h1 { flex: 1; margin: 0; font-size: 18px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-space { width: 44px; }
.bar-actions { display: flex; min-width: 44px; justify-content: flex-end; }

main.screen { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 12px max(16px, env(safe-area-inset-right)) 90px max(16px, env(safe-area-inset-left)); }
main.screen.center { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; min-height: 70vh; }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-around; border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  padding: 6px env(safe-area-inset-right) calc(6px + env(safe-area-inset-bottom)) env(safe-area-inset-left); }
nav.tabs a { flex: 1; text-align: center; padding: 8px 0; color: var(--muted); text-decoration: none; font-size: 15px; }
nav.tabs a.active { color: var(--accent); font-weight: 600; }

ul.decks, ul.notes { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
li.deck { display: flex; align-items: center; min-height: 52px; border-bottom: 1px solid var(--line); padding-right: 4px; }
li.deck:last-child, ul.notes li:last-child { border-bottom: none; }
.deck-name { flex: 1; color: var(--text); text-decoration: none; padding: 14px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.counts { display: flex; gap: 10px; font-variant-numeric: tabular-nums; font-size: 15px; }
.counts span { min-width: 22px; text-align: right; }
.new { color: var(--new); } .learn { color: var(--learn); } .review { color: var(--review); }
.row-buttons { display: flex; gap: 10px; margin: 14px 0; } .row-buttons button { flex: 1; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.muted { color: var(--muted); font-size: 15px; }
.today { text-align: center; white-space: pre-line; }

main.screen.study { display: flex; flex-direction: column; padding-bottom: 0; max-width: 820px; height: calc(100dvh - var(--bar) - env(safe-area-inset-top)); }
.study-counts { display: flex; justify-content: center; gap: 18px; font-variant-numeric: tabular-nums; padding: 2px 0 8px; }
.study-counts .active { text-decoration: underline; text-underline-offset: 4px; font-weight: 700; }
.card-host { flex: 1; min-height: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.card-frame { width: 100%; height: 100%; border: 0; display: block; background: var(--surface); }
.study-bottom { padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }
.answers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
button.answer { display: flex; flex-direction: column; align-items: center; padding: 8px 4px; min-height: 58px; color: #fff; border: none; font-weight: 600; }
button.answer small { font-weight: 400; font-size: 13px; opacity: .92; }
button.answer.again { background: var(--again); } button.answer.hard { background: var(--hard); }
button.answer.good { background: var(--good); } button.answer.easy { background: var(--easy); }
.congrats { padding: 40px 20px; text-align: center; white-space: pre-line; }

.form { display: flex; flex-direction: column; gap: 12px; }
label.field { display: flex; flex-direction: column; gap: 4px; }
label.field > span { font-size: 14px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
label.check input { width: 22px; height: 22px; }
input[type=text], input[type=search], input[type=number], select, textarea { font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px; }
textarea { resize: vertical; }
.search { display: flex; gap: 8px; margin-bottom: 8px; } .search input { flex: 1; }
ul.notes li { border-bottom: 1px solid var(--line); }
ul.notes a { display: block; padding: 10px 14px; color: var(--text); text-decoration: none; }
ul.notes .front { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ul.notes .back { display: block; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
section.group { background: var(--surface); border-radius: var(--radius); padding: 4px 16px 12px; margin-bottom: 16px; }
section.group h2 { font-size: 16px; margin: 12px 0 4px; }

.backdrop { position: fixed; inset: 0; z-index: 20; background: #0007; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; background: var(--surface); border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 85vh; overflow: auto; }
@media (min-width: 640px) { .backdrop { align-items: center; } .sheet { border-radius: 16px; } }
.sheet h2 { margin: 0 0 8px; font-size: 18px; text-align: center; }
.sheet-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; z-index: 30;
  background: #333d; color: #fff; padding: 10px 16px; border-radius: 20px; transition: .25s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); } .toast.error { background: #c62828ee; }
.busy { position: fixed; inset: 0; z-index: 40; background: #0006; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; }
.spinner { width: 40px; height: 40px; border: 4px solid #fff4; border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.update-banner { position: fixed; top: calc(var(--bar) + env(safe-area-inset-top) + 8px); left: 50%; transform: translateX(-50%); z-index: 25;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 6px 8px 6px 14px; display: flex; gap: 8px; align-items: center; }
/* backups kept in the app (settings) */
.backups { list-style: none; padding: 0; margin: 10px 0; }
.backups li { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-bottom: 1px solid #8883; font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
p.error { color: #c62828; }
