:root {
  --ocean-teal: #0D9488;
  --ocean-deep: #075985;
  --coral: #F97316;
  --sky: #38BDF8;
  --sand: #FDE68A;
  --ink: #1E2937;
  --white: #FFFFFF;
  --focus: #F97316;
  --touch-min: 56px;
}

*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: #0E7490;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

.living-ocean {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.42), transparent 18%),
    linear-gradient(180deg, #62D6EE 0%, #0D9488 42%, #075985 100%);
}

.ocean-backdrop {
  position: absolute;
  inset: -6%;
  background: url("../assets/maps/ocean-map-home-hybrid-b-grok-v1.jpg") center / cover no-repeat;
  opacity: 0.18;
  filter: saturate(0.95) blur(2.2px);
}

.light-rays {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(105deg, transparent 0 18%, rgba(255,255,255,0.22) 21%, transparent 31% 100%),
    linear-gradient(80deg, transparent 0 56%, rgba(255,255,255,0.16) 61%, transparent 72% 100%);
  mix-blend-mode: screen;
  opacity: 0.65;
  pointer-events: none;
}

.bubble-field,
.animal-layer,
.creation-layer,
.celebration-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bubble {
  position: absolute;
  width: var(--size);
  height: var(--size);
  left: var(--x);
  bottom: -60px;
  border: 2px solid rgba(255,255,255,0.7);
  border-radius: 50%;
  background: rgba(255,255,255,0.13);
  animation: bubble-rise var(--duration) linear infinite;
  animation-delay: var(--delay);
}

@keyframes bubble-rise {
  to { transform: translate3d(var(--drift), -112vh, 0); opacity: 0; }
}

.swimmer,
.made-pal {
  --x: 50vw;
  --y: 50vh;
  --scale: 1;
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: clamp(96px, 16vw, 154px);
  height: clamp(96px, 16vw, 154px);
  min-width: 96px;
  min-height: 96px;
  padding: 0;
  border: 5px solid rgba(255,255,255,0.78);
  border-radius: 42% 58% 50% 50% / 48% 44% 56% 52%;
  background: rgba(255,255,255,0.42);
  box-shadow: 0 16px 38px rgba(7, 89, 133, 0.25), inset 0 0 0 3px rgba(255,255,255,0.45);
  cursor: pointer;
  overflow: hidden;
  pointer-events: auto;
  transform: translate3d(-50%, -50%, 0) scale(var(--scale));
  animation: swim-drift var(--speed) ease-in-out infinite alternate;
  animation-delay: var(--delay);
}

.swimmer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.swimmer .svg-fallback,
.made-pal svg {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.76);
}

@keyframes swim-drift {
  from { transform: translate3d(calc(-50% - var(--dx)), calc(-50% - var(--dy)), 0) scale(var(--scale)) rotate(-2deg); }
  to { transform: translate3d(calc(-50% + var(--dx)), calc(-50% + var(--dy)), 0) scale(var(--scale)) rotate(2deg); }
}

.swimmer.attract,
.made-pal.attract { animation-name: swim-drift, happy-wiggle; animation-duration: var(--speed), 700ms; }
.guide-button.attract { box-shadow: 0 0 0 9px rgba(253,230,138,0.58), 0 16px 36px rgba(15,23,42,0.2); }

.riddle-choice { box-shadow: 0 0 0 8px rgba(253,230,138,0.75), 0 0 28px rgba(253,230,138,0.9); }
.riddle-wrong { animation: gentle-shake 360ms ease; }

@keyframes happy-wiggle {
  20% { rotate: -7deg; }
  50% { rotate: 8deg; }
  80% { rotate: -4deg; }
}

@keyframes gentle-shake {
  25% { translate: -8px 0; }
  50% { translate: 8px 0; }
  75% { translate: -4px 0; }
}

.guide-button,
.scene-object,
.parent-shell {
  position: absolute;
  z-index: 20;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  border: 0;
  cursor: pointer;
  pointer-events: auto;
}

.guide-button {
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 106px;
  height: 106px;
  padding: 8px;
  border-radius: 42% 58% 50% 50% / 48% 44% 56% 52%;
  background: rgba(255,255,255,0.82);
  box-shadow: 0 14px 32px rgba(15,23,42,0.18);
  animation: guide-bob 5s ease-in-out infinite;
}

.guide-art {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border: 5px solid rgba(255,255,255,0.92);
  border-radius: inherit;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.42);
}

@keyframes guide-bob {
  50% { transform: translateY(-8px) rotate(-1deg); }
}

.scene-object {
  width: 112px;
  height: 112px;
  padding: 8px;
  border-radius: 30px;
  background: rgba(255,255,255,0.68);
  box-shadow: 0 14px 30px rgba(15,23,42,0.18);
}

.color-object { right: 20px; bottom: 22px; }
.book-object { right: 22px; top: 22px; }
.object-art { display: block; width: 100%; height: 100%; filter: drop-shadow(0 7px 8px rgba(15,23,42,0.14)); }

