:root {
  --ink: #102d31;
  --ocean: #136575;
  --ocean-deep: #0b4b59;
  --ocean-light: #b9dde0;
  --paper: #f4f1e7;
  --white: #fffef8;
  --red: #c7423f;
  --yellow: #f2c94c;
  --turf: #5f8552;
  --turf-dark: #355d43;
  --sky: #76b9c5;
  --shadow: 0 18px 46px rgba(9, 37, 42, .2);
}

* { box-sizing: border-box; }

html {
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  user-select: none;
  -webkit-touch-callout: none;
}

button, a { color: inherit; font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-bar {
  position: relative;
  z-index: 20;
  display: grid;
  min-height: 62px;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: var(--ink);
  color: var(--white);
  box-shadow: 0 3px 16px rgba(6, 30, 34, .22);
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 5px;
  background: transparent;
  color: var(--white);
  font-size: 19px;
  font-weight: 850;
  text-decoration: none;
}

.icon-button:hover { background: rgba(255, 255, 255, .09); }
.app-bar > :last-child { justify-self: end; }

.brand {
  display: flex;
  align-items: center;
  justify-self: start;
  gap: 11px;
  color: var(--white);
  text-decoration: none;
}

.brand > span:last-child { display: grid; }
.brand strong { font-family: Georgia, "Times New Roman", serif; font-size: 18px; }
.brand small { color: var(--yellow); font-size: 8px; font-weight: 900; }

.globe-mark {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
  border: 2px solid var(--white);
  border-radius: 50%;
}

.globe-mark::before,
.globe-mark::after,
.globe-mark i,
.globe-mark b {
  position: absolute;
  display: block;
  content: "";
}

.globe-mark::before { top: 6px; right: 0; left: 0; border-top: 1px solid var(--white); }
.globe-mark::after { right: 0; bottom: 6px; left: 0; border-top: 1px solid var(--white); }
.globe-mark i { top: 0; bottom: 0; left: 13px; border-left: 1px solid var(--white); }
.globe-mark b { inset: 2px 7px; border: 1px solid var(--white); border-top: 0; border-bottom: 0; border-radius: 50%; }

.screen { min-height: calc(100dvh - 62px); }

.menu-screen {
  display: grid;
  grid-template-columns: minmax(420px, 47%) minmax(420px, 1fr);
  background: var(--paper);
}

.menu-visual {
  position: sticky;
  top: 0;
  display: grid;
  min-height: calc(100dvh - 62px);
  place-items: center;
  overflow: hidden;
  background: var(--ocean-deep);
}

.menu-grid-lines {
  position: absolute;
  inset: 0;
  opacity: .18;
  background-image: linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);
  background-size: 56px 56px;
}

