/*
  euc design system: plain CSS, no build step. Mobile first (from 360 px), light and dark.

  Tokens (custom properties on :root, redefined for dark mode):
    colours   --bg --surface --surface-2 --fg --muted --border --accent --accent-hover --accent-fg
              --accent-soft --focus --ok --ok-soft --bad --bad-soft
    regions   --region-north --region-west --region-central --region-south --region-southeast --region-east
              (the quiz-region hues from web/dev/geo.js; light enough for --ink text in both themes)
    mastery   --mastery-1 … --mastery-5: Leitner boxes 1–5 on the progress map (defined in the progress section)
    spacing   --space-1 … --space-7 (0.25 … 3 rem)
    shape     --radius-sm --radius --radius-pill --shadow
    sizes     --tap (44 px minimum touch target) --content (64rem page width) --gutter

  Page frame (index.html, js/shell.js):
    .app-header .app-main .app-footer   landmarks; .container centres content at --content
    .brand .brand-mark .lang-switch     header parts (language buttons use aria-pressed)
    .skip-link .app-live                skip link; polite live region (ctx.announce)

  Views (js/views/):
    .view                 root of every view (the router creates it); .view-narrow limits it to reading width,
                          .view-centered centres a narrow view
    .view-title           the view's h1 (focused after navigation)
    .lead .muted .prose   subtitle text, secondary text, long-form text with spaced headings and lists
    .stack .cluster       vertical rhythm / wrapping row of items
    .card                 surface panel
    .btn                  button or button-like link (≥ 44 px); variants .btn-primary .btn-quiet .btn-block;
                          answer states .is-correct .is-wrong; :disabled is dimmed
    .tiles > li > .tile   big link cards: .tile-icon .tile-body .tile-title .tile-text, colour from
                          data-accent="north|west|central|south|southeast|east"
    .segmented            <fieldset> with <legend> and .segmented-options > label > input[type=radio] + span
    .flag                 a flag image (4:3, hairline frame)
    .placeholder          centred "coming soon" card; .room-code shows a 4-letter room code
    .visually-hidden      hidden on screen, read by screen readers
*/

:root {
  color-scheme: light dark;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;

  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #ebeae4;
  --fg: #1d2026;
  --muted: #5a616d;
  --border: #d8d6cf;
  --accent: #1f5fbf;
  --accent-hover: #184c99;
  --accent-fg: #ffffff;
  --accent-soft: #e2ebf9;
  --focus: #1f5fbf;
  --ok: #1d7a3a;
  --ok-soft: #dcf1e2;
  --bad: #b3261e;
  --bad-soft: #fbe2df;
  --ink: #1d2026;

  --region-north: #7fa8d6;
  --region-west: #e3a65f;
  --region-central: #8fc488;
  --region-south: #dd8f8f;
  --region-southeast: #b394d6;
  --region-east: #d6c35e;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --radius-sm: 0.5rem;
  --radius: 0.875rem;
  --radius-pill: 999px;
  --shadow: 0 1px 2px rgb(29 32 38 / 0.06), 0 4px 12px rgb(29 32 38 / 0.05);

  --tap: 2.75rem;
  --content: 64rem;
  --gutter: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1d2027;
    --surface-2: #272b34;
    --fg: #e8e9ec;
    --muted: #a4aab5;
    --border: #353a45;
    --accent: #7aa7f0;
    --accent-hover: #9bbdf5;
    --accent-fg: #0f1a2e;
    --accent-soft: #1e2a3e;
    --focus: #9bbdf5;
    --ok: #74d08f;
    --ok-soft: #16301f;
    --bad: #f28b82;
    --bad-soft: #3b1d1b;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.35);
  }
}

@media (min-width: 40rem) {
  :root {
    --gutter: 1.5rem;
  }
}

/* ---- base */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* No grey flash on tap (mobile WebKit/Blink); buttons show their own :active state instead. */
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: break-word;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 var(--space-3);
}

h2 {
  font-size: 1.25rem;
}

p {
  margin: 0 0 var(--space-4);
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent-hover);
}

img,
svg {
  max-width: 100%;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Headings and <main> get focus only programmatically (after navigation, skip link): no ring needed. */
[tabindex="-1"]:focus {
  outline: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- frame */

.container {
  width: 100%;
  max-width: var(--content);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 10;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
  color: var(--accent-fg);
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 3.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  min-width: 0;
  color: var(--fg);
  font-size: 1.0625rem;
  font-weight: 700;
  text-decoration: none;
}

.brand:hover {
  color: var(--fg);
}

.brand-mark {
  flex: none;
  width: 2rem;
  height: 2rem;
}

.brand-mark-bg {
  fill: var(--accent);
}

.brand-mark-pin {
  fill: var(--accent-fg);
}

.lang-switch {
  display: inline-flex;
  flex: none;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.lang-switch button {
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.lang-switch button[aria-pressed="false"]:hover {
  color: var(--fg);
}

.lang-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-fg);
}

.app-main {
  flex: 1;
  padding-block: var(--space-5) var(--space-7);
}

.app-loading,
.load-error {
  padding-block: var(--space-7);
  color: var(--muted);
  text-align: center;
}

.app-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9375rem;
}

.app-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-5);
  min-height: 3.5rem;
}

.app-footer a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

/* ---- views */

.view-narrow {
  max-width: 42rem;
}

.view-centered {
  margin-inline: auto;
}

.view-title {
  font-size: clamp(1.75rem, 1.35rem + 2vw, 2.5rem);
  letter-spacing: -0.01em;
}

.lead {
  color: var(--muted);
  font-size: 1.125rem;
}

.muted {
  color: var(--muted);
}

.prose h2 {
  margin-top: var(--space-6);
}

