:root {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe9de;
  --ink: #1f1c17;
  --muted: #71695c;
  --line: #e3dccf;
  --accent: #c4553b;
  --accent-ink: #ffffff;
  --accent-soft: #f6e1d9;
  --again: #c2412f;
  --hard: #a86b12;
  --good: #2d7a4b;
  --easy: #2c66a8;
  --c-new: #2c66a8;
  --c-lrn: #c2412f;
  --c-rev: #2d7a4b;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 10px 28px rgba(40, 30, 10, .08);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120e;
    --surface: #1e1b16;
    --surface-2: #2a261f;
    --ink: #f1ebe0;
    --muted: #a59c8d;
    --line: #353028;
    --accent: #e27457;
    --accent-ink: #1a0f0a;
    --accent-soft: #3a2219;
    --again: #ec7563;
    --hard: #dba548;
    --good: #5cb882;
    --easy: #6aa1e0;
    --c-new: #6aa1e0;
    --c-lrn: #ec7563;
    --c-rev: #5cb882;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 28px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    env(safe-area-inset-top)
    max(16px, env(safe-area-inset-right))
    env(safe-area-inset-bottom)
    max(16px, env(safe-area-inset-left));
}
button, a, input, textarea, select { font: inherit; color: inherit; touch-action: manipulation; }
h1, h2, h3 { letter-spacing: -.01em; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 4px; min-height: 60px; padding: 8px 0; }
.brand { flex: 1; margin: 0 0 0 2px; font-size: 30px; font-weight: 760; letter-spacing: -.03em; }
.brand span { color: var(--accent); }
.top-title { flex: 1; min-width: 0; text-align: center; }
.top-title h1 { margin: 0; font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title .sub { font-size: 13px; color: var(--muted); }
.icon-btn {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink);
  cursor: pointer; text-decoration: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn[disabled] { opacity: .28; pointer-events: none; }
.icon-btn svg { width: 24px; height: 24px; }
.top-spacer { width: 44px; flex: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 620; cursor: pointer; text-decoration: none; text-align: center;
  transition: transform .08s ease;
}
.btn svg { width: 20px; height: 20px; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--again); border-color: color-mix(in srgb, var(--again) 40%, transparent); }
.btn.danger.solid { background: var(--again); border-color: var(--again); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 58px; font-size: 17px; border-radius: 16px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- sections & lists ---------- */
.section-title { margin: 26px 2px 10px; font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel.pad { padding: 18px; }
.list { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 64px;
  text-decoration: none; color: inherit; border-top: 1px solid var(--line); cursor: pointer;
}
.list li:first-child .list-row { border-top: 0; }
.list-row:active { background: var(--surface-2); }
.list-row .main { flex: 1; min-width: 0; }
.list-row .name { font-weight: 640; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .meta { font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .chev { width: 18px; height: 18px; color: var(--muted); flex: none; }
.pills { display: flex; gap: 6px; flex: none; }
.pill { font-size: 13px; font-weight: 650; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); white-space: nowrap; }
.pill.new { color: var(--c-new); }
.pill.lrn { color: var(--c-lrn); }
.pill.rev { color: var(--c-rev); }
.pill.done { color: var(--muted); font-weight: 560; }

.today { margin: 6px 2px 18px; font-size: 15px; color: var(--muted); }
.today b { color: var(--ink); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 34px 22px 24px; }
.empty .art { width: 104px; height: 104px; margin: 0 auto 14px; }
.empty h2 { margin: 0 0 6px; font-size: 22px; }
.empty p { margin: 0 auto 22px; max-width: 320px; color: var(--muted); }

/* ---------- install hint ---------- */
.hint { display: flex; gap: 12px; align-items: flex-start; padding: 14px 14px 14px 16px; margin-bottom: 16px; border-radius: 16px; background: var(--accent-soft); font-size: 14.5px; }
.hint p { margin: 0; flex: 1; }
.hint .icon-btn { width: 32px; height: 32px; margin: -4px -4px 0 0; }
.hint .icon-btn svg { width: 18px; height: 18px; }
.share-glyph { display: inline-block; width: 16px; height: 16px; vertical-align: -2px; }

/* ---------- deck page ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 18px 8px 16px; }
.stat b { display: block; font-size: 30px; font-weight: 720; letter-spacing: -.02em; line-height: 1.15; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.new b { color: var(--c-new); }
.stat.lrn b { color: var(--c-lrn); }
.stat.rev b { color: var(--c-rev); }
.deck-actions { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.note { text-align: center; color: var(--muted); font-size: 14.5px; margin: 2px 0 4px; }
.search { width: 100%; margin-bottom: 10px; }
.more-note { text-align: center; font-size: 13.5px; color: var(--muted); padding: 12px; }
.status-tag { font-size: 12.5px; color: var(--muted); flex: none; }
.status-tag.new { color: var(--c-new); }
.status-tag.due { color: var(--c-rev); font-weight: 600; }

/* ---------- forms ---------- */
.field {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; outline: none; appearance: none; -webkit-appearance: none;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea.field { min-height: 110px; resize: vertical; line-height: 1.4; }
select.field { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 38px; }
label.lbl { display: block; margin: 16px 2px 6px; font-size: 14px; font-weight: 620; color: var(--muted); }
.form-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.setting { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.setting .main { flex: 1; }
.setting .name { font-weight: 620; }
.setting .meta { font-size: 13.5px; color: var(--muted); }
.setting input[type=number] { width: 84px; text-align: center; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
details.paste { margin-top: 14px; }
details.paste summary { cursor: pointer; color: var(--muted); font-size: 14.5px; padding: 6px 2px; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin: 6px 0; }
.preview-card { padding: 12px 14px; border-top: 1px solid var(--line); font-size: 14.5px; }
.preview-card:first-child { border-top: 0; }
.preview-card .b { color: var(--muted); }

/* ---------- study ---------- */
.study-main { flex: 1; display: flex; flex-direction: column; padding: 4px 0 14px; min-height: 0; }
.counts { display: flex; justify-content: center; gap: 14px; font-size: 13.5px; color: var(--muted); }
.counts b { font-weight: 700; }
.counts .new b { color: var(--c-new); }
.counts .lrn b { color: var(--c-lrn); }
.counts .rev b { color: var(--c-rev); }
.card-face {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  margin-top: 10px; padding: 30px 22px; min-height: 300px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow);
  text-align: center; font-size: 25px; line-height: 1.35; overflow-wrap: anywhere; cursor: pointer;
  user-select: text; -webkit-user-select: text;
}
.card-face.long { font-size: 19px; text-align: left; justify-content: flex-start; }
.card-face .a { animation: rise .18s ease-out; }
.card-face .divider { width: 100%; border: 0; border-top: 1px dashed var(--line); margin: 22px 0; }
.card-face .tap-hint { margin-top: 18px; font-size: 13.5px; color: var(--muted); }
.card-face ul, .card-face ol { text-align: left; display: inline-block; margin: 6px auto; }
.card-face table { margin: 8px auto; border-collapse: collapse; font-size: .8em; }
.card-face td, .card-face th { border: 1px solid var(--line); padding: 4px 8px; }
.cloze { color: var(--accent); font-weight: 680; }
.media-note { font-size: 13px; color: var(--muted); font-style: italic; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.answer-bar { position: sticky; bottom: 0; padding: 10px 0 14px; background: var(--bg); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 64px; border-radius: 16px; border: 0; cursor: pointer; font-weight: 680; font-size: 15px;
  color: #fff; transition: transform .08s ease;
}
.grade:active { transform: scale(.96); }
.grade .ivl { font-size: 12.5px; font-weight: 560; opacity: .9; }
.grade.again { background: var(--again); }
.grade.hard { background: var(--hard); }
.grade.good { background: var(--good); }
.grade.easy { background: var(--easy); }
@media (prefers-color-scheme: dark) { .grade { color: #111; } }

.done { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px 12px; }
.done .badge { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); margin-bottom: 16px; }
.done .badge svg { width: 42px; height: 42px; }
.done h2 { margin: 0 0 6px; font-size: 24px; }
.done p { margin: 0 0 4px; color: var(--muted); }
.done .stack { width: 100%; max-width: 340px; margin-top: 24px; }

/* ---------- modal & toast ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); background: rgba(10, 8, 5, .42); animation: fade .15s ease-out; }
.modal { width: 100%; max-width: 440px; padding: 20px; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); animation: rise .18s ease-out; }
.modal h2 { margin: 0 0 6px; font-size: 19px; }
.modal p { margin: 0 0 14px; color: var(--muted); }
.modal .field { margin: 6px 0 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
.modal .menu { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
@media (min-width: 600px) { .modal-wrap { align-items: center; } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-size: 14.5px; font-weight: 560; box-shadow: var(--shadow);
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.footer-note { text-align: center; font-size: 12.5px; color: var(--muted); padding: 26px 0 18px; }