.parent-shell {
  left: max(14px, env(safe-area-inset-left));
  top: max(14px, env(safe-area-inset-top));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 6px;
  background: rgba(255,255,255,0.38);
  opacity: 0.78;
}

.parent-shell svg { width: 100%; height: 100%; display: block; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}

.overlay[hidden] { display: none; }
.overlay-scrim {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(8,47,73,0.52);
  cursor: pointer;
}

.round-close {
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 3;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 5px solid #FFFFFF;
  background: #F97316;
  color: #FFFFFF;
  font-size: 44px;
  line-height: 1;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(15,23,42,0.18);
}

.encounter-card,
.color-workbench,
.book-pages,
.parent-panel {
  position: relative;
  z-index: 1;
  width: min(94vw, 760px);
  max-height: 94vh;
  overflow: auto;
  border-radius: 28px;
  background: rgba(255,255,255,0.95);
  box-shadow: 0 26px 60px rgba(15,23,42,0.34);
}

.encounter-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 22px 18px 26px;
  background:
    radial-gradient(circle at 22% 12%, rgba(255,255,255,0.92), transparent 28%),
    linear-gradient(180deg, rgba(224,242,254,0.98) 0%, rgba(204,251,241,0.96) 58%, rgba(186,230,253,0.96) 100%);
  border: 4px solid rgba(255,255,255,0.72);
}

.encounter-stage {
  width: min(60vh, 60vw, 430px);
  aspect-ratio: 1;
  border-radius: 44% 56% 51% 49% / 49% 44% 56% 51%;
  overflow: hidden;
  background: #BAE6FD;
  border: 7px solid #FFFFFF;
  box-shadow: 0 16px 42px rgba(7,89,133,0.26);
  animation: closeup-bob 4s ease-in-out infinite;
}

.encounter-stage img,
.encounter-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.encounter-stage .stage-svg {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: #E0F2FE;
}

.encounter-stage .stage-svg svg { width: 82%; height: 82%; }

@keyframes closeup-bob {
  50% { transform: translateY(-8px) rotate(1deg); }
}

.encounter-card h1,
.color-header h1,
.book-pages h1,
.parent-panel h1 {
  margin: 2px 76px 0;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.05;
  color: #0F766E;
  text-align: center;
}

.spoken-caption {
  min-height: 58px;
  max-width: 640px;
  margin: 0;
  padding: 8px 14px;
  border-radius: 18px;
  background: #F0FDFA;
  color: #134E4A;
  font-size: clamp(18px, 2.4vw, 22px);
  font-weight: 750;
  text-align: center;
}

.ask-buttons {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 14px;
  padding: 8px 4px 0;
  justify-items: center;
}

