@font-face { font-family: "Fredoka"; src: url("/fonts/fredoka.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "Nunito"; src: url("/fonts/nunito.woff2") format("woff2"); font-weight: 200 1000; font-display: swap; }

:root {
  --cream: #fff8ef;
  --paper: #fffdf9;
  --sand: #f1e6d8;
  --ink: #2b1d14;
  --muted: #6b5547;
  --pink: #c4455b;
  --pink-soft: #fde1e4;
  --orange: #f2a24a;
  --green: #4caf7a;
  --radius: 20px;
  --shadow: 0 4px 0 var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--cream); color: var(--ink); }
body {
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3, .display { font-family: "Fredoka", sans-serif; font-weight: 600; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(28px, 8vw, 40px); }
h2 { font-size: clamp(24px, 7vw, 34px); }
h3 { font-size: 20px; }
p { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

#app { min-height: 100svh; }

.screen {
  min-height: 100svh;
  max-width: 520px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.screen.center { justify-content: center; text-align: center; align-items: center; }
.fade-in { animation: fade-in .45s ease both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(12px); } }

.level-tag {
  align-self: flex-start;
  font-family: "Fredoka", sans-serif;
  font-weight: 500;
  font-size: 14px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--cream);
}
.screen.center .level-tag { align-self: center; }

.btn {
  appearance: none;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--pink);
  color: #fff;
  font: 600 19px/1 "Fredoka", sans-serif;
  padding: 15px 22px;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--paper); color: var(--ink); box-shadow: none; }
.btn.secondary:active { transform: none; box-shadow: none; background: var(--sand); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); font-size: 16px; padding: 10px; min-height: 44px; }

