/*
 * World History Quiz — web styles.
 * Colours, radii and type follow the Flutter app (lib/constants.dart,
 * lib/widgets/common_widgets.dart). The app has a single dark theme, so the
 * page is always dark, whatever the system colour scheme.
 */

:root {
  color-scheme: dark;

  /* App palette */
  --dark-brown: #3d2b1f;
  --deep-brown: #2a1c13;
  --surface: #4a3628;
  --surface-high: #5a4332;
  --cream: #f5ecd7;
  --gold: #c8a96e;
  --gold-light: #f2d896;
  --correct: #4caf50;
  --incorrect: #f44336;
  --correct-fill: #3f7d3a;
  --incorrect-fill: #b63a2e;
  --ring-fail: #d0654b;
  /* Web: a lighter red so "Reset Progress" text clears 4.5:1 on a card. */
  --danger-text: #ff8a80;

  /* Cream at the app's alpha steps */
  --cream-90: rgba(245, 236, 215, 0.92);
  --cream-80: rgba(245, 236, 215, 0.8);
  --cream-70: rgba(245, 236, 215, 0.7);
  --cream-60: rgba(245, 236, 215, 0.62);
  --cream-45: rgba(245, 236, 215, 0.45);
  --cream-12: rgba(245, 236, 215, 0.12);
  --cream-10: rgba(245, 236, 215, 0.1);
  --cream-08: rgba(245, 236, 215, 0.08);
  --cream-07: rgba(245, 236, 215, 0.07);

  --card-radius: 16px;
  --button-radius: 14px;
  --dialog-radius: 20px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.18);

  --font-body: 'Roboto', 'Noto Sans KR', system-ui, -apple-system, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-display: 'Noto Serif', 'Noto Sans KR', Georgia, 'Times New Roman', serif;

  --gutter: 16px;
  --focus: 0 0 0 3px var(--deep-brown), 0 0 0 5px var(--gold-light);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::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-color: var(--dark-brown);
  background-image: linear-gradient(180deg, var(--dark-brown) 0%, var(--deep-brown) 100%);
  background-attachment: fixed;
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Korean breaks between words, not syllables (the app's keepWordsTogether). */
:lang(ko) {
  word-break: keep-all;
  overflow-wrap: break-word;
}

h1,
h2,
h3,
p,
ul,
ol {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

svg.icon {
  display: inline-block;
  flex: none;
  fill: currentColor;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* Headings get programmatic focus for screen readers; no ring for them. */
[tabindex='-1']:focus {
  outline: none;
  box-shadow: none;
}

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--deep-brown);
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

/* -------------------------------------------------------------------------
   Page frame
   ------------------------------------------------------------------------- */

.view {
  display: block;
  outline: none;
}

.page {
  width: 100%;
  max-width: calc(520px + 2 * var(--gutter));
  margin: 0 auto;
  padding: 12px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

.page.enter {
  animation: fade-up 260ms var(--ease-out) both;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}

.spacer {
  flex: 1;
}

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--cream-08);
  background: var(--surface);
  color: var(--cream);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 150ms;
}

.icon-btn:hover {
  background: var(--surface-high);
}

.badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--incorrect);
  border: 2px solid var(--surface);
}

.display {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--cream);
}

.screen-title {
  padding: 4px 8px 18px;
  text-align: center;
}

.screen-title h1 {
  font-size: 26px;
  line-height: 1.25;
}

.screen-subtitle {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: rgba(200, 169, 110, 0.9);
}

.section-label {
  padding: 0 4px 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--cream-60);
}

.card {
  display: block;
  border-radius: var(--card-radius);
  border: 1px solid var(--cream-07);
  background: var(--surface);
  box-shadow: var(--shadow);
}

a.card {
  text-decoration: none;
  color: inherit;
  transition: background-color 150ms, transform 150ms var(--ease-out);
}

a.card:hover {
  background: var(--surface-high);
}

