/* ============================================================
   Reef Companion — full pixel-art treatment
   Background PNGs + sprites generated by
   pipeline/assets/make_web_pixel_assets.py
   ============================================================ */

@font-face {
  font-family: "Press Start 2P";
  src: url("assets/px/press-start-2p.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  /* lighter pixel face for body text — same aesthetic, easier to read long letters */
  font-family: "VT323";
  src: url("assets/px/vt323.woff2") format("woff2");
  font-display: swap;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --ink: #1d2b3a;
  --paper: #eef1f0;
  --paper-2: #dde3e1;
  --accent: #1b8a9e;
  --px-font: "Press Start 2P", monospace;
  --px-body: "VT323", monospace;
  --hard-shadow: 4px 4px 0 rgba(9, 20, 32, .45);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--px-body);
  background: #081225;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

img { image-rendering: pixelated; }

/* ---------- scene: one full-bleed underwater painting ---------- */

#scene {
  position: fixed; inset: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center bottom;
  image-rendering: pixelated;
  transition: filter 1.2s ease;
}
#scene.time-morning   { background-image: url("assets/px/bg_morning.png"); }
#scene.time-afternoon { background-image: url("assets/px/bg_afternoon.png"); }
#scene.time-sunset    { background-image: url("assets/px/bg_sunset.png"); }
#scene.time-night     { background-image: url("assets/px/bg_night.png"); }
#scene.drifted { filter: saturate(.6) brightness(.92); }

/* hotspots painted into the background */
#moonSpot, #pinkCoralSpot {
  position: absolute; background: none; border: none; z-index: 5;
}
#moonSpot { top: 1%; right: 8%; width: 30%; height: 13%; display: none; }
.time-night #moonSpot { display: block; }
#pinkCoralSpot { left: 60%; bottom: 5%; width: 20%; height: 11%; }

/* ---------- creature: centered ---------- */

#creatureWrap {
  position: absolute; left: 0; right: 0; bottom: 34%;
  display: flex; justify-content: center;
  pointer-events: none;
  z-index: 4;
}
#creature {
  width: min(52vw, 250px);
  pointer-events: auto;
  filter: drop-shadow(0 8px 0 rgba(6, 18, 34, .35));
  animation: bob 3.6s ease-in-out infinite;
  cursor: pointer;
  transition: width .8s steps(6), opacity .6s ease;
}
#creature.stage-1 { width: min(62vw, 310px); }
#creature.stage-2 { width: min(74vw, 380px); }
#creature.sleeping { animation: bob 6.5s steps(5) infinite; filter: drop-shadow(0 8px 0 rgba(6,18,34,.35)) brightness(.8); }
#creature.eating   { animation: chomp .5s steps(3) 2; }
#creature.happy    { animation: hop .55s steps(4) 2; }
#creature.wiggle   { animation: wiggle .5s steps(4) 1; }
@keyframes bob    { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
@keyframes chomp  { 0%,100% { transform: scale(1,1);} 40% { transform: scale(1.06,.92);} 70% { transform: scale(.97,1.05);} }
@keyframes hop    { 0%,100% { transform: translateY(0);} 45% { transform: translateY(-22px);} }
@keyframes wiggle { 0%,100% { transform: rotate(0);} 25% { transform: rotate(4deg);} 75% { transform: rotate(-4deg);} }
.reduced-motion #creature { animation: none !important; }

/* ---------- the egg (onboarding hatch) ---------- */

#eggWrap {
  position: absolute; left: 50%; bottom: 0;
  transform: translateX(-50%);
  pointer-events: none;
}
#egg {
  width: min(30vw, 150px); display: block;
  pointer-events: auto; cursor: pointer;
  animation: bob 3.2s ease-in-out infinite;
  filter: drop-shadow(0 8px 0 rgba(6, 18, 34, .35));
}
#egg.wobble { animation: eggWobble .5s steps(4) 1; }
@keyframes eggWobble {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(9deg); }
  75% { transform: rotate(-9deg); }
}
#eggCue {
  position: absolute; inset: -20px;
  border: 3px dashed rgba(255, 255, 255, .9); border-radius: 50%;
  animation: markerPulse 1.6s steps(4) infinite;
}
#coverCreature.egg { width: min(36vw, 180px); }

