:root {
  --ink: #18231d;
  --muted: #647068;
  --paper: #f6f3eb;
  --card: #fffdf7;
  --line: #d9d8cf;
  --green: #245d45;
  --green-soft: #dfece3;
  --coral: #d96f4e;
  --coral-soft: #f6dfd7;
  --gold: #e9b949;
  --gold-soft: #f8edc9;
  --blue: #416f83;
  --blue-soft: #dcebf0;
  --plum: #745b78;
  --plum-soft: #ece2ed;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 9% 5%, rgba(233, 185, 73, 0.13), transparent 24rem),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  min-height: 100vh;
}

button,
a {
  font: inherit;
}

button {
  margin: 0;
  color: inherit;
}

img {
  max-width: 100%;
}

.level-reference {
  max-width: 100%;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  vertical-align: middle;
}

.level-reference-title {
  min-width: 0;
  overflow-wrap: anywhere;
}

.level-badge {
  --level-badge-size: 2.3rem;
  width: var(--level-badge-size);
  height: var(--level-badge-size);
  flex: 0 0 var(--level-badge-size);
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--stage-badge, var(--stage-accent, #4f5d56));
  color: var(--stage-on-badge, #18231d);
  box-shadow: 0 3px 9px color-mix(in srgb, var(--stage-badge, var(--stage-accent, #4f5d56)) 22%, transparent);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 850;
  line-height: 1;
}

.level-badge > span {
  color: inherit;
  font: inherit;
  line-height: 1;
}

.level-badge-small { --level-badge-size: 1.45rem; font-size: 0.66rem; }
.level-badge-compact { --level-badge-size: 1.9rem; font-size: 0.78rem; }
.level-badge-large { --level-badge-size: 3.2rem; font-size: 1.15rem; }

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.site-shell,
.quiz-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.brand-bar,
.quiz-header {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.app-header {
  position: relative;
  z-index: 30;
  background: var(--paper);
}

.app-header-sticky {
  position: sticky;
  top: 0;
}

.setup-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.setup-shell {
  min-height: 0;
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

.setup-shell .brand-bar {
  min-height: 64px;
}

.brand-group {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.48);
}

.language-button {
  width: 34px;
  height: 26px;
  padding: 4px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  opacity: 0.58;
  transition:
    background-color 150ms ease,
    opacity 150ms ease,
    transform 150ms ease;
}

.language-button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.language-button.is-selected {
  background: var(--paper);
  box-shadow: 0 1px 5px rgba(24, 35, 29, 0.18);
  opacity: 1;
}

.language-button img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(24, 35, 29, 0.16);
}

.brand {
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-home-link {
  padding-left: 16px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.035em;
  text-decoration: none;
  white-space: nowrap;
}

.site-home-link:hover {
  color: var(--green);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.setup-shell .site-home-link {
  padding-left: 0;
  border-left: 0;
}

.setup-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 35px;
  height: 35px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: contain;
  filter: drop-shadow(0 4px 7px rgba(24, 35, 29, 0.18));
}

.kicker {
  margin: 0 0 18px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.question-prompt h1,
.result-card h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: -0.045em;
  line-height: 0.98;
}

.region-map-card {
  width: min(100%, 600px);
  justify-self: center;
  position: relative;
}

.region-map {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.map-ocean {
  fill: rgba(220, 235, 240, 0.8);
  stroke: rgba(65, 111, 131, 0.24);
  stroke-width: 1;
}

.map-country {
  fill: #b9c8be;
  stroke: rgba(255, 253, 247, 0.92);
  stroke-width: 0.75;
  fill-rule: evenodd;
  transition:
    fill 150ms ease,
    stroke 150ms ease,
    opacity 150ms ease;
}

.map-country.is-merged-shape {
  paint-order: stroke fill;
}

.map-context {
  pointer-events: none;
}

.map-context .map-country {
  fill: #cbd3cd;
}

.map-region {
  cursor: pointer;
  outline: none;
}

.map-marker {
  fill: #82998a;
  stroke: var(--card);
  stroke-width: 1.2;
  pointer-events: none;
  transition:
    fill 150ms ease,
    r 150ms ease;
}

.map-country.is-active,
.map-marker.is-active {
  fill: var(--green);
}

.map-country.is-preview,
.map-marker.is-preview {
  fill: var(--coral);
}

.map-region:focus .map-country,
.map-region:focus .map-marker {
  stroke: var(--gold);
  stroke-width: 2.2;
}

.map-region:hover .map-country:not(.is-preview) {
  fill: #d88467;
}

.open-challenge-overlay {
  position: fixed;
  z-index: 120;
  inset: 0;
  padding: 24px;
  background: rgba(16, 29, 23, 0.7);
  display: grid;
  place-items: center;
}

.open-challenge-dialog {
  width: min(540px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  padding: clamp(24px, 6vw, 38px);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(11, 25, 18, 0.3);
}

.open-challenge-dialog h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 7vw, 42px);
  font-weight: 400;
  line-height: 1.05;
}

.open-challenge-dialog > p {
  margin: 14px 0 24px;
  color: var(--muted);
  line-height: 1.5;
}

.open-challenge-dialog form,
.open-challenge-dialog label {
  display: grid;
}

.open-challenge-dialog label {
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 800;
}

.open-challenge-dialog input {
  width: 100%;
  min-height: 50px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.open-challenge-dialog input:focus {
  border-color: var(--green);
  outline: 3px solid rgba(36, 93, 69, 0.18);
  outline-offset: 1px;
}

.open-challenge-dialog input[aria-invalid="true"] {
  border-color: var(--coral);
}

.open-challenge-error {
  min-height: 1.4em;
  margin: 7px 0 14px;
  color: #a23f26;
  font-size: 13px;
  font-weight: 700;
}

.open-challenge-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.open-challenge-actions .primary-button,
.open-challenge-actions .secondary-button {
  min-height: 46px;
}

@media (max-width: 420px) {
  .open-challenge-actions {
    display: grid;
  }
}

.region-card {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(255, 253, 247, 0.82);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.region-card:hover {
  border-color: var(--green);
}

.region-card.is-selected {
  border-color: var(--green);
  background: var(--card);
  box-shadow: inset 4px 0 0 var(--green);
}

.region-card.is-preview {
  border-color: var(--coral);
  background: var(--coral-soft);
  box-shadow: inset 4px 0 0 var(--coral);
}

.region-card span {
  font-weight: 720;
  font-size: 13px;
  line-height: 1.18;
}

.region-card small {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.primary-button {
  border: 0;
  background: var(--coral);
  color: #fff;
  border-radius: 999px;
  min-height: 54px;
  padding: 0 24px 0 27px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 9px 24px rgba(146, 66, 42, 0.2);
  transition:
    transform 160ms ease,
    background 160ms ease;
}

.primary-button:hover {
  transform: translateY(-2px);
  background: #c95e3d;
}

.primary-button span {
  font-size: 22px;
  line-height: 1;
}

footer {
  border-top: 1px solid var(--line);
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.action-feedback-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.action-feedback-icon {
  display: inline-grid;
  width: 1em;
  min-width: 1em;
  place-items: center;
  color: var(--green);
  font-size: 1em !important;
  font-weight: 900;
  line-height: 1;
}

.action-feedback-button.is-copied .action-feedback-icon::before {
  content: "✓";
}

.action-feedback-toast {
  position: fixed;
  z-index: 200;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  width: fit-content;
  max-width: min(32rem, calc(100% - 32px));
  margin-inline: auto;
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 12px 32px rgba(24, 35, 29, 0.24);
  font-size: 14px;
  font-weight: 750;
  text-align: center;
}

.setup-shell footer {
  min-height: 52px;
  margin-top: auto;
  gap: 8px 16px;
}

footer a {
  color: var(--muted);
  text-underline-offset: 3px;
}

.license-links {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 5px 16px;
}

.copyright {
  white-space: nowrap;
}

.install-app-button {
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.install-app-button img {
  width: 20px;
  height: 20px;
}

.install-app-button:focus-visible,
.install-help-close:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

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

/* Responsive base layout */
@media (max-width: 979px) {
  .region-map-card {
      width: min(100%, 680px);
    }
}

@media (max-width: 600px) {
  .app-header-mobile-sticky {
      position: sticky;
      z-index: 30;
      top: 0;
    }

  .brand-group {
      gap: 10px;
    }

  .language-switcher {
      gap: 2px;
      padding: 2px;
    }

  .language-button {
      width: 31px;
      height: 24px;
    }

  .region-card {
      min-height: 56px;
    }

  footer {
      align-items: flex-start;
      flex-direction: column;
      justify-content: center;
      gap: 7px;
    }
}

@media (orientation: landscape) and (max-height: 599px) {
  .app-header-mobile-sticky {
      position: sticky;
      z-index: 30;
      top: 0;
    }
}

@media (max-width: 600px) {
  .challenge-card {
      padding: 18px 0 max(18px, env(safe-area-inset-bottom));
    }

  .challenge-card .kicker {
      margin-bottom: 10px;
    }

  .challenge-card h1 {
      font-size: clamp(30px, 9vw, 42px);
      line-height: 1;
    }

  .challenge-details {
      margin-bottom: 16px;
    }

  .challenge-details div {
      padding: 11px 6px;
    }

  .challenge-details strong {
      font-size: 16px;
    }
}

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