/* Layout: one narrow column like a wine list page; study screen pins the answer buttons to the thumb zone. */
:root {
  --bg: #f5f3f6;          /* paper with a faint claret bias */
  --surface: #ffffff;
  --ink: #1c1620;
  --muted: #6b6270;
  --rule: #e2dde4;
  --claret: #7a2433;      /* accent */
  --claret-soft: #f3e4e7;
  --new: #2f5d8a;
  --lrn: #9a5b12;
  --due: #2e6b45;
  --again: #a3283a;
  --hard: #8a6420;
  --good: #2e6b45;
  --easy: #2f5d8a;
  --shadow: 0 1px 2px rgba(40, 20, 30, .06), 0 8px 24px rgba(40, 20, 30, .07);

  --f-display: "Newsreader", "Iowan Old Style", Georgia, serif;
  --f-body: "Public Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151117; --surface: #1f1a22; --ink: #eee8f0; --muted: #a59aa9; --rule: #322a36;
    --claret: #e3909e; --claret-soft: #3a222a;
    --new: #8db8e6; --lrn: #e2b06a; --due: #86c79c;
    --again: #ef8796; --hard: #d9b574; --good: #86c79c; --easy: #8db8e6;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151117; --surface: #1f1a22; --ink: #eee8f0; --muted: #a59aa9; --rule: #322a36;
  --claret: #e3909e; --claret-soft: #3a222a;
  --new: #8db8e6; --lrn: #e2b06a; --due: #86c79c;
  --again: #ef8796; --hard: #d9b574; --good: #86c79c; --easy: #8db8e6;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--f-body);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--claret); outline-offset: 2px; border-radius: 6px; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
}
.screen {
  display: flex; flex-direction: column;
  min-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
}

/* ---------- Home ---------- */
.masthead { padding-block: 40px 20px; border-bottom: 1px solid var(--ink); }
.eyebrow {
  margin: 0 0 6px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--claret); font-weight: 600;
}
.masthead h1 {
  margin: 0; font-family: var(--f-display); font-weight: 400; font-style: italic;
  font-size: clamp(44px, 13vw, 64px); line-height: .95; letter-spacing: -.02em; text-wrap: balance;
}
.summary { margin: 12px 0 0; color: var(--muted); font-size: 15px; }
.summary strong { color: var(--ink); font-weight: 600; }

.deck-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding-block: 18px 6px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.cols { display: grid; grid-template-columns: repeat(3, 52px); text-align: right; }

.deck-list { list-style: none; margin: 0; padding: 0; }
.deck-list li { border-bottom: 1px solid var(--rule); }
.deck-row {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 14px; background: none; border: 0; text-align: left; cursor: pointer;
}
.deck-row:hover .deck-name { color: var(--claret); }
.deck-name {
  min-width: 0; font-family: var(--f-display); font-size: 21px; line-height: 1.2;
  display: flex; align-items: baseline; gap: 8px;
}
.deck-name .dots { color: var(--muted); font-family: var(--f-mono); font-size: 13px; }
.depth-0 .deck-name { font-size: 24px; font-weight: 600; }
.depth-1 .deck-row { padding-left: 14px; }
.depth-2 .deck-row { padding-left: 32px; }
.depth-2 .deck-name { font-size: 18px; font-style: italic; }
.deck-total { display: block; font-family: var(--f-body); font-size: 12px; color: var(--muted); font-style: normal; font-weight: 400; }
.counts {
  display: grid; grid-template-columns: repeat(3, 52px); text-align: right; flex: none;
  font-family: var(--f-mono); font-size: 15px; font-variant-numeric: tabular-nums;
}
.counts .zero { color: var(--rule); }
.c-new { color: var(--new); }
.c-lrn { color: var(--lrn); }
.c-due { color: var(--due); }
.deck-head .c-new, .deck-head .c-lrn, .deck-head .c-due { color: inherit; }