a.card:active {
  transform: scale(0.99);
}

.icon-badge {
  --size: 44px;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--size);
  height: var(--size);
  border-radius: calc(var(--size) * 0.3);
  color: var(--cream);
  background-color: var(--accent);
  background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.18));
}

/* Progress bar (AnimatedProgressBar) */
.bar {
  --h: 6px;
  position: relative;
  height: var(--h);
  border-radius: 999px;
  background: var(--cream-12);
  overflow: hidden;
}

.bar.bar-strong {
  background: rgba(245, 236, 215, 0.15);
}

.bar-fill {
  --v: 0%;
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--v);
  border-radius: inherit;
  background: var(--gold);
  transition: width 400ms cubic-bezier(0.33, 1, 0.68, 1);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(200, 169, 110, 0.14);
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 700;
}

.pill .icon {
  color: var(--gold);
}

/* Buttons (PrimaryButton / SecondaryButton) */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 52px;
  padding: 14px 18px;
  border-radius: var(--button-radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  transition: background-color 150ms, transform 120ms;
}

.btn:active {
  transform: scale(0.985);
}

.btn-primary {
  background: var(--gold);
  color: var(--deep-brown);
}

.btn-primary:hover {
  background: #d4b67c;
}

.btn-secondary {
  background: var(--surface);
  color: var(--cream);
  border-color: var(--cream-10);
  font-size: 16px;
  font-weight: 700;
}

.btn-secondary:hover {
  background: var(--surface-high);
}

/* Language toggle */
.lang-toggle {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--cream-08);
}

.lang-chip {
  min-height: 36px;
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--cream-80);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 200ms, color 200ms;
}

.lang-chip[aria-pressed='true'] {
  background: var(--gold);
  color: var(--deep-brown);
}

.lang-chip[aria-pressed='false']:hover {
  color: var(--cream);
}

/* -------------------------------------------------------------------------
   Menu cards (ProgressMenuButton)
   ------------------------------------------------------------------------- */

.menu-list {
  display: grid;
  gap: 10px;
}

.menu-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 12px 14px 14px;
}

.menu-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.menu-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.menu-label {
  flex: 1;
  min-width: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

.menu-count {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 700;
  color: var(--cream-70);
  font-variant-numeric: tabular-nums;
}

.menu-count.is-complete {
  color: var(--gold);
}

.menu-sub {
  margin-top: 2px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--cream-70);
}

.menu-body .bar {
  margin-top: 10px;
}

.chevron {
  color: var(--cream-45);
}

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

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    'hero'
    'eras'
    'lang'
    'footer';
}

.home-hero {
  grid-area: hero;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.emblem {
  display: block;
  width: 112px;
  height: 112px;
}

.home-title {
  margin-top: 6px;
  font-size: 30px;
  line-height: 1.2;
}

.overall {
  align-self: stretch;
  margin-top: 18px;
  padding: 12px 16px 14px;
  border-radius: var(--card-radius);
  background: rgba(200, 169, 110, 0.1);
  border: 1px solid rgba(200, 169, 110, 0.3);
  text-align: left;
}

.overall-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 14px;
}

.overall-row .gold {
  color: var(--gold);
}

.overall-label {
  flex: 1;
  font-weight: 600;
}

.overall-count {
  font-weight: 600;
  color: var(--cream-60);
  font-variant-numeric: tabular-nums;
}

.overall-count strong {
  color: var(--gold-light);
  font-weight: 800;
}

.home-eras {
  grid-area: eras;
  margin-top: 22px;
}

.home-lang {
  grid-area: lang;
  display: flex;
  justify-content: center;
  padding: 18px 0 6px;
}

.home-footer {
  grid-area: footer;
}

.site-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 18px;
}

.play-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 7px 18px 7px 14px;
  border-radius: 12px;
  border: 1px solid rgba(200, 169, 110, 0.45);
  background: rgba(0, 0, 0, 0.22);
  color: var(--cream);
  text-decoration: none;
  transition: background-color 150ms, border-color 150ms;
}