/* ---------- world objects ---------- */

.world-btn {
  position: absolute; z-index: 5;
  background: none; border: none; padding: 4px;
  cursor: pointer;
  filter: drop-shadow(3px 3px 0 rgba(6, 18, 34, .4));
}
.world-btn img { width: 54px; display: block; }
.world-btn:active { transform: translate(2px, 2px); filter: none; }
#pouch    { left: 4%;  bottom: calc(env(safe-area-inset-bottom, 0px) + 3%); }
#conch    { right: 4%; bottom: calc(env(safe-area-inset-bottom, 0px) + 3%); }
#playSpot { right: 6%; bottom: 38%; animation: bob 4.5s steps(5) infinite; }
#playSpot img { width: 40px; }
#bottle   { left: 40%; bottom: 12%; animation: sink 3s steps(6) infinite alternate; }
#bottle img { width: 46px; }
@keyframes sink { from { transform: translateY(0); } to { transform: translateY(10px); } }

#decor { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.decor-item { position: absolute; animation: bloomIn .9s steps(5) both; }
.decor-item img { width: 44px; }
@keyframes bloomIn { from { transform: scale(0); } to { transform: scale(1); } }

/* coral garden (Lagarva's arrange mode) */
#gardenMarkers { position: absolute; inset: 0; z-index: 7; }
.garden-marker {
  position: absolute; width: 38px; height: 38px;
  border: 2px dashed rgba(238, 241, 240, .8); border-radius: 50%;
  background: rgba(238, 241, 240, .12);
  cursor: pointer;
  animation: markerPulse 2s steps(4) infinite;
}
@keyframes markerPulse { 50% { border-color: rgba(238, 241, 240, .35); } }
.garden-mode #decor { z-index: 8; }  /* above the markers so items stay tappable */
.garden-mode .decor-item { pointer-events: auto; cursor: pointer; }
.garden-mode .decor-item img { animation: bob 2.2s steps(4) infinite; } /* reads as movable */
.decor-item.selected { filter: drop-shadow(0 0 6px #fff) drop-shadow(0 2px 3px rgba(0,20,40,.3)); }
.decor-item.selected img { animation: bob 1s steps(4) infinite; }
#gardenBar {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 60px);
  left: 50%; transform: translateX(-50%); z-index: 12;
  background: var(--paper); border: 3px solid var(--ink);
  box-shadow: var(--hard-shadow);
  font-family: var(--px-font); font-size: 8px; line-height: 1.7; color: var(--ink);
  padding: 10px 14px; max-width: 80vw; text-align: center;
}
#gardenBar .overlay-x { top: -14px; right: -12px; width: 28px; height: 28px; font-size: 10px;
  box-shadow: 2px 2px 0 rgba(9, 20, 32, .45); }

#debris { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.debris-item { position: absolute; cursor: pointer; pointer-events: auto;
  animation: bob 5s steps(5) infinite; }
.debris-item img { width: 38px; opacity: .92; }
.debris-cloud { width: 120px; height: 74px;
  background:
    radial-gradient(ellipse, rgba(205, 214, 205, .5), transparent 68%);
  image-rendering: auto; }

/* ---------- particles ---------- */

#particles { position: absolute; inset: 0; pointer-events: none; z-index: 8; }
.particle { position: absolute; animation: rise 1.4s steps(8) forwards; }
.particle img { width: 22px; }
@keyframes rise { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-64px); opacity: 0; } }
.ripple { position: absolute; border: 3px solid rgba(232, 248, 255, .8);
  width: 14px; height: 14px; transform: translate(-50%,-50%);
  animation: rippleOut 1.1s steps(6) forwards; }
