:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #1b1b1a;
  --ink-2: #5a5955;
  --line: #e2e1dc;
  --accent: #3f51b5;
  --accent-ink: #ffffff;
  --new: #2a78d6;
  --learn: #d03b3b;
  --review: #0f8a3c;
  --again: #d03b3b;
  --hard: #6b6a65;
  --good: #0f8a3c;
  --easy: #2a78d6;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1d1d1c;
    --ink: #eeede9;
    --ink-2: #b4b3ad;
    --line: #34342f;
    --accent: #8c9eff;
    --accent-ink: #10142e;
    --new: #6da7ec;
    --learn: #e66767;
    --review: #4cc27a;
    --again: #e66767;
    --hard: #b4b3ad;
    --good: #4cc27a;
    --easy: #6da7ec;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; text-decoration: none; color: var(--ink); }
nav { display: flex; gap: 4px; }
nav a {
  text-decoration: none; color: var(--ink-2);
  padding: 6px 12px; border-radius: 8px;
}
nav a.active { background: var(--bg); color: var(--ink); font-weight: 600; }

main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; }
main.wide { max-width: none; padding: 0; display: flex; flex-direction: column; }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--line); background: var(--surface);
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=search], textarea, select {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg);
}
textarea { min-height: 64px; resize: vertical; }
.row > select { width: auto; max-width: 100%; }
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.error { color: var(--learn); }

/* login */
.login { max-width: 340px; margin: 12vh auto 0; text-align: center; }
.login input { text-align: center; margin-bottom: 4px; }

/* deck list */
table.decks { width: 100%; border-collapse: collapse; }
table.decks td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.decks tr:last-child td { border-bottom: 0; }
table.decks td.n { width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
table.decks th { text-align: right; font-weight: 500; font-size: 12px; color: var(--ink-2); padding: 0 6px 6px; }
table.decks th:first-child { text-align: left; }
.zero { color: var(--line); }
.new { color: var(--new); } .learn { color: var(--learn); } .review { color: var(--review); }
.deck-link { text-decoration: none; color: var(--ink); font-weight: 500; }
.deck-link:hover { text-decoration: underline; }
.deck-actions a { font-size: 13px; margin-left: 10px; }
.drop {
  margin-top: 16px; border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 22px; text-align: center; color: var(--ink-2);
}
.drop.over { border-color: var(--accent); color: var(--ink); }

/* study */
.study-bar {
  display: flex; align-items: center; gap: 12px; padding: 8px 20px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.counts span { margin: 0 6px; font-weight: 600; font-variant-numeric: tabular-nums; }
.counts span.current { text-decoration: underline; }
.card-frame { flex: 1; border: 0; width: 100%; background: transparent; min-height: 300px; }
.answer-bar {
  display: flex; justify-content: center; gap: 10px; padding: 12px;
  border-top: 1px solid var(--line); background: var(--surface);
}
.answer-bar .btn { min-width: 110px; padding: 8px 14px; display: flex; flex-direction: column; align-items: center; }
.answer-bar .btn small { font-size: 12px; color: var(--ink-2); }
.answer-bar .btn kbd { font-size: 11px; color: var(--ink-2); }
.ease1 { color: var(--again); } .ease2 { color: var(--hard); } .ease3 { color: var(--good); } .ease4 { color: var(--easy); }
.finished { text-align: center; margin-top: 15vh; }
kbd {
  font: 11px ui-monospace, monospace; border: 1px solid var(--line);
  border-radius: 4px; padding: 0 4px; background: var(--bg);
}
.menu { position: relative; }
.menu-items {
  position: absolute; right: 0; top: 110%; z-index: 5; min-width: 200px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px; box-shadow: 0 6px 24px rgba(0,0,0,.15);
}
.menu-items button {
  display: flex; width: 100%; justify-content: space-between; gap: 12px;
  background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; text-align: left;
}
.menu-items button:hover { background: var(--bg); }

/* browse */
.browse { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.browse > .panel:first-child { overflow-x: auto; }
@media (min-width: 900px) { .browse.with-detail { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
table.cards { width: 100%; border-collapse: collapse; font-size: 14px; }
table.cards th { text-align: left; font-weight: 500; color: var(--ink-2); padding: 6px; border-bottom: 1px solid var(--line); }
table.cards td { padding: 6px; border-bottom: 1px solid var(--line); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.cards tr { cursor: pointer; }
table.cards tr:hover td { background: var(--bg); }
table.cards tr.sel td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
table.cards tr.suspended td { color: var(--ink-2); font-style: italic; }
.flag { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.preview { width: 100%; height: 240px; border: 1px solid var(--line); border-radius: 8px; background: transparent; }

/* stats */
.stat-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
table.simple { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.simple td, table.simple th { padding: 4px 6px; text-align: right; }
table.simple td:first-child, table.simple th:first-child { text-align: left; }
.chart { display: flex; align-items: flex-end; gap: 2px; height: 140px; border-bottom: 1px solid var(--line); }
.chart .bar { flex: 1; display: flex; flex-direction: column-reverse; gap: 1px; min-width: 2px; }
.chart .seg:last-child { border-radius: 3px 3px 0 0; }
.chart .bar:hover { opacity: .75; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-top: 4px; }

#toast {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 10;
  background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw;
}
#toast.show { opacity: 1; }
@media (max-width: 600px) {
  .answer-bar .btn { min-width: 0; flex: 1; }
  .top { gap: 12px; padding: 10px 12px; }
}