.cat-talk { display: flex; align-items: flex-end; gap: 10px; }
.cat-talk .avatar {
  flex: 0 0 auto;
  width: 104px;
  height: 104px;
  object-fit: contain;
}
.cat-talk.flip { flex-direction: row-reverse; }
.wiggle { transform-origin: 50% 100%; will-change: transform; }
.scene-banner {
  height: 150px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--sand) center / cover no-repeat;
}
.bubble {
  position: relative;
  flex: 1;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 12px 14px;
  font-family: "Fredoka", sans-serif;
  font-weight: 500;
  font-size: 17px;
}
.bubble.pop { animation: pop .35s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes pop { from { transform: scale(.85); } }
.shake { animation: shake .4s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.helpers { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.hint-box {
  width: 100%;
  background: var(--pink-soft);
  border: 2px dashed var(--pink);
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, calc(100% + 60px));
  background: var(--ink);
  color: var(--cream);
  padding: 12px 18px;
  border-radius: 14px;
  font-family: "Fredoka", sans-serif;
  font-size: 16px;
  max-width: calc(100vw - 32px);
  transition: transform .3s ease;
  z-index: 50;
  text-align: center;
}
.toast.show { transform: translate(-50%, 0); }

.status-cat { width: 160px; height: 160px; object-fit: contain; }
.status-text { max-width: 320px; font-family: "Fredoka", sans-serif; font-size: 19px; }

@media (prefers-reduced-motion: reduce) {
  .fade-in, .bubble.pop, .shake, .scroll-hint, .paw-digit, .vault-dial.spin { animation: none; }
  .toast, .scene-bubble { transition: none; }
}

/* Intro scroll scene */
.intro-panel {
  min-height: 92svh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  text-align: center;
}
.intro-panel p { color: var(--muted); margin-top: 10px; }
.scroll-hint { margin-top: 26px; font-size: 28px; animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(8px); } }
.intro-track { height: 300svh; position: relative; }
.intro-stage { position: sticky; top: 0; height: 100svh; display: grid; place-items: center; overflow: hidden; }
.intro-scene {
  position: relative;
  width: min(100vw, calc(100svh * 1122 / 1402), 520px);
  aspect-ratio: 1122 / 1402;
  overflow: hidden;
}
@media (min-width: 521px) { .intro-scene { border-radius: 24px; } }
.intro-scene img { position: absolute; display: block; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.intro-scene .bg { inset: 0; width: 100%; height: 100%; }
.intro-scene .layer { will-change: transform; object-fit: contain; }
.scene-bubble {
  position: absolute;
  max-width: 54%;
  padding: 8px 12px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 16px;
  font: 500 clamp(13px, 3.6vw, 17px)/1.25 "Fredoka", sans-serif;
  opacity: 0;
  transform: scale(.6);
  transition: opacity .25s ease, transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
.scene-bubble.show { opacity: 1; transform: scale(1); }
.scene-bubble.hiro { right: 4%; top: 6%; transform-origin: 70% 100%; }
.scene-bubble.nyanku { left: 4%; top: 37%; transform-origin: 30% 100%; }

/* L1 gate */
.code-input {
  width: 100%;
  font: 600 34px/1 "Fredoka", sans-serif;
  letter-spacing: .12em;
  text-align: center;
  padding: 16px 10px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  box-shadow: inset 0 3px 0 rgba(43, 29, 20, .08);
}
.code-input::placeholder { color: #7d6858; letter-spacing: .08em; }
.code-input:focus { outline: 3px solid var(--orange); outline-offset: 2px; }
.code-preview { text-align: center; color: var(--muted); font-size: 15px; min-height: 22px; }
.gate-form { display: flex; flex-direction: column; gap: 12px; }

/* Digit reveal */
.paw-digit {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  font: 600 72px/1 "Fredoka", sans-serif;
  color: var(--pink);
  position: relative;
  animation: pop .6s cubic-bezier(.34, 1.56, .64, 1);
}
.digit-bag { display: flex; gap: 10px; justify-content: center; }
.digit-chip {
  min-width: 56px;
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  font: 600 24px/1 "Fredoka", sans-serif;
  text-align: center;
}
.digit-chip small { display: block; font: 600 11px/1.2 "Nunito", sans-serif; color: var(--muted); margin-top: 4px; }

/* L2 puzzle */
.puzzle {
  position: relative;
  width: min(100%, 420px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--sand);
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
.tile {
  position: absolute;
  width: calc(100% / 3);
  height: calc(100% / 3);
  border: 1.5px solid var(--paper);
  background-size: 300% 300%;
  transition: transform .16s ease-out;
  cursor: pointer;
}
.tile .num {
  position: absolute;
  left: 6px;
  top: 4px;
  font: 600 16px/1 "Fredoka", sans-serif;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  display: none;
}
.puzzle.numbered .tile .num { display: block; }
.puzzle.solved .tile { border-color: transparent; transition: border-color .6s ease, transform .16s ease-out; }
.puzzle-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 15px; }
.peek { width: 120px; height: auto; border-radius: 12px; border: 2px solid var(--ink); margin: 0 auto; display: block; }

/* L3 fish game */
.fish-wrap {
  position: relative;
  width: 100%;
  height: min(62svh, 560px);
  border: 3px solid var(--ink);
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(#cfeaf6, #fef3e4 85%);
  box-shadow: var(--shadow);
  touch-action: none;
}
.fish-wrap canvas { width: 100%; height: 100%; display: block; }
.fish-hud {
  position: absolute;
  inset: 10px 12px auto;
  display: flex;
  justify-content: space-between;
  font: 600 18px/1 "Fredoka", sans-serif;
  pointer-events: none;
}
.fish-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  background: rgba(255, 248, 239, .88);
}
.fish-overlay .inner { display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* L4 vault */
.vault {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #3a3f4a;
  color: #fff;
  border: 3px solid var(--ink);
  border-radius: 24px;
  padding: 20px 16px;
  box-shadow: var(--shadow);
}
.vault label { font-size: 14px; color: #d8dbe2; display: block; margin-bottom: 6px; }
.vault-digits { display: flex; gap: 12px; justify-content: center; }
.vault-digits input {
  width: 72px;
  height: 84px;
  text-align: center;
  font: 600 44px/1 "Fredoka", sans-serif;
  border-radius: 14px;
  border: 2px solid var(--ink);
  background: #fff8ef;
  color: var(--ink);
}
.vault-answer {
  width: 100%;
  font: 500 19px/1.2 "Nunito", sans-serif;
  padding: 14px;
  border-radius: 14px;
  border: 2px solid var(--ink);
  background: #fff8ef;
  color: var(--ink);
}
.vault-question { font-family: "Fredoka", sans-serif; font-size: 19px; }
.vault-dial { font-size: 54px; text-align: center; line-height: 1; }
.vault-dial.spin { animation: spin 1s ease-in-out; }
@keyframes spin { to { transform: rotate(360deg); } }
