:root {
  --ink: #173c35;
  --forest: #176b55;
  --leaf: #54ad57;
  --lime: #d9f36a;
  --cream: #fffbed;
  --coral: #ff755f;
  --sky: #aee8f4;
  --white: #fff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(145deg, #f7ffe8 0%, #e1f8d3 50%, #c8f1e5 100%);
  font-family: "Nunito", sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: auto;
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  align-items: center;
  gap: clamp(28px, 5vw, 76px);
  padding: clamp(24px, 5vw, 72px);
}

.hero { text-align: center; }

.brand-mark {
  width: 84px;
  height: 84px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  border-radius: 28px 28px 34px 34px;
  color: var(--white);
  background: var(--forest);
  box-shadow: 0 10px 0 #0e4e3d, 0 18px 32px rgba(18, 80, 60, .2);
  transform: rotate(-3deg);
}

.paw { font-size: 44px; filter: grayscale(1) brightness(0) invert(1); }
.eyebrow { margin: 24px 0 0; color: var(--coral); font-weight: 800; text-transform: uppercase; letter-spacing: .14em; }
h1, h2 { font-family: "Baloo 2", sans-serif; }
h1 { margin: -3px 0 0; color: var(--forest); font-size: clamp(48px, 7vw, 78px); line-height: .95; letter-spacing: -.04em; }
.tagline { margin: 18px 0 28px; font-size: clamp(17px, 2vw, 21px); line-height: 1.55; font-weight: 700; }

.catch-card {
  padding: 22px;
  border: 3px solid rgba(23, 107, 85, .12);
  border-radius: 25px;
  background: rgba(255, 255, 255, .75);
  box-shadow: 0 20px 50px rgba(31, 91, 68, .12);
  backdrop-filter: blur(8px);
}