.play-link:hover {
  background: rgba(0, 0, 0, 0.35);
  border-color: var(--gold);
}

.play-link .icon {
  color: var(--gold);
}

.play-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  text-align: left;
}

.play-small {
  font-size: 11.5px;
  color: var(--cream-70);
}

.play-big {
  font-size: 15px;
  font-weight: 700;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 10px;
  font-size: 13px;
  color: var(--cream-60);
}

.footer-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 4px;
  border-radius: 6px;
  color: var(--cream-70);
  text-decoration: underline;
  text-decoration-color: rgba(245, 236, 215, 0.3);
  text-underline-offset: 3px;
}

.footer-link:hover {
  color: var(--cream);
  text-decoration-color: currentColor;
}

/* -------------------------------------------------------------------------
   Category and stage screens
   ------------------------------------------------------------------------- */

.era-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 4px;
}

.era-head .icon-badge {
  margin-bottom: 14px;
}

.menu-list--categories {
  gap: 12px;
}

.stage-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 14px 14px;
}

.stage-summary-body {
  flex: 1;
  min-width: 0;
}

.stage-summary-text {
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.stage-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border-radius: var(--button-radius);
  border: 1px solid transparent;
  text-decoration: none;
  font: inherit;
  transition: transform 120ms, background-color 150ms;
}

.stage-num {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
}

a.stage-tile {
  cursor: pointer;
}

a.stage-tile:active {
  transform: scale(0.96);
}

.stage-tile.is-cleared {
  background: rgba(200, 169, 110, 0.18);
  border-color: rgba(200, 169, 110, 0.45);
  color: var(--gold-light);
}

.stage-tile.is-cleared .icon {
  color: var(--gold);
}

.stage-tile.is-cleared:hover {
  background: rgba(200, 169, 110, 0.26);
}

.stage-tile.is-current {
  background: var(--gold);
  border: 2px solid var(--gold-light);
  color: var(--deep-brown);
}

.stage-tile.is-current:hover {
  background: #d4b67c;
}

.stage-tile.is-locked {
  background: rgba(74, 54, 40, 0.55);
  border-color: rgba(245, 236, 215, 0.06);
  color: var(--cream-45);
  cursor: not-allowed;
}

.difficulty-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 0 4px;
  font-size: 13px;
  color: var(--cream-60);
  text-align: center;
}

/* -------------------------------------------------------------------------
   Quiz
   ------------------------------------------------------------------------- */

.hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(200, 169, 110, 0.5);
  background: rgba(200, 169, 110, 0.16);
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 150ms;
}

.hint-btn:hover {
  background: rgba(200, 169, 110, 0.26);
}

.hint-btn[hidden] {
  display: none;
}

.quiz-head {
  padding-top: 6px;
}

.quiz-meta-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.quiz-meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--cream-70);
}

.page--quiz > .quiz-meta {
  padding-top: 6px;
}