.prose ul {
  margin: 0 0 var(--space-4);
  padding-left: 1.25rem;
}

.prose li + li {
  margin-top: var(--space-2);
}

.stack > * + * {
  margin-top: var(--space-4);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.card {
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: var(--space-4);
  padding-block: var(--space-6);
  text-align: center;
}

.placeholder-icon {
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  margin-bottom: var(--space-4);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}

.placeholder-icon svg {
  width: 1.75rem;
  height: 1.75rem;
}

.room-code {
  padding: 0.1em 0.4em;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--fg);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 1.125em;
  letter-spacing: 0.12em;
}

/* ---- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: var(--space-2) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 0.15s,
    border-color 0.15s;
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
}

/* Hover only where a pointer can hover: on touch screens :hover sticks to the last tapped button
   (e.g. a quiz answer), so touch gets :active feedback instead. */
@media (hover: hover) {
  .btn:hover {
    background: var(--surface-2);
    color: var(--fg);
  }

  .btn-primary:hover {
    border-color: var(--accent-hover);
    background: var(--accent-hover);
    color: var(--accent-fg);
  }

  .btn-quiet:hover {
    background: var(--accent-soft);
    color: var(--accent);
  }
}

.btn:active {
  background: var(--surface-2);
}

.btn-primary:active {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.btn-quiet:active {
  background: var(--accent-soft);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.is-correct,
.btn.is-correct:disabled {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--fg);
  opacity: 1;
}

.btn.is-wrong,
.btn.is-wrong:disabled {
  border-color: var(--bad);
  background: var(--bad-soft);
  color: var(--fg);
  opacity: 1;
}

/* ---- segmented control (radio group) */

.segmented {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented legend {
  margin-bottom: var(--space-2);
  padding: 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.segmented-options {
  display: inline-flex;
  max-width: 100%;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.segmented label {
  position: relative;
  display: flex;
  flex: 1 1 auto;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  transition:
    background-color 0.15s,
    color 0.15s;
}

.segmented label:hover span {
  color: var(--fg);
}

.segmented input:checked + span {
  background: var(--accent);
  color: var(--accent-fg);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---- tiles */

.tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 36rem) {
  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }
}

@media (min-width: 60rem) {
  .tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.tile {
  --tile-accent: var(--accent);
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  height: 100%;
  min-height: 5rem;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--fg);
  text-decoration: none;
  transition:
    border-color 0.15s,
    transform 0.15s;
}

.tile:hover {
  border-color: var(--tile-accent);
  color: var(--fg);
  transform: translateY(-2px);
}

.tile-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-sm);
  background: var(--tile-accent);
  color: var(--ink);
}

.tile-icon svg {
  width: 1.625rem;
  height: 1.625rem;
}

.tile-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.tile-title {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.25;
}

.tile-text {
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.4;
}

[data-accent="north"] {
  --tile-accent: var(--region-north);
}

[data-accent="west"] {
  --tile-accent: var(--region-west);
}

[data-accent="central"] {
  --tile-accent: var(--region-central);
}

[data-accent="south"] {
  --tile-accent: var(--region-south);
}

[data-accent="southeast"] {
  --tile-accent: var(--region-southeast);
}

[data-accent="east"] {
  --tile-accent: var(--region-east);
}

/* ---- home */

.hero {
  margin-bottom: var(--space-6);
}

.hero .view-title {
  font-size: clamp(2.25rem, 1.6rem + 3.2vw, 3.5rem);
  letter-spacing: -0.02em;
}

.hero .lead {
  max-width: 38rem;
  margin-bottom: var(--space-5);
}

.progress-line {
  margin: var(--space-5) 0 0;
  padding: var(--space-3) var(--space-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.9375rem;
}

/* ---- flags */

.flag {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 4px;
  box-shadow: 0 0 0 1px var(--border);
  object-fit: cover;
}

/* ---- motion */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .tile:hover {
    transform: none;
  }
}

/* ---- quiz

  Quiz view (js/views/quiz.js), question renderers (js/questions/) and the mini card (js/ui/minicard.js):
    .quiz .quiz-title .quiz-body           view root, its h1 (hidden while playing), the current screen
    .quiz-setup .chips                     setup card; checkbox chips: .chips-options > label > input + span
    .form-error                            inline validation message
    .quiz-status .quiz-position .quiz-stats .quiz-stat .quiz-bar .quiz-bar-fill   header while playing
    .question                              a renderer's root: .question-prompt (h2) with .question-instruction and
                                           .question-subject or .question-picture (.question-flag, .question-shape)
    .choice-options > .btn.choice          answer buttons: .choice-key .choice-label .choice-mark;
                                           states .is-chosen .is-correct .is-wrong, locked via aria-disabled
    .quiz-feedback .quiz-verdict .quiz-next  panel after an answer (.is-correct / .is-wrong; .is-auto moves on)
    .quiz-results .quiz-summary .quiz-final .quiz-facts .quiz-actions .quiz-mistakes .quiz-perfect
    .minicard .minicard-flag .minicard-body .minicard-name .minicard-eu .minicard-capital .minicard-note
*/

.quiz-body {
  margin-top: var(--space-2);
}

/* setup */

.quiz-setup {
  display: grid;
  gap: var(--space-5);
  padding: var(--space-4);
}

.quiz-setup .lead {
  margin: 0;
  font-size: 1.0625rem;
}

.quiz-start {
  width: 100%;
}

@media (min-width: 36rem) {
  .quiz-setup {
    padding: var(--space-5);
  }

  .quiz-start {
    justify-self: start;
    width: auto;
    min-width: 12rem;
  }
}

.chips {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.chips legend {
  margin-bottom: var(--space-2);
  padding: 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.chips-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chips label {
  position: relative;
  display: flex;
}

.chips input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.chips span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.chips label:hover span {
  border-color: var(--accent);
  color: var(--fg);
}

.chips input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
}

.chips input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.chip-check {
  display: none;
  width: 1.125rem;
  height: 1.125rem;
  color: var(--accent);
}

.chips input:checked + span .chip-check {
  display: block;
}

.form-error {
  margin: var(--space-2) 0 0;
  color: var(--bad);
  font-weight: 600;
}

/* status while playing */

.quiz-status {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--space-2) var(--space-4);
}

.quiz-position,
.quiz-stats {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.quiz-position {
  font-size: 1.125rem;
  font-weight: 700;
}

.quiz-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-1) var(--space-4);
  color: var(--muted);
  font-size: 0.9375rem;
}

