/* Apple-style layout: a translucent top bar over one centred column on a grouped background. Study screens put a
   single elevated card in the middle. Motion uses critically damped springs; everything respects reduced motion,
   reduced transparency and increased contrast. */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --card: #ffffff;
  --elevated: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --faint: #aeaeb2;
  --line: #e5e5ea;
  --line-strong: #d1d1d6;
  --fill: rgba(118, 118, 128, .12);
  --fill-strong: rgba(118, 118, 128, .2);
  --fill-soft: rgba(118, 118, 128, .07);
  --hover: rgba(118, 118, 128, .08);
  --seg-thumb: #ffffff;
  --accent: #0071e3;
  --accent-ink: #ffffff;
  --accent-soft: rgba(0, 113, 227, .1);
  --accent-ring: rgba(0, 113, 227, .4);
  --switch-on: #34c759;
  --again: #d70015;
  --hard: #c93400;
  --good: #248a3d;
  --easy: #0071e3;
  --again-soft: rgba(255, 59, 48, .12);
  --hard-soft: rgba(255, 149, 0, .14);
  --good-soft: rgba(52, 199, 89, .14);
  --easy-soft: rgba(0, 122, 255, .1);
  --bar: rgba(249, 249, 251, .72);
  --scrim: rgba(0, 0, 0, .3);
  --toast-bg: rgba(44, 44, 46, .86);
  --toast-ink: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 28px rgba(0, 0, 0, .07);
  --shadow-sheet: 0 2px 8px rgba(0, 0, 0, .08), 0 24px 64px rgba(0, 0, 0, .18);
  --f-text: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --f-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --f-rounded: ui-rounded, "SF Pro Rounded", var(--f-display);
  --f-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 18px;
  /* Critically damped spring (damping 1.0). Durations set the response: ~.45s for UI, ~.4s for sheets. */
  --spring: cubic-bezier(.2, .8, .2, 1);
}
@supports (transition-timing-function: linear(0, 1)) {
  :root { --spring: linear(0, 0.0667 5%, 0.2048 10%, 0.3577 15%, 0.4991 20%, 0.6189 25%, 0.7154 30%, 0.7905 35%, 0.8475 40%, 0.89 45%, 0.9213 50%, 0.9441 55%, 0.9605 60%, 0.9722 65%, 0.9805 70%, 0.9864 75%, 0.9905 80%, 0.9934 85%, 0.9955 90%, 0.9969 95%, 1); }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --surface: #1c1c1e; --card: #1c1c1e; --elevated: #2c2c2e; --ink: #f5f5f7; --muted: #98989d; --faint: #636366;
    --line: #38383a; --line-strong: #48484a; --fill: rgba(118, 118, 128, .24); --fill-strong: rgba(118, 118, 128, .32); --fill-soft: rgba(118, 118, 128, .14); --hover: rgba(118, 118, 128, .16);
    --seg-thumb: #636366; --accent: #0a84ff; --accent-soft: rgba(10, 132, 255, .18); --accent-ring: rgba(10, 132, 255, .5); --switch-on: #30d158;
    --again: #ff453a; --hard: #ff9f0a; --good: #30d158; --easy: #0a84ff;
    --again-soft: rgba(255, 69, 58, .18); --hard-soft: rgba(255, 159, 10, .18); --good-soft: rgba(48, 209, 88, .16); --easy-soft: rgba(10, 132, 255, .18);
    --bar: rgba(22, 22, 24, .72); --scrim: rgba(0, 0, 0, .5); --toast-bg: rgba(58, 58, 60, .88);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35); --shadow-sheet: 0 2px 8px rgba(0, 0, 0, .3), 0 24px 64px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --surface: #1c1c1e; --card: #1c1c1e; --elevated: #2c2c2e; --ink: #f5f5f7; --muted: #98989d; --faint: #636366;
  --line: #38383a; --line-strong: #48484a; --fill: rgba(118, 118, 128, .24); --fill-strong: rgba(118, 118, 128, .32); --fill-soft: rgba(118, 118, 128, .14); --hover: rgba(118, 118, 128, .16);
  --seg-thumb: #636366; --accent: #0a84ff; --accent-soft: rgba(10, 132, 255, .18); --accent-ring: rgba(10, 132, 255, .5); --switch-on: #30d158;
  --again: #ff453a; --hard: #ff9f0a; --good: #30d158; --easy: #0a84ff;
  --again-soft: rgba(255, 69, 58, .18); --hard-soft: rgba(255, 159, 10, .18); --good-soft: rgba(48, 209, 88, .16); --easy-soft: rgba(10, 132, 255, .18);
  --bar: rgba(22, 22, 24, .72); --scrim: rgba(0, 0, 0, .5); --toast-bg: rgba(58, 58, 60, .88);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35); --shadow-sheet: 0 2px 8px rgba(0, 0, 0, .3), 0 24px 64px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
