:root {
  --aoe-blue: #0b3d91;
  --aoe-blue-dark: #07286a;
  --aoe-gold: #ffd84d;
  --aoe-gold-dark: #e6b800;
  --aoe-green: #2ecc71;
  --aoe-red: #e74c3c;
  --aoe-bg: #f4f8ff;
  --aoe-card: #ffffff;
  --aoe-text: #1a1f2e;
  --aoe-muted: #6b7280;
  --aoe-shadow: 0 10px 30px rgba(11, 61, 145, 0.18);
  --aoe-shadow-sm: 0 4px 12px rgba(11, 61, 145, 0.12);
  --aoe-radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  color: var(--aoe-text);
  background: linear-gradient(160deg, #dbe9ff 0%, #f4f8ff 60%, #ffffff 100%);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#aoe-app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px 32px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.aoe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 16px;
}

.aoe-header .aoe-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--aoe-blue-dark);
  letter-spacing: -0.3px;
}

.aoe-header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.aoe-mute-btn {
  background: #fff;
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--aoe-shadow-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}
.aoe-mute-btn:hover { transform: scale(1.08); }

.aoe-lang-toggle {
  display: inline-flex;
  background: #fff;
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--aoe-shadow-sm);
}
.aoe-lang-toggle button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  color: var(--aoe-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.aoe-lang-toggle button.aoe-active {
  background: var(--aoe-blue);
  color: #fff;
}

/* ---------- Practice / Test toggle ---------- */
.aoe-type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 720px;
}
.aoe-type-btn {
  border: 2px solid transparent;
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  box-shadow: var(--aoe-shadow-sm);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: all 0.15s ease;
}
.aoe-type-btn:hover { transform: translateY(-2px); }
.aoe-type-btn.aoe-active {
  background: var(--aoe-blue);
  color: #fff;
  border-color: var(--aoe-blue-dark);
}
.aoe-type-name {
  font-weight: 800;
  font-size: 15px;
}
.aoe-type-desc {
  font-size: 12px;
  opacity: 0.75;
}

/* ---------- Home screen ---------- */
.aoe-home {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
  padding: 24px 8px;
}

.aoe-hero {
  text-align: center;
}
.aoe-hero h1 {
  font-size: clamp(32px, 7vw, 48px);
  margin: 0 0 8px;
  color: var(--aoe-blue-dark);
  letter-spacing: -1px;
  line-height: 1.05;
}
.aoe-hero .aoe-flag-row {
  font-size: clamp(28px, 5vw, 36px);
  letter-spacing: 4px;
  margin-bottom: 8px;
  animation: aoe-float 6s ease-in-out infinite;
}
.aoe-hero p {
  margin: 0;
  font-size: 16px;
  color: var(--aoe-muted);
}

@keyframes aoe-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.aoe-mode-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  width: 100%;
  max-width: 720px;
}
@media (min-width: 640px) {
  .aoe-mode-grid { grid-template-columns: repeat(3, 1fr); }
}

.aoe-mode-card {
  background: var(--aoe-card);
  border: 0;
  border-radius: var(--aoe-radius);
  padding: 22px 18px;
  cursor: pointer;
  box-shadow: var(--aoe-shadow);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}
.aoe-mode-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 36px rgba(11, 61, 145, 0.22);
}
.aoe-mode-card:active { transform: translateY(0); }

.aoe-mode-card .aoe-mode-icon {
  font-size: 32px;
  line-height: 1;
  margin-bottom: 6px;
}
.aoe-mode-card .aoe-mode-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--aoe-blue-dark);
}
.aoe-mode-card .aoe-mode-desc {
  font-size: 13px;
  color: var(--aoe-muted);
}
.aoe-mode-card .aoe-mode-best {
  font-size: 12px;
  font-weight: 700;
  color: var(--aoe-muted);
}

.aoe-mode-card .aoe-bar {
  margin-top: 10px;
  height: 6px;
  border-radius: 999px;
  background: #e7eefb;
  overflow: hidden;
}
.aoe-mode-card .aoe-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--aoe-blue), var(--aoe-gold));
  width: 0;
  transition: width 0.6s cubic-bezier(.2,.8,.2,1);
}

