:root {
  --ink: #17324a;
  --card: rgba(255, 255, 255, .82);
  --accent: #ff7a59;
  --accent-2: #2bb3c0;
  --radius: 18px;
  font-family: "Nunito", "Quicksand", ui-rounded, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: #0b4f6c; overflow-x: hidden; }
button { font: inherit; cursor: pointer; }

/* ------------------------------------------------------------ ocean ---- */
.ocean {
  position: fixed; inset: 0; overflow: hidden; z-index: 0;
  background: linear-gradient(180deg, #8fe3f0 0%, #3fb7d4 38%, #1b86b0 75%, #126f96 100%);
  transition: background 1s;
}
.ocean.night { background: linear-gradient(180deg, #123a63 0%, #0c2b4f 45%, #08203c 100%); }
.rays { position: absolute; inset: -10% 0 0 0; pointer-events: none; }
.rays i {
  position: absolute; top: -10%; width: 14%; height: 90%;
  background: linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0));
  transform-origin: top center; filter: blur(6px);
  animation: ray 9s ease-in-out infinite alternate;
}
.rays i:nth-child(1) { left: 12%; transform: rotate(14deg); }
.rays i:nth-child(2) { left: 36%; transform: rotate(8deg); animation-delay: -3s; width: 9%; }
.rays i:nth-child(3) { left: 58%; transform: rotate(-6deg); animation-delay: -5s; }
.rays i:nth-child(4) { left: 80%; transform: rotate(-12deg); animation-delay: -1s; width: 8%; }
.night .rays { opacity: .25; }
@keyframes ray { from { opacity: .35; } to { opacity: .9; } }

.sand { position: absolute; bottom: 0; left: 0; width: 100%; height: 26vh; min-height: 140px; }
.night .sand { filter: brightness(.45) saturate(.7); }
.weeds { position: absolute; inset: 0; pointer-events: none; }
.weed {
  position: absolute; bottom: 8vh; width: 34px; transform-origin: bottom center;
  animation: sway 5s ease-in-out infinite alternate;
}
.night .weed, .night .deco { filter: brightness(.5); }
@keyframes sway { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }
.deco { position: absolute; bottom: 7vh; }
.deco.shell svg { width: 42px; }
.deco.rock svg { width: 130px; }

.bubbles i {
  position: absolute; bottom: -20px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.9), rgba(255,255,255,.15) 60%);
  border: 1px solid rgba(255,255,255,.5);
  animation: rise linear forwards;
}
@keyframes rise {
  0% { transform: translate(0, 0); opacity: 0; }
  10% { opacity: .9; }
  50% { transform: translate(12px, -55vh); }
  100% { transform: translate(-8px, -110vh); opacity: .2; }
}
.glow i {
  position: absolute; width: 4px; height: 4px; border-radius: 50%;
  background: #8ffcff; box-shadow: 0 0 8px 2px #4ff0ff;
  animation: twinkle 6s ease-in-out infinite;
}
@keyframes twinkle { 0%,100% { opacity: .1; } 50% { opacity: .9; } }

/* ------------------------------------------------------------ layout --- */
.app {
  position: relative; z-index: 1; min-height: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 14px 24px; gap: 12px;
}
.card {
  background: var(--card); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0, 40, 70, .18);
  padding: 14px 18px; width: min(560px, 100%);
}
h1 { margin: 0; font-size: 1.5rem; letter-spacing: .3px; }
.sub { margin: 2px 0 0; opacity: .75; font-size: .92rem; }
.btn {
  border: 0; border-radius: 999px; padding: 11px 20px; font-weight: 800;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 #d85b3c;
  transition: transform .08s, box-shadow .08s, filter .2s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d85b3c; }