.quiz-stat-value {
  color: var(--fg);
}

.quiz-bar {
  grid-column: 1 / -1;
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.quiz-bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease-out;
}

/* question (renderers) */

.question {
  margin-top: var(--space-4);
}

.question-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-5);
  text-align: center;
}

.question-instruction {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

.question-subject {
  font-size: clamp(1.875rem, 1.4rem + 2.4vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.question-picture {
  display: block;
  width: 100%;
}

.question-flag {
  width: min(14rem, 66vw);
  margin-inline: auto;
  border-radius: var(--radius-sm);
}

.question-shape {
  display: block;
  width: 100%;
  height: clamp(8rem, 24vh, 15rem);
  fill: var(--accent);
  stroke: var(--accent);
  stroke-linejoin: round;
}

.question-shape path {
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

@media (min-width: 36rem) {
  .question-flag {
    width: 18rem;
  }
}

.choice-options {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
}

@media (min-width: 36rem) {
  .choice-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.btn.choice {
  justify-content: flex-start;
  gap: var(--space-3);
  width: 100%;
  min-height: max(var(--tap), 3.5rem);
  padding: var(--space-2) var(--space-3);
  font-size: 1.0625rem;
  text-align: left;
}

.choice-key {
  display: grid;
  flex: none;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
  transition:
    background-color 0.15s,
    color 0.15s;
}

.choice-label {
  flex: 1;
  min-width: 0;
}

.choice-mark {
  display: none;
  flex: none;
}

.choice-mark .icon {
  display: none;
  width: 1.375rem;
  height: 1.375rem;
}

.btn.choice.is-correct .choice-mark,
.btn.choice.is-wrong .choice-mark,
.btn.choice.is-correct .choice-check,
.btn.choice.is-wrong .choice-cross {
  display: block;
}

.btn.choice.is-correct .choice-check {
  color: var(--ok);
}

.btn.choice.is-wrong .choice-cross {
  color: var(--bad);
}

.btn.choice.is-correct .choice-key {
  background: var(--ok);
  color: var(--surface);
}

.btn.choice.is-wrong .choice-key {
  background: var(--bad);
  color: var(--surface);
}

.btn.choice[aria-disabled="true"] {
  cursor: default;
}

.btn.choice[aria-disabled="true"]:not(.is-correct, .is-wrong):hover,
.btn.choice[aria-disabled="true"]:not(.is-correct, .is-wrong):active {
  background: var(--surface);
}

.btn.choice.is-chosen {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  opacity: 1;
}

.btn.choice.is-correct {
  box-shadow: inset 0 0 0 1px var(--ok);
}

.btn.choice.is-wrong {
  box-shadow: inset 0 0 0 1px var(--bad);
}

/* feedback after an answer */

.quiz-feedback {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.quiz-feedback.is-correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.quiz-feedback.is-wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.quiz-verdict {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.quiz-verdict .icon {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
}

.quiz-feedback.is-correct .quiz-verdict .icon {
  color: var(--ok);
}

.quiz-feedback.is-wrong .quiz-verdict .icon {
  color: var(--bad);
}

.quiz-next {
  position: relative;
  overflow: hidden;
}

/* The bar under "Next" fills while a correct answer moves on by itself (AUTO_ADVANCE_MS in quiz-session.js). */
.quiz-next.is-auto::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: currentColor;
  opacity: 0.6;
  transform-origin: left;
  animation: quiz-auto-advance 1.2s linear forwards;
}

@keyframes quiz-auto-advance {
  from {
    transform: scaleX(0);
  }

  to {
    transform: scaleX(1);
  }
}

@media (min-width: 36rem) {
  .quiz-feedback {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: var(--space-5);
  }

  .quiz-verdict {
    grid-column: 1 / -1;
  }

  .quiz-next {
    min-width: 10rem;
  }
}

.quiz-failure {
  padding: var(--space-5);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  background: var(--bad-soft);
  text-align: center;
}

/* results */

.quiz-summary {
  display: grid;
  justify-items: center;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.quiz-summary h2 {
  margin: 0;
}

.quiz-final {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  margin: 0;
}

.quiz-final-score {
  font-size: clamp(3.25rem, 2.4rem + 5vw, 4.75rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.quiz-final-percent {
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 700;
}

.quiz-facts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3) var(--space-6);
  margin: 0;
}

.quiz-facts dt {
  color: var(--muted);
  font-size: 0.875rem;
}

.quiz-facts dd {
  margin: 0;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.quiz-actions {
  justify-content: center;
}

.quiz-mistakes-title {
  margin-top: var(--space-6);
}

.quiz-mistakes {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 36rem) {
  .quiz-mistakes {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.quiz-mistakes li {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.quiz-mistakes .minicard-note {
  color: var(--bad);
  font-weight: 600;
}

.quiz-perfect {
  margin: var(--space-5) 0 0;
  color: var(--ok);
  font-size: 1.125rem;
  font-weight: 700;
  text-align: center;
}

/* mini card */

.minicard {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.minicard-flag {
  flex: none;
  width: 3.5rem;
}

.minicard-body {
  min-width: 0;
}

.minicard-body p {
  margin: 0;
}

.minicard-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.3;
}

.minicard-eu {
  padding: 0 0.45em;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
}

.minicard-capital,
.minicard-note {
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.4;
}

.minicard-capital-name {
  color: var(--fg);
  font-weight: 600;
}

/* ---- typing

  Typing view (js/views/typing.js). It reuses the quiz classes for the setup (.quiz-setup .chips), the status
  (.quiz-status …), the prompt (.question .question-prompt), the feedback panel (.quiz-feedback .quiz-verdict), the
  auto-advance bar (.quiz-next.is-auto) and the results (.quiz-results …, js/ui/results.js).
    .typing-flag                         the flag above "Type the capital" (smaller than a flag question's)
    .typing-form .typing-label .typing-input   the one answer field; states .is-bad (a failed try or the answer
                                         missed), .is-ok, .is-locked (the question is over: aria-readonly)
    .typing-message                      the line under the field after an empty or failed try (.is-bad)
    .typing-actions                      Check / Show the answer, then Next
    .typing-feedback .typing-note .typing-forms .typing-forms-label .typing-forms-list   panel after a question
*/

.typing .question {
  margin-top: var(--space-3);
}

.typing .question-prompt {
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.typing-flag {
  width: min(8rem, 36vw);
  margin: 0 auto var(--space-2);
}

.typing-form {
  display: grid;
  gap: var(--space-2);
}

.typing-label {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.typing-input {
  width: 100%;
  min-height: 3.25rem;
  padding: 0 var(--space-4);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  /* At least 16 px, or iOS zooms the page when the field gets the focus. */
  font-size: 1.25rem;
  font-weight: 600;
  transition:
    background-color 0.15s,
    border-color 0.15s;
}

.typing-input:focus {
  border-color: var(--accent);
}

.typing-input.is-bad {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.typing-input.is-ok {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.typing-input.is-locked {
  cursor: default;
}

.typing-message {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.typing-message.is-bad {
  color: var(--bad);
}

.typing-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.typing-actions .btn {
  flex: 1 1 0;
  min-width: 0;
  padding-inline: var(--space-3);
}

/* .btn sets display, which would beat the hidden attribute. */
.typing-actions .btn[hidden] {
  display: none;
}

@media (min-width: 36rem) {
  .typing-actions .btn {
    flex: 0 0 auto;
    min-width: 10rem;
    padding-inline: var(--space-5);
  }
}

/* One column at every width: the quiz's panel has Next beside the card, this one has it above. */
.typing-feedback {
  grid-template-columns: minmax(0, 1fr);
}

.typing-feedback p {
  margin: 0;
}

.typing-note {
  font-weight: 600;
}

.typing-note[hidden] {
  display: none;
}

.typing-forms {
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.4;
}

.typing-forms-list {
  display: inline;
  margin: 0;
  padding: 0;
  list-style: none;
}

.typing-forms-list li {
  display: inline;
  color: var(--fg);
  font-weight: 600;
}

.typing-forms-list li + li::before {
  content: " · ";
  content: " · " / "";
  color: var(--muted);
  font-weight: 400;
}

/* ---- learn

  Learn view (js/views/learn.js):
    .learn .learn-tabs .learn-panel         view root, the Mapa / Fiszki segmented control, one panel per tab
    .learn-layout .learn-map .learn-side    the map and the card: stacked on phones, side by side from 60rem
    .learn-hint                             shown in .learn-side before a country is chosen
    .learn-card                             the country card (data-accent = its region):
                                            .learn-card-pictures (.learn-card-flag, .learn-card-shape-box >
                                            .learn-card-shape), .learn-badges (.learn-badge, .learn-badge-eu,
                                            .learn-badge-region with .learn-swatch), .learn-card-title,
                                            .learn-card-capital, .learn-alt (.learn-alt-label),
                                            .learn-card-heading, .learn-neighbours > li > .btn.learn-neighbour,
                                            .learn-outside, .learn-none
    .learn-filter .learn-cards-actions .learn-cards-hint   flashcard controls: region chips, reveal / hide all
    .flashcards > li > .flashcard           button[aria-expanded] > .flashcard-inner > .flashcard-face
                                            (.flashcard-front: .flashcard-flag .flashcard-name;
                                            .flashcard-back: .flashcard-country .flashcard-capital .flashcard-native);
                                            it turns over in 3D only without prefers-reduced-motion
*/

/* Both views toggle [hidden] on elements that have a display of their own. */
.learn [hidden],
.progress-view [hidden] {
  display: none !important;
}

.learn-tabs {
  margin-bottom: var(--space-4);
}

.learn-layout {
  display: grid;
  align-items: start;
  gap: var(--space-4);
}

/* From 60rem the card sits beside the map; the map column is the map's own size (map.css), the card takes the rest. */
@media (min-width: 60rem) {
  .learn-layout {
    grid-template-columns: minmax(0, min(70vh, 40rem)) minmax(20rem, 1fr);
    grid-template-columns: minmax(0, min(70svh, 40rem)) minmax(20rem, 1fr);
  }

  .learn-side {
    position: sticky;
    top: var(--space-4);
  }
}

.learn-hint {
  margin: 0;
  color: var(--muted);
}

.learn-card {
  padding: var(--space-4);
}

.learn-card-pictures {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.learn-card-shape-box {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  border-radius: 4px;
  background: var(--surface-2);
}

.learn-card-shape {
  display: block;
  width: 100%;
  height: 100%;
  fill: var(--tile-accent);
  stroke: var(--muted);
  stroke-linejoin: round;
}

.learn-card-shape path {
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

.learn-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
}

.learn-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.1em 0.65em;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--fg);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.6;
}

.learn-badge-eu {
  background: var(--accent-soft);
  color: var(--accent);
  letter-spacing: 0.04em;
}

.learn-swatch {
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--tile-accent);
  box-shadow: 0 0 0 1px var(--border);
}

.learn-card-title {
  margin: 0 0 var(--space-1);
  font-size: clamp(1.625rem, 1.4rem + 1vw, 2rem);
  letter-spacing: -0.01em;
}

.learn-card-capital {
  margin: 0 0 var(--space-1);
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.25;
}

.learn-alt,
.learn-outside {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.45;
}

.learn-alt-label {
  color: var(--muted);
}

.learn-card-heading {
  margin: var(--space-4) 0 var(--space-2);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.learn-neighbours {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.btn.learn-neighbour {
  padding-inline: var(--space-4);
}

.learn-neighbours + .learn-outside {
  margin-top: var(--space-3);
}

.learn-none {
  margin: 0;
}

/* flashcards */

.learn-filter {
  margin-bottom: var(--space-3);
}

.learn-cards-actions {
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

/* Both fit one row on a 390 px phone. */
.learn-cards-actions .btn {
  padding-inline: var(--space-4);
}

.learn-cards-hint {
  margin: 0 0 var(--space-3);
  font-size: 0.9375rem;
}

.flashcards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(9.5rem, 100%), 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.flashcards > li {
  display: flex;
}

.flashcard {
  display: block;
  width: 100%;
  min-height: 10.5rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font: inherit;
  text-align: center;
  cursor: pointer;
  perspective: 60rem;
}

.flashcard-inner {
  display: grid;
  height: 100%;
}

.flashcard-face {
  display: flex;
  grid-area: 1 / 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.flashcard-back {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Without motion the faces simply swap. */
.flashcard[aria-expanded="false"] .flashcard-back,
.flashcard[aria-expanded="true"] .flashcard-front {
  visibility: hidden;
}

@media (hover: hover) {
  .flashcard:hover .flashcard-face {
    border-color: var(--accent);
  }
}

.flashcard-flag {
  width: min(7.5rem, 100%);
}

.flashcard-name {
  font-weight: 700;
  line-height: 1.25;
}

.flashcard-country,
.flashcard-native {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.3;
}

.flashcard-country {
  font-weight: 600;
}

.flashcard-capital {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
}

@media (prefers-reduced-motion: no-preference) {
  .flashcard-inner {
    transform-style: preserve-3d;
    transition: transform 0.45s ease;
  }

  .flashcard[aria-expanded="true"] .flashcard-inner {
    transform: rotateY(180deg);
  }

  .flashcard-face {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }

  .flashcard-back {
    transform: rotateY(180deg);
  }

  .flashcard[aria-expanded] .flashcard-face {
    visibility: visible;
  }
}

/* ---- progress

  Progress view (js/views/progress.js) and the home page line:
    --mastery-1 … --mastery-5     Leitner boxes 1–5: one green, light → dark (dark mode: dim → bright), validated as
                                  an ordinal ramp; box 1 still clears 2:1 against the default country fill
    [data-level="1…5"]            sets --level to that box's colour (swatches, pips, table cells)
    .progress-view .progress-body .progress-skills   view root, its content, the skill selector
    .progress-layout              counters, map, key and the chosen country (the map beside them from 60rem)
    .progress-counters            .progress-known .progress-seen .progress-rule .progress-practice
    .progress-map .progress-key   the mastery map; legend (.progress-legend, .map-legend) and .progress-excluded
    .progress-legend-title .progress-legend-row .progress-legend-none .progress-ramp (.progress-ramp-number
                                  .progress-ramp-low .progress-ramp-known) .progress-swatch
    .progress-detail              .progress-hint, or .progress-country: .progress-country-head (-flag, -name),
                                  .progress-levels (-skill, -text, li.is-current), .progress-country-learn
    .progress-pips .progress-pip  five pips; the first n are .is-on
    .progress-breakdown           .progress-breakdown-title -scope, .progress-bar-key, .progress-bars > li
                                  (.progress-bars-skill -value, .progress-bar > .progress-bar-known .progress-bar-seen)
    .progress-table               <details> with every country's levels
    .progress-reset .progress-confirm .progress-confirm-text .btn-danger   reset, confirmed inline
    .progress-empty               nothing answered yet
    .progress-line.has-progress   the home page line once something was answered
*/

:root {
  --mastery-1: #6ec286;
  --mastery-2: #4caa6b;
  --mastery-3: #309154;
  --mastery-4: #1c7740;
  --mastery-5: #155d32;
}

@media (prefers-color-scheme: dark) {
  :root {
    --mastery-1: #549768;
    --mastery-2: #5fb479;
    --mastery-3: #72cf8e;
    --mastery-4: #92e8aa;
    --mastery-5: #c2fad0;
  }
}

[data-level="1"] {
  --level: var(--mastery-1);
}

[data-level="2"] {
  --level: var(--mastery-2);
}

[data-level="3"] {
  --level: var(--mastery-3);
}

[data-level="4"] {
  --level: var(--mastery-4);
}

[data-level="5"] {
  --level: var(--mastery-5);
}

.progress-line.has-progress {
  border-style: solid;
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
}

.progress-skills {
  margin-bottom: var(--space-4);
}

/* Four options fit a 360 px phone when they share the width. */
.progress-skills .segmented-options {
  display: flex;
  width: 100%;
}

.progress-skills .segmented span {
  padding: 0 var(--space-2);
}

@media (min-width: 36rem) {
  .progress-skills .segmented-options {
    display: inline-flex;
    width: auto;
  }

  .progress-skills .segmented span {
    padding: 0 var(--space-4);
  }
}

.progress-layout {
  display: grid;
  align-items: start;
  gap: var(--space-4);
}

@media (min-width: 60rem) {
  .progress-layout {
    grid-template-areas:
      "map counters"
      "map key"
      "map detail";
    grid-template-columns: minmax(0, min(70vh, 40rem)) minmax(20rem, 1fr);
    grid-template-columns: minmax(0, min(70svh, 40rem)) minmax(20rem, 1fr);
    grid-template-rows: auto auto 1fr;
  }

  .progress-counters {
    grid-area: counters;
  }

  .progress-map {
    grid-area: map;
  }

  .progress-key {
    grid-area: key;
  }

  .progress-detail {
    grid-area: detail;
  }
}

.progress-counters {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4);
}

.progress-counters p {
  margin: 0;
}

.progress-known {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.progress-seen {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.progress-rule {
  font-size: 0.875rem;
}

.progress-practice {
  justify-self: start;
  margin-top: var(--space-2);
}

/* legend */

.progress-key p {
  margin: 0;
}

.progress-legend {
  display: grid;
  gap: var(--space-2);
  font-size: 0.875rem;
}

.progress-legend-title {
  color: var(--muted);
  font-weight: 700;
}

.progress-legend-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-3) var(--space-5);
}

.progress-legend-none {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.progress-swatch {
  display: inline-block;
  width: 1.75rem;
  height: 0.875rem;
  border-radius: 3px;
  background: var(--level, var(--surface-2));
}

.progress-swatch[data-level="0"] {
  background: var(--map-country);
  box-shadow: inset 0 0 0 1px var(--map-border);
}

.progress-ramp {
  display: grid;
  grid-template-columns: repeat(5, 1.75rem);
  gap: 2px;
}

.progress-ramp-number {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.progress-ramp-low {
  grid-column: 1 / 4;
  color: var(--muted);
}

.progress-ramp-known {
  grid-column: 4 / 6;
  padding-top: 1px;
  border-top: 2px solid var(--fg);
  font-weight: 700;
  text-align: center;
}

.progress-excluded {
  margin-top: var(--space-3) !important;
  font-size: 0.875rem;
}

/* chosen country */

.progress-hint {
  margin: 0;
  color: var(--muted);
}

.progress-country {
  padding: var(--space-4);
}

.progress-country-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.progress-country-flag {
  flex: none;
  width: 3rem;
}

.progress-country-name {
  margin: 0;
  font-size: 1.25rem;
}

.progress-levels {
  display: grid;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
  padding: 0;
  list-style: none;
}

.progress-levels li {
  display: grid;
  grid-template-columns: 5.5rem auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-3);
  font-size: 0.9375rem;
}

.progress-levels li.is-current {
  font-weight: 700;
}

.progress-levels-text {
  color: var(--muted);
}

.progress-pips {
  display: inline-flex;
  gap: 2px;
}

.progress-pip {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 2px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}

.progress-pip.is-on {
  background: var(--level);
  box-shadow: none;
}

.btn.progress-country-learn {
  margin-left: calc(-1 * var(--space-3));
  padding-inline: var(--space-3);
}

/* all skills */

.progress-breakdown {
  margin-top: var(--space-5);
  padding: var(--space-4);
}

.progress-breakdown-title {
  margin-bottom: var(--space-1);
}

.progress-breakdown-scope {
  margin-bottom: var(--space-3);
  font-size: 0.9375rem;
}

.progress-bar-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: 0 0 var(--space-3);
  color: var(--muted);
  font-size: 0.875rem;
}

.progress-bar-key > span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.progress-bars {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.progress-bars li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--space-1) var(--space-3);
}

.progress-bars-skill {
  font-weight: 600;
}

.progress-bars li.is-current .progress-bars-skill {
  font-weight: 800;
}

.progress-bars-value {
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.progress-bar {
  display: flex;
  grid-column: 1 / -1;
  gap: 2px;
  height: 0.75rem;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.progress-bar-known,
.progress-bar-seen {
  display: block;
  flex: none;
  width: calc(var(--part, 0) * 100%);
}

.progress-bar-key .progress-bar-known,
.progress-bar-key .progress-bar-seen {
  width: 1rem;
  height: 0.625rem;
  border-radius: 2px;
}

.progress-bar-known {
  background: var(--mastery-4);
}

.progress-bar-seen {
  background: var(--mastery-1);
}

/* table */

.progress-table {
  margin-top: var(--space-4);
}

.progress-table summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.progress-table-scroll {
  margin-top: var(--space-2);
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.progress-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

.progress-table th,
.progress-table td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}

.progress-table th[scope="row"],
.progress-table thead th:first-child {
  text-align: left;
  white-space: normal;
}

.progress-table thead th {
  color: var(--muted);
  font-size: 0.8125rem;
}

.progress-table tbody tr:last-child > * {
  border-bottom: 0;
}

.progress-table td .progress-swatch {
  width: 0.625rem;
  height: 0.625rem;
  margin-right: var(--space-1);
}

@media (min-width: 36rem) {
  .progress-table th,
  .progress-table td {
    padding-inline: var(--space-3);
  }
}

/* reset */

.progress-reset {
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}

.progress-reset > p {
  margin-bottom: var(--space-3);
}

.progress-confirm {
  padding: var(--space-4);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  background: var(--bad-soft);
}

.progress-confirm-text {
  margin-bottom: var(--space-3);
  font-weight: 700;
}

.btn-danger {
  border-color: var(--bad);
  background: var(--bad);
  color: var(--surface);
}

@media (hover: hover) {
  .btn-danger:hover {
    border-color: var(--bad);
    background: var(--bad);
    color: var(--surface);
    filter: brightness(0.92);
  }
}

.btn-danger:active {
  background: var(--bad);
  filter: brightness(0.88);
}

/* nothing answered yet */

.progress-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 42rem;
  margin-inline: auto;
  padding-block: var(--space-6);
  text-align: center;
}

.progress-empty .lead {
  max-width: 30rem;
}

.progress-empty-actions {
  justify-content: center;
}

/* ---- rooms

  Play with friends (#14): the create / join page (js/views/play.js, join.js) and the room (js/views/room.js).
    .play .play-form .play-panel .play-error .play-submit .play-alt   the create / join form
    .field .field-label .field-hint .text-input                      a labelled text field (nick, room code, link)
    .room                       the room view; .room-body holds the current screen
    .room-bar                   code, connection (data-status = connecting | joined | reconnecting | offline | ended),
                                .room-bar-actions (Retry, Leave); .room-dot is the state dot (also in the player list)
    .room-confirm .room-notice  "Leave the game?" and a line for refused actions or why the client is offline
    .room-lobby                 .room-invite (.room-big-code, .room-qr > svg.qr, .room-link) and .room-people
                                (.room-players > .room-player[data-connected], .room-start-row, .room-settings)
    .room-name .room-nick .room-badge   a nick with its host / you badges
    .room-starting .room-countdown      the 3-2-1 lead-in (the number pops unless reduced motion is asked for)
    .room-play                  a question: .room-play-status (with .room-timer, .is-low near the end), .room-note,
                                then .room-result (.is-correct | .is-wrong | .is-none) with .room-board rows (.room-row)
    .room-final                 .room-podium > .room-podium-place[data-position][data-rank], .room-ranking rows
    .room-connecting .room-end  before the first snapshot; after the room closed or the join was refused
*/

:root {
  --warn: #9a6700;
  --warn-soft: #fbf0d9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --warn: #e7b85c;
    --warn-soft: #33290f;
  }
}

/* .btn and the flex containers below set display, which would beat the hidden attribute. */
.play [hidden],
.room [hidden] {
  display: none !important;
}

/* fields */

.field {
  display: grid;
  gap: var(--space-1);
}

.field-label {
  font-weight: 600;
}

.field-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.text-input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  /* At least 16 px, or iOS zooms the page when the field gets the focus. */
  font-size: 1.0625rem;
}

.text-input:focus {
  border-color: var(--accent);
}

.text-input[aria-invalid="true"] {
  border-color: var(--bad);
}

.room-code-input {
  max-width: 12rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* create / join */

.play-form {
  display: grid;
  gap: var(--space-5);
  padding: var(--space-4);
}

.play-panel {
  display: grid;
  gap: var(--space-5);
}

.play-error {
  margin: 0;
}

.play-submit {
  width: 100%;
}

.play-alt {
  margin-top: var(--space-4);
  text-align: center;
}

@media (min-width: 36rem) {
  .play-form {
    padding: var(--space-5);
  }

  .play-submit {
    justify-self: start;
    width: auto;
    min-width: 12rem;
  }
}

/* the room frame */

.room {
  max-width: 60rem;
  margin-inline: auto;
}

/* One line while connected or reconnecting (the status text wraps); offline adds Retry, and the buttons then move
   to a second line on a phone. */
.room-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.room-bar p {
  margin: 0;
}

.room-bar-code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.room-status {
  display: flex;
  flex: 1 1 8rem;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.room-bar-actions {
  display: flex;
  gap: var(--space-1);
  margin-left: auto;
}

.room-bar .btn {
  padding-inline: var(--space-3);
}

.room-dot {
  flex: none;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: var(--muted);
}

.room-bar[data-status="joined"] .room-dot,
.room-player[data-connected="true"] .room-dot {
  background: var(--ok);
}

.room-bar[data-status="connecting"] .room-dot,
.room-bar[data-status="reconnecting"] .room-dot {
  background: var(--warn);
}

.room-bar[data-status="offline"] .room-dot {
  background: var(--bad);
}

.room-bar[data-status="reconnecting"] .room-status-text,
.room-bar[data-status="offline"] .room-status-text {
  color: var(--fg);
  font-weight: 600;
}

@media (prefers-reduced-motion: no-preference) {
  .room-bar[data-status="connecting"] .room-dot,
  .room-bar[data-status="reconnecting"] .room-dot {
    animation: room-blink 1s ease-in-out infinite alternate;
  }
}

@keyframes room-blink {
  to {
    opacity: 0.25;
  }
}

.room-confirm,
.room-notice {
  margin: 0 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
}

.room-confirm p {
  margin: 0 0 var(--space-3);
  font-weight: 600;
}

.room-notice {
  font-weight: 600;
}

.room-connecting,
.room-end,
.room-starting {
  max-width: 32rem;
  margin-inline: auto;
  text-align: center;
}

.room-end .cluster {
  justify-content: center;
}

/* lobby */

.room-lobby {
  display: grid;
  gap: var(--space-4);
}

/* In one column the host sees the invite first (to share it), the others see who is there and the wait. */
.room-lobby:not(.is-host) .room-people {
  order: -1;
}

@media (min-width: 48rem) {
  .room-lobby:not(.is-host) .room-people {
    order: 0;
  }

  .room-lobby {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }
}

.room-invite {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  text-align: center;
}

.room-invite > * {
  margin: 0;
}

.room-code-label {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.room-big-code {
  /* the letter spacing also follows the last letter; pull it back so the code stays centred */
  margin-right: -0.18em;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: clamp(2.75rem, 2rem + 4vw, 3.75rem);
  font-weight: 800;
  letter-spacing: 0.18em;
  line-height: 1.1;
}

.room-qr {
  width: min(13rem, 62vw);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: 0 0 0 1px var(--border);
}

.qr {
  display: block;
  width: 100%;
  height: auto;
}

.room-invite-hint {
  max-width: 24rem;
  font-size: 0.9375rem;
}

.room-link {
  display: grid;
  gap: var(--space-1);
  width: 100%;
  text-align: left;
}

.room-link-row {
  display: flex;
  gap: var(--space-2);
}

.room-link-input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1rem;
}

.room-copy {
  flex: none;
  padding-inline: var(--space-4);
}

.room-copy-status:empty {
  display: none;
}

.room-copy-status {
  color: var(--ok);
  font-size: 0.9375rem;
  font-weight: 600;
}

.room-people {
  padding: var(--space-4);
}

.room-players {
  display: grid;
  gap: var(--space-1);
  margin: 0 0 var(--space-4);
  padding: 0;
  list-style: none;
}

.room-player {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.room-player[data-connected="false"] .room-nick {
  color: var(--muted);
}

.room-offline {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.875rem;
}

.room-name {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  min-width: 0;
}

.room-nick {
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.room-badge {
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--fg);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
  text-transform: uppercase;
}

.room-badge-you {
  background: var(--ok-soft);
}

.room-start-row {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.room-start-row p {
  margin: 0;
}

.room-waiting {
  font-weight: 600;
}

.room-settings-title {
  font-size: 1rem;
}

.room-settings {
  display: grid;
  gap: var(--space-2);
  margin: 0;
}

.room-settings div {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: var(--space-3);
}

.room-settings dt {
  color: var(--muted);
}

.room-settings dd {
  margin: 0;
  font-weight: 600;
}

/* starting */

.room-starting-title {
  margin-bottom: var(--space-2);
}

.room-starting-text {
  margin: 0;
  color: var(--muted);
}

.room-countdown {
  margin: 0;
  color: var(--accent);
  font-size: clamp(5rem, 4rem + 6vw, 7rem);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1.1;
}

@media (prefers-reduced-motion: no-preference) {
  .room-countdown.is-tick {
    animation: room-pop 0.45s ease-out;
  }
}

@keyframes room-pop {
  from {
    opacity: 0.2;
    transform: scale(1.35);
  }
}

/* a question */

.room-play {
  max-width: 42rem;
  margin-inline: auto;
}

.room-timer {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: var(--space-3);
}

.room-timer-bar {
  flex: 1 1 auto;
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.room-timer-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transition: transform 0.2s linear;
}

.room-timer-text {
  min-width: 3ch;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

.room-timer.is-low .room-timer-fill {
  background: var(--bad);
}

.room-timer.is-low .room-timer-text {
  color: var(--bad);
}

.room-note {
  margin: var(--space-4) 0 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  font-weight: 600;
  text-align: center;
}

/* the reveal */

.room-result {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.room-result.is-correct {
  border-color: var(--ok);
}

.room-result.is-wrong {
  border-color: var(--bad);
}

.room-result.is-correct .quiz-verdict .icon {
  color: var(--ok);
}

.room-result.is-wrong .quiz-verdict .icon,
.room-result.is-none .quiz-verdict .icon {
  color: var(--bad);
}

.room-result p {
  margin: 0;
}

.room-board-title {
  margin: var(--space-2) 0;
  font-size: 1rem;
}

.room-board,
.room-ranking {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.room-row {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}

.room-row:nth-child(odd) {
  background: var(--surface-2);
}

.room-row.is-you {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.room-row-rank {
  color: var(--muted);
  font-weight: 700;
}

.room-row-score {
  font-weight: 700;
  text-align: right;
}

.room-row-gain {
  min-width: 3.5rem;
  color: var(--ok);
  font-weight: 700;
  text-align: right;
}

.room-row-correct {
  min-width: 5rem;
  color: var(--muted);
  font-size: 0.875rem;
  text-align: right;
}

.room-place {
  margin-top: var(--space-2);
  font-weight: 700;
}

.room-next {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* final */

.room-final {
  max-width: 42rem;
  margin-inline: auto;
}

.room-final-card {
  padding: var(--space-5) var(--space-3) var(--space-4);
  text-align: center;
}

.room-final-card .room-place {
  margin: var(--space-4) 0 0;
}

.room-podium {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.room-podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}

/* the winner in the middle, second on the left, third on the right */
.room-podium-place[data-position="1"] {
  grid-row: 1;
  grid-column: 2;
}

.room-podium-place[data-position="2"] {
  grid-row: 1;
  grid-column: 1;
}

.room-podium-place[data-position="3"] {
  grid-row: 1;
  grid-column: 3;
}

.room-podium-place .room-name {
  justify-content: center;
}

.room-podium-score {
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.room-podium-step {
  display: grid;
  place-items: start center;
  width: 100%;
  height: 3.5rem;
  padding-top: var(--space-2);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.5rem;
  font-weight: 800;
}

.room-podium-place[data-rank="1"] .room-podium-step {
  height: 6rem;
  background: var(--accent);
  color: var(--accent-fg);
}

.room-podium-place[data-rank="2"] .room-podium-step {
  height: 4.5rem;
}

.room-podium-place.is-you .room-nick {
  color: var(--accent);
}

.room-final-actions {
  justify-content: center;
  margin: var(--space-4) 0 var(--space-2);
}

.room-final-wait {
  text-align: center;
}

.room-ranking-title {
  margin-top: var(--space-5);
  font-size: 1.125rem;
}
