/* =====================================================================
   StudyDeck styles: "paper and ink"
   Mobile first: the base styles are for phones; @media (min-width: …)
   blocks add extras for bigger screens. Colours are CSS variables, so
   dark mode only has to swap the variables.
   ===================================================================== */

/* ---------- Colours and type: light theme (default) ---------- */
:root {
  --bg: #f6f4ef; /* paper */
  --surface: #fffdf8; /* card stock */
  --surface-2: #efece4;
  --text: #1c1b18; /* ink */
  --muted: #6b675e;
  --border: #e3dfd5;
  --border-strong: #cdc8bb;
  --primary: #1c1b18; /* main buttons are ink-black */
  --primary-hover: #3a3832;
  --on-primary: #fffdf8;
  --accent: #2d5b8a; /* blue pen: links, progress, selection */
  --accent-soft: #e4ebf3;
  --good: #2e7650;
  --good-soft: #e2efe6;
  --bad: #b23a2e; /* red pen */
  --bad-soft: #f7e4e0;
  --warn: #86650f;
  --warn-soft: #f4ecd5;
  --rule-red: #e0857e; /* index-card header line */
  --rule-blue: #dbe5ef; /* index-card ruled lines */
  --lift: 0 1px 0 rgb(28 27 24 / 5%), 0 10px 24px -14px rgb(28 27 24 / 25%);

  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', 'URW Palladio L', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --radius: 10px;
  --radius-sm: 8px;
  --tap: 48px; /* minimum size of anything you can tap */
  --nav-height: 60px;
  color-scheme: light;
}