@keyframes rippleOut { to { width: 110px; height: 110px; opacity: 0; } }
.shooting-star { position: absolute; width: 60px; height: 3px;
  background: linear-gradient(90deg, #fff, transparent);
  transform: rotate(24deg);
  animation: shoot 1s steps(10) forwards; }
@keyframes shoot { from { opacity: 0; translate: 0 0; } 15% { opacity: 1; } to { opacity: 0; translate: 42vw 24vh; } }

/* ---------- dialogue box (classic handheld-RPG style, bottom) ---------- */

#speech {
  position: absolute; z-index: 12;
  left: 8px; right: 8px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: var(--paper);
  border: 4px solid var(--ink);
  box-shadow: inset 0 0 0 3px #fbfdfc, 0 4px 0 rgba(9, 20, 32, .45);
  padding: 18px 30px 20px 18px;
  min-height: 68px;
  cursor: pointer;
  animation: popIn .15s steps(2);
}
#speech.raised { bottom: calc(env(safe-area-inset-bottom, 0px) + 104px); }
#speech p { font-family: var(--px-font); font-size: 10px; line-height: 1.9; color: var(--ink); }
#speechX {
  position: absolute; top: -14px; right: -6px;
  width: 30px; height: 30px;
  border: 3px solid var(--ink); background: var(--paper-2);
  font-family: var(--px-font); font-size: 11px; color: var(--ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(9, 20, 32, .45);
}
#speech::after {
  content: "▼";
  position: absolute; right: 12px; bottom: 9px;
  font-family: var(--px-font); font-size: 10px; color: var(--ink);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes popIn { from { transform: scale(.92); opacity: 0; } }

/* ---------- HUD ---------- */

#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 8px;
  font-family: var(--px-font);
  color: #eaf6ff; text-shadow: 2px 2px 0 rgba(9, 20, 32, .6);
  pointer-events: none;
}
#hud button, #moodChip { pointer-events: auto; }
#hudName strong { font-size: 12px; display: block; margin-bottom: 5px; }
#hudName span { font-size: 7px; opacity: .85; letter-spacing: .12em; }
#hudRight { display: flex; gap: 8px; align-items: center; }
#moodChip {
  font-size: 7px; letter-spacing: .08em;
  background: rgba(9, 22, 38, .6);
  border: 2px solid rgba(234, 246, 255, .35);
  padding: 6px 8px;
}
#hud button {
  font-family: var(--px-font); font-size: 14px; color: #eaf6ff;
  background: rgba(9, 22, 38, .6); border: 2px solid rgba(234, 246, 255, .35);
  width: 38px; height: 38px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#hud button img { width: 24px; }
#hud button:active { transform: translate(1px, 1px); }

/* ---------- food tray ---------- */

#foodTray {
  position: fixed; left: 10px; bottom: calc(env(safe-area-inset-bottom, 0px) + 84px);
  z-index: 11;
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: var(--hard-shadow);
  padding: 10px 12px;
  animation: popIn .2s steps(3);
}
#foodTray .overlay-x { top: -16px; right: -12px; width: 30px; height: 30px; font-size: 11px;
  box-shadow: 2px 2px 0 rgba(9, 20, 32, .45); }