.quiz-count {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-pill {
  margin-top: 10px;
}

.question-card {
  margin-top: 12px;
  padding: 22px 18px;
  text-align: center;
}

.question-text {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.45;
}

.hint-pill {
  margin-top: 12px;
}

.answers {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.answer {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 14px 16px 14px 12px;
  border-radius: var(--button-radius);
  border: 1.5px solid var(--cream-08);
  background: var(--surface);
  color: var(--cream);
  text-align: left;
  cursor: pointer;
  transition:
    background-color 280ms var(--ease-out),
    border-color 280ms var(--ease-out),
    color 280ms var(--ease-out);
}

.answer:hover:not([aria-disabled='true']) {
  background: var(--surface-high);
}

.answer[aria-disabled='true'] {
  cursor: default;
}

.answer-badge {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--cream-10);
  color: var(--gold-light);
  font-size: 14px;
  font-weight: 800;
  transition: background-color 280ms, color 280ms;
}

.answer-badge > * {
  grid-area: 1 / 1;
}

.answer-badge .mark-correct,
.answer-badge .mark-incorrect {
  display: none;
}

.answer-label {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.answer.is-correct {
  background: var(--correct-fill);
  border-color: rgba(76, 175, 80, 0.7);
  color: #fff;
}

.answer.is-incorrect {
  background: var(--incorrect-fill);
  border-color: rgba(244, 67, 54, 0.7);
  color: #fff;
}

.answer.is-correct .answer-badge,
.answer.is-incorrect .answer-badge {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.answer.is-correct .answer-letter,
.answer.is-incorrect .answer-letter {
  display: none;
}

.answer.is-correct .mark-correct,
.answer.is-incorrect .mark-incorrect {
  display: block;
}

.answer.is-dimmed {
  background: rgba(74, 54, 40, 0.5);
  color: var(--cream-60);
}

.answer.is-dimmed .answer-badge {
  color: var(--cream-45);
}

.answer.shake {
  animation: shake 420ms ease-out;
}

@keyframes shake {
  0% {
    transform: translateX(0);
  }
  12.5% {
    transform: translateX(-8px);
  }
  37.5% {
    transform: translateX(8px);
  }
  62.5% {
    transform: translateX(-6px);
  }
  87.5% {
    transform: translateX(6px);
  }
  100% {
    transform: translateX(0);
  }
}

.after-answer:empty {
  display: none;
}

.explanation {
  margin-top: 20px;
  padding: 14px 16px 16px;
  border-radius: var(--card-radius);
  background: rgba(200, 169, 110, 0.08);
  border: 1px solid rgba(200, 169, 110, 0.35);
  animation: fade-in 280ms var(--ease-out);
}

.explanation-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 800;
  color: var(--gold-light);
}

.explanation-title .icon {
  color: var(--gold);
}

.explanation-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--cream-90);
}

.continue-btn {
  margin-top: 16px;
  scroll-margin-bottom: 24px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.kbd-hint {
  display: none;
}

.quiz-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 40px;
  padding: 24px;
  text-align: center;
  color: var(--cream-80);
}

.quiz-status .btn {
  max-width: 240px;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 4px solid var(--cream-12);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* -------------------------------------------------------------------------
   Result
   ------------------------------------------------------------------------- */

.page--result {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
}

.result {
  width: 100%;
  max-width: 440px;
  padding: 16px 0;
  text-align: center;
}

.result-meta {
  font-size: 13px;
  font-weight: 600;
  color: var(--cream-70);
}

.ring-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 260px;
  height: 190px;
  margin: 12px auto 0;
}

.ring-wrap > * {
  grid-area: 1 / 1;
}

.ring circle {
  fill: none;
  stroke-width: 10;
}

.ring-track {
  stroke: var(--cream-10);
}

.ring-fill {
  stroke: var(--ring-fail);
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 700ms cubic-bezier(0.33, 1, 0.68, 1);
}

.ring-wrap.is-cleared .ring-fill {
  stroke: var(--gold);
}

.ring-score {
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  animation: score-pop 700ms both;
}

.ring-big {
  font-size: 54px;
}

.ring-small {
  font-size: 22px;
  color: var(--cream-60);
}

