/* Memorare. Calm and legible, for a parent holding a phone across the
   dinner table and for building decks at a desk. One loud thing: the quiz
   card, drawn as a ruled index card. Everything else stays quiet: cool desk
   paper, ink blue, and the Leitner box bar that darkens box by box. */

@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --desk: #E9ECF5;
  --paper: #FFFFFF;
  --sunk: #F4F5FA;
  --ink: #1C2140;
  --muted: #5B6185;
  --rule: #D5DAEA;
  --rule-strong: #B9C0DA;
  --accent: #2B3990;
  --accent-ink: #FFFFFF;
  --accent-soft: #DFE3F7;
  --rule-red: #D9473F;
  --got: #1D7550;
  --got-ink: #FFFFFF;
  --got-soft: #DDF1E6;
  --missed: #A9443A;
  --missed-soft: #F8E2DE;
  --warn: #8A5A00;
  --warn-soft: #FBEFCF;
  --reveal: #FFF0A8;
  --reveal-ink: #2A2300;
  --focus: #2F6FEB;
  --shadow: 0 1px 2px rgba(28, 33, 64, 0.08), 0 6px 18px rgba(28, 33, 64, 0.08);
  --lift: 0 2px 4px rgba(28, 33, 64, 0.1), 0 18px 40px rgba(28, 33, 64, 0.14);
  --logo-card: #FFFFFF;

  --b-new: #EEF0F7;
  --b1: #CDD4F1;
  --b2: #ABB7E6;
  --b3: #96A4DC;
  --b4: #7584CC;
  --b5: #5566BB;
  --b6: #3B4BA5;
  --b7: #26338A;

  --s-2: 0.75rem;
  --s-1: 0.875rem;
  --s0: 1.0625rem;
  --s1: 1.3125rem;
  --s2: 1.625rem;
  --s3: 2.0625rem;
  --tap: 44px;
  --gutter: 16px;
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --desk: #141729;
    --paper: #1E2238;
    --sunk: #191C30;
    --ink: #E8EAF6;
    --muted: #A3A8C8;
    --rule: #30355A;
    --rule-strong: #454B78;
    --accent: #93A0F2;
    --accent-ink: #11142B;
    --accent-soft: #2A3062;
    --rule-red: #EC6B61;
    --got: #4EC48C;
    --got-ink: #062014;
    --got-soft: #173528;
    --missed: #F0897D;
    --missed-soft: #3D2024;
    --warn: #F1C25B;
    --warn-soft: #3A3018;
    --reveal: #5B4C0B;
    --reveal-ink: #FFF3BF;
    --focus: #8DB4FF;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.25);
    --lift: 0 2px 4px rgba(0, 0, 0, 0.4), 0 18px 40px rgba(0, 0, 0, 0.4);
    --logo-card: #1E2238;

    --b-new: #262A44;
    --b1: #2E3561;
    --b2: #38427A;
    --b3: #455296;
    --b4: #5565B3;
    --b5: #6A7BCE;
    --b6: #8796E6;
    --b7: #AAB6FF;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 400 var(--s0)/1.5 "Atkinson Hyperlegible", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: var(--s1); }
h3 { font-size: var(--s0); }
p { margin: 0; }
a { color: var(--accent); }
ul, ol { margin: 0; padding: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
[hidden] { display: none !important; }

.boot { padding: 40px var(--gutter); color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: var(--s-1); }
.center { text-align: center; }
.pad { padding: 24px 0; }
.spacer { flex: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--missed); font-weight: 700; }
.note { background: var(--warn-soft); color: var(--ink); border-radius: var(--r-sm); padding: 8px 12px; font-size: var(--s-1); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--rule-strong); border-radius: var(--r);
  background: var(--paper); color: var(--ink);
  font-weight: 700; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--missed); border-color: var(--missed); color: var(--paper); }
.btn.danger-text { color: var(--missed); border-color: transparent; background: transparent; padding: 0 8px; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: var(--s-1); }
.btn.wide { width: 100%; }
.btn:disabled, .btn.disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap);
  border: 0; border-radius: var(--r); background: transparent; color: var(--muted); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn:disabled { opacity: 0.4; cursor: default; background: transparent; }