/* Theme changes ease rather than flash */
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--f-text); letter-spacing: -.01em; -webkit-font-smoothing: antialiased;
  font-optical-sizing: auto; transition: background-color .3s ease, color .3s ease; }
/* Tracking is size-specific: tighter as type grows, near zero for body, slightly open for small print */
h1, h2, h3 { font-family: var(--f-display); margin: 0; text-wrap: balance; }
h1 { font-size: clamp(28px, 4vw, 34px); font-weight: 700; line-height: 1.1; letter-spacing: -.022em; }
h2 { font-size: 22px; font-weight: 650; line-height: 1.2; letter-spacing: -.017em; }
h3 { font-size: 17px; font-weight: 600; line-height: 1.3; letter-spacing: -.012em; }
p { margin: 0; }
a { color: var(--accent); }
code, pre { font-family: var(--f-mono); font-size: .9em; letter-spacing: 0; }
kbd { font: 500 12px/1.5 var(--f-text); letter-spacing: 0; padding: 0 6px; border-radius: 6px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--line-strong); box-shadow: inset 0 -1px 0 var(--line-strong); }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 3px solid var(--accent-ring); outline-offset: 2px; }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- press feedback: instant on pointer-down, springs back on release ---------- */
.btn, .mode, .rate button, .quiz-options button, .seg button, .twisty, .nav a, .brand {
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: transform .45s var(--spring), background-color .2s ease, color .2s ease, box-shadow .2s ease, filter .2s ease;
}
:is(.btn, .seg button, .twisty, .nav a, .brand):active:not(:disabled) { transform: scale(.96); transition-duration: .1s; transition-timing-function: ease-out; }
:is(.mode, .rate button, .quiz-options button):active:not(:disabled) { transform: scale(.98); transition-duration: .1s; transition-timing-function: ease-out; }

/* ---------- top bar: a translucent material that content scrolls under ---------- */
.topbar { position: sticky; top: 0; z-index: 10; padding-top: env(safe-area-inset-top, 0px); border-bottom: 1px solid transparent; transition: border-color .2s ease; }
/* The material lives on a pseudo-element so the bar itself isn't a containing block for the fixed tab bar inside it */
.topbar::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
.scrolled .topbar { border-bottom-color: var(--line); }
.topbar-in { max-width: 1080px; margin: 0 auto; padding-inline: 16px; height: 52px; display: flex; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--f-display); font-weight: 700; font-size: 19px; letter-spacing: -.02em; color: var(--ink); text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.nav a { padding: 6px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: 14px; white-space: nowrap; display: flex; align-items: center; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--fill); }
.nav svg { display: none; }
.sync { font-size: 12.5px; letter-spacing: 0; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: var(--good); display: inline-block; transition: background-color .3s ease; }
.sync.busy i { background: var(--hard); }
.sync.off i { background: var(--again); }