@keyframes score-pop {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  30% {
    opacity: 1;
    transform: scale(1.08);
  }
  50% {
    transform: scale(0.97);
  }
  72% {
    transform: scale(1.02);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.sparkles {
  position: relative;
  width: 0;
  height: 0;
}

.sparkle {
  position: absolute;
  left: calc(var(--s) / -2);
  top: calc(var(--s) / -2);
  width: var(--s);
  height: var(--s);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0;
  animation: sparkle 1200ms linear both;
}

.sparkle.gold {
  background: var(--gold);
}

.sparkle.cream {
  background: var(--cream);
}

@keyframes sparkle {
  from {
    opacity: 0.9;
    transform: var(--from);
  }
  to {
    opacity: 0;
    transform: var(--to);
  }
}

.stars {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.stars .star-on {
  color: var(--gold);
}

.stars .star-off {
  color: rgba(245, 236, 215, 0.3);
}

.result-title {
  margin-top: 14px;
  font-size: 28px;
  line-height: 1.25;
}

.result-title.is-cleared {
  color: var(--gold-light);
}

.result-message {
  margin-top: 8px;
  font-size: 17px;
  line-height: 1.4;
  color: var(--cream-80);
}

.result-actions {
  display: grid;
  gap: 10px;
  margin-top: 28px;
}

.result-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* -------------------------------------------------------------------------
   Settings
   ------------------------------------------------------------------------- */

.settings-grid {
  display: grid;
  gap: 22px;
}

.settings-col > .section-label:not(:first-child) {
  margin-top: 22px;
}

.progress-card {
  padding: 14px 16px 12px;
}

.progress-era + .progress-era {
  margin-top: 14px;
}

.progress-era-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--gold-light);
}

.progress-era-title .accent {
  color: var(--accent);
  filter: brightness(1.35);
}

.progress-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12.5px;
  color: var(--cream-70);
}

.progress-row-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.settings-lang {
  display: flex;
}

.list-card {
  overflow: hidden;
}

.list-card li + li {
  border-top: 1px solid var(--cream-07);
}

.list-item {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 56px;
  padding: 8px 16px;
  border: 0;
  background: transparent;
  color: var(--cream);
  text-align: left;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms;
}

.list-item:hover {
  background: var(--surface-high);
}

.list-item:focus-visible {
  box-shadow: inset 0 0 0 2px var(--gold-light);
}

.list-item .lead {
  color: var(--gold);
}

.list-item .link-label {
  flex: 1;
}

.list-item .trail {
  color: var(--cream-45);
}

.list-item.is-danger,
.list-item.is-danger .lead {
  color: var(--danger-text);
}

.version {
  margin-top: 24px;
  min-height: 1.4em;
  font-size: 12px;
  text-align: center;
  color: var(--cream-60);
}

/* -------------------------------------------------------------------------
   Notices
   ------------------------------------------------------------------------- */

.notice-list {
  display: grid;
  gap: 10px;
}

.notice-card {
  padding: 16px;
}

.notice-card.is-unread {
  border-color: rgba(200, 169, 110, 0.55);
}

.notice-title {
  display: block;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
}

.notice-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--cream-80);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
}

.empty {
  padding: 48px 16px;
  text-align: center;
  font-size: 16px;
  font-weight: 400;
  color: var(--cream-70);
}

.notice-heading {
  font-size: 20px;
}

.notice-date {
  margin-top: -10px;
  font-size: 13px;
  text-align: center;
  color: var(--cream-70);
}

.notice-body {
  padding: 16px 4px 20px;
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-line;
}

/* -------------------------------------------------------------------------
   Dialogs and toast
   ------------------------------------------------------------------------- */

.dialog {
  width: min(420px, calc(100vw - 48px));
  max-height: 80vh;
  max-height: 80dvh;
  padding: 22px 22px 14px;
  border-radius: var(--dialog-radius);
  border: 1px solid rgba(200, 169, 110, 0.45);
  background: var(--surface);
  color: var(--cream);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}

.dialog[open] {
  display: flex;
  flex-direction: column;
  animation: dialog-in 200ms var(--ease-out);
}

.dialog::backdrop {
  background: rgba(10, 6, 3, 0.62);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.dialog-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
}

.dialog-text {
  margin-top: 14px;
  line-height: 1.5;
  color: rgba(245, 236, 215, 0.85);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.btn-text,
.btn-fill {
  min-height: 40px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 0;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-text {
  background: transparent;
  color: var(--cream-80);
}

.btn-text:hover {
  background: var(--cream-08);
}

.btn-fill {
  background: var(--gold);
  color: var(--deep-brown);
}

.btn-fill:hover {
  background: #d4b67c;
}

.tag {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--dark-brown);
  font-size: 11px;
  font-weight: 700;
}

.notice-pop-title {
  margin-top: 10px;
  font-size: 18px;
  font-weight: 800;
}

.notice-pop-date {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--cream-70);
}

