:root {
  --bg: #fbf6ee;
  --ink: #1c1410;
  --muted: #3f342c;
  --card: #fffdf8;
  --line: #e4d7c6;
  --red: #8e1b1b;
  --red-dark: #6d1212;
  --link: #1e3a8a;
  --focus: #1d4ed8;
  --ok-bg: #e7f6ec;
  --ok-ink: #14532d;
  --bad-bg: #fdecec;
  --bad-ink: #7f1d1d;
  --gold-bg: #f6e7c1;
  --gold-ink: #4a3200;
  --footer: #1c1410;
  --footer-ink: #fbf6ee;
  --footer-link: #f8e7b0;
}

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

[hidden] { display: none !important; }

html { font-size: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
}

h1, h2, h3, .brand span, .prompt, .flash-face, .score {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  line-height: 1.2;
}

h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 0.6rem; }
h2 { font-size: 1.45rem; margin: 0 0 0.5rem; }
h3 { font-size: 1.2rem; margin: 0 0 0.4rem; }
p { margin: 0.4rem 0 0.8rem; }

a { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }

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

.skip {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  transform: translateY(-200%);
  background: #fff;
  color: var(--ink);
  padding: 0.55rem 0.8rem;
  z-index: 5;
  border-radius: 8px;
}

.skip:focus { transform: none; }

.stripe {
  height: 10px;
  background: repeating-linear-gradient(
    90deg,
    #8e1b1b 0 14px,
    #fbf6ee 14px 22px,
    #1e3a5f 22px 36px,
    #fbf6ee 36px 44px
  );
}

.wrap {
  width: min(72rem, calc(100% - 2rem));
  margin-inline: auto;
}

main.wrap { padding-top: 1.25rem; padding-bottom: 1rem; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.25rem;
  padding: 0.75rem 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
}

.brand span { font-size: 1.35rem; }
.mark { width: 2.5rem; height: 2.5rem; flex: none; }

.nav { display: flex; flex-wrap: wrap; gap: 0.25rem 0.35rem; }
.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.2rem 0.45rem;
  color: var(--ink);
  text-decoration: none;
}
.nav a:hover, .nav a:focus, .nav a[aria-current="page"] {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}
.nav a[aria-current="page"] { font-weight: 700; }

.site-footer {
  background: var(--footer);
  color: var(--footer-ink);
}
.footer-inner { padding: 1.2rem 0 1.6rem; }
.site-footer p { margin-top: 0; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; }
.site-footer a {
  color: var(--footer-link);
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.45rem;
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.crumbs li { display: flex; align-items: center; gap: 0.45rem; }
.crumbs a { min-height: 44px; display: inline-flex; align-items: center; }

.lede, .prose { max-width: 65ch; }

.hero, .tile, #study-app > section, #map-app > section, #movie-app > section, .element-detail, .steps li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.hero {
  border-top: 8px solid var(--red);
  padding: 1.25rem 1.1rem 1.3rem;
  margin-bottom: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.82rem;
  color: var(--red);
}

.hero-actions, .tiles, .steps, .legend, .best-list, .set-list, .misses {
  list-style: none;
  padding: 0;
  margin: 0.6rem 0 0;
}