/* ---------- Game screen ---------- */
.aoe-game {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.aoe-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  border-radius: var(--aoe-radius);
  padding: 12px 16px;
  box-shadow: var(--aoe-shadow-sm);
}
.aoe-status-btn {
  background: transparent;
  border: 0;
  color: var(--aoe-blue);
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}
.aoe-status-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--aoe-blue-dark);
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.aoe-status-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.aoe-status-stats {
  display: flex;
  gap: 18px;
  font-weight: 700;
  font-size: 14px;
}
.aoe-status-stats span small {
  display: block;
  font-size: 10px;
  color: var(--aoe-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.aoe-status-stats .aoe-streak-hot {
  color: var(--aoe-red);
  animation: aoe-streak-pop 0.4s ease;
}
@keyframes aoe-streak-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.aoe-progress {
  height: 6px;
  background: #e7eefb;
  border-radius: 999px;
  overflow: hidden;
}
.aoe-progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--aoe-blue), var(--aoe-gold));
  width: 0;
  transition: width 0.4s ease;
}

.aoe-prompt {
  position: relative;
  background: #fff;
  border-radius: var(--aoe-radius);
  padding: 18px 16px;
  box-shadow: var(--aoe-shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.aoe-prompt .aoe-prompt-q {
  font-size: 15px;
  color: var(--aoe-muted);
  font-weight: 600;
}
.aoe-prompt .aoe-prompt-a {
  font-size: clamp(22px, 5vw, 30px);
  font-weight: 800;
  color: var(--aoe-blue-dark);
  letter-spacing: -0.5px;
}
.aoe-prompt .aoe-map {
  width: 100%;
  max-width: 360px;
  border-radius: 14px;
  display: block;
  background: #eef3ff;
  aspect-ratio: 1 / 1;
  object-fit: contain;
}
.aoe-prompt .aoe-bigflag {
  font-size: 96px;
  line-height: 1;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.15));
}

.aoe-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.aoe-opt {
  background: #fff;
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 16px 12px;
  font-size: clamp(15px, 4vw, 19px);
  font-weight: 700;
  color: var(--aoe-text);
  cursor: pointer;
  box-shadow: var(--aoe-shadow-sm);
  transition: transform 0.1s ease, border-color 0.2s, background 0.2s;
  min-height: 70px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-word;
}
.aoe-opt.aoe-flag-opt {
  font-size: 48px;
  padding: 12px;
}
@media (hover: hover) {
  .aoe-opt:hover { transform: translateY(-2px); border-color: var(--aoe-blue); }
}
.aoe-opt:active { transform: translateY(0); }
.aoe-opt:focus { outline: none; }
.aoe-opt:focus-visible { outline: 3px solid var(--aoe-gold-dark); outline-offset: 2px; }
.aoe-opt.aoe-correct {
  background: var(--aoe-green);
  color: #fff;
  border-color: var(--aoe-green);
  animation: aoe-pulse 0.5s ease;
}
.aoe-opt.aoe-wrong {
  background: var(--aoe-red);
  color: #fff;
  border-color: var(--aoe-red);
  animation: aoe-shake 0.5s ease;
}
.aoe-opt:disabled { cursor: default; }
.aoe-opt:disabled:hover { transform: none; border-color: transparent; }
.aoe-opt.aoe-dim { opacity: 0.35; }