#menuMap { position: relative; width: 92%; max-height: 84vh; filter: drop-shadow(0 17px 18px rgba(0,0,0,.25)); }
.preview-sphere { fill: #8fc7ce; stroke: rgba(255,255,255,.75); stroke-width: 1.3; }
.preview-graticule { fill: none; stroke: rgba(255,255,255,.22); stroke-width: .6; }
.preview-country { stroke: var(--paper); stroke-width: .55; }
.preview-country.color-1 { fill: #507b54; }
.preview-country.color-2 { fill: #d7b14f; }
.preview-country.color-3 { fill: #6c9565; }
.preview-country.color-4 { fill: #d27455; }
.preview-country.color-5 { fill: #3d7771; }
.preview-faroe { fill: var(--red); stroke: var(--white); stroke-width: 2; animation: marker-pulse 1.4s ease-in-out infinite; }

.map-caption {
  position: absolute;
  right: 20px;
  bottom: 18px;
  padding: 9px 12px;
  border-left: 3px solid var(--yellow);
  background: rgba(9, 43, 49, .86);
  color: var(--white);
  font-size: 9px;
  font-weight: 900;
}

.menu-content {
  display: flex;
  min-height: calc(100dvh - 62px);
  flex-direction: column;
  justify-content: center;
  padding: clamp(42px, 6vw, 86px);
}

.menu-heading > p,
.difficulty-control > span,
#promptKicker,
.result-copy > p:first-child,
dialog > p:first-of-type {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 9px;
  font-weight: 950;
}

.menu-heading h1,
.result-copy h1 {
  max-width: 600px;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(35px, 4.4vw, 60px);
  line-height: 1.02;
  letter-spacing: 0;
}

.progress-summary { display: flex; gap: 8px; margin-top: 22px; }
.progress-summary span {
  padding: 8px 10px;
  border-left: 3px solid var(--turf);
  background: #dce9dc;
  font-size: 10px;
  font-weight: 850;
}
.progress-summary strong { font-size: 15px; }

.difficulty-control { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 34px 0 13px; }
.segments { display: grid; grid-template-columns: repeat(3, minmax(70px, 1fr)); overflow: hidden; border: 1px solid #9ba7a2; border-radius: 6px; }
.segments button { min-height: 38px; padding: 0 14px; border: 0; border-right: 1px solid #9ba7a2; background: var(--white); font-size: 12px; font-weight: 850; }
.segments button:last-child { border-right: 0; }
.segments button[aria-pressed="true"] { background: var(--ink); color: var(--white); }

.mode-grid { display: grid; gap: 9px; }
.mode-card {
  display: grid;
  min-height: 92px;
  grid-template-columns: 48px 1fr 24px;
  align-items: center;
  gap: 14px;
  padding: 14px 17px;
  border: 1px solid #b9b9ad;
  border-left-width: 6px;
  border-radius: 6px;
  background: var(--white);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 4px 0 rgba(16,45,49,.06);
}
.mode-card:hover { transform: translateY(-1px); border-color: var(--ink); box-shadow: 0 8px 18px rgba(16,45,49,.12); }
.mode-card.locate-mode { border-left-color: var(--red); }
.mode-card.identify-mode { border-left-color: var(--yellow); }
.mode-number { color: #8b928e; font-family: Georgia, "Times New Roman", serif; font-size: 22px; font-weight: 800; }
.mode-card > span:nth-child(2) { display: grid; gap: 5px; }
.mode-card strong { font-size: 17px; }
.mode-card small { color: #536467; font-size: 12px; line-height: 1.35; }
.mode-card > b { font-size: 22px; }

.play-screen { display: grid; height: calc(100dvh - 62px); min-height: 560px; grid-template-rows: 56px minmax(0,1fr); background: #d7e6e4; }
.round-bar { display: grid; grid-template-columns: 110px minmax(0,1fr) 66px; align-items: center; gap: 18px; padding: 7px max(12px,env(safe-area-inset-right)) 7px max(12px,env(safe-area-inset-left)); border-bottom: 1px solid #aab8b5; background: var(--paper); }
.round-back { height: 38px; border: 1px solid #9da8a5; border-radius: 5px; background: var(--white); font-size: 10px; font-weight: 900; }
.round-back span { margin-right: 6px; font-size: 16px; }
.round-progress { display: grid; min-width: 0; grid-template-columns: minmax(100px,auto) minmax(80px,320px); align-items: center; justify-content: center; gap: 14px; }
.round-progress > span { overflow: hidden; font-size: 11px; font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.round-progress > div { height: 7px; overflow: hidden; border-radius: 4px; background: #c7d0cc; }
#roundProgressFill { display: block; width: 0; height: 100%; background: var(--red); transition: width .3s ease; }
.round-score { display: grid; justify-items: end; }
.round-score span { color: #63706e; font-size: 8px; font-weight: 900; }
.round-score strong { font-family: Georgia, "Times New Roman", serif; font-size: 22px; }

.play-layout { display: grid; min-height: 0; grid-template-columns: minmax(0,1fr) 370px; }
.map-shell { position: relative; min-width: 0; min-height: 0; overflow: hidden; border-right: 1px solid #719499; background: #8fc7ce; }
#mapSvg { display: block; width: 100%; height: 100%; touch-action: none; }
.map-sphere { fill: #aad6d9; }
.map-graticule { fill: none; stroke: rgba(255,255,255,.62); stroke-width: .7; vector-effect: non-scaling-stroke; }
.country { stroke: rgba(255,254,248,.92); stroke-width: .8; vector-effect: non-scaling-stroke; transition: fill .16s ease, opacity .16s ease; }
.country:not(.in-region) { opacity: .47; }
.country.color-1 { fill: #638965; }
.country.color-2 { fill: #d4b052; }
.country.color-3 { fill: #79a06d; }
.country.color-4 { fill: #cc765c; }
.country.color-5 { fill: #4d7e76; }
.country.in-region { cursor: pointer; }
.country.in-region:hover,
.country.in-region:focus-visible { fill: #f0cd58; outline: none; }
.country.wrong { fill: var(--red); animation: wrong-flash .5s ease; }
.country.question-target { fill: var(--yellow); stroke: var(--ink); stroke-width: 2.4; animation: target-country 1.15s ease-in-out infinite; }
.country.correct { fill: #238a5c; stroke: var(--white); stroke-width: 2.2; animation: correct-flash .7s ease; }

.country-marker { cursor: pointer; outline: none; }
.marker-hit { fill: transparent; }
.marker-dot { fill: var(--ink); stroke: var(--white); stroke-width: 2; vector-effect: non-scaling-stroke; }
.country-marker:hover .marker-dot,
.country-marker:focus-visible .marker-dot { fill: var(--yellow); }
.marker-ring { fill: rgba(255,255,255,.28); stroke: var(--yellow); stroke-width: 4; vector-effect: non-scaling-stroke; animation: marker-pulse 1.1s ease-in-out infinite; }
.country-marker.correct .marker-dot { fill: #238a5c; }
.country-marker.correct .marker-ring { stroke: #238a5c; }

.map-legend { position: absolute; bottom: 14px; left: 14px; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 90px); padding: 8px 11px; border: 1px solid rgba(16,45,49,.3); border-radius: 5px; background: rgba(255,254,248,.9); color: var(--ink); font-size: 9px; font-weight: 900; }
.map-legend i { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--red); }
.map-controls { position: absolute; top: 14px; right: 14px; display: grid; overflow: hidden; border: 1px solid #728b8e; border-radius: 6px; box-shadow: 0 5px 14px rgba(17,55,62,.18); }
.map-controls button { display: grid; width: 42px; height: 42px; place-items: center; padding: 0; border: 0; border-bottom: 1px solid #a6b7b6; background: rgba(255,254,248,.95); color: var(--ink); font-size: 20px; font-weight: 800; }
.map-controls button:last-child { border-bottom: 0; font-size: 16px; }

.lesson-panel { position: relative; z-index: 3; display: flex; min-height: 0; flex-direction: column; padding: 22px 24px max(22px,env(safe-area-inset-bottom)); background: var(--paper); box-shadow: -10px 0 26px rgba(18,51,55,.12); }
.question-progress { display: flex; justify-content: space-between; margin-bottom: clamp(22px,5vh,54px); color: #63706e; font-size: 9px; font-weight: 900; }
#promptTitle { margin: 0; overflow-wrap: anywhere; font-family: Georgia, "Times New Roman", serif; font-size: clamp(28px,3vw,38px); line-height: 1.08; letter-spacing: 0; }
.question-region { margin: 10px 0 0; color: #60716f; font-size: 11px; font-weight: 800; }
.country-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 22px; }
.country-choices button { min-height: 48px; padding: 8px; overflow-wrap: anywhere; border: 1px solid #92a09c; border-radius: 5px; background: var(--white); font-size: 12px; font-weight: 850; }
.country-choices button:hover { border-color: var(--ink); background: #e4eddf; }
.country-choices button.wrong-choice { border-color: var(--red); color: var(--red); }
.country-choices button.correct-choice { border-color: #267a54; background: #dceade; color: #194a38; }
.country-choices button:disabled:not(.correct-choice) { opacity: .34; cursor: default; }

.previous-answer { display: grid; grid-template-columns: 24px minmax(0,1fr); gap: 9px; align-items: center; margin: -8px 0 18px; padding: 8px 0 10px; border-bottom: 1px solid #b7c8c4; color: #194a38; }
.previous-answer[hidden] { display: none; }
.previous-answer-mark { display: grid; width: 23px; height: 23px; place-items: center; border-radius: 50%; background: #2a7e56; color: var(--white); font-size: 13px; font-weight: 900; }
.previous-answer > span:last-child { display: grid; min-width: 0; gap: 1px; }
.previous-answer small { color: #60716f; font-size: 8px; font-weight: 900; }
.previous-answer strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.feedback { min-height: 54px; margin-top: 20px; padding: 11px 12px; border-left: 4px solid transparent; color: #475b5e; font-size: 13px; line-height: 1.35; }
.feedback:empty { padding: 0; }
.feedback.good { border-left-color: #2a7e56; background: #dceade; color: #194a38; }
.feedback.try-again { border-left-color: var(--red); background: #f5dfdd; color: #773034; }
.feedback.hint { border-left-color: var(--yellow); background: #fff0bd; color: #614b14; }
.lesson-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 15px; }
.lesson-actions button,
.result-actions button { min-height: 46px; padding: 0 16px; border: 1px solid #8e9a97; border-radius: 5px; background: transparent; font-size: 10px; font-weight: 950; }
.result-actions button:first-child { margin-left: auto; border-color: var(--ink); background: var(--ink); color: var(--white); }
.lesson-actions button:disabled { opacity: .4; cursor: default; }

.result-screen { display: grid; grid-template-columns: minmax(400px,1fr) minmax(380px,620px); background: var(--ocean-deep); color: var(--white); }
.result-map { display: grid; min-height: calc(100dvh - 62px); place-items: center; padding: 7vh 4vw; background-color: var(--ocean-deep); background-image: linear-gradient(rgba(255,255,255,.08) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,.08) 1px,transparent 1px); background-size: 64px 64px; }
#resultMap { width: min(100%,760px); max-height: 78vh; filter: drop-shadow(0 14px 18px rgba(0,0,0,.3)); }
.result-sphere { fill: #8fc7ce; }
.result-country { fill: #577f5a; stroke: var(--paper); stroke-width: .45; }
.result-country.learned { fill: var(--yellow); }
.result-copy { display: flex; flex-direction: column; justify-content: center; padding: clamp(38px,7vw,90px); background: var(--paper); color: var(--ink); }
.result-copy > strong { margin-top: 13px; font-size: 13px; }
.result-copy > p:not(:first-child) { max-width: 460px; color: #536467; font-size: 15px; line-height: 1.5; }
.result-stars { display: flex; gap: 7px; margin-top: 28px; }
.result-stars i { width: 33px; height: 33px; background: #c6ccc7; clip-path: polygon(50% 0,61% 35%,98% 35%,68% 56%,79% 93%,50% 70%,21% 93%,32% 56%,2% 35%,39% 35%); }
.result-stars i.earned { background: var(--yellow); }
.result-facts { display: flex; gap: 30px; margin: 25px 0 30px; }
.result-facts span { display: grid; gap: 3px; color: #667471; font-size: 9px; font-weight: 900; }
.result-facts b { color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 29px; }
.result-actions { display: flex; gap: 8px; }

dialog { width: min(540px,calc(100vw - 32px)); padding: 30px; border: 0; border-radius: 6px; background: var(--paper); color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.4); user-select: text; }
dialog::backdrop { background: rgba(8,29,32,.72); }
dialog h2 { margin: 0 0 20px; font-family: Georgia, "Times New Roman", serif; font-size: 30px; }
dialog li { margin: 0 0 12px; padding-left: 5px; line-height: 1.4; }
.dialog-close { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; border: 1px solid #9da8a5; border-radius: 5px; background: transparent; font-size: 22px; }
.source-note { margin: 22px 0 0; padding-top: 14px; border-top: 1px solid #cbc9bd; color: #63706e; font-size: 11px; }
.source-note a { color: var(--ocean); }
.load-error { display: grid; min-height: calc(100dvh - 62px); place-content: center; padding: 30px; text-align: center; }

@keyframes marker-pulse { 0%,100% { opacity: .72; transform: scale(.86); } 50% { opacity: 1; transform: scale(1.18); } }
@keyframes target-country { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.25); } }
@keyframes wrong-flash { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.5); } }
@keyframes correct-flash { 0% { filter: brightness(1); } 45% { filter: brightness(1.5); } 100% { filter: brightness(1); } }

@media (max-width: 900px) {
  .menu-screen { grid-template-columns: 40% 1fr; }
  .menu-content { padding: 38px 28px; }
  .play-layout { grid-template-columns: minmax(0,1fr) 330px; }
}

@media (max-width: 720px) {
  .app-bar { min-height: 56px; }
  .brand strong { font-size: 15px; }
  .screen { min-height: calc(100dvh - 56px); }
  .menu-screen { display: block; }
  .menu-visual { position: relative; height: 34dvh; min-height: 245px; }
  #menuMap { width: 96%; height: 94%; }
  .menu-content { width: 100%; min-height: auto; padding: 27px max(16px,env(safe-area-inset-right)) max(34px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left)); }
  .menu-heading h1 { font-size: 32px; }
  .difficulty-control { display: grid; margin-top: 27px; }
  .segments { width: 100%; }
  .mode-card { min-height: 82px; grid-template-columns: 39px 1fr 20px; padding: 11px 12px; }
  .mode-card small { font-size: 11px; }
  .play-screen { height: auto; min-height: calc(100dvh - 56px); grid-template-rows: 52px auto; }
  .round-bar { min-height: 52px; grid-template-columns: 76px minmax(0,1fr) 43px; gap: 8px; }
  .round-back { height: 36px; padding: 0 8px; }
  .round-progress { display: block; }
  .round-progress > span { display: block; margin-bottom: 5px; font-size: 9px; text-align: center; }
  .round-score strong { font-size: 18px; }
  .play-layout { display: grid; grid-template-columns: 1fr; grid-template-rows: minmax(420px,58dvh) auto; }
  .map-shell { border-right: 0; border-bottom: 1px solid #719499; }
  .map-controls { top: 10px; right: 10px; }
  .map-controls button { width: 38px; height: 38px; }
  .lesson-panel { min-height: 254px; padding: 16px max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left)); box-shadow: 0 -8px 22px rgba(18,51,55,.11); }
  .question-progress { margin-bottom: 13px; }
  #promptTitle { font-size: 27px; }
  .question-region { margin-top: 6px; }
  .country-choices { gap: 5px; margin-top: 13px; }
  .country-choices button { min-height: 43px; padding: 5px; font-size: 11px; }
  .feedback { min-height: 40px; margin-top: 10px; padding-top: 8px; padding-bottom: 8px; }
  .lesson-actions { padding-top: 7px; }
  .result-screen { display: block; min-height: calc(100dvh - 56px); }
  .result-map { min-height: 36dvh; height: 36dvh; padding: 2vh 4vw; }
  .result-copy { min-height: 58dvh; padding: 30px max(19px,env(safe-area-inset-right)) max(36px,env(safe-area-inset-bottom)) max(19px,env(safe-area-inset-left)); }
  .result-copy h1 { font-size: 35px; }
}

@media (max-width: 420px) {
  .brand small { display: none; }
  .play-layout { grid-template-rows: minmax(390px,55dvh) auto; }
  .map-caption { right: 10px; bottom: 10px; }
  .country-choices button { font-size: 10px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .app-bar { min-height: 50px; padding-top: 4px; padding-bottom: 4px; }
  .play-screen { height: calc(100dvh - 50px); min-height: 0; grid-template-rows: 44px minmax(0,1fr); }
  .play-layout { grid-template-columns: minmax(0,1fr) minmax(300px,36vw); grid-template-rows: minmax(0,1fr); }
  .lesson-panel { min-height: 0; padding: 12px 16px; }
  .question-progress { margin-bottom: 8px; }
  #promptTitle { font-size: 24px; }
  .country-choices { margin-top: 8px; }
  .country-choices button { min-height: 39px; }
  .feedback { min-height: 34px; margin-top: 7px; padding: 6px 9px; }
  .lesson-actions { padding-top: 4px; }
}

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