.home-foot { margin-top: auto; padding-block: 32px 28px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.fine { margin: 0; color: var(--muted); font-size: 13px; max-width: 46ch; }
.link-btn {
  background: none; border: 0; padding: 0; color: var(--claret); font-weight: 600; font-size: 15px;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.empty { padding-block: 24px; color: var(--muted); }

/* ---------- Study ---------- */
.study-bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px;
  padding-block: 10px; background: var(--bg); border-bottom: 1px solid var(--rule);
}
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 22px; cursor: pointer; color: var(--ink);
}
.icon-btn:disabled { color: var(--rule); cursor: default; }
.study-title { text-align: center; min-width: 0; display: flex; flex-direction: column; }
.study-deck { font-family: var(--f-display); font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.study-counts { font-family: var(--f-mono); font-size: 13px; font-variant-numeric: tabular-nums; display: flex; gap: 12px; justify-content: center; }
.study-counts .cur { text-decoration: underline; text-underline-offset: 3px; font-weight: 500; }

.card {
  margin-block: 20px; padding: 28px 22px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  text-align: center; min-height: 240px; display: flex; flex-direction: column; justify-content: center; gap: 4px;
  cursor: pointer; outline-offset: 4px;
}
.card.revealed { cursor: default; }
.card-back { border-top: 1px dashed var(--rule); margin-top: 18px; padding-top: 18px; }
.card-meta { margin: 14px 0 0; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

/* classes produced by the Anki decks */
.card .q { font-family: var(--f-display); font-size: 26px; line-height: 1.2; font-weight: 500; text-wrap: balance; margin: 4px 0; }
.card .v { font-family: var(--f-mono); color: var(--claret); font-size: 15px; letter-spacing: .04em; }
.card .l { margin-top: 12px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.card .a { font-size: 21px; line-height: 1.4; text-wrap: balance; }
.card-front .l:first-child { margin-top: 0; margin-bottom: 6px; }

.actions {
  position: sticky; bottom: 0; margin-top: auto; z-index: 5;
  padding-block: 12px max(14px, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}
.btn {
  appearance: none; border: 1px solid var(--ink); background: var(--ink); color: var(--bg);
  border-radius: 12px; padding: 12px 18px; font-weight: 600; font-size: 16px; cursor: pointer; min-height: 48px;
}
.btn:active { transform: translateY(1px); }
.btn-quiet { background: transparent; color: var(--ink); }
.btn-danger { background: var(--again); border-color: var(--again); color: var(--bg); }
.btn-show { width: 100%; min-height: 56px; font-size: 17px; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade {
  appearance: none; border: 1.5px solid currentColor; background: var(--surface); border-radius: 12px;
  min-height: 60px; padding: 6px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.grade .lbl { font-weight: 600; font-size: 15px; }
.grade .ivl { font-family: var(--f-mono); font-size: 12px; opacity: .85; font-variant-numeric: tabular-nums; }
.g-again { color: var(--again); }
.g-hard { color: var(--hard); }
.g-good { color: var(--good); }
.g-easy { color: var(--easy); }

.done { margin-block: 48px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.done h2 { margin: 0; font-family: var(--f-display); font-style: italic; font-weight: 400; font-size: 34px; }
.done p { margin: 0 0 12px; color: var(--muted); max-width: 36ch; }
.done-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; }

/* ---------- Settings ---------- */
.panel { padding-block: 22px; border-bottom: 1px solid var(--rule); display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 0; font-family: var(--f-display); font-weight: 600; font-size: 22px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input, .field textarea {
  font: 16px var(--f-mono); color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; width: 100%;
}
.field input { max-width: 120px; }
.msg { margin: 0; font-size: 14px; color: var(--due); min-height: 1.2em; }
.msg.err { color: var(--again); }
.stats { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.stats div { display: flex; flex-direction: column; }
.stats dt { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 0; font-family: var(--f-mono); font-size: 22px; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: no-preference) {
  .card-back:not([hidden]) { animation: rise .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