.linkish { display: flex; align-items: center; gap: 8px; border: 0; background: none; color: var(--accent); font-weight: 700; cursor: pointer; padding: 8px 10px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------------------------------------------------------------- shell */

.app { min-height: 100dvh; }
.sidebar { display: none; }
.main-col { display: flex; flex-direction: column; min-height: 100dvh; }

header.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: color-mix(in srgb, var(--desk) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
  min-height: 56px;
}
.titles { flex: 1; min-width: 0; padding-left: 4px; }
.titles h1 { font-size: var(--s1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kicker { font-size: var(--s-2); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.top-actions { display: flex; align-items: center; gap: 4px; }
.brand-mark { display: grid; place-items: center; width: var(--tap); height: var(--tap); }
.logo { --accent: var(--accent); }

.sync {
  font-size: var(--s-2); color: var(--muted); white-space: nowrap;
  padding: 4px 8px 4px 18px; border-radius: 999px; position: relative;
}
.sync::before {
  content: ""; position: absolute; left: 7px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px;
  border-radius: 50%; background: var(--got);
}
.sync[data-state=sending]::before { background: var(--accent); animation: pulse 1s infinite alternate; }
.sync[data-state=offline]::before, .sync[data-state=connecting]::before { background: var(--rule-strong); }
.sync[data-state=problem] { color: var(--missed); }
.sync[data-state=problem]::before { background: var(--missed); }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.3; } }

.banner {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  margin: 10px var(--gutter) 0; padding: 10px 14px; border-radius: var(--r);
  background: var(--warn-soft); font-size: var(--s-1);
}

main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 18px var(--gutter) 110px; display: flex; flex-direction: column; gap: 18px; }
main.wide-main { max-width: none; }
main section > h2 { margin-bottom: 10px; }

/* deck tabs: a tab bar on phones, a segmented control on wide screens */
nav.segmented { display: none; }
nav.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--rule);
}
nav.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border-radius: var(--r); color: var(--muted); text-decoration: none; font-size: var(--s-2); font-weight: 700;
}
nav.tabbar a[aria-current=page] { color: var(--accent); background: var(--accent-soft); }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 252px minmax(0, 1fr); }
  .sidebar {
    display: flex; flex-direction: column; gap: 6px;
    position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    padding: 14px 10px; border-right: 1px solid var(--rule); background: var(--sunk);
  }
  .brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: var(--s1); }
  .deck-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .deck-nav h2 { font-size: var(--s-1); color: var(--muted); padding: 14px 10px 4px; }
  .deck-nav a {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--r-sm);
    color: var(--ink); text-decoration: none;
  }
  .deck-nav a .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .deck-nav a:hover { background: var(--accent-soft); }
  .deck-nav a[aria-current=page] { background: var(--paper); box-shadow: var(--shadow); font-weight: 700; }
  .deck-nav a.lost { color: var(--muted); }
  .deck-nav .count { font-size: var(--s-2); font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; }
  .side-foot { display: flex; align-items: center; gap: 8px; padding: 10px; color: var(--muted); text-decoration: none; border-radius: var(--r-sm); }
  .side-foot:hover { color: var(--accent); background: var(--accent-soft); }
  header.top { padding-left: 16px; padding-right: 16px; }
  header.top .brand-mark { display: none; }
  nav.tabbar { display: none; }
  main { padding-bottom: 60px; }
  nav.segmented {
    display: flex; gap: 4px; align-self: flex-start;
    margin: 14px 0 0 var(--gutter); padding: 4px; border-radius: 12px; background: var(--sunk); border: 1px solid var(--rule);
  }
  .in-deck nav.segmented { margin-left: max(var(--gutter), calc((100% - 760px) / 2 + var(--gutter))); }
  nav.segmented a {
    display: flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 9px;
    color: var(--muted); text-decoration: none; font-weight: 700; font-size: var(--s-1);
  }
  nav.segmented a .icon { width: 18px; height: 18px; }
  nav.segmented a[aria-current=page] { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
  :root { --gutter: 28px; }
}

/* ---------------------------------------------------------------- shared bits */