main.page { max-width: 1080px; margin: 0 auto; padding-inline: 16px; padding-block: 28px 80px; display: grid; gap: 24px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; }
.page-head .sub { color: var(--muted); margin-top: 6px; font-size: 15px; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

/* ---------- phones: the nav becomes an iOS-style tab bar ---------- */
@media (max-width: 640px) {
  .topbar-in { height: 48px; justify-content: space-between; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; overflow: visible;
    padding: 6px 4px calc(4px + env(safe-area-inset-bottom, 0px)); background: var(--bar); border-top: 1px solid var(--line);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
  .nav a { display: grid; justify-items: center; gap: 2px; padding: 2px 0; font-size: 10.5px; letter-spacing: .01em; color: #8e8e93; border-radius: 10px; }
  .nav a:hover { color: #8e8e93; }
  .nav a[aria-current="page"] { color: var(--accent); background: none; }
  .nav svg { display: block; width: 25px; height: 25px; }
  body[data-view="study"] .nav { display: none; }
  main.page { padding-block: 20px calc(100px + env(safe-area-inset-bottom, 0px)); }
  body[data-view="study"] main.page { padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 0; background: var(--fill); color: var(--ink);
  padding: 8px 16px; border-radius: 999px; font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; line-height: 1.25; white-space: nowrap; }
.btn:hover { background: var(--fill-strong); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary kbd { color: rgba(255, 255, 255, .9); background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .3); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--again); }
.btn.ghost.danger:hover, .btn.danger:hover { background: var(--again-soft); }
.btn.small { padding: 5px 12px; font-size: 13.5px; }
.btn.big { padding: 13px 24px; font-size: 17px; letter-spacing: -.015em; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; letter-spacing: 0; }
.mono { font-variant-numeric: tabular-nums; }

label.field { display: grid; gap: 6px; font-weight: 600; font-size: 14px; letter-spacing: -.005em; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 13px; letter-spacing: 0; }
/* 16px inputs stop iOS Safari zooming the page on focus */
.input, select.input, textarea.input { width: 100%; border: 1px solid transparent; background: var(--fill); border-radius: 12px; padding: 10px 14px; font-size: 16px; font-weight: 400;
  transition: background-color .2s ease, border-color .2s ease, box-shadow .2s ease; }
select.input { -webkit-appearance: none; appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; }
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { outline: none; background-color: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* Settings-style checkboxes render as switches */
.check { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; line-height: 1.45; cursor: pointer; }
.check input[type="checkbox"] { -webkit-appearance: none; appearance: none; flex: none; position: relative; width: 42px; height: 26px; margin: -1px 0 0; border-radius: 999px;
  background: var(--fill-strong); cursor: pointer; transition: background-color .25s ease; }
.check input[type="checkbox"]::before { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .18), 0 0 1px rgba(0, 0, 0, .1); transition: transform .4s var(--spring); }
.check input[type="checkbox"]:checked { background: var(--switch-on); }
.check input[type="checkbox"]:checked::before { transform: translateX(16px); }
.check input[type="checkbox"]:focus-visible { outline: 3px solid var(--accent-ring); outline-offset: 2px; }

/* iOS segmented control */
.seg { display: inline-flex; background: var(--fill); border-radius: 10px; padding: 2px; gap: 0; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px; letter-spacing: -.005em; color: var(--ink); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--seg-thumb); box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 3px 1px rgba(0, 0, 0, .04); }

.panel { background: var(--surface); border-radius: var(--radius); padding: 20px; display: grid; gap: 14px; min-width: 0; box-shadow: var(--shadow-sm); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }
.error { color: var(--again); font-size: 14.5px; }
.tag { display: inline-block; font-size: 12px; letter-spacing: 0; padding: 1px 8px; border-radius: 999px; background: var(--fill); color: var(--muted); }

/* ---------- counts ---------- */
.counts { display: inline-flex; gap: 10px; font-size: 13.5px; font-weight: 600; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.counts .n { color: var(--easy); } .counts .l { color: var(--again); } .counts .r { color: var(--good); }
.counts span.zero { color: var(--faint); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; letter-spacing: 0; color: var(--muted); }
.legend b { font-weight: 600; }

/* ---------- today strip ---------- */
.today { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.today .stat { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.today .stat b { display: block; font-family: var(--f-rounded); font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.today .stat span { color: var(--muted); font-size: 13px; letter-spacing: 0; }
@media (max-width: 640px) { .today { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- deck tree ---------- */
.tree { display: grid; margin: -6px -8px; }
.deck-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 12px; transition: background-color .15s ease; }
.deck-row:hover { background: var(--hover); }
.deck-row + .deck-row::before { content: ""; position: absolute; top: 0; left: 12px; right: 12px; border-top: 1px solid var(--line); }
.deck-row:hover::before, .deck-row:hover + .deck-row::before { opacity: 0; }
.deck-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.deck-name a { color: var(--ink); text-decoration: none; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-name a:hover { color: var(--accent); }
/* Row actions use the App Store "Get" style: grey capsule, accent label */
.deck-row .btn.primary { background: var(--fill); color: var(--accent); }
.deck-row .btn.primary:hover { background: var(--fill-strong); filter: none; }
.deck-row .btn:not(.primary) { color: var(--muted); }
.twisty { width: 24px; height: 24px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 6px; flex: none; display: grid; place-items: center; padding: 0; }
.twisty:hover { background: var(--fill); }
.twisty svg { width: 14px; height: 14px; transition: transform .3s var(--spring); }
.twisty[aria-expanded="true"] svg { transform: rotate(90deg); }
.twisty.blank { visibility: hidden; }
@media (max-width: 520px) { .deck-row { grid-template-columns: minmax(0, 1fr) auto; } .deck-row .btn { display: none; } }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 40px 16px; display: grid; gap: 14px; justify-items: center; }
.empty h2 { font-size: 24px; }
.empty p { color: var(--muted); max-width: 52ch; }

/* ---------- card table ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .input { max-width: 320px; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
table.cards { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.cards th { text-align: left; font-size: 12.5px; letter-spacing: 0; color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.cards td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.cards tr:last-child td { border-bottom: 0; }
table.cards tr.clickable { cursor: pointer; }
table.cards tr.clickable:hover td { background: var(--hover); }
table.cards td.clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.cards input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
.state { font-size: 12px; letter-spacing: 0; padding: 2px 9px; border-radius: 999px; white-space: nowrap; font-weight: 600; }
.state.new { background: var(--easy-soft); color: var(--easy); }
.state.learning { background: var(--again-soft); color: var(--again); }
.state.review { background: var(--good-soft); color: var(--good); }
.state.suspended { background: var(--fill); color: var(--muted); }

/* ---------- modes ---------- */
.modes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.mode { display: grid; gap: 4px; align-content: start; text-align: left; padding: 16px; border-radius: var(--radius); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); box-shadow: var(--shadow-sm); }
.mode:hover { box-shadow: var(--shadow); }
.mode b { font-family: var(--f-display); font-size: 17px; font-weight: 600; letter-spacing: -.012em; }
.mode span { color: var(--muted); font-size: 13.5px; letter-spacing: 0; line-height: 1.4; }
.mode.lead { background: var(--accent); color: var(--accent-ink); }
.mode.lead span { color: var(--accent-ink); opacity: .85; }
@media (max-width: 860px) { .modes { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- study ---------- */
.study { max-width: 720px; margin: 0 auto; width: 100%; display: grid; gap: 18px; }
.study-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.index-card { position: relative; background: var(--card); border-radius: 24px; box-shadow: var(--shadow); padding: 20px 28px 30px; min-height: 300px; display: grid; align-content: start; gap: 18px; }
/* A new card rises into place; the same card re-drawn (e.g. on reveal) stays put */
.index-card.enter { transition: opacity .2s ease-out, transform .5s var(--spring); }
@starting-style { .index-card.enter { opacity: 0; transform: translateY(12px) scale(.985); } }
.card-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; letter-spacing: 0; color: var(--muted); font-weight: 500; }
.card-meta span:first-child { color: var(--accent); font-weight: 600; }
.card-meta span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.card-face { font-size: 18px; line-height: 1.55; overflow-wrap: anywhere; min-width: 0; }
.card-face.front { font-family: var(--f-display); font-size: clamp(22px, 3.6vw, 30px); font-weight: 600; line-height: 1.25; letter-spacing: -.02em; text-wrap: pretty; }
.card-face pre { background: var(--fill-soft); border-radius: 12px; padding: 12px 14px; overflow-x: auto; font-size: 14px; line-height: 1.5; }
.card-face ul, .card-face ol { padding-left: 22px; margin: 6px 0; }
.card-face p { margin: 6px 0; }
.card-face mark { background: var(--hard-soft); color: inherit; padding: 0 3px; border-radius: 4px; }
/* The answer unfolds downward from the divider */
.answer { border-top: 1px solid var(--line); padding-top: 18px; transition: opacity .25s ease-out, transform .45s var(--spring); }
@starting-style { .answer { opacity: 0; transform: translateY(-6px); } }
@media (max-width: 520px) { .index-card { padding: 18px 18px 24px; border-radius: 22px; } }

.rate { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.rate button { border: 0; border-radius: 14px; padding: 12px 8px; cursor: pointer; display: grid; gap: 2px; justify-items: center; font-weight: 600; font-size: 16px; letter-spacing: -.01em; }
.rate button small { font-weight: 500; font-size: 12.5px; letter-spacing: 0; opacity: .8; font-variant-numeric: tabular-nums; }
.rate .r1 { background: var(--again-soft); color: var(--again); }
.rate .r2 { background: var(--hard-soft); color: var(--hard); }
.rate .r3 { background: var(--good-soft); color: var(--good); }
.rate .r4 { background: var(--easy-soft); color: var(--easy); }
.rate button.suggested { box-shadow: 0 0 0 2px currentColor inset; }
.rate button:hover { filter: brightness(.96) saturate(1.1); }
.reveal { width: 100%; }
.progress { height: 4px; background: var(--fill); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .45s var(--spring); }
.verdict { border-radius: 14px; padding: 12px 16px; display: grid; gap: 4px; }
.verdict b { font-family: var(--f-display); font-size: 17px; font-weight: 600; letter-spacing: -.012em; }
.verdict.correct { background: var(--good-soft); color: var(--good); }
.verdict.partial { background: var(--hard-soft); color: var(--hard); }
.verdict.wrong { background: var(--again-soft); color: var(--again); }
.verdict .said { color: var(--ink); font-size: 15px; }
.quiz-options { display: grid; gap: 10px; }
.quiz-options button { text-align: left; border: 0; background: var(--surface); border-radius: 14px; padding: 14px 16px; cursor: pointer; display: grid; grid-template-columns: auto 1fr; gap: 12px; font-size: 16px; box-shadow: var(--shadow-sm); }
.quiz-options button:hover { box-shadow: var(--shadow); }
.quiz-options button.right { background: var(--good-soft); box-shadow: 0 0 0 2px var(--good) inset; }
.quiz-options button.wrongpick { background: var(--again-soft); box-shadow: 0 0 0 2px var(--again) inset; }
.quiz-options .k { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.done { text-align: center; display: grid; gap: 12px; justify-items: center; padding: 32px 12px; }

/* voice */
.voice-stage { display: grid; gap: 16px; }
.mic-ring { width: 120px; height: 120px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); position: relative; transition: box-shadow .3s ease; }
/* The ring follows the microphone level continuously */
.mic-ring::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 3px solid var(--accent); opacity: var(--lvl, 0); transform: scale(calc(1 + var(--lvl, 0) * .12)); transition: opacity .08s, transform .08s; }
.mic-ring.listening { box-shadow: var(--shadow), 0 0 0 6px var(--accent-soft); }
.mic-ring.thinking { outline: 2px dashed var(--line-strong); outline-offset: 6px; }
.mic-ring svg { width: 44px; height: 44px; color: var(--muted); transition: color .2s ease; }
.mic-ring.listening svg { color: var(--accent); }
.voice-status { text-align: center; font-family: var(--f-display); font-weight: 600; font-size: 20px; letter-spacing: -.015em; }
.log { display: grid; gap: 8px; max-height: 320px; overflow-y: auto; }
.log-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; font-size: 14.5px; padding: 9px 12px; border-radius: 12px; background: var(--fill-soft); }
.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; }
.dot.correct { background: var(--good); } .dot.partial { background: var(--hard); } .dot.wrong { background: var(--again); } .dot.skip { background: var(--faint); }
.dl { display: grid; gap: 6px; }
.dl .bar { height: 6px; border-radius: 999px; background: var(--fill); overflow: hidden; }
.dl .bar i { display: block; height: 100%; background: var(--accent); width: 0; border-radius: inherit; transition: width .3s ease-out; }
/* microphone test: follows the input level live */
.meter { flex: 1; min-width: 120px; max-width: 260px; height: 6px; border-radius: 999px; background: var(--fill); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--good); transition: width .08s linear; }

/* import */
.drop { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 36px 16px; text-align: center; display: grid; gap: 10px; justify-items: center; background: var(--surface);
  cursor: pointer; transition: border-color .2s ease, background-color .2s ease; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.formats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.formats div { border-radius: 14px; padding: 12px 14px; background: var(--surface); font-size: 14px; color: var(--muted); box-shadow: var(--shadow-sm); }
.formats b { display: block; font-family: var(--f-display); font-size: 15.5px; font-weight: 600; letter-spacing: -.01em; color: var(--ink); margin-bottom: 2px; }
.preview { display: grid; gap: 8px; }
.preview .pv { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; padding: 9px 12px; border-radius: 10px; background: var(--fill-soft); font-size: 14px; }
.preview .pv div { overflow: hidden; max-height: 4.6em; }

/* stats */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-family: var(--f-text); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar-good { fill: var(--good); } .chart .bar-again { fill: var(--again); } .chart .bar-due { fill: var(--accent); }
.chart .grid { stroke: var(--line); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-size: 15px; }
.kv b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- modal: dims the page; the sheet materialises from the control that opened it, and leaves the same way ---------- */
.modal-back { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; padding: 16px; z-index: 50; transition: opacity .3s ease; }
@starting-style { .modal-back { opacity: 0; } }
.modal-back.closing { opacity: 0; transition-duration: .22s; pointer-events: none; }
.modal { background: var(--elevated); border-radius: 24px; box-shadow: var(--shadow-sheet); width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain;
  padding: 24px; display: grid; gap: 16px; transform-origin: var(--origin, 50% 50%);
  transition: opacity .2s ease-out, transform .4s var(--spring), filter .3s ease-out; }
@starting-style { .modal { opacity: 0; transform: scale(.94); filter: blur(6px); } }
.closing .modal { opacity: 0; transform: scale(.94); filter: blur(6px); transition-duration: .18s, .22s, .2s; transition-timing-function: ease-in; }
.modal.wide { width: min(800px, 100%); }
.sheet-handle { display: none; }
/* Phones: a bottom sheet that slides up, can be dragged down to dismiss, and leaves the way it came */
@media (max-width: 640px) {
  .modal-back { place-items: end stretch; padding: 0; }
  .modal, .modal.wide { width: 100%; border-radius: 24px 24px 0 0; max-height: calc(100dvh - 44px - env(safe-area-inset-top, 0px)); transform-origin: 50% 100%;
    padding: 0 20px calc(20px + env(safe-area-inset-bottom, 0px)); transition: transform .4s var(--spring); }
  @starting-style { .modal { opacity: 1; transform: translateY(100%); filter: none; } }
  .closing .modal { opacity: 1; transform: translateY(100%); filter: none; transition: transform .26s cubic-bezier(.4, 0, 1, 1); }
  .sheet-handle { display: grid; place-items: center; height: 22px; margin: 0 -20px -8px; position: sticky; top: 0; z-index: 1; touch-action: none; cursor: grab; background: var(--elevated); }
  .sheet-handle::before { content: ""; width: 36px; height: 5px; border-radius: 3px; background: var(--line-strong); }
}
.editor { border: 1px solid transparent; border-radius: 12px; background: var(--fill); font-weight: 400; transition: background-color .2s ease, border-color .2s ease, box-shadow .2s ease; }
.editor:focus-within { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.editor .tools { display: flex; gap: 2px; padding: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.editor .tools button { border: 0; background: transparent; padding: 4px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.editor .tools button:hover { background: var(--fill); color: var(--ink); }
.editor .area { min-height: 90px; padding: 10px 14px; outline: none; overflow-wrap: anywhere; font-size: 16px; }
.editor .area pre { background: var(--fill-soft); padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; }

/* auth */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); display: grid; gap: 18px; }
.auth-card .panel { padding: 24px; box-shadow: var(--shadow); }
.auth-card .seg { display: flex; }
.auth-card .seg button { flex: 1; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-family: var(--f-display); font-size: 32px; font-weight: 700; letter-spacing: -.025em; }
.auth-brand img { width: 46px; height: 46px; }
.auth-lead { color: var(--muted); font-size: 15px; }

/* toasts rise from the bottom and sink back the same way */
#toasts { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); display: grid; justify-items: center; gap: 8px; z-index: 60; width: min(460px, calc(100% - 32px)); pointer-events: none; }
@media (max-width: 640px) { body:not([data-view="study"]):not([data-view="auth"]) #toasts { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); } }
.toast { background: var(--toast-bg); color: var(--toast-ink); padding: 11px 18px; border-radius: 16px; font-size: 14.5px; font-weight: 500; box-shadow: var(--shadow-sheet);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); max-width: 100%;
  transition: opacity .25s ease-out, transform .45s var(--spring); }
@starting-style { .toast { opacity: 0; transform: translateY(16px) scale(.96); } }
.toast-error { background: var(--again); color: #fff; }
.toast.out { opacity: 0; transform: translateY(16px) scale(.96); transition-duration: .2s, .25s; transition-timing-function: ease-in; }

/* ---------- accessibility preferences ---------- */
/* Reduced motion keeps the cross-fades but drops movement, scaling and blur */
@media (prefers-reduced-motion: reduce) {
  :is(.btn, .seg button, .twisty, .nav a, .brand, .mode, .rate button, .quiz-options button):active:not(:disabled) { transform: none; }
  .index-card.enter, .answer, .modal, .closing .modal, .toast, .toast.out { transform: none !important; filter: none !important; }
  .check input[type="checkbox"]::before, .twisty svg, .progress i, .dl .bar i { transition: none; }
  body { transition: none; }
}
/* Reduced transparency makes the materials solid */
@media (prefers-reduced-transparency: reduce) {
  .topbar::before, .nav, .toast { -webkit-backdrop-filter: none; backdrop-filter: none; }
  .topbar::before { background: var(--surface); }
  @media (max-width: 640px) { .nav { background: var(--surface); } }
  .toast:not(.toast-error) { background: #2c2c2e; }
}
/* Increased contrast: solid surfaces with defined edges */
@media (prefers-contrast: more) {
  :root { --line: var(--line-strong); }
  .panel, .today .stat, .table-wrap, .mode, .index-card, .quiz-options button, .formats div, .modal, .input, .editor { outline: 1px solid var(--faint); outline-offset: -1px; }
  .topbar::before, .nav, .toast { -webkit-backdrop-filter: none; backdrop-filter: none; }
  .topbar::before { background: var(--surface); }
}