/* ---------- Colours: dark theme ----------
   Used when the device is in dark mode (unless the user picked light),
   or when the user picked dark with the toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #161512;
    --surface: #1f1e1a;
    --surface-2: #2a2924;
    --text: #ece8de;
    --muted: #a29d91;
    --border: #322f29;
    --border-strong: #46433b;
    --primary: #ece8de;
    --primary-hover: #fffdf8;
    --on-primary: #161512;
    --accent: #8fb4dd;
    --accent-soft: #23303e;
    --good: #7cc49b;
    --good-soft: #1d3226;
    --bad: #ee8b7f;
    --bad-soft: #3b211d;
    --warn: #dfc06a;
    --warn-soft: #383020;
    --rule-red: #8c4744;
    --rule-blue: #29313b;
    --lift: 0 1px 0 rgb(0 0 0 / 35%), 0 10px 24px -14px rgb(0 0 0 / 60%);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #161512;
  --surface: #1f1e1a;
  --surface-2: #2a2924;
  --text: #ece8de;
  --muted: #a29d91;
  --border: #322f29;
  --border-strong: #46433b;
  --primary: #ece8de;
  --primary-hover: #fffdf8;
  --on-primary: #161512;
  --accent: #8fb4dd;
  --accent-soft: #23303e;
  --good: #7cc49b;
  --good-soft: #1d3226;
  --bad: #ee8b7f;
  --bad-soft: #3b211d;
  --warn: #dfc06a;
  --warn-soft: #383020;
  --rule-red: #8c4744;
  --rule-blue: #29313b;
  --lift: 0 1px 0 rgb(0 0 0 / 35%), 0 10px 24px -14px rgb(0 0 0 / 60%);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  /* Leave room for the bottom navigation bar and the phone's home indicator. */
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 24px);
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3 {
  margin: 0 0 0.5rem;
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.005em;
}
h1 {
  font-size: 1.85rem;
}
h2 {
  font-size: 1.3rem;
}
h3 {
  font-size: 1.1rem;
}
p {
  margin: 0 0 1rem;
}
a {
  color: var(--accent);
  text-underline-offset: 3px;
}
code {
  font-size: 0.9em;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[hidden] {
  display: none !important;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus {
  left: 8px;
}

/* Small uppercase label used above titles and as section headings */
.eyebrow,
.section-label {
  margin: 0 0 6px;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.section-label {
  margin: 28px 0 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-strong);
}
.section > .section-label {
  margin: 0 0 14px;
}
.section-label.with-action {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.section-label a {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  text-decoration: none;
  white-space: nowrap;
}
.section-label a:hover {
  text-decoration: underline;
}

/* ---------- Top bar and bottom navigation ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.2rem;
}
.brand img {
  border-radius: 6px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover {
  color: var(--text);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  position: relative;
  flex: 1;
  max-width: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.bottom-nav a[aria-current='page'] {
  color: var(--text);
}
.bottom-nav a[aria-current='page']::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 50%;
  width: 28px;
  height: 2px;
  transform: translateX(-50%);
  background: var(--text);
}
.nav-icon {
  display: grid;
  place-items: center;
  height: 24px;
}
.nav-icon svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.75;
}
.nav-badge {
  position: absolute;
  top: 7px;
  left: calc(50% + 8px);
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--bad);
  color: var(--surface);
  font-size: 0.68rem;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- Page layout ---------- */
main {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  outline: none;
  overflow-x: clip; /* cards swiped off screen must not make the page scroll sideways */
}

.page-header {
  margin-bottom: 20px;
}
.page-header h1 {
  margin: 0;
}
.page-header .subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 40px;
  margin: -8px 0 4px -6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.back-link svg {
  width: 18px;
  height: 18px;
}
.back-link:hover {
  color: var(--text);
}

.section {
  margin: 28px 0;
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 0.875rem;
}
.center {
  text-align: center;
}

.loading,
.empty-state {
  padding: 56px 16px;
  text-align: center;
  color: var(--muted);
}
.empty-state h1,
.empty-state h2 {
  color: var(--text);
}

.notice {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
.btn svg {
  width: 18px;
  height: 18px;
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-ghost:hover {
  background: var(--surface);
  border-color: var(--muted);
}
.btn-good,
.btn-bad {
  background: var(--surface);
}
.btn-good {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good) 45%, var(--border));
}
.btn-good:hover {
  background: var(--good-soft);
  border-color: var(--good);
}
.btn-bad {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 45%, var(--border));
}
.btn-bad:hover {
  background: var(--bad-soft);
  border-color: var(--bad);
}
.btn-small {
  min-height: 38px;
  padding: 6px 14px;
  font-size: 0.9rem;
}
.btn-block {
  width: 100%;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.button-row.split > * {
  flex: 1 1 0;
}

/* Toggles used for filters and options */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}
.chip:hover {
  background: var(--surface);
}
.chip[aria-pressed='true'] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.chip svg {
  width: 16px;
  height: 16px;
}
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 6px;
  margin: 0 -2px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar {
  display: none;
}

.tag {
  display: inline-block;
  color: var(--muted);
  font-size: 0.78rem;
}

/* ---------- Form controls ---------- */
.input,
.select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* 16px+ stops iPhones zooming in when you tap the box */
}
.input:focus,
.select:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 25%, transparent);
  outline-offset: 0;
}
.sync-form .input {
  flex: 1 1 220px;
  width: auto;
}
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 1rem;
  cursor: pointer;
}
.toggle-row input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  flex: none;
  accent-color: var(--primary);
}

/* Welcome / sign-in screen (shown until signed in with a username) */
body.gated .bottom-nav {
  display: none;
}
.welcome {
  max-width: 480px;
  margin: 24px auto 0;
}
.welcome .page-header img {
  margin-bottom: 12px;
}

/* "@username" in the top bar when signed in */
.account-chip {
  margin-left: auto;
  margin-right: 8px;
  max-width: 45vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}
.account-chip:hover {
  color: var(--text);
}