.tray-hint { font-family: var(--px-font); font-size: 7px; color: #6a7884; margin-bottom: 8px; padding-right: 16px; }
#foodRow { display: flex; gap: 8px; }
.food {
  padding: 6px; background: var(--paper-2); border: 2px solid var(--ink);
  cursor: grab; touch-action: none; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.food img { width: 30px; }
.food small { font-family: var(--px-font); font-size: 5px; color: #6a7884; white-space: nowrap; }
.food-drag { position: fixed; z-index: 50; pointer-events: none;
  transform: translate(-50%, -50%); }
.food-drag img { width: 36px; }

/* ---------- overlays ---------- */

#letter { z-index: 22; }  /* letters always win over menu sheets */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(6, 18, 34, .72);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.overlay-x {
  position: absolute; top: 10px; right: 10px;
  width: 34px; height: 34px;
  border: 3px solid var(--ink); background: var(--paper-2);
  font-family: var(--px-font); font-size: 13px; color: var(--ink);
  cursor: pointer; z-index: 1;
}
.overlay-x:active { transform: translate(1px, 1px); }
.paper, .panel {
  position: relative;
  width: min(92vw, 420px); max-height: 82vh; overflow-y: auto;
  background: var(--paper);
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 rgba(9, 20, 32, .55);
  padding: 22px 20px;
  color: #3d4a56;
  animation: paperIn .25s steps(4);
}
@keyframes paperIn { from { transform: translateY(24px); opacity: 0; } }
.paper h2, .panel h2 {
  font-family: var(--px-font); font-size: 11px; line-height: 1.8;
  margin-bottom: 12px; color: var(--ink);
}
.naming-sub { font-size: 20px; margin-bottom: 4px; }
#letterBody { white-space: pre-wrap; font-size: 21px; line-height: 1.35; margin-bottom: 18px; }
.btn {
  display: block; width: 100%; padding: 12px;
  border: 3px solid var(--ink);
  background: var(--accent); color: #fff;
  font-family: var(--px-font); font-size: 9px;
  box-shadow: 3px 3px 0 rgba(9, 20, 32, .4);
  cursor: pointer;
}
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn.ghost { background: var(--paper-2); color: var(--ink); margin-top: 8px; }

#naming input {
  width: 100%; font-size: 21px; font-family: inherit; padding: 10px 12px;
  border: 3px solid var(--ink); background: #fff; margin: 10px 0;
}
#nameChips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip { background: var(--paper-2); border: 2px solid var(--ink);
  padding: 8px 10px; font-family: var(--px-font); font-size: 7px;
  color: var(--ink); cursor: pointer; }

/* sheets */
.menu-list { display: grid; gap: 10px; margin-bottom: 8px; }
.menu-list .btn { text-align: left; background: var(--paper-2); color: var(--ink); }
.stat-line { font-family: var(--px-font); font-size: 7px; line-height: 1.9; color: #6a7884; margin: 6px 0 14px; }
.note-grid { display: grid; gap: 8px; margin-bottom: 10px; }
.note-card { background: #fff; padding: 10px 12px; font-size: 19px;
  border: 2px solid var(--ink); cursor: pointer; }
.note-card.locked { opacity: .45; font-style: italic; cursor: default; }
.journal-stage { display: flex; gap: 12px; align-items: center; margin-bottom: 12px;
  background: #fff; padding: 10px; border: 2px solid var(--ink); }
.journal-stage img { width: 72px; }
.journal-stage.locked img { filter: brightness(0) opacity(.35); }
.journal-stage h3 { font-family: var(--px-font); font-size: 9px; margin-bottom: 6px; }
.journal-stage p { font-size: 16px; line-height: 1.2; color: #6a7884; }
.setting-row { display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 2px solid var(--paper-2); font-size: 20px; }
.setting-row .btn { width: auto; }

/* ---------- bubble game ---------- */

#game { position: fixed; inset: 0; z-index: 15; }
#gameHud {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 12px); left: 50%;
  transform: translateX(-50%);
  background: rgba(9, 22, 38, .7); color: #eaf6ff;
  border: 2px solid rgba(234, 246, 255, .35);
  padding: 8px 14px; font-family: var(--px-font); font-size: 10px; z-index: 2;
}
#gameArea { position: absolute; inset: 0; }
.bubble { position: absolute; cursor: pointer; animation: floatUp linear forwards; }
.bubble img { width: 100%; }
@keyframes floatUp { to { transform: translateY(-110vh); } }
.pop { position: absolute; pointer-events: none; animation: rise .5s steps(4) forwards; }
.pop img { width: 26px; }

/* ---------- starlight flight ---------- */

#flight {
  position: fixed; inset: 0; z-index: 15;
  background-image: url("assets/px/bg_night.png");
  background-size: cover; background-position: center bottom;
  image-rendering: pixelated;
  touch-action: none;
  overflow: hidden;
}
#flightHud {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 12px); left: 50%;
  transform: translateX(-50%);
  background: rgba(9, 22, 38, .7); color: #eaf6ff;
  border: 2px solid rgba(234, 246, 255, .35);
  padding: 8px 14px; font-family: var(--px-font); font-size: 10px; z-index: 3;
}
#flightArea { position: absolute; inset: 0; }
#flightCoralux {
  position: absolute; left: auto; right: 8%; top: 40%;
  width: min(38vw, 190px);
  filter: drop-shadow(0 0 10px rgba(160, 240, 255, .45));
  z-index: 2;
}
.flight-ring { position: absolute; z-index: 1; }
.flight-ring img { width: 62px; }
.flight-ring.hit img { animation: rise 0.6s steps(4) forwards; }
.flight-streak {
  position: absolute; z-index: 0; opacity: .7;
}
.flight-streak img { width: 12px; }
#flightHint {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  left: 0; right: 0; text-align: center;
  font-family: var(--px-font); font-size: 8px; color: rgba(234, 246, 255, .8);
  text-shadow: 2px 2px 0 rgba(9, 20, 32, .6);
  animation: blink 2s steps(2) infinite;
  pointer-events: none;
}

