/* Phase 4 — accessibility: disable every decorative animation when
   the OS-level prefers-reduced-motion setting is on. Non-negotiable.
   Placed first with !important so it wins over later keyframe rules. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none; }

body {
  font-family: 'Comic Sans MS', 'Chalkboard SE', system-ui, sans-serif;
  background: linear-gradient(135deg, #1e3a8a 0%, #312e81 50%, #1e1b4b 100%);
  color: #fff;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden { display: none !important; }

/* Rotate prompt */
.rotate-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #1e3a8a, #312e81);
  z-index: 9999;
  display: none;
  align-items: center; justify-content: center;
  text-align: center; padding: 20px;
}
.rotate-content { max-width: 280px; }
.rotate-icon {
  font-size: 80px;
  animation: rotateHint 2s ease-in-out infinite;
  display: inline-block;
  margin-bottom: 20px;
}
@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}
.rotate-overlay p { font-size: 20px; font-weight: bold; }

@media (orientation: portrait) and (max-width: 900px) {
  .rotate-overlay { display: flex; }
}

/* Language screen */
.language-screen {
  position: fixed; inset: 0;
  background: radial-gradient(circle at 30% 40%, #4f46e5, #1e1b4b);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.lang-card {
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 30px;
  padding: 40px 50px;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0,0,0,0.4);
  max-width: 90vw;
}
.lang-title {
  font-size: clamp(28px, 5vw, 48px);
  margin-bottom: 10px;
  text-shadow: 3px 3px 0 #ec4899, 6px 6px 20px rgba(0,0,0,0.5);
}
.lang-subtitle {
  font-size: clamp(12px, 2vw, 16px);
  opacity: 0.8;
  margin-bottom: 30px;
}
.lang-buttons {
  display: flex; gap: 15px;
  flex-wrap: wrap; justify-content: center;
}
.lang-btn {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border: none;
  color: #1e1b4b;
  font-family: inherit;
  font-weight: bold;
  font-size: clamp(14px, 2vw, 18px);
  padding: 18px 24px;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 110px;
  box-shadow: 0 6px 0 #b45309, 0 10px 25px rgba(0,0,0,0.3);
  transition: all 0.15s;
}
.lang-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b45309, 0 5px 15px rgba(0,0,0,0.3);
}
.flag { font-size: 32px; }