@keyframes aoe-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes aoe-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- End screen ---------- */
.aoe-end {
  background: #fff;
  border-radius: var(--aoe-radius);
  padding: 28px 20px;
  box-shadow: var(--aoe-shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}
.aoe-end .aoe-end-title {
  font-size: 32px;
  font-weight: 800;
  color: var(--aoe-blue-dark);
  letter-spacing: -1px;
}
.aoe-end .aoe-end-score {
  font-size: 56px;
  font-weight: 900;
  color: var(--aoe-gold-dark);
  line-height: 1;
}
.aoe-end .aoe-end-score small {
  font-size: 22px;
  color: var(--aoe-muted);
  font-weight: 700;
}
.aoe-end .aoe-end-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(90deg, var(--aoe-gold), var(--aoe-gold-dark));
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.5px;
}
/* ---------- Stars ---------- */
.aoe-stars {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.aoe-star {
  line-height: 1;
  display: inline-block;
}
.aoe-stars-lg .aoe-star {
  font-size: 64px;
  animation: aoe-star-pop 0.5s cubic-bezier(.2,1.6,.4,1) backwards;
}
.aoe-stars-sm .aoe-star {
  font-size: 18px;
}
.aoe-star-on { color: var(--aoe-gold-dark); text-shadow: 0 2px 6px rgba(230,184,0,0.45); }
.aoe-star-off { color: #d6deea; }

@keyframes aoe-star-pop {
  from { transform: scale(0) rotate(-30deg); opacity: 0; }
  to   { transform: scale(1) rotate(0);      opacity: 1; }
}

/* ---------- Miss grid (end screen review) ---------- */
.aoe-miss-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--aoe-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 8px;
}
.aoe-miss-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  width: 100%;
}
.aoe-miss-card {
  background: #f4f8ff;
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.aoe-miss-card img {
  width: 100%;
  border-radius: 6px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
}
.aoe-miss-flag {
  font-size: 22px;
  line-height: 1;
  margin-top: 4px;
}
.aoe-miss-name {
  font-weight: 800;
  font-size: 13px;
  color: var(--aoe-blue-dark);
}
.aoe-miss-cap {
  font-size: 11px;
  color: var(--aoe-muted);
}

.aoe-btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.aoe-btn {
  background: var(--aoe-blue);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--aoe-shadow-sm);
  transition: transform 0.1s, background 0.2s;
}
.aoe-btn:hover { background: var(--aoe-blue-dark); transform: translateY(-2px); }
.aoe-btn:active { transform: translateY(0); }
.aoe-btn.aoe-btn-secondary {
  background: #fff;
  color: var(--aoe-blue);
  border: 2px solid #e7eefb;
}
.aoe-btn.aoe-btn-secondary:hover { background: #f0f4ff; }

/* ---------- Confetti / fireworks ---------- */
#aoe-fireworks {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1000;
}
.aoe-confetti {
  position: absolute;
  width: 10px;
  height: 14px;
  top: -20px;
  border-radius: 2px;
  animation: aoe-fall linear forwards;
}
@keyframes aoe-fall {
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0;
  }
}

/* ---------- Diagnostic reveal panel ---------- */
.aoe-explain {
  background: #fff;
  border-radius: var(--aoe-radius);
  padding: 14px 14px 16px;
  box-shadow: var(--aoe-shadow-sm);
  animation: aoe-explain-in 0.25s ease both;
}
.aoe-explain-right { border-left: 6px solid var(--aoe-green); }
.aoe-explain-wrong { border-left: 6px solid var(--aoe-red); }

@keyframes aoe-explain-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* When the reveal lives inside the prompt it floats as a banner/card centered
   over the map, so it adds no page height and never needs scrolling to see. */
.aoe-prompt > .aoe-explain {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 20px);
  max-width: 340px;
  z-index: 5;
  box-shadow: var(--aoe-shadow);
  animation: aoe-explain-pop 0.22s ease both;
}
@keyframes aoe-explain-pop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.aoe-fact {
  font-size: clamp(15px, 3.6vw, 17px);
  line-height: 1.4;
  color: var(--aoe-text);
  text-align: center;
}
.aoe-fact strong { color: var(--aoe-blue-dark); }
.aoe-fact-coa {
  display: block;
  height: clamp(48px, 12vw, 64px);
  width: auto;
  margin: 0 auto 6px;
}
.aoe-fact .aoe-fact-region {
  color: var(--aoe-muted);
  font-weight: 600;
}

