/* Master <24 m Near Coastal — flashcards.
   Dark is the primary case (couch, night). Light exists but is the override. */

:root {
  --bg:        #10151b;   /* near-black blue-grey, not pure black */
  --bg-raise:  #1a2129;
  --bg-press:  #232c36;
  --line:      #2b3644;
  --ink:       #e7e3da;   /* warm off-white, easy at night */
  --ink-dim:   #96a0ab;
  --ink-faint: #5c6773;
  --accent:    #d8a03d;   /* buoy-lamp amber; the only decorative colour */
  --good:      #4f9e6b;
  --warn:      #c8873a;
  --bad:       #c05b52;
  --radius: 12px;
  --pad: 16px;
}

body[data-theme="light"] {
  --bg:        #f4f2ec;
  --bg-raise:  #ffffff;
  --bg-press:  #e8e4da;
  --line:      #d8d2c4;
  --ink:       #23282e;
  --ink-dim:   #5c6773;
  --ink-faint: #96a0ab;
  --accent:    #a56f14;
  --good:      #2e7d4f;
  --warn:      #a2661a;
  --bad:       #a63c33;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }

button {
  font: inherit; color: inherit; background: none; border: none;
  cursor: pointer; touch-action: manipulation;
}
button:active { opacity: 0.75; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--pad) 10px;
  min-height: 48px;
}
.topbar .title { font-size: 17px; font-weight: 600; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12px; color: var(--ink-dim); font-weight: 400; }
.btn-back { font-size: 15px; color: var(--ink-dim); padding: 8px 10px 8px 0; }

/* ---------- decks ---------- */
.home-head { padding: calc(env(safe-area-inset-top, 0px) + 22px) var(--pad) 6px; }
.home-head h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.home-head p { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }

.scroll { flex: 1; overflow-y: auto; padding: 8px var(--pad)
  calc(env(safe-area-inset-bottom, 0px) + 16px); }

.btn-primary {
  display: block; width: 100%;
  background: var(--accent); color: #14100a;
  border-radius: var(--radius);
  padding: 15px; margin: 10px 0 16px;
  font-size: 17px; font-weight: 700; text-align: center;
}
.btn-primary:disabled { background: var(--bg-press); color: var(--ink-faint); font-weight: 600; }

.deck-row {
  display: flex; align-items: center; width: 100%; text-align: left;
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 8px;
}
.deck-row .name { flex: 1; min-width: 0; }
.deck-row .name b { display: block; font-size: 15.5px; font-weight: 600; }
.deck-row .name span { font-size: 12px; color: var(--ink-faint); }
.deck-row .due {
  font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--accent); min-width: 44px; text-align: right;
}
.deck-row .due.zero { color: var(--ink-faint); font-size: 15px; font-weight: 500; }
.deck-row .due.zero .fresh { font-size: 18px; font-weight: 600; color: var(--ink-dim); }

.footnav {
  display: flex; gap: 8px; padding: 8px var(--pad)
  calc(env(safe-area-inset-bottom, 0px) + 10px);
}
.footnav button {
  flex: 1; padding: 11px; border-radius: 10px;
  background: var(--bg-raise); border: 1px solid var(--line);
  color: var(--ink-dim); font-size: 14px;
}

/* ---------- study ---------- */
.study-meta { font-size: 12.5px; color: var(--ink-faint);
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.study-meta b { color: var(--accent); font-weight: 600; }

.practice-banner {
  text-align: center; font-size: 12.5px; color: var(--warn);
  padding: 4px var(--pad) 6px;
}

.card-area {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  padding: 4px var(--pad) 8px;
}
.card {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}

/* Front (question only): centred, whole card is the reveal target. */
.card.front-only { justify-content: center; }
.card.front-only .q {
  padding: 24px 20px; text-align: center;
  font-size: 20px; line-height: 1.45; font-weight: 500;
}
.reveal-hint {
  text-align: center; color: var(--ink-faint); font-size: 13px;
  padding-bottom: 18px;
}

/* Back: question pinned small at top, answer scrolls, source pinned to answer end. */
.card .q-small {
  padding: 14px 18px 10px; font-size: 14.5px; color: var(--ink-dim);
  border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.card .back-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px; }
.card .a { font-size: 17.5px; line-height: 1.55; white-space: pre-line; }
/* Image slot: renders only when a card carries a real image (future field `image`).
   It sits above the answer inside the same scroll region, so adding images later
   changes no layout rule — the answer block is identical with or without it. */
.card .img-slot { margin: 0 0 14px; }
.card .img-slot img { display: block; max-width: 100%; border-radius: 8px; }
.card .src {
  margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink-dim);
}
.card .src::before { content: "Source — "; color: var(--ink-faint); }
.card .leech-note {
  margin-top: 10px; font-size: 12.5px; color: var(--warn);
}
.card-tools { display: flex; justify-content: flex-end; padding: 2px 18px 10px; flex-shrink: 0; }
.btn-report { font-size: 12.5px; color: var(--ink-faint); padding: 6px 0; }