/* Tablet bezel */
.tablet {
  position: relative;
  width: min(96vw, calc(100vh * 1.6));
  height: min(96vh, calc(96vw / 1.6));
  background: linear-gradient(145deg, #1e3a8a, #1e40af);
  border-radius: 28px;
  padding: 12px;
  box-shadow:
    0 0 0 4px #1e293b,
    0 25px 50px rgba(0,0,0,0.6),
    inset 0 2px 4px rgba(255,255,255,0.1);
}

.bezel-light {
  position: absolute;
  top: 50%; right: 6px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  animation: pulseLight 2s ease-in-out infinite;
}
@keyframes pulseLight {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.screen {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: #3b82f6;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.2);
}

.logo-badge {
  position: absolute;
  top: 10px; left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,0.92);
  color: #1e3a8a;
  font-weight: 800;
  font-size: clamp(11px, 1.4vw, 14px);
  padding: 4px 11px 4px 6px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.logo-mark {
  width: 22px;
  height: 22px;
  display: block;
  flex-shrink: 0;
}
.logo-text {
  font-family: 'Comic Sans MS', 'Chalkboard SE', system-ui, sans-serif;
  line-height: 1;
  white-space: nowrap;
}

/* Map stage occupies whole screen, side controls overlay on top */
.map-stage {
  position: absolute;
  inset: 0;
}
.world-svg {
  width: 100%; height: 100%;
  display: block;
}

/* Phase 2 — desktop gutters so side controls + power btn sit OUTSIDE
   the rendered SVG content area on viewports >= 768px. SVG preserves
   its aspect ratio inside the padded box. */
@media (min-width: 768px) {
  .map-stage { padding: 0 90px; }
}

/* Continent paths */
.continent {
  cursor: default;
  transition: filter 0.2s;
}

/* Animal hotspots inside SVG */
.animal-hotspot {
  cursor: pointer;
}
.animal-hotspot text {
  text-anchor: middle;
  dominant-baseline: middle;
  font-size: 22px;
  pointer-events: none;
}
.animal-hotspot circle {
  fill: rgba(255,255,255,0.7);
  stroke: white;
  stroke-width: 1.5;
}
.animal-hotspot circle {
  opacity: 0.92;
  transition: transform 0.1s, opacity 0.15s;
  transform-origin: center;
  transform-box: fill-box;
}
.animal-hotspot:hover circle,
.animal-hotspot:focus circle {
  opacity: 1;
}
.animal-hotspot text {
  transform-origin: center;
  transform-box: fill-box;
  transition: transform 0.1s;
}
.animal-hotspot:active circle,
.animal-hotspot:active text {
  transform: scale(0.85);
}
.animal-hotspot.pulse circle {
  animation: hotspotPulse 1s ease-in-out 3;
}
@keyframes hotspotPulse {
  0%, 100% { fill: rgba(255,255,255,0.7); }
  50% { fill: #fde047; stroke: #f59e0b; }
}
.animal-hotspot.correct circle {
  animation: correctFlash 0.6s ease;
}
.animal-hotspot.wrong circle {
  animation: wrongShake 0.5s ease;
}
@keyframes correctFlash {
  0%, 100% { fill: rgba(255,255,255,0.7); }
  50% { fill: #22c55e; stroke: #166534; }
}
@keyframes wrongShake {
  0%, 100% { fill: rgba(255,255,255,0.7); }
  50% { fill: #ef4444; }
}

/* Phase 4a — ambient life */

/* Idle hotspot pulse: gentle stroke breathing, staggered so they
   don't all pulse in sync. Doesn't conflict with click scale or
   .pulse/.correct/.wrong fill animations. */
@keyframes hotspotIdle {
  0%, 100% { stroke-width: 1.5; }
  50%      { stroke-width: 2.4; }
}
.animal-hotspot circle {
  animation: hotspotIdle 3s ease-in-out infinite;
}
.animal-hotspot:nth-child(3n) circle   { animation-delay: -1s; }
.animal-hotspot:nth-child(3n+1) circle { animation-delay: -2s; }

/* Ocean shimmer: subtle opacity drift on the wave overlay rect.
   It's the 2nd <rect> direct child of #worldSvg (oceanGrad is 1st). */
@keyframes oceanShimmer {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 0.85; }
}
.world-svg > rect:nth-of-type(2) {
  animation: oceanShimmer 8s ease-in-out infinite;
}

/* Region lift: triggered by JS adding .lift to the continent path
   for 600ms after a region tap. Tiny scale + vertical nudge. */
@keyframes regionLift {
  0%   { transform: scale(1) translateY(0); }
  40%  { transform: scale(1.03) translateY(-2px); }
  100% { transform: scale(1) translateY(0); }
}
.continent.lift {
  transform-origin: center;
  transform-box: fill-box;
  animation: regionLift 0.6s ease;
}

/* Continent / ocean labels */
.region-label {
  cursor: pointer;
  pointer-events: auto;
}
.region-label rect {
  fill: rgba(255,255,255,0.85);
  stroke: rgba(0,0,0,0.15);
  stroke-width: 0.5;
  rx: 8;
}
.region-label.ocean rect {
  fill: rgba(255,255,255,0.7);
}
.region-label text {
  text-anchor: middle;
  dominant-baseline: middle;
  font-weight: bold;
  font-size: 14px;
  fill: #1e1b4b;
  pointer-events: none;
}
.region-label.ocean text {
  fill: #1e3a8a;
}

/* Side controls */
.side-controls {
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
  padding-left: 6px;
}

/* Phase 2 — translucent backdrop on narrow screens where controls
   must overlap the map content (no room for a gutter). */
@media (max-width: 767px) {
  .side-controls {
    background: rgba(30,58,138,0.32);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 8px 6px 8px 4px;
    border-radius: 0 18px 18px 0;
  }
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 7px 14px;
  border: none;
  border-radius: 0 25px 25px 0;
  font-family: inherit;
  font-weight: bold;
  font-size: clamp(11px, 1.5vw, 15px);
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25), 0 6px 12px rgba(0,0,0,0.2);
  transition: all 0.12s;
  min-width: 95px;
}
.mode-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.25); }
.mode-btn.active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.25), 0 0 0 3px white, 0 0 20px rgba(255,255,255,0.5);
}
.mode-listen { background: linear-gradient(135deg, #ec4899, #db2777); }
.mode-learn  { background: linear-gradient(135deg, #84cc16, #65a30d); }
.mode-play   { background: linear-gradient(135deg, #f97316, #ea580c); }

.mode-icon {
  background: rgba(255,255,255,0.95);
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.mode-listen .mode-icon { color: #db2777; }
.mode-learn  .mode-icon { color: #65a30d; }
.mode-play   .mode-icon { color: #ea580c; }

.vol-btn, .lang-switch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.9);
  color: #1e3a8a;
  font-size: 15px;
  cursor: pointer;
  margin-top: 4px;
  margin-left: 4px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}
.vol-btn:active, .lang-switch:active { transform: translateY(1px); box-shadow: 0 2px 0 rgba(0,0,0,0.2); }

/* Phase 4c — age-mode pill, top-right */
.age-toggle {
  position: absolute;
  top: 10px; right: 64px;
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: rgba(255,255,255,0.92);
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
  padding: 2px;
}
.age-btn {
  background: transparent;
  border: none;
  padding: 3px 9px;
  font-size: 17px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  color: #1e3a8a;
  line-height: 1;
}
.age-btn.active {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.18);
}
@media (max-width: 767px) {
  .age-toggle { right: 56px; padding: 1px; }
  .age-btn { font-size: 15px; padding: 2px 7px; }
}

.power-btn {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 5px 0 #991b1b, 0 8px 15px rgba(0,0,0,0.3);
  z-index: 20;
}
.power-btn:active { transform: translateY(calc(-50% + 3px)); box-shadow: 0 2px 0 #991b1b; }

/* Speech bubble */
.speech-bubble {
  position: absolute;
  bottom: 15px; left: 50%;
  transform: translateX(-50%);
  background: white;
  color: #1e1b4b;
  padding: 10px 18px;
  border-radius: 16px;
  font-weight: bold;
  font-size: clamp(12px, 1.7vw, 17px);
  max-width: 75%;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
  border: 3px solid #fbbf24;
  z-index: 30;
  animation: bubbleIn 0.3s ease;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px) scale(0.8); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* Phase 4b — fact popup card */
.fact-popup {
  position: absolute;
  z-index: 40;
  background: white;
  color: #1e1b4b;
  border-radius: 22px;
  padding: 22px 26px 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  border: 3px solid #fbbf24;
  pointer-events: auto;
}
@keyframes popupSlideUp {
  from { opacity: 0; transform: translate(-50%, 40px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes popupFadeIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
/* Desktop: centered card */
@media (min-width: 768px) {
  .fact-popup {
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: clamp(320px, 38vw, 480px);
    max-width: 80vw;
    animation: popupFadeIn 0.35s ease;
  }
}
/* Mobile/landscape phones: slide up from bottom */
@media (max-width: 767px) {
  .fact-popup {
    bottom: 10px; left: 50%;
    transform: translateX(-50%);
    width: min(94vw, 520px);
    max-height: 62vh;
    overflow-y: auto;
    padding: 16px 20px 14px;
    animation: popupSlideUp 0.35s ease;
  }
}
.fact-icon {
  font-size: clamp(34px, 5vw, 48px);
  text-align: center;
  margin-bottom: 4px;
  line-height: 1;
}
.fact-name {
  font-family: inherit;
  font-size: clamp(18px, 2.6vw, 24px);
  font-weight: 900;
  color: #1e3a8a;
  margin-bottom: 8px;
  text-align: center;
}
.fact-text {
  font-size: clamp(13px, 1.7vw, 16px);
  line-height: 1.45;
  margin-bottom: 14px;
  text-align: center;
}
.fact-text:empty { display: none; }
.fact-replay {
  display: block;
  margin: 0 auto;
  background: linear-gradient(135deg, #ec4899, #db2777);
  color: white;
  font-family: inherit;
  font-weight: bold;
  font-size: clamp(13px, 1.6vw, 15px);
  padding: 9px 20px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}
.fact-replay:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.2);
}
.fact-close {
  position: absolute;
  top: 6px; right: 12px;
  background: transparent;
  color: #6b7280;
  border: none;
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  font-family: inherit;
}
.fact-close:hover { color: #1e1b4b; }

/* Off screen */
.off-screen {
  position: fixed; inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.power-on-btn {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #991b1b);
  color: white;
  font-size: 32px;
  border: 3px solid #ef4444;
  cursor: pointer;
  box-shadow: 0 0 30px rgba(239,68,68,0.5), inset 0 0 15px rgba(0,0,0,0.4);
  animation: pulsePower 2s ease-in-out infinite;
}
@keyframes pulsePower {
  0%, 100% { box-shadow: 0 0 30px rgba(239,68,68,0.5), inset 0 0 15px rgba(0,0,0,0.4); }
  50% { box-shadow: 0 0 50px rgba(239,68,68,0.8), inset 0 0 15px rgba(0,0,0,0.4); }
}

/* Mobile landscape optimizations */
@media (max-width: 900px) and (orientation: landscape) {
  .tablet { padding: 8px; border-radius: 18px; }
  .screen { border-radius: 12px; }
  .mode-btn { min-width: 80px; padding: 5px 10px 5px 12px; gap: 6px; }
  .mode-icon { width: 22px; height: 22px; font-size: 11px; }
  .power-btn { width: 36px; height: 36px; font-size: 16px; }
  .vol-btn, .lang-switch { width: 28px; height: 28px; font-size: 12px; }
}