/* Leaderboard table */
.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.leaderboard th,
.leaderboard td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.leaderboard th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.leaderboard .num {
  text-align: right;
}
.leaderboard .rank {
  width: 2.5em;
  color: var(--muted);
}
.leaderboard tr.me td {
  background: var(--accent-soft);
  font-weight: 600;
}
.search-box {
  position: relative;
}
.search-box svg {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-box .input {
  padding-left: 40px;
}

.filters {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px 12px 16px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.banner p {
  margin: 0;
  font-weight: 600;
}

/* ---------- Deck lists (home page, review page) ---------- */
.deck-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
}
/* My decks: the deck row plus a remove (×) button beside it */
.deck-list .removable {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.deck-list .removable .deck-row {
  flex: 1;
  min-width: 0;
  border-bottom: 0;
}
.deck-list .removable .icon-btn:hover {
  color: var(--bad, var(--text));
}
.deck-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 16px;
  padding: 14px 2px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.deck-row .title {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.3;
}
.deck-row:hover .title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
.deck-row .desc {
  grid-column: 1;
  color: var(--muted);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck-row .meta {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  text-align: right;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
.deck-row .due {
  display: block;
  color: var(--accent);
  font-weight: 650;
}
.deck-row .progress {
  grid-column: 1 / -1;
  margin-top: 8px;
  height: 3px;
}

/* Progress bar split into mastered / learning / new */
.progress {
  display: flex;
  gap: 2px;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--surface-2);
}
.progress > span {
  display: block;
  height: 100%;
}
.progress > span[style*='width:0%'] {
  display: none;
}
.progress .mastered {
  background: var(--good);
}
.progress .learning {
  background: var(--accent);
}
.progress-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: 1px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}
.dot.mastered {
  background: var(--good);
  box-shadow: none;
}
.dot.learning {
  background: var(--accent);
  box-shadow: none;
}

/* ---------- Deck page ---------- */
.deck-meta-line {
  color: var(--muted);
  font-size: 0.875rem;
}

.mode-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.mode-list li + li {
  border-top: 1px solid var(--border);
}
.mode-row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 12px 14px;
  color: var(--text);
  text-decoration: none;
}
.mode-row:hover {
  background: var(--bg);
}
.mode-row .icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.mode-row .icon svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.75;
}
.mode-row strong {
  display: block;
  font-weight: 650;
}
.mode-row .text {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}
.mode-row .count {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 650;
  white-space: nowrap;
}
.mode-row .chev {
  color: var(--border-strong);
}
.mode-row.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.card-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.card-list li {
  display: grid;
  gap: 2px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--border);
}
.card-list .front {
  font-family: var(--serif);
  font-weight: 600;
}
.card-list .back {
  color: var(--muted);
  white-space: pre-wrap;
}

details > summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: 650;
}

/* ---------- Study screens ---------- */
.study-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.study-top svg {
  width: 15px;
  height: 15px;
  vertical-align: -2px;
}
.tally {
  display: flex;
  gap: 12px;
}
.tally .good {
  color: var(--good);
}
.tally .bad {
  color: var(--bad);
}
.bar {
  height: 3px;
  margin-bottom: 18px;
  background: var(--border);
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--text);
  transition: width 0.25s;
}