.ask-button {
  width: clamp(96px, 16vw, 122px);
  height: clamp(96px, 16vw, 122px);
  min-height: 96px;
  border: 5px solid rgba(255,255,255,0.92);
  border-radius: 50%;
  background: var(--ask-bg);
  box-shadow: inset 0 0 0 5px var(--ask-color), 0 12px 24px rgba(15,23,42,0.16);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.ask-button svg { width: 72%; height: 72%; filter: drop-shadow(0 3px 0 rgba(255,255,255,0.65)); }
.ask-button.answered { background: #FEF3C7; transform: scale(1.04); }

.riddle-panel {
  position: absolute;
  left: 50%;
  top: 18px;
  z-index: 30;
  width: min(86vw, 560px);
  min-height: 92px;
  transform: translateX(-50%);
  padding: 14px 86px 14px 92px;
  border-radius: 28px;
  background: rgba(255,255,255,0.94);
  box-shadow: 0 18px 36px rgba(15,23,42,0.24);
  pointer-events: auto;
}

.riddle-panel .round-close {
  width: 56px;
  height: 56px;
  font-size: 36px;
  right: 12px;
  top: 18px;
}

.riddle-replay {
  position: absolute;
  left: 14px;
  top: 16px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 0;
  background: #0D9488;
}

.riddle-replay span {
  display: block;
  width: 30px;
  height: 30px;
  margin: 16px auto;
  background: #FFFFFF;
  clip-path: polygon(0 34%, 36% 34%, 72% 0, 72% 100%, 36% 66%, 0 66%);
}

.riddle-panel p {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 28px);
  font-weight: 850;
  color: #0F766E;
}

.color-workbench {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  padding: 18px;
  height: min(94vh, 900px);
}

.color-header {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
}

.done-button {
  position: absolute;
  left: 14px;
  top: 14px;
  width: 70px;
  height: 70px;
  border: 0;
  border-radius: 50%;
  background: #16A34A;
  box-shadow: 0 10px 22px rgba(15,23,42,0.18);
}

.done-button span {
  display: block;
  width: 38px;
  height: 24px;
  margin: 18px auto;
  border-left: 8px solid #FFFFFF;
  border-bottom: 8px solid #FFFFFF;
  transform: rotate(-45deg);
}

.creature-picker,
.palette {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px;
}

.creature-choice {
  flex: 0 0 86px;
  width: 86px;
  height: 86px;
  border-radius: 22px;
  border: 4px solid transparent;
  background: #E0F2FE;
}

.creature-choice.active { border-color: #F97316; background: #FEF3C7; }
.creature-choice svg { width: 74px; height: 74px; }

.color-canvas {
  min-height: 260px;
  display: grid;
  place-items: center;
  border-radius: 28px;
  background: linear-gradient(180deg, #E0F2FE, #CCFBF1);
  overflow: hidden;
}

.color-canvas svg {
  width: min(86vw, 520px);
  height: min(48vh, 420px);
}

.fill-region {
  cursor: pointer;
  transition: fill 120ms ease;
}

.palette-button {
  flex: 0 0 68px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 5px solid #FFFFFF;
  box-shadow: 0 0 0 3px rgba(15,23,42,0.2);
}

.palette-button.active { box-shadow: 0 0 0 5px #F97316; }
.palette-button.rainbow {
  background: conic-gradient(#EF4444, #F97316, #FDE047, #22C55E, #38BDF8, #8B5CF6, #EF4444);
}

.made-pal {
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,0.82);
}

.made-pal svg { padding: 4px; }

.swim-away { animation: swim-off 1.1s ease-in forwards; }
@keyframes swim-off {
  to { transform: translate3d(110vw, -30vh, 0) rotate(18deg) scale(0.55); opacity: 0; }
}

.book-pages {
  padding: 24px 18px;
}

.book-content {
  display: grid;
  gap: 20px;
  padding-top: 12px;
}

.book-section h2 {
  margin: 0 0 8px;
  color: #075985;
  font-size: 22px;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 12px;
}

.sticker-button {
  min-height: 126px;
  border: 0;
  border-radius: 24px;
  background: #F8FAFC;
  box-shadow: inset 0 0 0 4px #BAE6FD;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 6px;
}

.sticker-button.locked { filter: grayscale(1); opacity: 0.45; }
.sticker-button img,
.sticker-button svg { width: 82px; height: 82px; border-radius: 18px; object-fit: cover; }
.sticker-button span { font-size: 14px; font-weight: 800; }

.parent-panel {
  max-width: 560px;
  padding: 28px 18px 22px;
}

.parent-panel p {
  max-width: 420px;
  margin: 8px auto 18px;
  text-align: center;
  font-size: 18px;
}

.parent-actions,
.progress-readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.primary-button,
.plain-button,
.danger-button {
  min-height: 60px;
  border: 0;
  border-radius: 18px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button { background: #0D9488; color: #FFFFFF; }
.plain-button { background: #E0F2FE; color: #075985; }
.danger-button { width: 100%; margin-top: 14px; background: #FEE2E2; color: #991B1B; }

.toggle-row {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 8px;
  font-size: 19px;
  font-weight: 750;
}

.toggle-row input { width: 38px; height: 38px; }

.progress-readout {
  margin: 12px 0 0;
}

.progress-readout div {
  padding: 12px;
  border-radius: 18px;
  background: #F0FDFA;
}

.progress-readout dt { font-size: 13px; color: #0F766E; font-weight: 800; }
.progress-readout dd { margin: 0; font-size: 24px; font-weight: 900; }

.confetti,
.pop-bubble {
  position: absolute;
  pointer-events: none;
}

.confetti {
  width: 14px;
  height: 22px;
  left: var(--x);
  top: -24px;
  border-radius: 5px;
  background: var(--c);
  animation: confetti-fall 1300ms ease-in forwards;
}

@keyframes confetti-fall {
  to { transform: translate3d(var(--dx), 105vh, 0) rotate(520deg); opacity: 0; }
}

.pop-bubble {
  width: var(--size);
  height: var(--size);
  left: var(--x);
  top: var(--y);
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.88);
  animation: pop-bubble 900ms ease-out forwards;
}

@keyframes pop-bubble {
  to { transform: translateY(-90px) scale(1.6); opacity: 0; }
}

.speech-fallback {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 300;
  max-width: 88vw;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 16px;
  background: #FEF3C7;
  color: #78350F;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(15,23,42,0.18);
}

.speech-fallback:empty { display: none; }

@media (orientation: portrait) {
  .swimmer { width: clamp(100px, 19vw, 142px); height: clamp(100px, 19vw, 142px); }
  .guide-button { max-width: 230px; }
  .scene-object { width: 98px; height: 98px; }
  .object-art { height: 70px; }
  .ask-buttons { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .encounter-stage { width: min(54vh, 76vw, 440px); }
}

@media (max-width: 620px) {
  .guide-button { width: 96px; padding: 10px; }
  .riddle-panel { padding-right: 76px; }
}

@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;
  }
}

body.reduced-motion .bubble,
body.reduced-motion .swimmer,
body.reduced-motion .made-pal,
body.reduced-motion .guide-button,
body.reduced-motion .encounter-stage {
  animation: none !important;
}
