:root {
  --bg: #14213d;
  --bg2: #1d3461;
  --ink: #f6f7fb;
  --muted: #b9c3d9;
  --card: #fffdf7;
  --card-ink: #22263a;
  --accent: #e63946;
  --gold: #f2b233;
  --ok: #4fb286;
  --radius: 18px;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg));
  color: var(--ink);
  overflow-x: hidden;
}

#snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.flake {
  position: absolute; top: -10px; color: #fff; opacity: .8;
  animation: fall linear infinite;
}
@keyframes fall { to { transform: translateY(110vh) translateX(20px); } }

#app { position: relative; z-index: 1; max-width: 480px; margin: 0 auto; min-height: 100dvh; }
.screen { display: none; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); min-height: 100dvh; flex-direction: column; gap: 16px; }
.screen.active { display: flex; animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }

h1 { font-size: 2.3rem; line-height: 1.1; margin: 0; }
h2 { font-size: 1.5rem; line-height: 1.25; margin: 0; }
h3 { margin: 0 0 8px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--gold); margin: 0; font-weight: 700; }
.lead { font-size: 1.05rem; line-height: 1.5; color: var(--ink); margin: 0; }
.fine { font-size: .8rem; color: var(--muted); margin: 0; }
.center, .center-text { text-align: center; }
.center { display: flex; flex-direction: column; align-items: center; gap: 14px; margin: auto 0; }
.hidden { display: none !important; }

.landing { margin: auto 0; display: flex; flex-direction: column; gap: 16px; }
.perks { list-style: none; padding: 0; margin: 4px 0 8px; display: grid; gap: 8px; color: var(--muted); }

.btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 999px; padding: 12px 18px;
  cursor: pointer; color: var(--card-ink); background: var(--card);
  transition: transform .1s ease, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.gold { background: var(--gold); color: #2b1d00; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid rgba(255,255,255,.35); }
.btn.big { padding: 16px 22px; font-size: 1.1rem; width: 100%; }

/* Setup */
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hero-slot { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.avatar-pick { background: none; border: 0; color: var(--ink); display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; font: inherit; }
.avatar {
  width: 112px; height: 112px; border-radius: 50%; display: grid; place-items: center; font-size: 56px;
  background: rgba(255,255,255,.12); border: 3px dashed rgba(255,255,255,.4); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.filled { border: 3px solid #fff; }
.pick-label { font-size: .85rem; color: var(--muted); }
.field {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 0;
  background: rgba(255,255,255,.95); color: var(--card-ink); text-align: center;
}
.seg { display: flex; background: rgba(255,255,255,.12); border-radius: 999px; padding: 3px; }
.seg-btn { font: inherit; border: 0; background: none; color: var(--muted); padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.seg-btn.on { background: #fff; color: var(--card-ink); font-weight: 700; }
.consent { font-size: .85rem; color: var(--muted); display: flex; gap: 8px; align-items: flex-start; }
#setup-next { margin-top: auto; }

/* Quiz */
.options { display: grid; gap: 10px; }
.option { text-align: left; border-radius: 14px; padding: 16px; font-weight: 600; }
#screen-quiz h2 { margin: 12px 0; }

/* Duo (owner + pet avatars) */
.duo { display: flex; justify-content: center; }
.duo .mini-av {
  width: 96px; height: 96px; border-radius: 50%; overflow: hidden; border: 3px solid #fff; background: #2a3f6b;
  display: grid; place-items: center; font-size: 48px; box-shadow: 0 6px 18px rgba(0,0,0,.3);
  animation: bob 1.6s ease-in-out infinite;
}
.duo .mini-av + .mini-av { margin-left: -16px; animation-delay: .3s; }
.duo .mini-av img { width: 100%; height: 100%; object-fit: cover; }
.duo.small .mini-av { width: 64px; height: 64px; font-size: 32px; border-width: 2px; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
.glow { color: var(--gold); text-shadow: 0 0 18px rgba(242,178,51,.5); }

/* Stats */
.statbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { text-align: center; position: relative; }
.stat .ico { font-size: 1.3rem; }
.stat .meter { height: 8px; border-radius: 4px; background: rgba(255,255,255,.15); overflow: hidden; margin-top: 4px; }
.stat .fill { height: 100%; background: #fff; transition: width .4s ease, background .3s; }
.stat .fill.danger { background: var(--accent); }
.stat .dot {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%) scale(0);
  width: 8px; height: 8px; border-radius: 50%; background: var(--gold); transition: transform .15s;
}
.stat .dot.show { transform: translateX(-50%) scale(1); }
.stat .dot.big { width: 12px; height: 12px; }
.stat.flash-up .fill { background: var(--ok); }
.stat.flash-down .fill { background: var(--accent); }

/* Scene */
.scene {
  height: 150px; border-radius: var(--radius); position: relative; overflow: hidden;
  background: linear-gradient(#2b4a7a, #8fb3d9 70%, #eef4fb 70%);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 10px;
}
.scene::before { content: "🌲  🌲     🌲   🌲"; position: absolute; bottom: 26%; left: 0; right: 0; text-align: center; font-size: 2rem; letter-spacing: 4px; opacity: .85; }
.scene.yard::before { content: "🌲  🛷       🌲"; }
.scene.pond { background: linear-gradient(#22406e, #7da3cc 65%, #bfe3f5 65%); }
.scene.pond::before { content: "🌲            🌲"; }
.scene.cave { background: linear-gradient(#0e1a33, #3b2a5e 70%, #d9e4f2 70%); }
.scene.cave::before { content: "🪨  ✨     ✨  🪨"; }
.scene .duo { position: relative; z-index: 1; }
.beast { font-size: 64px; position: relative; z-index: 1; animation: bob 2s ease-in-out infinite; filter: hue-rotate(180deg); }

/* Card */
.deck { position: relative; min-height: 190px; }
.card {
  background: var(--card); color: var(--card-ink); border-radius: var(--radius); padding: 28px 20px;
  min-height: 190px; display: flex; align-items: center; justify-content: center; text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,.35); touch-action: pan-y; user-select: none; cursor: grab;
  position: relative; transition: transform .3s ease, opacity .3s ease; will-change: transform;
}
.card.dragging { transition: none; cursor: grabbing; }
.card p { font-size: 1.15rem; line-height: 1.45; margin: 0; font-weight: 600; }
.hint {
  position: absolute; top: 10px; font-size: .8rem; font-weight: 800; padding: 4px 10px; border-radius: 999px;
  background: var(--card-ink); color: #fff; opacity: 0; transition: opacity .1s; max-width: 60%;
}
.hint.left { left: 10px; } .hint.right { right: 10px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.choice { font-size: .9rem; padding: 12px 10px; }

/* Minigames */
.mini-head { text-align: center; display: grid; gap: 6px; }
.mini-head p { margin: 0; color: var(--muted); }
.mini-hud { display: flex; justify-content: center; gap: 18px; font-weight: 800; font-size: 1.2rem; }
.mini-area { position: relative; flex: 1; min-height: 340px; border-radius: var(--radius); background: rgba(255,255,255,.08); overflow: hidden; touch-action: none; }
.holes { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 14px; }
.hole { border-radius: 50%; background: radial-gradient(#0c1528 55%, #e9f1fa 57%); display: grid; place-items: center; font-size: 44px; position: relative; aspect-ratio: 1; align-self: center; }
.hole .sq { transform: scale(0); transition: transform .12s; cursor: pointer; }
.hole .sq.up { transform: scale(1); }
.hole .sq.hit { transform: scale(1.3) rotate(20deg); opacity: .3; }
.lane-player { position: absolute; bottom: 16px; width: 33.33%; text-align: center; transition: left .12s; }
.lane-player .mini-av { width: 56px; height: 56px; margin: 0 auto; font-size: 30px; animation: none; }
.tree { position: absolute; width: 33.33%; text-align: center; font-size: 40px; top: -50px; }
.print { position: absolute; width: 33.33%; text-align: center; font-size: 20px; opacity: .6; }
.flash-hit { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* Ending */
.flip { perspective: 1000px; width: 100%; aspect-ratio: 3 / 4; max-height: 60dvh; margin: 0 auto; cursor: pointer; }
.flip-inner { position: relative; width: 100%; height: 100%; transition: transform .8s cubic-bezier(.2,.8,.2,1); transform-style: preserve-3d; }
.flip.open .flip-inner { transform: rotateY(180deg); }
.flip-front, .flip-back {
  position: absolute; inset: 0; border-radius: 22px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px;
}
.flip-front { background: linear-gradient(135deg, #2b4a7a, #14213d); border: 3px solid rgba(255,255,255,.3); font-size: 64px; animation: pulse 1.4s ease-in-out infinite; }
.flip-front span { font-size: 1rem; color: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 40px rgba(242,178,51,.45); } }
.flip-back { transform: rotateY(180deg); background: var(--card); color: var(--card-ink); border: 4px solid var(--gold); }
.rarity { font-weight: 800; text-transform: uppercase; letter-spacing: .1em; font-size: .8rem; padding: 4px 12px; border-radius: 999px; color: #fff; }
.ending-emoji { font-size: 72px; }
.ending-body { display: flex; flex-direction: column; gap: 14px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { background: rgba(255,255,255,.12); border-radius: 999px; padding: 6px 12px; font-size: .85rem; }
.unlocked { margin: 0; color: var(--gold); font-weight: 700; }
.upsell { background: rgba(255,255,255,.08); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(5,10,25,.75); display: grid; place-items: center; z-index: 10; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--card); color: var(--card-ink); border-radius: var(--radius); padding: 20px; width: min(420px, 100%); display: grid; gap: 14px; text-align: center; }
.crop-frame { width: 240px; height: 240px; border-radius: 50%; overflow: hidden; margin: 0 auto; position: relative; background: #ddd; touch-action: none; cursor: move; }
.crop-frame img { position: absolute; left: 50%; top: 50%; transform-origin: center; user-select: none; -webkit-user-drag: none; max-width: none; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