.btn:disabled { filter: grayscale(.8) opacity(.6); cursor: default; }
.btn.alt { background: var(--accent-2); box-shadow: 0 4px 0 #1b8792; }
.btn.alt:active { box-shadow: 0 1px 0 #1b8792; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 4px 0 #b9d3df; }
input[type=text] {
  font: inherit; border: 2px solid #b9d3df; border-radius: 12px; padding: 10px 14px;
  width: 100%; background: #fff; color: var(--ink);
}
input[type=text]:focus { outline: none; border-color: var(--accent-2); }

/* --------------------------------------------------------- landing ----- */
.hero { margin-top: 6vh; text-align: center; }
.hero .logo { width: 180px; margin: -10px auto 4px; animation: bob 3.5s ease-in-out infinite; }
.hero h1 { font-size: 2.2rem; }
.hatch { display: flex; gap: 10px; margin-top: 14px; }
.hatch .btn { white-space: nowrap; }
.how { font-size: .92rem; line-height: 1.45; }
.how ul { margin: 6px 0 0; padding-left: 20px; }
.mine a { color: var(--ink); font-weight: 700; }
.mine li { margin: 4px 0; }
.error { color: #c0392b; font-weight: 700; min-height: 1.2em; margin: 6px 0 0; }

/* ------------------------------------------------------------ game ----- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.badge {
  background: #fff3c4; border-radius: 999px; padding: 4px 12px; font-weight: 800; font-size: .85rem;
  white-space: nowrap;
}
.stage-area {
  position: relative; width: min(560px, 100%); height: 330px;
  display: flex; align-items: flex-end; justify-content: center;
}
.pet {
  position: relative; width: 230px; cursor: pointer; user-select: none;
  transition: opacity 2s, filter 2s, transform .6s;
  -webkit-tap-highlight-color: transparent;
}
.pet .inner { animation: bob 3.5s ease-in-out infinite; transform-origin: 50% 60%; }
.pet .starfish-svg { width: 100%; display: block; overflow: visible; }
.pet.asleep .inner { animation: breathe 4s ease-in-out infinite; }
.pet.spin .inner { animation: spin .9s ease-in-out; }
.pet.wiggle .inner { animation: wiggle .5s ease-in-out; }
.pet.drifting .inner { animation: drift 6s ease-in-out infinite; }
.eyes { animation: blink 5s infinite; transform-origin: 0 -8px; }
.tear { animation: tear 2.5s ease-in infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-10px) rotate(2deg); } }
@keyframes breathe { 0%,100% { transform: scale(1, 1); } 50% { transform: scale(1.03, .97); } }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-10deg) scale(1.05); } 75% { transform: rotate(10deg) scale(1.05); } }
@keyframes drift { 0%,100% { transform: translateX(0) rotate(-4deg); } 50% { transform: translateX(26px) rotate(8deg); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes tear { 0% { transform: translateY(0); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(16px); opacity: 0; } }

.zzz { position: absolute; right: 8px; top: 0; font-weight: 900; color: #fff; text-shadow: 0 2px 6px rgba(0,0,0,.3); pointer-events: none; }
.zzz span { position: absolute; animation: zzz 3s linear infinite; opacity: 0; }
.zzz span:nth-child(2) { animation-delay: 1s; font-size: 1.3em; }
.zzz span:nth-child(3) { animation-delay: 2s; font-size: 1.6em; }
@keyframes zzz { 0% { transform: translate(0, 0); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(30px, -70px); opacity: 0; } }

.speech {
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  background: #fff; border-radius: 16px; padding: 8px 14px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(0, 40, 70, .2); max-width: 90%; text-align: center;
  opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none;
}
.speech.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.speech::after {
  content: ""; position: absolute; bottom: -8px; left: 50%; margin-left: -8px;
  border: 8px solid transparent; border-top-color: #fff; border-bottom: 0;
}

.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.fx i { position: absolute; font-style: normal; animation: floatup 1.6s ease-out forwards; }
.fx i.fall { animation: fall 1.2s ease-in forwards; }
@keyframes floatup { from { transform: translateY(0) scale(.6); opacity: 1; } to { transform: translateY(-120px) scale(1.2); opacity: 0; } }
@keyframes fall { from { transform: translateY(-140px); opacity: 0; } 20% { opacity: 1; } to { transform: translateY(0); opacity: 0; } }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.stat label { display: flex; justify-content: space-between; font-weight: 800; font-size: .88rem; }
.bar { height: 12px; background: #dbeaf1; border-radius: 999px; overflow: hidden; margin-top: 4px; }
.bar b { display: block; height: 100%; border-radius: 999px; transition: width .6s, background .6s; }

.actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.actions .btn { padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .82rem; }
.actions .btn .ico { font-size: 1.5rem; line-height: 1; }

.drift-warn {
  background: #fff0e6; border: 2px dashed #ff9a6b; color: #8a3b17; font-weight: 700;
  border-radius: 14px; padding: 10px 14px; text-align: center;
}
.save { font-size: .9rem; }
.save .row { display: flex; gap: 8px; margin-top: 8px; }
.save input { font-size: .85rem; font-family: ui-monospace, monospace; }

.modal {
  position: fixed; inset: 0; z-index: 10; background: rgba(5, 30, 50, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal .card { text-align: center; background: rgba(255,255,255,.96); }
.modal h2 { margin: 4px 0 8px; }

.vanished { text-align: center; }
.vanished .ghost-star { width: 140px; margin: 0 auto; opacity: .25; filter: grayscale(.4) blur(.5px); animation: drift 6s ease-in-out infinite; }
.footer { opacity: .7; font-size: .8rem; color: #fff; text-align: center; }
.footer a { color: #fff; }

@media (max-width: 480px) {
  .stage-area { height: 280px; }
  .pet { width: 190px; }
  .actions { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .actions .btn { font-size: .7rem; }
  .hatch { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