.empty { text-align: center; padding: 36px 8px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty p { max-width: 46ch; color: var(--muted); }
.empty .row-actions { justify-content: center; }
.hero-empty h2 { font-size: var(--s2); }

.card-section { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 18px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.card-section > * { align-self: stretch; }
.card-section > .btn, .card-section > button { align-self: flex-start; }
.card-section h3 { color: var(--muted); font-size: var(--s-1); margin-top: 4px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 700; font-size: var(--s-1); }
:where(input:not([type=checkbox], [type=radio], [type=file]), select, textarea) {
  width: 100%; min-height: var(--tap); padding: 9px 12px;
  border: 1px solid var(--rule-strong); border-radius: var(--r-sm); background: var(--paper);
}
textarea { resize: vertical; line-height: 1.45; }
:where(input, select, textarea, [contenteditable]):focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
select { appearance: auto; }
fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 700; padding: 0; margin-bottom: 8px; font-size: var(--s0); }

.check, .radio { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 4px 0; }
.check input, .radio input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.switch { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; align-items: center; cursor: pointer; padding: 6px 0; }
.switch input {
  appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--rule-strong); position: relative; margin: 0; cursor: pointer; transition: background .15s;
}
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--paper); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked { background: var(--got); }
.switch input:checked::after { transform: translateX(18px); }
.switch .muted { grid-column: 2; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: stretch; border-radius: 999px; overflow: hidden;
  border: 1px solid var(--rule-strong); background: var(--paper); font-weight: 700; font-size: var(--s0);
  line-height: 1; padding: 0; cursor: default; color: var(--ink);
}
button.chip { cursor: pointer; min-height: var(--tap); }
button.chip:hover { border-color: var(--accent); }
.chip-name { padding: 10px 6px 10px 14px; display: flex; align-items: center; }
.chip-count { padding: 10px 14px 10px 8px; display: flex; align-items: center; color: var(--accent); }
.chip-count::before { content: "·"; margin-right: 8px; color: var(--muted); }
.chip.zero .chip-count { color: var(--muted); font-weight: 400; }
.chip.me { border-color: var(--accent); }
.chip.small { font-size: var(--s-1); }
.chip.small .chip-name { padding: 5px 4px 5px 10px; }
.chip.small .chip-count { padding: 5px 10px 5px 4px; }
.chip.small .chip-count::before { margin-right: 5px; }
.chip.plain { padding: 4px 10px; font-weight: 400; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: var(--s-2); font-weight: 700; border-radius: 999px; padding: 2px 8px; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* the box bar */
.boxbar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--b-new); gap: 2px; box-shadow: inset 0 0 0 1px var(--rule); }
.boxbar .seg { min-width: 4px; flex-basis: 0; display: grid; place-items: center; }
.boxbar .seg.empty { flex: 1; background: transparent; }
/* New cards: hatched, not yet in any box. */
[data-box=new] { background: repeating-linear-gradient(-45deg, var(--b-new) 0 4px, var(--rule) 4px 6px); }
[data-box="1"] { background: var(--b1); }
[data-box="2"] { background: var(--b2); }
[data-box="3"] { background: var(--b3); }
[data-box="4"] { background: var(--b4); }
[data-box="5"] { background: var(--b5); }
[data-box="6"] { background: var(--b6); }
[data-box="7"] { background: var(--b7); }
.boxbar.large { height: 34px; border-radius: var(--r-sm); }
.boxbar.large .seg span { font-size: var(--s-1); font-weight: 700; color: var(--ink); }
.boxbar.large .seg[data-box="4"] span, .boxbar.large .seg[data-box="5"] span, .boxbar.large .seg[data-box="6"] span, .boxbar.large .seg[data-box="7"] span { color: #fff; }
@media (prefers-color-scheme: dark) {
  .boxbar.large .seg[data-box="5"] span, .boxbar.large .seg[data-box="6"] span, .boxbar.large .seg[data-box="7"] span { color: #11142B; }
}
.box-legend { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 10px; margin-top: 12px; }
.box-legend li { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; font-size: var(--s-1); background: none; box-shadow: none; }
.box-legend .swatch { width: 12px; height: 12px; border-radius: 3px; }
.box-legend .lbl { color: var(--muted); }

/* lists of things you tap */
.pick-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.pick-list button, .pick-list a {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  min-height: 52px; padding: 10px 14px; border-radius: var(--r); border: 1px solid var(--rule); background: var(--paper);
  text-align: left; cursor: pointer; color: var(--ink); text-decoration: none;
}
.pick-list button:hover { border-color: var(--accent); }

/* ---------------------------------------------------------------- Home */

main.home { gap: 28px; }
.due-strip h2, .decks h2 { font-size: var(--s1); }
.due-strip .chips { gap: 8px; margin-top: 12px; }
.due-strip .chip { font-size: var(--s1); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.deck-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.deck-row { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.deck-row::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--rule-red); opacity: 0.85; }
.deck-row > a { display: flex; flex-direction: column; gap: 8px; padding: 16px 16px 14px; color: var(--ink); text-decoration: none; }
.deck-row > a strong { font-size: var(--s1); }
.deck-row.lost { box-shadow: none; background: var(--sunk); }
.deck-row.lost::before { background: var(--rule-strong); }
.deck-row.lost > a strong { color: var(--muted); }
.deck-row.lost .btn { margin: 0 16px 14px; }
.home-foot { text-align: center; }
.home-foot a { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); text-decoration: none; padding: 10px; }
@media (min-width: 900px) { .home-foot { display: none; } }

/* ---------------------------------------------------------------- Study tab */

.learner-cards { list-style: none; display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.learner-card {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px;
}
.lc-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -8px 0 0; }
.lc-head h2 { font-size: var(--s2); }
.lc-due { font-size: var(--s1); }
.lc-due strong { color: var(--accent); }
.lc-sets { font-size: var(--s-1); }
.learner-card .btn.primary { min-height: 52px; font-size: var(--s1); margin-top: 4px; }

/* ---------------------------------------------------------------- Tables tab */

.tables-actions { margin-bottom: -4px; }
.type-list, .set-list, .tpl-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.type-row, .set-row, .tpl-row {
  display: flex; align-items: center; gap: 4px; padding-left: 4px;
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r);
}
.type-row > a, .set-row > a, .tpl-row > a { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding: 12px 8px; color: var(--ink); text-decoration: none; }
.type-row strong, .set-row strong, .tpl-row strong { font-size: var(--s1); }
.type-row .fields { font-size: var(--s-1); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grip { color: var(--rule-strong); cursor: grab; display: grid; place-items: center; width: 24px; }
.drag-item.dragging { opacity: 0.5; }
.set-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-words { font-size: var(--s-1); }
.set-row .chips { margin-top: 4px; }

.field-rows { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.field-rows li { display: grid; grid-template-columns: 1fr 9.5rem auto; gap: 6px; align-items: center; }

/* ---------------------------------------------------------------- table editor */

.table-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.table-head > p { flex: none; }
@media (max-width: 899px) {
  .table-head { display: grid; grid-template-columns: 1fr auto; }
  .table-head .search { grid-column: 1 / -1; grid-row: 2; }
}
.search { flex: 1; min-width: 160px; position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 10px; color: var(--muted); }
.search input { padding-left: 36px !important; }

.grid-wrap { overflow: auto; border: 1px solid var(--rule); border-radius: var(--r); background: var(--paper); max-height: calc(100dvh - 220px); }
.grid-wrap.small { max-height: 260px; }
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: var(--s0); }
.grid th, .grid td { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
.grid thead th { position: sticky; top: 0; z-index: 2; background: var(--sunk); font-weight: 700; padding: 0; }
.grid .th { display: flex; align-items: center; gap: 2px; padding-right: 2px; }
.th-name { flex: 1; display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 9px 10px; cursor: pointer; font-weight: 700; text-align: left; min-width: 0; }
.th-name > span:not(.kind):not(.sort) { white-space: nowrap; }
.th-menu { width: 32px; height: 32px; }
.kind { display: inline-grid; place-items: center; min-width: 24px; height: 20px; padding: 0 4px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: var(--s-2); font-weight: 700; }
.sort { font-size: 10px; color: var(--accent); }
.grid td { padding: 0 10px; height: 42px; max-width: 320px; min-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td:focus { outline: 2px solid var(--focus); outline-offset: -2px; background: var(--accent-soft); }
.grid td.editing { padding: 0; }
.grid td.editing input { border: 0; border-radius: 0; height: 42px; min-height: 0; outline: 2px solid var(--focus); outline-offset: -2px; background: var(--paper); }
.grid .rownum, .grid th.rownum { min-width: 0; width: 46px; padding: 0; text-align: center; color: var(--muted); font-size: var(--s-1); position: sticky; left: 0; background: var(--sunk); z-index: 1; }
.grid thead th.rownum { z-index: 3; }
.row-btn { width: 100%; height: 42px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: var(--s-1); }
.row-btn:hover { color: var(--accent); }
.grid tr.selected td { background: var(--warn-soft); }
.grid th.add-col { width: 48px; text-align: center; }
.grid td.filler { min-width: 0; width: 100%; border-right: 0; }
.grid .thumb { height: 32px; width: auto; max-width: 64px; border-radius: 3px; vertical-align: middle; object-fit: contain; }
.grid .yn[data-yes="1"] { color: var(--got); font-weight: 700; }
.grid .yn[data-yes="0"] { color: var(--muted); }
.grid .new-row td { background: var(--sunk); }
.grid .new-row td input, .grid .new-row td textarea { border: 0; background: transparent; min-height: 42px; height: 42px; padding: 0; border-radius: 0; resize: none; }
.grid .new-row td:focus-within { outline: 2px solid var(--focus); outline-offset: -2px; background: var(--paper); }
.grid.preview td { height: 34px; font-size: var(--s-1); }
.grid.preview tr.bad td { background: var(--missed-soft); }

.fact-list { list-style: none; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; }
.fact-list li + li { border-top: 1px solid var(--rule); }
.fact-list a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; color: var(--ink); text-decoration: none; }
.fact-list a > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fact-list a strong { flex: 1; }
.fact-list a .muted { flex: 1; text-align: right; }
.fact-list .thumb { height: 28px; width: auto; border-radius: 3px; }
.fact-list li.selected { background: var(--warn-soft); }

.paste-box { font-family: ui-monospace, monospace; font-size: var(--s-1); }
.paste-preview { display: flex; flex-direction: column; gap: 10px; }
.problems { list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: var(--s-1); }
.problems li { display: flex; gap: 6px; align-items: flex-start; color: var(--warn); }
.problems li .icon { margin-top: 3px; }
.paste-preview .problems li { color: var(--missed); }

.kind-preview { background: var(--sunk); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }

/* text editor (3.5) */
.cloze-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.cloze-edit {
  min-height: 220px; max-height: 55dvh; overflow-y: auto; padding: 12px 14px;
  border: 1px solid var(--rule-strong); border-radius: var(--r-sm); background: var(--paper);
  white-space: pre-wrap; line-height: 1.9; font-size: var(--s0);
}
.blank-chip {
  background: var(--accent-soft); color: var(--ink); border-radius: 4px; padding: 1px 3px;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.blank-chip::before {
  content: attr(data-label); display: inline-block; margin-right: 4px; padding: 0 5px; border-radius: 3px;
  background: var(--accent); color: var(--accent-ink); font-size: 0.7em; font-weight: 700; line-height: 1.5; vertical-align: 0.15em;
  user-select: none; -webkit-user-select: none;
}
.cloze-count { font-size: var(--s-1); color: var(--muted); align-self: center; }
.long-text-btn { width: 100%; text-align: left; border: 1px solid var(--rule-strong); border-radius: var(--r-sm); background: var(--paper); padding: 10px 12px; min-height: var(--tap); cursor: pointer; white-space: pre-wrap; line-height: 1.8; max-height: 14em; overflow: hidden; }

/* image picking */
.image-pick { border: 2px dashed var(--rule-strong); border-radius: var(--r); padding: 20px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.pick-current { max-width: 100%; max-height: 200px; border-radius: var(--r-sm); }
.image-btn { width: 100%; min-height: 96px; border: 1px dashed var(--rule-strong); border-radius: var(--r-sm); background: var(--sunk); display: grid; place-items: center; cursor: pointer; padding: 8px; }
.image-btn img { max-width: 100%; max-height: 220px; border-radius: 4px; }
.img-wait { display: grid; place-items: center; min-height: 80px; background: var(--sunk); color: var(--muted); border-radius: var(--r-sm); font-size: var(--s-1); padding: 10px; }
.img-wait.small { min-height: 0; padding: 0 6px; display: inline; }

/* ---------------------------------------------------------------- Fact form */

.fact-form { display: flex; flex-direction: column; gap: 16px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 18px; }
.fact-field { display: flex; flex-direction: column; gap: 6px; }
.ff-label { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: var(--s-1); }
.card-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.card-list li { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.cl-learners { font-size: var(--s-1); }
.editor-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fact-cards h2 { margin-bottom: 10px; }

/* ---------------------------------------------------------------- templates */

.tpl-editor { display: grid; gap: 22px; }
@media (min-width: 1100px) {
  .tpl-editor { grid-template-columns: minmax(0, 1fr) minmax(320px, 440px); align-items: start; max-width: 1180px; }
  .tpl-preview { position: sticky; top: 76px; }
}
.tpl-form { display: flex; flex-direction: column; gap: 14px; }
.tpl-sides-head { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.ref-area { position: relative; }
.ref-area textarea, .ref-backdrop {
  font: inherit; line-height: 1.5; padding: 10px 12px; margin: 0; border-width: 1px; letter-spacing: normal;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
}
.ref-backdrop {
  position: absolute; inset: 0; border: 1px solid transparent; color: transparent; overflow: hidden; pointer-events: none;
  border-radius: var(--r-sm); background: var(--paper);
}
.ref-area textarea { position: relative; background: transparent; min-height: 84px; display: block; resize: vertical; }
.ref-backdrop mark.ref { color: transparent; background: var(--accent-soft); border-radius: 4px; box-shadow: 0 0 0 2px var(--accent-soft); }
.ref-backdrop mark.ref.unknown { background: var(--missed-soft); box-shadow: 0 0 0 2px var(--missed-soft); }
.cloze-settings { display: flex; flex-direction: column; gap: 14px; padding: 14px; background: var(--sunk); border-radius: var(--r); }
.context-lines { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.context-lines input[type=number] { width: 5.5em !important; }
.tpl-preview { display: flex; flex-direction: column; gap: 12px; }
.pv-head { display: flex; align-items: center; justify-content: space-between; }
.pv-nav { display: flex; align-items: center; gap: 2px; }
.pv-cards { display: flex; flex-direction: column; gap: 12px; }

/* ---------------------------------------------------------------- study sets */

.set-editor { display: flex; flex-direction: column; gap: 22px; }
.tpl-group { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border: 1px solid var(--rule); border-radius: var(--r); background: var(--paper); }
.tpl-group h3 { color: var(--muted); font-size: var(--s-1); }
.templates-pick { gap: 10px; }
.conds { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.cond { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; align-items: center; }
@media (max-width: 520px) { .cond { grid-template-columns: 1fr 1fr auto; } .cond > :nth-child(3) { grid-column: 1 / 3; } }
.filter > .btn { align-self: flex-start; }
.set-preview { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.preview-cards { padding-left: 1.4em; display: flex; flex-direction: column; gap: 6px; }
.learners-pick { gap: 2px; }

/* ---------------------------------------------------------------- settings */

.people { list-style: none; display: flex; flex-direction: column; }
.person-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.person-row:last-child { border-bottom: 0; }
.person-row .who { flex: 1; display: flex; flex-direction: column; }
.learner-settings { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.learner-settings > li { border: 1px solid var(--rule); border-radius: var(--r); padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.ls-head { display: flex; justify-content: space-between; align-items: center; }
.ls-head strong { font-size: var(--s1); }
.ls-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--rule-strong); border-radius: var(--r); overflow: hidden; }
.stepper button { width: var(--tap); height: 40px; border: 0; background: var(--sunk); font-size: var(--s1); cursor: pointer; }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper output { min-width: 3em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.danger-zone .row-actions { margin-top: 4px; }
.invite { display: flex; flex-direction: column; gap: 8px; align-self: stretch; background: var(--sunk); padding: 12px; border-radius: var(--r); }
.invite .btn { align-self: flex-start; }
.inline-form { display: flex; gap: 8px; }

/* ---------------------------------------------------------------- progress */

.progress { display: flex; flex-direction: column; gap: 20px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, 1fr); } .box-legend { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); padding: 12px 14px; }
.stat dt { font-size: var(--s-1); color: var(--muted); }
.stat dd { margin: 0; font-size: var(--s2); font-weight: 700; font-variant-numeric: tabular-nums; }
.trouble { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.trouble li > a, .trouble li > span { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); color: var(--ink); text-decoration: none; }
.t-front { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.misses { color: var(--missed); font-size: var(--s-1); font-weight: 700; white-space: nowrap; }
.set-progress, .learner-decks { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.set-progress li, .learner-decks li { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; padding: 12px 14px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); }
.set-progress .boxbar { grid-column: 1; }
.set-progress .btn { grid-row: 1 / 3; grid-column: 2; }
.learner-decks a { display: flex; flex-direction: column; gap: 8px; color: var(--ink); text-decoration: none; }

/* ---------------------------------------------------------------- rendered card sides */

.side { display: flex; flex-direction: column; gap: 12px; overflow-wrap: anywhere; }
.side p { white-space: normal; }
.side .li { color: var(--muted); }
.side .context { color: var(--muted); }
.side mark.revealed { background: var(--reveal); color: var(--reveal-ink); border-radius: 4px; padding: 0 3px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.side .blank { display: inline-block; min-width: 3em; text-align: center; border-bottom: 3px solid var(--accent); color: var(--accent); font-weight: 700; line-height: 1.1; }
.side .dots { display: inline-block; color: var(--accent); font-weight: 700; letter-spacing: 0.08em; }
.side .missing { color: var(--missed); background: var(--missed-soft); border-radius: 4px; padding: 0 4px; font-size: 0.85em; }
.side .card-img { display: block; width: 100%; height: auto; max-height: 52dvh; object-fit: contain; border-radius: var(--r-sm); background: var(--sunk); }
.side.compact { gap: 4px; font-size: var(--s0); }
.side.compact .card-img { max-height: 80px; width: auto; max-width: 100%; }

/* ---------------------------------------------------------------- the index card */

.index-card {
  position: relative; background: var(--paper); border-radius: 6px; box-shadow: var(--lift);
  padding: 52px 22px 26px;
  background-image: linear-gradient(var(--rule-red), var(--rule-red));
  background-size: 100% 2px;
  background-position: 0 34px;
  background-repeat: no-repeat;
}
.index-card.mini { padding: 40px 16px 16px; background-position: 0 26px; box-shadow: var(--shadow); }
.ic-label { position: absolute; top: 4px; left: 16px; font-size: var(--s-2); color: var(--muted); font-weight: 700; }

/* ---------------------------------------------------------------- the quiz (3.6) */

body[data-screen=quiz] { background: var(--desk); }
.quiz { min-height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; padding: 0 var(--gutter); }
.quiz-top {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
}
.quiz-end { border: 0; background: none; color: var(--muted); font-weight: 700; min-height: var(--tap); padding: 0 8px; margin-left: -8px; cursor: pointer; }
.quiz-end:hover { color: var(--ink); }
.quiz-title { text-align: center; font-size: var(--s0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quiz-title .who { font-weight: 700; }
.quiz-title .what { color: var(--muted); }
.quiz-pos { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: right; }
[data-repeat] .quiz-pos { color: var(--missed); }
.quiz-progress { height: 4px; border-radius: 999px; background: var(--rule); overflow: hidden; }
.qp-fill { height: 100%; background: var(--accent); transition: width .25s ease; }
.quiz-stage { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 22px 0; }
.quiz-card { min-height: 46dvh; display: flex; flex-direction: column; gap: 22px; font-size: clamp(1.6rem, 4.6vw + 0.6rem, 2.5rem); line-height: 1.35; padding-top: 64px; }
.quiz-card .side { gap: 18px; }
.quiz-card .qc-front .side:not(.sequential) { text-align: center; }
.quiz-card .side.sequential { font-size: 0.82em; line-height: 1.5; }
.quiz-card .side.sequential .context { color: var(--muted); }
.quiz-card .side.sequential .dots { font-size: 1.3em; letter-spacing: 0.15em; }
.quiz-card .qc-front { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.quiz-card .qc-back { border-top: 2px dashed var(--rule); padding-top: 22px; animation: reveal .2s ease-out; }
.quiz-card .qc-back .side:not(.sequential) { text-align: center; font-weight: 700; }
.quiz-card:has(.qc-back) .qc-front { flex: none; }
.quiz-card .card-img { max-height: 46dvh; margin: 0 -8px; width: calc(100% + 16px); }
@keyframes reveal { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.boxtag, .again { position: absolute; top: 8px; right: 14px; font-size: var(--s-1); font-weight: 700; color: var(--muted); }
.boxtag.new { color: var(--accent); }
.again { color: var(--missed); }
.quiz-actions { position: sticky; bottom: 0; padding: 8px 0 calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; background: linear-gradient(to bottom, transparent, var(--desk) 22%); }
.btn.big { min-height: 64px; font-size: var(--s1); border-radius: var(--r-lg); width: 100%; }
.btn.big .k { font-size: var(--s-1); font-weight: 400; opacity: 0.6; display: none; }
@media (pointer: fine) { .btn.big .k { display: inline; } }
.answer-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn.missed { background: var(--paper); border: 2px solid var(--missed); color: var(--missed); }
.btn.missed:hover { background: var(--missed-soft); border-color: var(--missed); }
.btn.got { background: var(--got); border: 2px solid var(--got); color: var(--got-ink); }
.btn.got:hover { filter: brightness(1.06); }
.undo { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--muted); font-size: var(--s-1); padding: 6px 8px; margin-left: -8px; cursor: pointer; min-height: 36px; }
.undo:hover { color: var(--ink); }
.undo-space { height: 36px; }
.index-card.message, .index-card.summary { text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; padding-top: 70px; padding-bottom: 36px; }
.index-card.message h1, .index-card.summary h1 { font-size: var(--s3); }
.index-card.message p { font-size: var(--s1); color: var(--muted); max-width: 30ch; }
.sum-line { font-size: var(--s1); font-weight: 700; }
.sum-bars { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 420px; text-align: left; }
.sb { display: grid; grid-template-columns: 3.6em 1fr; align-items: center; gap: 10px; }
.sb .boxbar { height: 14px; }
@media (min-width: 900px) {
  .quiz { justify-content: flex-start; }
  .quiz-stage { flex: none; padding: 48px 0 28px; }
  .quiz-card { padding: 72px 44px 40px; min-height: 380px; }
  .quiz-actions { position: static; background: none; }
}

/* ---------------------------------------------------------------- sheets, menus, toasts */

.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(15, 18, 40, 0.42); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--paper); border-radius: 18px 18px 0 0; box-shadow: var(--lift);
  padding-bottom: env(safe-area-inset-bottom); animation: rise .2s ease-out;
}
.sheet.wide { max-width: 760px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0.6; } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--rule-strong); margin: 8px auto 0; flex: none; }
.sheet-content { display: flex; flex-direction: column; min-height: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 8px 4px 20px; }
.sheet-head h2 { font-size: var(--s1); }
.sheet-main { padding: 6px 20px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.sheet-main h3 { color: var(--muted); font-size: var(--s-1); margin-top: 6px; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 20px 16px; border-top: 1px solid var(--rule); flex-wrap: wrap; }
@media (min-width: 900px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 18px; max-height: 86dvh; }
  .grabber { display: none; }
  .sheet-head { padding-top: 12px; }
}

.menu {
  position: fixed; z-index: 60; min-width: 190px; max-width: 320px; padding: 6px;
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); box-shadow: var(--lift);
  display: flex; flex-direction: column;
}
.menu button { text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: var(--r-sm); cursor: pointer; min-height: 40px; }
.menu button:hover, .menu button:focus-visible { background: var(--accent-soft); outline: none; }
.menu button.danger { color: var(--missed); }
.menu button:disabled { opacity: 0.4; cursor: default; background: none; }
.menu hr { border: 0; border-top: 1px solid var(--rule); margin: 4px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: var(--r); background: var(--ink); color: var(--paper); box-shadow: var(--lift);
  animation: rise .2s ease-out;
}
.toast.error { background: var(--missed); color: #fff; }
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 4px; }
@media (min-width: 900px) { .toast { bottom: 24px; } }
body[data-screen=quiz] .toast { bottom: calc(170px + env(safe-area-inset-bottom)); }

/* boot and notices */
.notice-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.notice { max-width: 440px; display: flex; flex-direction: column; gap: 14px; background: var(--paper); padding: 28px; border-radius: var(--r-lg); box-shadow: var(--shadow); }
.quiz-btn { min-height: 52px; font-size: var(--s1); }