.aoe-explain-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.aoe-explain-card {
  border-radius: 12px;
  padding: 8px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.aoe-explain-card-picked {
  background: rgba(231, 76, 60, 0.10);
  border: 2px solid rgba(231, 76, 60, 0.35);
}
.aoe-explain-card-correct {
  background: rgba(46, 204, 113, 0.12);
  border: 2px solid rgba(46, 204, 113, 0.45);
}
.aoe-explain-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--aoe-muted);
}
.aoe-explain-card-picked .aoe-explain-label { color: var(--aoe-red); }
.aoe-explain-card-correct .aoe-explain-label { color: #1f8c4d; }
.aoe-explain-img {
  width: 100%;
  max-width: 140px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
}
.aoe-explain-flag {
  font-size: 56px;
  line-height: 1;
  margin: 4px 0;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.12));
}
.aoe-explain-name {
  font-weight: 800;
  font-size: 15px;
  color: var(--aoe-blue-dark);
  text-align: center;
  word-break: break-word;
}
.aoe-explain-meta {
  font-size: 12px;
  color: var(--aoe-muted);
  text-align: center;
  word-break: break-word;
}
.aoe-explain-soon {
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--aoe-blue);
  opacity: 0.8;
}
.aoe-explain-next {
  display: block;
  margin: 14px auto 2px;
  padding: 12px 32px;
  font-size: 16px;
  animation: aoe-next-pulse 1.6s ease-in-out infinite;
}
@keyframes aoe-next-pulse {
  0%, 100% { box-shadow: var(--aoe-shadow-sm); }
  50%      { box-shadow: 0 0 0 6px rgba(11, 61, 145, 0.15), var(--aoe-shadow-sm); }
}

/* ---------- Fylke map (SVG) ---------- */
.aoe-fylke-map {
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}
.aoe-fylke-map svg {
  width: 100%;
  height: auto;
  display: block;
}
.aoe-fylke-map svg path {
  fill: #e8eef7;
  stroke: #8895a8;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  transition: fill 0.2s ease;
}
.aoe-fylke-map svg path.aoe-fylke-active {
  fill: var(--aoe-gold);
  stroke: var(--aoe-blue-dark);
  stroke-width: 2;
  animation: aoe-fylke-glow 1.6s ease-in-out infinite;
}
@keyframes aoe-fylke-glow {
  0%, 100% { fill: var(--aoe-gold); }
  50%      { fill: #ffeb8a; }
}
.aoe-fylke-map-sm {
  max-width: 160px;
}

/* ---------- Home mastery ---------- */
.aoe-mode-card .aoe-bar > span.aoe-bar-mastery {
  background: linear-gradient(90deg, var(--aoe-green), var(--aoe-gold));
}
.aoe-mastery-hint {
  font-size: 12px;
  color: var(--aoe-muted);
  text-align: center;
  margin: 4px 0 0;
  max-width: 520px;
}

/* ---------- Small screens ---------- */
@media (max-width: 380px) {
  .aoe-options { grid-template-columns: 1fr; }
  .aoe-prompt .aoe-bigflag { font-size: 80px; }
  .aoe-explain-flag { font-size: 44px; }
  .aoe-explain-img { max-width: 110px; }
  .aoe-status-title { display: none; } /* keep the combined bar from overflowing */
  .aoe-status-right { gap: 8px; }
}

/* ---------- Landscape: split the screen — map left, answers right ---------- */
@media (orientation: landscape) and (min-width: 700px) {
  .aoe-game {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "status   status"
      "progress progress"
      "prompt   options";
    /* bars hug the top; only the prompt/options row absorbs leftover height —
       otherwise stretched auto rows open a huge gap under the status bar */
    grid-template-rows: auto auto 1fr;
    align-content: start;
    align-items: start;
    column-gap: 18px;
    row-gap: 6px; /* tighten space between the bars and the map/answers */
  }
  .aoe-prompt { padding: 10px; justify-content: center; }
  .aoe-statusbar { grid-area: status; }
  .aoe-progress  { grid-area: progress; }
  .aoe-prompt    { grid-area: prompt; align-self: stretch; }
  .aoe-options   {
    grid-area: options;
    grid-template-columns: 1fr; /* one tall column beside the map */
    align-content: start;
  }
}