.card-text {
  font-family: var(--serif);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.text-lg {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.25;
}
.text-md {
  font-size: 1.3rem;
  line-height: 1.4;
}
.text-sm {
  font-size: 1.1rem;
  line-height: 1.45;
}
.text-xs {
  font-size: 1rem;
  line-height: 1.45;
}

/* Flashcard styled like an index card. The outer element moves when you swipe; the inner one flips. */
.card-stage {
  position: relative;
  perspective: 1400px;
  margin-bottom: 12px;
}
.flashcard {
  position: relative;
  height: clamp(240px, 44vh, 420px);
  cursor: pointer;
  touch-action: pan-y; /* we handle sideways swipes; the page can still scroll up/down */
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.flashcard-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}
.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 52px 22px 24px;
  overflow-y: auto;
  text-align: center;
  background-color: var(--surface);
  /* the red line across the top of an index card */
  background-image: linear-gradient(to bottom, transparent 38px, var(--rule-red) 38px, var(--rule-red) 39.5px, transparent 39.5px);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: var(--lift);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.back {
  transform: rotateY(180deg);
  /* the back also gets faint blue ruled lines */
  background-image:
    linear-gradient(to bottom, transparent 38px, var(--rule-red) 38px, var(--rule-red) 39.5px, transparent 39.5px),
    repeating-linear-gradient(to bottom, transparent 0, transparent 29px, var(--rule-blue) 29px, var(--rule-blue) 30px);
  background-position: 0 0, 0 40px;
}
.face-label {
  position: absolute;
  top: 12px;
  left: 16px;
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
/* Pictures on cards */
.card-image {
  display: block;
  max-width: 100%;
  max-height: 58%;
  margin: 0 auto 12px;
  object-fit: contain;
  border-radius: 3px;
  pointer-events: none; /* taps and swipes go to the card, not the picture */
  user-select: none;
  -webkit-user-select: none;
}
.flashcard.tall {
  height: clamp(300px, 50vh, 520px);
}
.face.has-image .text-lg {
  font-size: 1.35rem;
}
.face.has-image .text-md {
  font-size: 1.15rem;
}
.question-box .card-image,
.feedback .card-image {
  max-height: 260px;
  margin: 8px 0 12px;
}
.thumb {
  display: block;
  max-width: 160px;
  max-height: 120px;
  margin: 4px 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  object-fit: contain;
  background: var(--surface);
}

/* Speaker button for reading a card aloud */
.speak-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
  touch-action: manipulation;
}
.speak-btn:hover,
.speak-btn:active {
  color: var(--accent);
  border-color: var(--accent);
}
.speak-btn svg {
  width: 18px;
  height: 18px;
}
.face .speak-btn,
.question-box .speak-btn {
  position: absolute;
  top: 2px;
  right: 6px;
  z-index: 1;
  width: 34px; /* fits above the index card's red line */
  height: 34px;
}
.question-box {
  position: relative;
}
.card-list .speak-btn,
.feedback .speak-btn {
  width: 32px;
  height: 32px;
  margin-left: 4px;
}
.card-list .speak-btn svg,
.feedback .speak-btn svg {
  width: 15px;
  height: 15px;
}

/* "Know it" / "Still learning" stamps that appear while swiping */
.swipe-label {
  position: absolute;
  top: 54px;
  z-index: 2;
  padding: 3px 10px;
  border: 2px solid currentColor;
  border-radius: 4px;
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
}
.swipe-label.known {
  right: 16px;
  color: var(--good);
  transform: rotate(6deg);
}
.swipe-label.unknown {
  left: 16px;
  color: var(--bad);
  transform: rotate(-6deg);
}
.hint-box {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-left: 3px solid var(--warn);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--warn-soft);
}
.helper {
  margin-top: 12px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Quiz */
.question-box {
  margin-bottom: 16px;
}
.question-box .card-text {
  font-size: 1.3rem;
  line-height: 1.4;
}
.options {
  display: grid;
  gap: 8px;
}
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.option:hover:not(:disabled) {
  border-color: var(--text);
}
.option .letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-weight: 650;
  font-size: 0.8rem;
  color: var(--muted);
}
.option:disabled {
  cursor: default;
}
.option.correct {
  border-color: var(--good);
  background: var(--good-soft);
  box-shadow: inset 0 0 0 1px var(--good);
}
.option.correct .letter {
  border-color: var(--good);
  background: var(--good);
  color: var(--surface);
}
.option.incorrect {
  border-color: var(--bad);
  background: var(--bad-soft);
  box-shadow: inset 0 0 0 1px var(--bad);
}
.option.incorrect .letter {
  border-color: var(--bad);
  background: var(--bad);
  color: var(--surface);
}