.catch-card label { display: block; font-family: "Baloo 2", sans-serif; font-size: 25px; font-weight: 800; }
.catch-card > p { margin: 0 0 14px; font-size: 14px; }
.code-entry { display: flex; gap: 9px; }
.code-entry input {
  min-width: 0;
  flex: 1;
  padding: 14px 12px;
  border: 3px solid #bdd5c7;
  border-radius: 14px;
  outline: none;
  text-align: center;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: .09em;
}
.code-entry input:focus { border-color: var(--leaf); box-shadow: 0 0 0 4px rgba(84, 173, 87, .16); }
.code-entry button, dialog > button:not(.close) {
  padding: 13px 19px;
  border: 0;
  border-radius: 14px;
  color: var(--white);
  background: var(--coral);
  box-shadow: 0 5px 0 #d95240;
  font-weight: 800;
}
.catch-card .message { margin: 14px 0 0; color: #5c766f; font-size: 12px; }

.habitat-preview {
  position: relative;
  min-height: 610px;
  overflow: hidden;
  border: 7px solid var(--white);
  border-radius: 46px;
  background: linear-gradient(var(--sky) 0 52%, #99d965 52%);
  box-shadow: 0 28px 65px rgba(26, 85, 61, .2);
  isolation: isolate;
}
.habitat-preview::after { content: ""; position: absolute; inset: 0; border: 2px solid rgba(23,107,85,.14); border-radius: 39px; pointer-events: none; z-index: 10; }
.sun { position: absolute; top: 48px; right: 58px; width: 80px; height: 80px; border-radius: 50%; background: #ffe66f; box-shadow: 0 0 0 14px rgba(255,230,111,.25); }
.cloud { position: absolute; width: 105px; height: 28px; border-radius: 30px; background: rgba(255,255,255,.78); }
.cloud::before, .cloud::after { content: ""; position: absolute; bottom: 0; border-radius: 50%; background: inherit; }
.cloud::before { left: 18px; width: 48px; height: 48px; }
.cloud::after { right: 15px; width: 36px; height: 36px; }
.cloud-one { top: 90px; left: 35px; }
.cloud-two { top: 170px; right: 120px; transform: scale(.65); }
.hill { position: absolute; bottom: 80px; border-radius: 50% 50% 0 0; }
.hill-back { left: -130px; width: 480px; height: 240px; background: #67ba5e; }
.hill-front { right: -180px; width: 560px; height: 295px; background: #4ea84e; }
.pond { position: absolute; left: 45px; right: 80px; bottom: 44px; height: 120px; border-radius: 50%; background: #54c8de; box-shadow: inset 0 12px 0 rgba(255,255,255,.25); transform: rotate(-4deg); }
.reeds { position: absolute; right: 52px; bottom: 115px; font-size: 58px; z-index: 2; }
.habitat-copy { position: relative; z-index: 3; margin: 28px; padding: 15px 19px; width: max-content; max-width: calc(100% - 56px); border-radius: 18px; background: rgba(255,255,255,.84); box-shadow: 0 8px 30px rgba(23,60,53,.12); }
.habitat-copy p, .habitat-copy h2, .habitat-copy span { margin: 0; }
.habitat-copy p { color: var(--coral); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.habitat-copy h2 { color: var(--forest); font-size: 28px; line-height: 1.1; }
.habitat-copy span { color: #5b766e; font-size: 13px; font-weight: 700; }
.critter { position: absolute; z-index: 5; left: 38%; bottom: 142px; border: 0; background: transparent; animation: wander 7s ease-in-out infinite alternate; }
.critter-body { position: relative; display: block; font-size: 72px; filter: drop-shadow(0 7px 3px rgba(21,76,53,.15)); animation: bob .8s ease-in-out infinite alternate; }
.critter-shadow { position: absolute; left: 13px; right: 13px; bottom: 3px; height: 15px; border-radius: 50%; background: rgba(26,77,53,.24); }
.hidden { display: none; }

dialog { width: min(420px, calc(100% - 32px)); padding: 30px; border: 0; border-radius: 30px; color: var(--ink); text-align: center; box-shadow: 0 30px 90px rgba(15,60,45,.32); }
dialog::backdrop { background: rgba(11,53,42,.65); backdrop-filter: blur(5px); }
.reveal[open] { animation: pop .45s cubic-bezier(.2,1.5,.5,1); }
.reveal-kicker, .profile-type { margin: 0; color: var(--coral); font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.reveal-critter, .profile-portrait { margin: 8px 0; font-size: 104px; }
dialog h2 { margin: -7px 0 4px; color: var(--forest); font-size: 44px; }
dialog p { line-height: 1.45; }
.sparkles { position: absolute; inset: 24px 26px auto; font-size: 28px; letter-spacing: 195px; overflow: hidden; }
.close { position: absolute; top: 14px; right: 14px; width: 38px; height: 38px; border: 0; border-radius: 50%; color: var(--forest); background: #eaf5df; font-size: 27px; line-height: 1; }
.profile-blurb { margin: 8px auto 20px; max-width: 300px; }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 20px 0; }
.profile-stats div { padding: 12px 6px; border-radius: 15px; background: #edf7e4; }
.profile-stats span, .profile-stats strong { display: block; }
.profile-stats span { color: #668078; font-size: 11px; font-weight: 700; }
.profile-stats strong { color: var(--forest); font-family: "Baloo 2"; font-size: 21px; }
.play-button { width: 100%; font-size: 18px; }
.play-button small { display: block; font-size: 10px; opacity: .8; }

.game-screen {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  background: #102f2a;
}
.game-screen.hidden { display: none; }
.game-frame {
  width: min(100%, 520px);
  height: min(100%, 920px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border-radius: 30px;
  background: #126c74;
  box-shadow: 0 20px 70px rgba(0,0,0,.4);
}
.game-hud, .game-footer {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: white;
  background: #176b55;
}
.game-hud { min-height: 74px; padding: 9px 14px; }
.game-close { width: 42px; height: 42px; border: 0; border-radius: 50%; color: white; background: rgba(255,255,255,.16); font-size: 28px; line-height: 1; }
.game-title { text-align: center; line-height: 1; }
.game-title span { display: block; color: var(--lime); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.game-title strong { font-family: "Baloo 2"; font-size: 25px; }
.score-box { min-width: 63px; padding: 6px 9px; border-radius: 12px; text-align: center; background: rgba(255,255,255,.14); }
.score-box span, .score-box strong { display: block; }
.score-box span { font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.score-box strong { font-family: "Baloo 2"; font-size: 22px; line-height: 1; }
.canvas-wrap { position: relative; min-height: 0; overflow: hidden; background: #50c5de; touch-action: manipulation; user-select: none; }
#game-canvas { display: block; width: 100%; height: 100%; object-fit: contain; background: #50c5de; }
.game-overlay { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; padding: 24px; color: white; text-align: center; background: rgba(8,62,69,.7); backdrop-filter: blur(3px); }
.game-overlay.hidden { display: none; }
.overlay-frog { font-size: clamp(72px, 15vh, 118px); filter: drop-shadow(0 8px 4px rgba(0,0,0,.18)); }
.game-overlay h2 { margin: 0; color: var(--lime); font-size: clamp(40px, 8vh, 64px); line-height: 1; }
.game-overlay p { margin: 8px 0 22px; font-weight: 800; line-height: 1.45; }
.game-overlay button { min-width: 180px; padding: 15px 22px; border: 0; border-radius: 16px; color: white; background: var(--coral); box-shadow: 0 6px 0 #d95240; font-size: 18px; font-weight: 800; }
.game-footer { min-height: 48px; padding: 8px 15px; font-size: 12px; font-weight: 700; }
.game-footer strong { color: var(--lime); }
.tap-hint { padding: 5px 10px; border-radius: 20px; background: rgba(255,255,255,.13); }

@keyframes pop { from { opacity: 0; transform: scale(.65) translateY(35px); } }
@keyframes bob { to { transform: translateY(-7px) rotate(3deg); } }
@keyframes wander { from { transform: translateX(-30px); } to { transform: translateX(60px); } }

@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; padding: 30px 18px 50px; }
  .hero { max-width: 520px; margin: auto; }
  .habitat-preview { min-height: 500px; }
}

@media (max-width: 420px) {
  .brand-mark { width: 68px; height: 68px; border-radius: 22px; }
  .paw { font-size: 35px; }
  .eyebrow { margin-top: 20px; font-size: 12px; }
  h1 { font-size: 51px; }
  .tagline { font-size: 16px; }
  .code-entry { flex-direction: column; }
  .code-entry button { min-height: 50px; }
  .habitat-preview { min-height: 460px; border-radius: 34px; }
  .habitat-copy { margin: 20px; max-width: calc(100% - 40px); }
  .profile-stats { gap: 5px; }
  .game-screen { padding: 0; }
  .game-frame { height: 100%; border-radius: 0; }
  .game-hud { padding-top: max(9px, env(safe-area-inset-top)); }
  .game-footer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

@media (orientation: landscape) and (max-height: 600px) {
  .game-frame { width: min(46vh, 420px); }
  .game-title span, .tap-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