.hero-actions { display: grid; gap: 0.75rem; }
.hero-actions a {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 44px;
  background: var(--red);
  color: #fff;
  text-decoration: none;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  border: 2px solid var(--red-dark);
}
.hero-actions strong { font-size: 1.15rem; text-decoration: underline; text-underline-offset: 0.15em; }
.hero-actions .sub { color: #fff; font-weight: 400; margin-top: 0.15rem; }

.section-gap { margin: 1.6rem 0; }

.tiles { display: grid; gap: 0.9rem; }
.tile { padding: 1rem 1.05rem 1.1rem; height: 100%; }
.tile h2, .tile h3 { margin-top: 0; }
.tile a { color: inherit; }
.tile-soon { background: #fbf6ee; }
.set-list { margin-top: 0.6rem; }
.set-list li { margin: 0.35rem 0; }

.badge {
  display: inline-block;
  background: var(--gold-bg);
  color: var(--gold-ink);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin: 0 0 0.45rem;
}

.steps { display: grid; gap: 0.75rem; }
.steps li { padding: 0.95rem 1rem; }
.steps h3 { margin-top: 0; }

.notice, .good-note, .feedback {
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
}
.notice {
  background: #fff8e8;
  border: 1px solid var(--line);
  border-left: 6px solid var(--red);
}
.good-note { background: var(--ok-bg); color: var(--ok-ink); }
.reveal-answer { margin: 0.35rem 0 0; font-weight: 700; }
.question-explainer {
  margin: 0.5rem 0 0;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ink-muted, #4a5568);
}
.feedback:empty { padding: 0; }
.feedback:not(:empty) {
  background: var(--card);
  border: 1px solid var(--line);
  margin-top: 0.8rem;
}
.spell-lead { font-weight: 700; margin: 0 0 0.45rem; }
.spell-line, .spell-legend, .spell-feedback p { margin: 0.35rem 0; }
.spell-line {
  font-size: 1.125rem;
  overflow-wrap: anywhere;
}
.spell-legend { font-size: 1rem; }
.diff {
  font-weight: 700;
  padding: 0 0.12em;
  border-radius: 0.2em;
  color: var(--bad-ink);
}
.diff-tag { font-weight: 700; }
.diff-missing, .diff-needed {
  background: #fff;
  border: 2px solid var(--bad-ink);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.12em;
}
.diff-extra {
  background: var(--bad-bg);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.diff-wrong {
  background: var(--bad-bg);
  text-decoration: underline wavy;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.15em;
}

.hint, .quiz-meta { color: var(--muted); }
.hint { font-size: 0.98rem; }

#study-app > section, #map-app > section, #movie-app > section { padding: 1rem 1rem 1.15rem; margin: 1rem 0; }

.movie-quiz-menu { display: flex; flex-direction: column; gap: 0.45rem; }
.movie-quiz-top {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin: 0;
}
.matrix-boring-slot .matrix-theme-toggle {
  margin: 0;
  font-size: 0.82rem;
}
.movie-start {
  width: 100%;
  min-height: 56px;
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}
.movie-best { margin: 0.15rem 0 0; }
.movie-best[hidden],
.movie-retry[hidden] { display: none !important; }
.movie-retry { width: 100%; margin: 0; }
.movie-settings-trigger {
  min-height: 40px;
  padding: 0.3rem 0.6rem;
  font-size: 0.88rem;
}
.movie-settings-trigger::before {
  content: "⚙ ";
  speak-as: none;
}
.movie-settings-panel {
  margin: 0;
  padding: 0;
}
.movie-settings-panel:not([hidden]) {
  margin-bottom: 0.15rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}
.movie-settings-panel fieldset:last-of-type { margin-bottom: 0.5rem; }
.movie-settings-progress { margin-top: 0.75rem; padding-top: 0.65rem; border-top: 1px dashed var(--line); }
.movie-sources-details {
  font-size: 0.88rem;
  max-width: 65ch;
}
.movie-sources-details summary {
  cursor: pointer;
  font-weight: 700;
  min-height: 44px;
  display: flex;
  align-items: center;
  list-style: none;
}
.movie-sources-details summary::-webkit-details-marker { display: none; }
.movie-sources-details[open] summary { margin-bottom: 0.35rem; }
.movie-sources-details .set-list {
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0 0 0.9rem;
  padding: 0.35rem 0.85rem 0.7rem;
}
legend { font-weight: 700; padding: 0 0.3rem; }

.radio {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  font-weight: 450;
}
.radio input { width: 1.2rem; height: 1.2rem; accent-color: var(--red); }

.field label, .typed label { display: block; font-weight: 700; margin-bottom: 0.35rem; }

input[type="text"], select {
  width: min(100%, 32rem);
  min-height: 44px;
  padding: 0.5rem 0.7rem;
  border: 2px solid #8a7764;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: max(16px, 1.0625rem);
  line-height: 1.4;
}

.typed {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.6rem;
  align-items: stretch;
}
.typed label,
.typed .hint { margin: 0; }
.typed input[type="text"] {
  display: block;
  width: 100%;
  max-width: none;
  min-width: 0;
  min-height: 48px;
}
#typed-answer:focus {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-color: var(--focus);
}
.typed .btn { width: 100%; }

button, .btn {
  font: inherit;
  cursor: pointer;
  min-height: 44px;
  padding: 0.45rem 0.9rem;
  border-radius: 10px;
  border: 2px solid #8a7764;
  background: #fff;
  color: var(--ink);
}
a.btn {
  display: inline-flex;
  align-items: center;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.btn-primary, .btn-danger {
  background: var(--red);
  border-color: var(--red-dark);
  color: #fff;
}
.btn-quiet { background: transparent; }
button:disabled { cursor: default; }

.row-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.85rem; }

.choices { display: grid; gap: 0.6rem; }
.choice {
  width: 100%;
  text-align: left;
  background: var(--card);
}
.choice.is-correct, input.is-correct {
  background: var(--ok-bg);
  color: var(--ok-ink);
  border-color: #166534;
}
.choice.is-wrong, input.is-wrong {
  background: var(--bad-bg);
  color: var(--bad-ink);
  border-color: #991b1b;
}

.quiz-head { display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem; font-size: 1rem; }
.prompt, .flash-face {
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  font-weight: 700;
  overflow-wrap: anywhere;
  margin: 0.2rem 0;
}
.flash-back {
  font-size: 1.25rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
}
.score { font-size: clamp(2rem, 6vw, 3rem); margin: 0.2rem 0 0.4rem; }

.best-list li, .misses li { padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.misses p { margin: 0.12rem 0; }
.misses .question-explainer { margin-top: 0.35rem; }
.confirm p { margin-top: 0.4rem; }

.key-wrap { margin-top: 1.4rem; }
summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 700;
}
.key { margin-top: 0.4rem; }
.table-scroll { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; margin-top: 0.6rem; }
caption { text-align: left; font-weight: 700; margin-bottom: 0.35rem; }
th, td { text-align: left; padding: 0.45rem 0.55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 700; }

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; }
.legend li { display: flex; align-items: center; gap: 0.4rem; min-height: 2rem; }
.swatch { width: 1rem; height: 1rem; border-radius: 3px; flex: none; }

.element-detail { padding: 0.9rem 1rem; margin: 0.8rem 0; }
.element-detail h3, .element-detail p { margin-top: 0; }

.ptable {
  display: grid;
  grid-template-columns: repeat(18, 2.75rem);
  grid-template-rows: repeat(7, 2.75rem) 0.7rem repeat(2, 2.75rem);
  gap: 3px;
  width: max-content;
}
.el, .el-gap {
  border-radius: 4px;
  color: var(--ink);
  padding: 0;
}
.el {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 0;
  min-height: 0;
  line-height: 1.05;
  background: #fff;
}
.el .z { font-size: 0.65rem; }
.el .sym { font-size: 0.92rem; font-weight: 700; }
.el:hover, .el.is-selected { outline: 2px solid #1c1410; outline-offset: -2px; }
.el-gap {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #efe8dc;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.el-nonmetal, .swatch.el-nonmetal { background: #f8f1d8; box-shadow: inset 0 3px 0 #a16207; }
.el-halogen, .swatch.el-halogen { background: #f8e8f4; box-shadow: inset 0 3px 0 #9d174d; }
.el-noble-gas, .swatch.el-noble-gas { background: #ece9fb; box-shadow: inset 0 3px 0 #5b21b6; }
.el-alkali-metal, .swatch.el-alkali-metal { background: #fde8e4; box-shadow: inset 0 3px 0 #9f1239; }
.el-alkaline-earth, .swatch.el-alkaline-earth { background: #fde7d6; box-shadow: inset 0 3px 0 #9a3412; }
.el-metalloid, .swatch.el-metalloid { background: #f3ead4; box-shadow: inset 0 3px 0 #854d0e; }
.el-post-transition-metal, .swatch.el-post-transition-metal { background: #e7f2ea; box-shadow: inset 0 3px 0 #166534; }
.el-transition-metal, .swatch.el-transition-metal { background: #e7eef8; box-shadow: inset 0 3px 0 #1e3a8a; }
.el-lanthanoid, .swatch.el-lanthanoid { background: #e5f6f4; box-shadow: inset 0 3px 0 #0f766e; }
.el-actinoid, .swatch.el-actinoid { background: #f8eee4; box-shadow: inset 0 3px 0 #9a3412; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 40rem) {
  .hero { padding: 1.6rem 1.5rem 1.7rem; }
  .hero-actions, .tiles { grid-template-columns: 1fr 1fr; }
  .typed {
    grid-template-columns: minmax(0, 36rem) auto;
    align-items: center;
  }
  .typed label,
  .typed .hint { grid-column: 1 / -1; }
  .typed .btn { width: auto; }
}

@media (min-width: 52rem) {
  .steps { grid-template-columns: repeat(3, 1fr); }
}

@media (forced-colors: active) {
  .btn, .choice, .tile, .el, .hero-actions a, a, .diff { border: 1px solid ButtonText; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.2rem 0 1.1rem;
}
.subnav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
}
.subnav a[aria-current="page"] {
  background: var(--red);
  border-color: var(--red-dark);
  color: #fff;
  font-weight: 700;
}

.map-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  margin: 0.4rem 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #d3e4f2;
}
.map-stage { position: relative; }
.quiz-map {
  display: block;
  width: 100%;
  height: auto;
}
.quiz-map .ocean,
.quiz-map .land-bg,
.quiz-map .leaders,
.quiz-map .leaders line,
.quiz-map .markers,
.quiz-map .markers circle,
.quiz-map .country {
  pointer-events: none;
}
.quiz-map .country {
  vector-effect: non-scaling-stroke;
  scroll-margin: 16px;
}
.quiz-map .country.is-live { pointer-events: auto; cursor: pointer; }
.quiz-map .country.is-live:hover,
.quiz-map .country.is-live:focus {
  fill: #fff8ee;
  stroke: #1c1410;
  stroke-width: 2px;
}
.quiz-map .country.is-target {
  fill: #f6e7c1;
  stroke: #8e1b1b;
  stroke-width: 2.5px;
  stroke-dasharray: 6 4;
}
.quiz-map .country.is-correct {
  fill: #b7e4c7;
  stroke: #14532d;
  stroke-width: 2px;
  stroke-dasharray: none;
}
.quiz-map .country.is-wrong {
  fill: #f5b5b5;
  stroke: #7f1d1d;
  stroke-width: 2px;
}

.map-pins {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.map-pin {
  position: absolute;
  z-index: 2;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  scroll-margin: 12px;
}
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid #fffdf8;
  box-shadow: 0 0 0 1px #6a5346;
}
.map-pin.is-target {
  border-color: #8e1b1b;
  background: rgba(246, 231, 193, 0.72);
}
.map-pin.is-correct {
  border-color: #14532d;
  background: rgba(183, 228, 199, 0.8);
}
.map-pin.is-wrong {
  border-color: #7f1d1d;
  background: rgba(245, 181, 181, 0.85);
}
.map-pin:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.country-index {
  columns: 2;
  list-style: none;
  padding: 0.4rem 0 0;
  margin: 0;
}
.country-index li { break-inside: avoid; padding: 0.2rem 0.6rem 0.2rem 0; }

@media (min-width: 52rem) {
  .country-index { columns: 3; }
}

@media (forced-colors: active) {
  .subnav a, .map-pin, .quiz-map .country { border: 1px solid ButtonText; }
  .quiz-map .country { fill: Canvas; stroke: CanvasText; }
  .quiz-map .country.is-target { stroke: Highlight; }
  .pin-dot { background: ButtonText; }
  .subnav a[aria-current="page"] { background: Highlight; color: HighlightText; }
}