.notice-pop-body {
  min-height: 0;
  margin-top: 12px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-line;
  border-radius: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100vw - 48px);
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--cream);
  color: var(--deep-brown);
  font-weight: 700;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
}

.toast.show {
  animation: toast-in 220ms var(--ease-out);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Boot screen (before app.js runs, and the no-JS message) */
.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 72px 16px;
  text-align: center;
}

.boot h1 {
  font-size: 30px;
}

.boot-note {
  max-width: 420px;
  margin-top: 12px;
  color: var(--cream-80);
}

.boot-note a {
  color: var(--gold-light);
}

/* -------------------------------------------------------------------------
   Wider screens: real layouts instead of a stretched phone column
   ------------------------------------------------------------------------- */

@media (min-width: 600px) {
  :root {
    --gutter: 24px;
  }

  .stage-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
  }

  .page--stages,
  .page--settings,
  .page--notices,
  .page--notice {
    max-width: calc(640px + 2 * var(--gutter));
  }
}

@media (min-width: 960px) {
  .page {
    padding-top: 20px;
  }

  /* Home: brand and progress on the left, eras on the right. */
  .page--home {
    max-width: calc(1040px + 2 * var(--gutter));
  }

  .home-grid {
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      'hero eras'
      'lang eras'
      'footer eras';
    column-gap: 56px;
    align-items: start;
  }

  .home-hero {
    padding-top: 12px;
  }

  .emblem {
    width: 144px;
    height: 144px;
  }

  .home-title {
    font-size: 36px;
  }

  .home-eras {
    margin-top: 0;
  }

  .home-eras .menu-card {
    padding: 18px 16px 18px 18px;
  }

  .home-lang {
    padding-top: 22px;
  }

  .site-footer {
    padding-top: 22px;
  }

  /* Quiz types side by side. */
  .page--category {
    max-width: calc(960px + 2 * var(--gutter));
  }

  .menu-list--categories {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }

  .menu-list--categories .menu-card {
    height: 100%;
    padding: 20px 14px 20px 18px;
  }

  .page--stages {
    max-width: calc(720px + 2 * var(--gutter));
  }

  /* Quiz: question on the left, answers and explanation on the right. */
  .page--quiz {
    max-width: calc(1080px + 2 * var(--gutter));
  }

  .quiz-layout {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    grid-template-areas:
      'head head'
      'question answers';
    column-gap: 28px;
    align-items: start;
  }

  .quiz-head {
    grid-area: head;
  }

  .question-card {
    grid-area: question;
    position: sticky;
    top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    margin-top: 16px;
    padding: 32px 28px;
  }

  .question-text {
    font-size: 24px;
  }

  .quiz-answers {
    grid-area: answers;
    margin-top: 2px;
  }

  .answers {
    margin-top: 14px;
  }

  .kbd-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
    font-size: 12.5px;
    color: var(--cream-60);
  }

  .page--settings {
    max-width: calc(960px + 2 * var(--gutter));
  }

  .settings-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 32px;
    align-items: start;
  }
}

/* The keyboard hint only helps where there is a keyboard. */
@media (hover: none), (pointer: coarse) {
  .kbd-hint {
    display: none !important;
  }
}

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

  .spinner {
    animation-duration: 1.6s !important;
    animation-iteration-count: infinite !important;
  }
}

@media (forced-colors: active) {
  .bar-fill,
  .stage-tile.is-current,
  .lang-chip[aria-pressed='true'] {
    forced-color-adjust: none;
  }

  .answer.is-correct,
  .answer.is-incorrect {
    border-width: 3px;
  }
}
