@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@500;600;700&family=Space+Mono:wght@400;700&display=swap");

:root {
  --paper: #f3efe5;
  --ink: #141414;
  --red: #ff4d38;
  --blue: #2d65f2;
  --green: #188859;
  --line: rgba(20, 20, 20, 0.22);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(20, 20, 20, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 20, 20, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  font-family: "DM Sans", Arial, sans-serif;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.app {
  width: min(100%, 1020px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 28px 30px;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 84px;
  border-bottom: 2px solid var(--ink);
}

.home-link, .wordmark {
  color: inherit;
  text-decoration: none;
  font-family: "Space Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.09em;
}

.home-link { justify-self: start; }
.home-link span { display: inline-block; margin-right: 7px; transition: transform 160ms ease; }
.home-link:hover span { transform: translateX(-4px); }

.wordmark { font-size: 20px; letter-spacing: -0.02em; }
.wordmark span { color: var(--red); }

.help-button, .mode-button, .close-button {
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  font-family: "Space Mono", monospace;
  font-weight: 700;
}

.header-actions { display: flex; gap: 9px; justify-self: end; }
.help-button, .mode-button { width: 38px; height: 38px; }
.mode-button { border-radius: 0; font-size: 20px; line-height: 1; }
.mode-button.is-active { color: var(--paper); background: var(--blue); }
.help-button:hover, .help-button:focus-visible, .mode-button:hover, .mode-button:focus-visible { color: var(--paper); background: var(--ink); }

.game { position: relative; padding-top: 22px; }

.scorebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  margin-bottom: 14px;
  font-family: "Space Mono", monospace;
}

.scorebar p { display: flex; gap: 8px; align-items: baseline; margin: 0; }
.scorebar p:last-child { justify-self: end; }
.scorebar span { color: #6c685f; font-size: 10px; letter-spacing: 0.12em; }
.scorebar strong { font-size: 13px; }
.scorebar .prompt {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-align: center;
}

.flag-stage {
  position: relative;
  display: grid;
  place-items: center;
  height: clamp(245px, 43vh, 430px);
  min-height: 245px;
  overflow: hidden;
  border: 2px solid var(--ink);
  background: rgba(255, 255, 255, 0.46);
}

.flag-stage::before, .flag-stage::after {
  position: absolute;
  content: "";
  background: var(--line);
}

.flag-stage::before { width: 100%; height: 1px; }
.flag-stage::after { width: 1px; height: 100%; }

.flag-stage img {
  position: relative;
  z-index: 2;
  width: min(72%, 360px);
  height: min(72%, 300px);
  object-fit: contain;
  filter: drop-shadow(0 14px 11px rgba(20, 20, 20, 0.12));
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transition: opacity 220ms ease, transform 350ms cubic-bezier(.2,.8,.2,1);
}

.flag-stage img.loaded { opacity: 1; transform: none; }

.flag-stage.pulse img { animation: flag-pulse 380ms ease; }

.corner { position: absolute; z-index: 3; width: 14px; height: 14px; }
.corner-a { top: 10px; left: 10px; border-top: 2px solid var(--ink); border-left: 2px solid var(--ink); }
.corner-b { top: 10px; right: 10px; border-top: 2px solid var(--ink); border-right: 2px solid var(--ink); }
.corner-c { bottom: 10px; left: 10px; border-bottom: 2px solid var(--ink); border-left: 2px solid var(--ink); }
.corner-d { right: 10px; bottom: 10px; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }

.flag-loader {
  position: absolute;
  z-index: 1;
  width: 25px;
  height: 25px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.flag-loader.done { display: none; }

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
}

.answer {
  position: relative;
  display: flex;
  gap: 16px;
  align-items: center;
  min-height: 71px;
  padding: 13px 19px;
  border: 0;
  border-top: 1px solid var(--line);
  color: var(--ink);
  background: rgba(243, 239, 229, 0.88);
  cursor: pointer;
  text-align: left;
  transition: color 130ms ease, background 130ms ease, transform 130ms ease;
}

.answer:nth-child(odd) { border-right: 1px solid var(--ink); }
.answer:nth-child(-n+2) { border-top: 0; }
.answer:hover:not(:disabled), .answer:focus-visible:not(:disabled) { z-index: 2; color: var(--paper); background: var(--ink); outline: none; }
.answer:active:not(:disabled) { transform: scale(0.985); }
.answer:disabled { cursor: default; }

.answer-key {
  flex: 0 0 auto;
  color: #6c685f;
  font-family: "Space Mono", monospace;
  font-size: 11px;
  font-weight: 700;
}

.answer-name { font-size: clamp(14px, 1.9vw, 18px); font-weight: 700; line-height: 1.15; }
.answer:hover .answer-key, .answer:focus-visible .answer-key { color: var(--paper); }
.answer.correct { color: #fff; background: var(--green); }
.answer.wrong { color: #fff; background: var(--red); }
.answer.correct .answer-key, .answer.wrong .answer-key { color: currentColor; }
.answer.dimmed { color: rgba(20, 20, 20, 0.32); }

.footer-line {
  display: grid;
  grid-template-columns: 1fr minmax(100px, 240px) 1fr;
  gap: 20px;
  align-items: center;
  padding: 14px 1px 0;
  font-family: "Space Mono", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.footer-line p { margin: 0; }
.footer-line p:last-child { text-align: right; }
.progress { height: 3px; background: rgba(20, 20, 20, 0.16); }
.progress span { display: block; width: 0; height: 100%; background: var(--blue); transition: width 280ms ease; }

.results {
  position: absolute;
  z-index: 5;
  inset: 22px 0 0;
  display: grid;
  place-content: center;
  justify-items: center;
  border: 2px solid var(--ink);
  background: var(--paper);
  text-align: center;
}

.results[hidden] { display: none; }
.eyebrow { margin: 0 0 16px; font-family: "Space Mono", monospace; font-size: 10px; font-weight: 700; letter-spacing: 0.18em; }
.results h1 { margin: 0; color: var(--red); font: 700 clamp(88px, 17vw, 170px)/0.9 "Space Mono", monospace; letter-spacing: -0.1em; }
.results h1 small { color: var(--ink); font-size: 0.18em; letter-spacing: 0; }
.results > p:not(.eyebrow):not(.result-time) { margin: 20px 0 25px; font-size: 15px; }
.results .result-time { display: flex; gap: 10px; align-items: baseline; margin: 25px 0 0; font-family: "Space Mono", monospace; }
.result-time span { color: #6c685f; font-size: 9px; letter-spacing: 0.14em; }
.result-time strong { font-size: 17px; }
.result-actions { display: flex; gap: 10px; }
.results button, .got-it-button {
  min-width: 210px;
  padding: 15px 20px;
  border: 2px solid var(--ink);
  color: var(--paper);
  background: var(--ink);
  cursor: pointer;
  font-family: "Space Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.results button:hover, .results button:focus-visible, .got-it-button:hover, .got-it-button:focus-visible { color: var(--ink); background: var(--red); outline: none; }
.results button span { margin-left: 22px; }
#shareButton { color: var(--ink); background: transparent; }
#shareButton:hover, #shareButton:focus-visible { color: var(--paper); background: var(--blue); }

.instructions {
  width: min(calc(100% - 32px), 510px);
  padding: 48px;
  border: 2px solid var(--ink);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 12px 12px 0 var(--ink);
}

.instructions::backdrop { background: rgba(20, 20, 20, 0.68); backdrop-filter: blur(3px); }
.instructions .close-button { position: absolute; top: 15px; right: 15px; width: 34px; height: 34px; font-size: 23px; line-height: 1; }
.instructions h1 { margin: 0 0 22px; font: 700 clamp(31px, 7vw, 48px)/0.98 "Space Mono", monospace; letter-spacing: -0.07em; }
.instructions > p:not(.eyebrow):not(.credit) { max-width: 380px; font-size: 16px; line-height: 1.55; }
.instructions .keys { margin: 24px 0; }
kbd { display: inline-grid; place-items: center; width: 30px; height: 30px; margin-right: 7px; border: 1px solid var(--ink); font: 700 11px "Space Mono", monospace; }
.credit { margin: 24px 0 0; color: #6c685f; font: 10px/1.5 "Space Mono", monospace; }
.credit a { color: inherit; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes flag-pulse { 45% { transform: scale(1.04); } }

@media (max-width: 640px) {
  .app { padding: 0 14px 18px; }
  .topbar { height: 65px; }
  .wordmark { font-size: 17px; }
  .help-button, .mode-button { width: 34px; height: 34px; }
  .game { padding-top: 14px; }
  .flag-stage { height: min(37vh, 330px); min-height: 210px; }
  .flag-stage img { width: min(80%, 290px); height: 76%; }
  .answer { min-height: 67px; padding: 11px 12px; gap: 10px; }
  .answer-name { font-size: 14px; }
  .footer-line { grid-template-columns: 1fr 90px 1fr; gap: 12px; }
  .instructions { padding: 44px 28px 30px; box-shadow: 7px 7px 0 var(--ink); }
  .result-actions { flex-direction: column; }
  .results button { min-width: 225px; }
}

@media (max-width: 390px) {
  .scorebar .prompt { font-size: 9px; }
  .scorebar span { display: none; }
  .answer { min-height: 62px; }
  .answer-key { font-size: 9px; }
}

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