/* ---------- ambient reef life ---------- */

#ambient { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.ambient-bubble { position: absolute; animation: ambientRise linear forwards; }
.ambient-bubble img { width: 14px; opacity: .55; }
@keyframes ambientRise {
  from { transform: translateY(0); opacity: .6; }
  to { transform: translateY(-58vh); opacity: 0; }
}
.ambient-fish { position: absolute; }
.ambient-fish img { width: 26px; opacity: .8; }
.side-bubble img { opacity: .4; }
.reduced-motion #ambient { display: none; }

/* ---------- cover page ---------- */

#cover {
  position: fixed; inset: 0; z-index: 40;
  background-image: url("assets/px/bg_sunset.png");
  background-size: cover; background-position: center bottom;
  image-rendering: pixelated;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: opacity .5s steps(5);
}
#cover.fade-out { opacity: 0; }
#coverInner { text-align: center; padding: 0 24px; }
#coverCreature {
  width: min(56vw, 280px);
  animation: bob 3.6s ease-in-out infinite;
  filter: drop-shadow(0 10px 0 rgba(6, 18, 34, .3));
}
#coverTitle {
  font-family: var(--px-font); font-size: 22px; color: #fff;
  text-shadow: 3px 3px 0 rgba(9, 20, 32, .6);
  margin: 26px 0 10px; letter-spacing: .04em;
}
#coverSub {
  font-family: var(--px-body); font-size: 23px; color: #ffeede;
  text-shadow: 2px 2px 0 rgba(9, 20, 32, .5);
  margin-bottom: 48px;
}
#coverPrompt {
  font-family: var(--px-font); font-size: 9px; color: #fff;
  text-shadow: 2px 2px 0 rgba(9, 20, 32, .6);
  animation: blink 1.6s steps(2) infinite;
}

/* ---------- onboarding cues ---------- */

.materialize { animation: materialize 1s steps(7) both !important; }
@keyframes materialize {
  from { opacity: 0; transform: scale(.45); }
  to { opacity: 1; transform: scale(1); }
}
.cued::after {
  content: "";
  position: absolute; inset: -12px;
  border: 3px dashed rgba(255, 255, 255, .9); border-radius: 50%;
  animation: markerPulse 1.6s steps(4) infinite;
  pointer-events: none;
}

/* ---------- evolution & toast ---------- */

#evoGlow {
  position: fixed; inset: 0; z-index: 14; pointer-events: none;
  background-image: url("assets/px/fx_glow.png");
  background-size: cover; background-position: center;
  image-rendering: pixelated;
  animation: evoPulse 3.2s steps(16);
}
@keyframes evoPulse { 0% { opacity: 0; } 25% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }

#toast {
  pointer-events: none;
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 66px);
  left: 50%; transform: translateX(-50%); z-index: 30;
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: var(--hard-shadow);
  padding: 10px 14px;
  font-family: var(--px-font); font-size: 8px; line-height: 1.7;
  max-width: 84vw; text-align: center;
  animation: popIn .2s steps(3);
}

.hidden { display: none !important; }
