:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a64;
  --border: #e2e0d8;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --good: #1f8a4c;
  --bad: #c2372c;
  --warn: #b7791f;
  --again: #c2372c;
  --hard: #b7791f;
  --goodbtn: #1f8a4c;
  --easy: #2f5bd3;
  --mark: #fff1b8;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --surface: #1f1f1d;
    --text: #ecebe6;
    --muted: #9b9a93;
    --border: #34332f;
    --accent: #7a9cff;
    --accent-text: #0e1320;
    --good: #4cc47f;
    --bad: #ff7a6e;
    --warn: #e0a84a;
    --mark: #4a4220;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
  /* Installed (standalone) on a notched phone: keep clear of the status bar and rounded corners. */
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  position: sticky; top: 0; z-index: 1;
}
.brand { font-weight: 700; letter-spacing: .02em; }
nav { display: flex; gap: 4px; }
nav button { border: 0; background: none; padding: 6px 10px; border-radius: 8px; color: var(--muted); }
nav button.active { background: var(--bg); color: var(--text); font-weight: 600; }
main {
  max-width: 760px; margin: 0 auto; padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
/* Standalone app: no rubber-band overscroll and no tap highlight, so it feels native. */
@media (display-mode: standalone) {
  html, body { overscroll-behavior-y: none; }
  button { -webkit-tap-highlight-color: transparent; }
}

button, input, select {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
}
button { cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
input, select { width: 100%; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; min-width: 140px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters.panel { margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
h3 { margin: 28px 0 10px; font-size: 16px; }

.session-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; min-height: 240px; display: flex; flex-direction: column; gap: 14px;
}
.card-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.prompt { font-size: 22px; line-height: 1.4; overflow-wrap: anywhere; }
.answer { font-size: 20px; border-top: 1px dashed var(--border); padding-top: 14px; overflow-wrap: anywhere; }
.explanation { font-size: 15px; color: var(--muted); overflow-wrap: anywhere; }
.blank { background: var(--mark); border-radius: 4px; padding: 0 4px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.feedback { font-weight: 600; }
.feedback.ok { color: var(--good); }
.feedback.no { color: var(--bad); }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choices button { text-align: left; padding: 12px 14px; }
.choices button.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choices button.right { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }
.choices button.wrong { border-color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); }
.tf { display: flex; gap: 8px; }
.tf button { flex: 1; padding: 12px; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.actions button { flex: 1; min-width: 72px; padding: 12px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.actions button small { font-size: 12px; color: var(--muted); font-weight: 400; }
.actions .r1 { border-color: var(--again); }
.actions .r2 { border-color: var(--hard); }
.actions .r3 { border-color: var(--goodbtn); }
.actions .r4 { border-color: var(--easy); }
.hint { font-size: 12px; text-align: center; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.tile .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .k { font-size: 12px; color: var(--muted); }

.history { display: flex; align-items: flex-end; gap: 3px; height: 120px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.history .bar { flex: 1; display: flex; flex-direction: column-reverse; min-width: 3px; height: 100%; }
.history .ok { background: var(--good); border-radius: 2px 2px 0 0; }
.history .miss { background: var(--bad); opacity: .8; border-radius: 2px 2px 0 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.meter { display: inline-block; width: 60px; height: 6px; background: var(--border); border-radius: 3px; vertical-align: middle; margin-right: 6px; }
.meter i { display: block; height: 100%; background: var(--bad); border-radius: 3px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.row { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.row .main { min-width: 0; overflow-wrap: anywhere; }
.row .sub { font-size: 12px; color: var(--muted); }
.row .ops { display: flex; gap: 4px; flex-shrink: 0; }
.row .ops button { padding: 4px 8px; font-size: 13px; }
.pill { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); margin-right: 4px; }
.pager { display: flex; justify-content: space-between; margin-top: 12px; }

#toast { position: fixed; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px); }

@media (max-width: 520px) {
  .brand { display: none; }
  nav { flex: 1; justify-content: space-between; }
  .prompt { font-size: 19px; }
  .actions button { min-width: 60px; }
}

/* Touch devices have no keyboard shortcuts to advertise. */
@media (hover: none) { .hint { display: none; } }