.feedback {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 3px solid;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.feedback p {
  margin: 4px 0 0;
}
.feedback.good {
  background: var(--good-soft);
  border-color: var(--good);
}
.feedback.close {
  background: var(--warn-soft);
  border-color: var(--warn);
}
.feedback.bad {
  background: var(--bad-soft);
  border-color: var(--bad);
}
.feedback strong {
  display: block;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.option-group {
  margin-bottom: 20px;
}
.option-group > .label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Results screen */
.result-score {
  margin: 4px 0 10px;
  font-family: var(--serif);
  font-size: 3.4rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.missed-list {
  display: grid;
  margin: 12px 0;
  padding: 0;
  list-style: none;
  text-align: left;
}
.missed-list li {
  display: grid;
  gap: 2px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--border);
}
.missed-list strong {
  font-family: var(--serif);
}

/* Match game tiles: little index cards */
.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: pan-y; /* up/down still scrolls the page; sideways drags move the tile */
  user-select: none;
  -webkit-user-select: none;
  box-shadow: var(--lift);
  transition: transform 0.15s, opacity 0.3s, border-color 0.15s, background 0.15s;
}
.tile.term {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
}
.tile.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.tile.drop-target {
  border-color: var(--accent);
  border-style: dashed;
}
.tile.dragging {
  position: relative;
  z-index: 10;
  opacity: 0.92;
  transition: none;
  pointer-events: none;
}
.tile.wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
  animation: shake 0.35s;
}
.tile.matched {
  border-color: var(--good);
  background: var(--good-soft);
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
}
@keyframes shake {
  0%,
  100% {
    translate: 0;
  }
  25% {
    translate: -5px;
  }
  75% {
    translate: 5px;
  }
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
}

/* ---------- Stats page ---------- */
.figures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--border-strong);
}
.figure {
  padding: 14px 2px 12px;
  border-bottom: 1px solid var(--border);
}
.figure:nth-child(odd) {
  padding-right: 12px;
}
.figure .value {
  display: block;
  font-family: var(--serif);
  font-size: 2.1rem;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.figure .label {
  display: block;
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--muted);
}

.box-chart {
  display: grid;
  gap: 10px;
}
.box-row {
  display: grid;
  grid-template-columns: 56px 1fr 32px;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
}
.box-row .track {
  height: 12px;
  border-radius: 0 4px 4px 0;
  background: var(--surface-2);
  overflow: hidden;
}
.box-row .fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
}
.box-row .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.calendar {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, auto);
  grid-auto-columns: minmax(14px, 1fr);
  gap: 3px;
  overflow-x: auto;
}
.calendar span {
  width: 100%;
  min-width: 14px;
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--surface-2);
}
.calendar .l1 {
  background: color-mix(in srgb, var(--accent) 35%, var(--surface-2));
}
.calendar .l2 {
  background: color-mix(in srgb, var(--accent) 65%, var(--surface-2));
}
.calendar .l3 {
  background: var(--accent);
}
.calendar .today {
  outline: 1.5px solid var(--text);
  outline-offset: -1.5px;
}
.calendar.legend {
  display: inline-flex;
  gap: 3px;
}
.calendar.legend span {
  width: 12px;
  min-width: 12px;
}

.deck-progress-list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}
.deck-progress-list li {
  padding: 14px 2px;
  border-bottom: 1px solid var(--border);
}
.deck-progress-list a {
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  text-decoration: none;
}
.deck-progress-list a:hover {
  text-decoration: underline;
}

/* ---------- Toast message ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 12px);
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Bigger screens ---------- */
@media (min-width: 640px) {
  h1 {
    font-size: 2.3rem;
  }
  main {
    padding-top: 32px;
  }
  .figures {
    grid-template-columns: repeat(3, 1fr);
  }
  .figure:nth-child(odd) {
    padding-right: 2px;
  }
  .match-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .filters {
    grid-template-columns: 1fr 220px;
  }
  .study {
    max-width: 620px;
    margin: 0 auto;
  }
}
@media (min-width: 900px) {
  .match-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* People who turn off animations in their device settings get none. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