/* Grade bar: fixed at the bottom, thumb territory. */
.grades {
  display: flex; gap: 6px;
  padding: 8px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 12px);
}
.grades button {
  flex: 1; border-radius: 10px; padding: 10px 2px 8px;
  background: var(--bg-raise); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-height: 58px;
}
.grades .g-label { font-size: 15px; font-weight: 600; }
.grades .g-when { font-size: 11px; color: var(--ink-faint);
  font-variant-numeric: tabular-nums; }
.grades .g1 .g-label { color: var(--bad); }
.grades .g2 .g-label { color: var(--warn); }
.grades .g3 .g-label { color: var(--ink); }
.grades .g4 .g-label { color: var(--good); }

/* Big single reveal button (before flip) */
.reveal-bar { padding: 8px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 12px); }
.reveal-bar button {
  width: 100%; padding: 16px; border-radius: 10px;
  background: var(--bg-press); border: 1px solid var(--line);
  font-size: 16px; font-weight: 600; color: var(--ink);
}

/* ---------- done ---------- */
.done-wrap { flex: 1; overflow-y: auto; padding: 12px var(--pad)
  calc(env(safe-area-inset-bottom, 0px) + 16px); }
.done-big { font-size: 21px; font-weight: 700; margin: 18px 0 4px; }
.done-sub { color: var(--ink-dim); font-size: 14.5px; margin-bottom: 18px; }
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.stat {
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.stat .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--ink-faint); }
.btn-secondary {
  display: block; width: 100%; text-align: center;
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px; margin-top: 8px;
  font-size: 15px; color: var(--ink);
}

/* ---------- progress ---------- */
.prog-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}
.prog-row .name { flex: 1; }
.prog-row .nums { color: var(--ink-dim); font-size: 12.5px;
  font-variant-numeric: tabular-nums; }
.prog-row .rate { font-weight: 600; min-width: 46px; text-align: right;
  font-variant-numeric: tabular-nums; }
.bignum { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bignum-label { color: var(--ink-faint); font-size: 13px; margin-bottom: 14px; }
.section-h { font-size: 13px; font-weight: 600; color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: 0.05em; margin: 20px 0 4px; }
.leech-item { padding: 9px 2px; border-bottom: 1px solid var(--line);
  font-size: 13.5px; }
.leech-item .why { color: var(--warn); font-size: 12px; }
.muted { color: var(--ink-faint); font-size: 13.5px; padding: 10px 2px; }

/* ---------- settings ---------- */
.set-row {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 2px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.set-row .grow { flex: 1; }
.set-row .hint { display: block; font-size: 12px; color: var(--ink-faint); }
.set-row select, .set-row input[type="number"] {
  font: inherit; color: var(--ink); background: var(--bg-press);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; width: 84px;
}
.btn-danger { color: var(--bad); font-size: 15px; padding: 13px 2px; text-align: left; width: 100%; }
.about { font-size: 12.5px; color: var(--ink-faint); line-height: 1.6; padding: 14px 2px; }

/* ---------- report sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: none; align-items: flex-end; justify-content: center; z-index: 10;
}
.sheet-backdrop.open { display: flex; }
.sheet {
  width: 100%; max-width: 520px;
  background: var(--bg-raise); border-radius: 16px 16px 0 0;
  padding: 18px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 18px);
}
.sheet h3 { font-size: 16px; margin-bottom: 2px; }
.sheet .which { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 12px; }
.chiprow { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  padding: 7px 12px; border-radius: 999px; font-size: 13.5px;
  background: var(--bg-press); border: 1px solid var(--line); color: var(--ink-dim);
}
.chip.sel { border-color: var(--accent); color: var(--accent); }
.sheet textarea {
  width: 100%; min-height: 70px; font: inherit; font-size: 14.5px;
  color: var(--ink); background: var(--bg-press);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical;
}
.sheet-btns { display: flex; gap: 8px; margin-top: 12px; }
.sheet-btns button { flex: 1; padding: 12px; border-radius: 10px; font-size: 15px; }
.sheet-btns .send { background: var(--accent); color: #14100a; font-weight: 700; }
.sheet-btns .cancel { background: var(--bg-press); border: 1px solid var(--line); }
.sheet .netnote { font-size: 11.5px; color: var(--ink-faint); margin-top: 10px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 90px);
  background: var(--bg-press); border: 1px solid var(--line);
  color: var(--ink); font-size: 13.5px;
  padding: 9px 16px; border-radius: 999px; z-index: 20;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
.toast.show { opacity: 1; }
