:root {
  --ink: #102a43;
  --ink-soft: #334e68;
  --sky: #d9f0ff;
  --sky-strong: #72c7ef;
  --sun: #ffd166;
  --nest: #9b6b43;
  --cream: #fffaf0;
  --panel: rgba(255, 255, 255, 0.92);
  --success: #268a58;
  --warning: #c47c17;
  --danger: #b43a3a;
  --focus: #ffb703;
  --shadow: 0 18px 45px rgba(16, 42, 67, 0.18);
  --radius: 24px;
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #dff3ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

/* Batch-14.2: iOS text-selection prevention on every interactive/game surface.
   Real text-input fields opt back in below so the swift-name/player-name inputs still work. */
body { -webkit-tap-highlight-color: transparent; }
button,
.brand, .brand-mark, .brand-mark img,
.topbar, .top-actions, .icon-btn, .soft-btn,
.hero-actions, .hero-actions > *,
.hud-pill, .hud-pause,
.joystick, .joystick-knob, .round-action,
.game-wrap, .game-canvas, .game-controls, .game-message, .game-hud,
.nest-scene, .chick-scene, .training-zone, .scene-caption,
.egg, .chick, .parent-bird, .cloud-hotspot, .sky-hotspot, .feather-hotspot,
.hold-button,
.choice-btn, .diary-entry, .encyclopedia-item,
.certificate-panel .certificate-frame, .certificate-panel .certificate-frame img,
.footer-note,
[data-testid="stage-retry"], [data-testid="stage-retry"] * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
}
input, textarea, select, [contenteditable="true"] {
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
}

/* --- Animations (batch 5) --- */
@keyframes screenIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes chickBreathe { 0%,100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.03); } }
@keyframes chickHop { 0% { transform: translateX(-50%) translateY(0); } 40% { transform: translateX(-50%) translateY(-14px) scale(1.05); } 100% { transform: translateX(-50%) translateY(0); } }
@keyframes chickBounceIn { 0% { transform: translateX(-50%) translateY(-30px) scale(0.6); opacity: 0; } 60% { transform: translateX(-50%) translateY(6px) scale(1.08); opacity: 1; } 100% { transform: translateX(-50%) translateY(0) scale(1); } }
@keyframes eggIdle { 0%,100% { transform: translate(-50%,-50%) rotate(-2deg); } 50% { transform: translate(-50%,-50%) rotate(2deg); } }
@keyframes trainingFlap { 0% { transform: translateY(0) scale(1); } 30% { transform: translateY(-12px) scale(1.08) rotate(-4deg); } 100% { transform: translateY(0) scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

#app > * { animation: screenIn 320ms cubic-bezier(.2,.7,.2,1) both; }
.chick { animation: chickBreathe 3.6s ease-in-out infinite; }
.chick.beak-open { animation: chickHop 420ms cubic-bezier(.2,.7,.2,1); }
.chick.bounce-in { animation: chickBounceIn 680ms cubic-bezier(.2,.7,.2,1); }
.egg { animation: eggIdle 3.8s ease-in-out infinite; }
.egg.wiggle { animation: eggwiggle .42s ease; }
.egg.hatch-shake { animation: eggwiggle .18s ease 3; }
.training-bird.flap { animation: trainingFlap 320ms cubic-bezier(.2,.7,.2,1); }
.training-bird.flying { animation: none; }
button, .primary-btn, .soft-btn, .icon-btn { transition: transform .12s ease, background .18s ease, box-shadow .18s ease; }
button:hover:not(:disabled), .primary-btn:hover, .soft-btn:hover, .icon-btn:hover { transform: translateY(-1px) scale(1.02); }
button:active:not(:disabled), .primary-btn:active, .soft-btn:active { transform: translateY(0) scale(.97); }
.toast { animation: toastIn 240ms cubic-bezier(.2,.7,.2,1) both; }

/* --- Certificate panel --- */
.certificate-panel .certificate-frame { display: flex; justify-content: center; margin: 12px 0 20px; }
.certificate-panel .certificate-frame img { max-width: min(100%, 720px); width: 100%; height: auto; border-radius: 18px; box-shadow: 0 24px 48px rgba(16,42,67,.28); background: #fbf3e2; aspect-ratio: 3 / 2; }

/* --- Pause overlay + HUD pause button (batch 8) --- */
.hud-pause { display:inline-flex; align-items:center; justify-content:center; min-width:46px; min-height:46px; padding:0 14px; border-radius:22px; border:0; background:rgba(255,255,255,.94); color:#1c2a3a; font-size:20px; font-weight:900; cursor:pointer; box-shadow:0 6px 14px rgba(0,0,0,.25); margin-left:auto; pointer-events:auto; }
.hud-pause:hover, .hud-pause:focus-visible { transform:scale(1.05); outline:none; }
.pause-overlay { position:absolute; inset:0; z-index:5; display:flex; align-items:center; justify-content:center; background:rgba(12,20,32,.72); backdrop-filter:blur(6px); animation:fadeIn 200ms ease both; }
.pause-overlay.hidden { display:none; }
.pause-overlay .pause-card { background:white; border-radius:22px; padding:26px 30px; max-width:min(90%, 420px); text-align:center; box-shadow:0 24px 50px rgba(0,0,0,.4); }
.pause-overlay h2 { margin:0 0 10px 0; font-size:clamp(24px, 4vw, 32px); color:#1c2a3a; }
.pause-overlay p { margin:0 0 16px 0; color:#4a5b70; }
.pause-actions { display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

/* --- PWA install modal (batch 16) --- */
.pwa-modal { position:fixed; inset:0; z-index:100; display:flex; align-items:center; justify-content:center; background:rgba(12,20,32,.68); backdrop-filter:blur(6px); padding:16px; animation:fadeIn 200ms ease both; }
.pwa-modal.hidden { display:none; }
.pwa-modal-card { position:relative; background:#fff; color:#1c2a3a; border-radius:22px; padding:28px 26px 22px; width:min(96vw,460px); max-height:92vh; overflow-y:auto; box-shadow:0 24px 50px rgba(0,0,0,.42); animation:fadeIn 260ms ease both; }
.pwa-modal-card h2 { margin:0 0 6px 0; font-size:clamp(22px, 3.6vw, 28px); }
.pwa-modal-note { margin:0 0 14px 0; color:#4a5b70; font-size:14px; }
.pwa-modal-close { position:absolute; top:10px; right:12px; width:38px; height:38px; border-radius:19px; border:0; background:#eef3f8; color:#1c2a3a; font-size:22px; line-height:1; cursor:pointer; display:inline-flex; align-items:center; justify-content:center; }
.pwa-modal-close:hover, .pwa-modal-close:focus-visible { background:#dde6ef; outline:none; }
.pwa-tabs { display:flex; gap:8px; margin:6px 0 14px 0; flex-wrap:wrap; }
.pwa-tab { flex:1 1 140px; min-height:44px; padding:10px 12px; border-radius:14px; border:2px solid #d7e3ee; background:#f2f7fb; color:#1c2a3a; font-weight:700; cursor:pointer; font-size:14px; }
.pwa-tab.active { background:#1c2a3a; color:#fff; border-color:#1c2a3a; }
.pwa-tab:focus-visible { outline:3px solid #2d7bff; outline-offset:2px; }
.pwa-steps { list-style:none; padding:0; margin:0 0 16px 0; display:flex; flex-direction:column; gap:10px; }
.pwa-steps li { display:flex; align-items:flex-start; gap:12px; background:#f6f9fc; border-radius:12px; padding:12px 14px; font-size:15px; line-height:1.4; color:#1c2a3a; }
.pwa-step-icon { flex:0 0 auto; font-size:22px; line-height:1; }
.pwa-modal-actions { display:flex; justify-content:flex-end; gap:10px; flex-wrap:wrap; }
@media (max-width:400px) { .pwa-modal-card { padding:22px 18px 18px; } .pwa-tab { font-size:13px; } }

/* Install button on home hero-actions — slightly smaller, secondary weight */
#install-btn { font-size:14px; padding:10px 16px; }
#install-btn[disabled] { opacity:.6; cursor:default; }

/* Difficulty choice card selection ring */
[data-difficulty].selected { outline:3px solid #2d7bff; outline-offset:2px; }

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #app > * { animation: none !important; }
  .chick, .egg, .parent-bird, .training-bird, .scene-object, .obj-feather, .obj-sky, .obj-parent { animation: none !important; }
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 15% 12%, rgba(255,255,255,.85), transparent 22rem),
    linear-gradient(180deg, #9edcff 0%, #e8f7ff 58%, #f8e9c7 100%);
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; }
button { touch-action: manipulation; }
/* Batch-14.3: iOS Safari occasionally still triggered double-tap zoom on rapid taps of
   the «ПОЗВАТЬ» button. The base `button { touch-action: manipulation }` rule (above)
   was being defeated when a finger-slop second tap landed on the surrounding container's
   padding — the container defaulted to `touch-action: auto` and iOS treated the tap pair
   as a zoom gesture. Force `manipulation` on every tap target AND its immediate flex
   container. `manipulation` preserves pinch-zoom (accessibility) and pan; only the
   double-tap-zoom gesture (and its ~300 ms delay) are removed. Drag-based controls
   (canvas, joystick, round-action, hold-button) keep their `touch-action: none` from
   earlier batches — that value is more restrictive and stays authoritative because it
   is declared with equal-or-higher specificity later in the sheet. */
button, [role="button"], a.btn,
.choice-btn, .icon-btn, .soft-btn, .primary-btn, .action-btn,
.egg, .scene-object, [data-observe],
.hero-actions, .scene-actions {
  touch-action: manipulation;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: rgba(255,255,255,.86);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(16,42,67,.1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: white;
  box-shadow: 0 8px 18px rgba(16,42,67,.25);
  background: transparent;
}
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; user-select: none; -webkit-user-select: none; }
.brand-text { min-width: 0; }
.brand-title { font-weight: 900; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-subtitle { font-size: 12px; color: var(--ink-soft); }

.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn, .soft-btn, .primary-btn, .choice-btn, .action-btn {
  border: 0;
  cursor: pointer;
  border-radius: 16px;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.icon-btn:hover, .soft-btn:hover, .primary-btn:hover, .choice-btn:hover, .action-btn:hover { transform: translateY(-1px); }
.icon-btn:active, .soft-btn:active, .primary-btn:active, .choice-btn:active, .action-btn:active { transform: translateY(1px) scale(.99); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 4px solid rgba(255,183,3,.45); outline-offset: 2px; }
button:disabled { opacity: .48; cursor: not-allowed; transform: none !important; }
.icon-btn { width: 42px; height: 42px; background: #edf6fb; color: var(--ink); font-size: 20px; }
.soft-btn { padding: 11px 15px; background: #edf6fb; color: var(--ink); font-weight: 800; }
.primary-btn, .action-btn {
  padding: 14px 22px;
  background: linear-gradient(145deg, #1f7fb1, #145577);
  color: white;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(20,85,119,.25);
}
.primary-btn.large { min-height: 58px; min-width: min(100%, 260px); font-size: 18px; }
.primary-btn.warm { background: linear-gradient(145deg, #f6a623, #d8790e); box-shadow: 0 10px 24px rgba(216,121,14,.25); }

.main-content {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 22px max(14px, env(safe-area-inset-right)) calc(30px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  flex: 1;
}

.hero {
  min-height: calc(100dvh - 105px);
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  align-items: center;
  gap: 32px;
}
.hero-copy h1 { font-size: clamp(42px, 7vw, 86px); line-height: .95; margin: 0 0 18px; letter-spacing: -.055em; }
.hero-copy p { font-size: clamp(17px, 2vw, 22px); line-height: 1.55; color: var(--ink-soft); max-width: 680px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.hero-note { margin-top: 14px; font-size: 13px; color: var(--ink-soft); }

.swift-card {
  position: relative;
  min-height: 470px;
  overflow: hidden;
  border-radius: 40px;
  background:
    linear-gradient(180deg, rgba(0,0,0,0) 45%, rgba(0,0,0,.32) 100%),
    url("assets/home_hero.webp") center center / cover no-repeat,
    #7fd2fa;
  box-shadow: var(--shadow);
  isolation: isolate;
}
.swift-card::before { content: none; }
.swift-illustration { display: none; }
.hero-badge {
  position: absolute;
  left: 20px;
  bottom: 20px;
  right: 20px;
  padding: 16px;
  border-radius: 22px;
  background: rgba(255,255,255,.87);
  backdrop-filter: blur(12px);
  font-weight: 800;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(16,42,67,.08);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 34px);
}
.panel h1, .panel h2 { margin-top: 0; }
.screen-heading { margin-bottom: 20px; }
.screen-heading h1 { font-size: clamp(30px, 5vw, 52px); margin-bottom: 8px; letter-spacing: -.035em; }
.screen-heading p { color: var(--ink-soft); font-size: 17px; line-height: 1.5; max-width: 800px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 900; }
.field input, .field select {
  width: 100%;
  border: 2px solid #c9dce8;
  border-radius: 14px;
  padding: 13px 14px;
  background: white;
  color: var(--ink);
}
.help { font-size: 13px; color: var(--ink-soft); }
.choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.choice-btn {
  min-height: 120px;
  padding: 14px;
  border: 3px solid transparent;
  background: #edf6fb;
  color: var(--ink);
  text-align: left;
}
.choice-btn.selected { border-color: #2382b2; background: #dff4ff; }
.choice-btn .choice-icon { font-size: 30px; display: block; margin-bottom: 6px; }
.choice-btn strong { display: block; margin-bottom: 4px; }
.choice-btn small { color: var(--ink-soft); }
.color-row { display: flex; gap: 12px; flex-wrap: wrap; }
.color-choice { width: 52px; height: 52px; border-radius: 50%; border: 4px solid white; box-shadow: 0 0 0 2px #9bb8c9; cursor: pointer; }
.color-choice.selected { box-shadow: 0 0 0 4px var(--focus); }
.form-actions { display: flex; justify-content: flex-end; margin-top: 24px; }

.stage-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; }
.stage-card { position: relative; overflow: hidden; min-height: 600px; }
.stage-side { display: flex; flex-direction: column; gap: 16px; }
.stat-card { background: rgba(255,255,255,.92); border-radius: 20px; padding: 16px; box-shadow: 0 12px 30px rgba(16,42,67,.12); }
.stat-card h3 { margin: 0 0 10px; }
.progress-track { height: 16px; background: #d7e6ee; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #58b179, #268a58); transition: width .25s ease; }
.fact-card { background: #fff8dd; border: 1px solid #f2d78c; }
.fact-card p { margin-bottom: 0; color: #684c14; line-height: 1.45; }

.nest-scene {
  position: relative;
  aspect-ratio: 3 / 2;
  min-height: 320px;
  overflow: hidden;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(0,0,0,.05) 0%, rgba(0,0,0,.35) 100%),
    url("assets/nest.webp") center center / cover no-repeat,
    #3a2a20;
}
.nest-opening { display: none; }
.nest-bowl { display: none; }
.egg {
  position: absolute;
  /* Batch-15: the new nest illustration places the egg at ~62% x, ~62% y (image-space). */
  left: 62%; top: 62%;
  transform: translate(-50%, -50%);
  width: 18%; height: 22%;
  min-width: 60px; min-height: 60px;
  border-radius: 50%;
  background: transparent;
  border: 0;
  box-shadow: none;
  cursor: pointer;
  outline: none;
}
.egg:hover, .egg:focus-visible {
  box-shadow: 0 0 0 3px rgba(255,255,255,.55), 0 0 32px 6px rgba(255,220,140,.45);
}
.egg:focus-visible { outline: 3px solid rgba(255,255,255,.9); outline-offset: 6px; }
.egg.ready {
  animation: eggReadyPulse 1.6s ease-in-out infinite;
  box-shadow: 0 0 0 4px rgba(255,220,140,.45), 0 0 40px 10px rgba(255,180,90,.55);
}
.egg.wiggle { animation: eggwiggle .42s ease; }
.egg.hatch-shake { animation: eggwiggle .18s ease 3; }
@keyframes eggwiggle { 0%,100%{transform:translate(-50%,-50%) rotate(0) scale(1)} 25%{transform:translate(-50%,-50%) rotate(-7deg) scale(1.05)} 70%{transform:translate(-50%,-50%) rotate(7deg) scale(1.05)} }
@keyframes eggReadyPulse { 0%,100%{ box-shadow: 0 0 0 4px rgba(255,220,140,.35), 0 0 32px 8px rgba(255,180,90,.4); } 50%{ box-shadow: 0 0 0 6px rgba(255,220,140,.65), 0 0 52px 14px rgba(255,180,90,.7); } }
.egg-hint {
  position: absolute;
  left: 50%; bottom: 6%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,.94);
  color: #7a3e12;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
  animation: eggHintIn 320ms cubic-bezier(.2,.7,.2,1) both;
}
@keyframes eggHintIn { from { opacity: 0; transform: translateX(-50%) translateY(6px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.scene-object { position: absolute; border: 0; padding: 0; cursor: pointer; background: transparent; box-shadow: none; min-width: 46px; min-height: 46px; border-radius: 22px; transition: transform .18s ease, filter .18s ease; }
.scene-object > .cloud-shape, .scene-object.obj-feather::before, .scene-object.obj-parent::before { filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); }
.scene-object:hover, .scene-object:focus-visible { transform: scale(1.08); filter: drop-shadow(0 0 6px rgba(255,255,255,.75)); outline: none; }
.scene-object:active { transform: scale(.96); }
.scene-object:focus-visible { outline: 3px solid rgba(255,255,255,.9); outline-offset: 4px; border-radius: 22px; }
.scene-object.done { opacity: .55; }
.scene-object.done::after { content: '✓'; position: absolute; right: -6px; top: -6px; width: 22px; height: 22px; border-radius: 50%; background: #29a15c; color: white; font-weight: 900; font-size: 14px; display: flex; align-items: center; justify-content: center; box-shadow: 0 3px 8px rgba(0,0,0,.35); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
/* Batch-15 re-anchor for the new volumetric nest illustration:
   - feather sits in the light-beam column just left of the egg
   - obj-parent sits on the wooden beams top-right (the "parents' rafters")
   - obj-sky overlays the small sky window at top-left (~13% x, ~26% y). */
.obj-feather { left: 34%; bottom: 25%; width: 15%; aspect-ratio: 1/1; height: auto; min-width: 68px; min-height: 68px; background: url("assets/feather.webp") center center / contain no-repeat; animation: featherSway 3.4s ease-in-out infinite; transform-origin: 50% 15%; }
.obj-feather::before { content: ''; display: none; }
.obj-parent { right: 6%; top: 20%; width: 16%; aspect-ratio: 7 / 10; height: auto; min-width: 76px; min-height: 108px; background: url("assets/parents.webp") center center / contain no-repeat; animation: parentBob 4.2s ease-in-out infinite; }
.obj-sky { left: 7%; top: 20%; width: 15%; height: 12%; min-width: 68px; min-height: 44px; background: transparent; animation: cloudDrift 6s ease-in-out infinite; }
.cloud-shape { position: absolute; inset: 0; }
/* Batch-15: illustrated nest already has a painted sky window with real clouds.
   The procedural cloud puffs are hidden so they don't overlay the artwork as ghost
   bubbles. A soft golden pulse on the sky hotspot signals "tap here" instead. */
.obj-sky > .cloud-shape { display: none; }
.obj-sky {
  border-radius: 42% / 55%;
  background: radial-gradient(ellipse at center, rgba(255,220,140,.35), rgba(255,220,140,.15) 55%, rgba(255,220,140,0) 78%);
  animation: skyGlow 3.4s ease-in-out infinite, cloudDrift 6s ease-in-out infinite;
}
@keyframes skyGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,220,140,0.0); }
  50%      { box-shadow: 0 0 22px 4px rgba(255,220,140,0.55); }
}
.cloud-puff { position: absolute; background: rgba(255,255,255,.95); border-radius: 50%; box-shadow: 0 4px 10px rgba(0,0,0,.15); }
.cloud-puff.a { left: 0; top: 30%; width: 44%; height: 70%; }
.cloud-puff.b { left: 28%; top: 5%; width: 50%; height: 90%; }
.cloud-puff.c { left: 55%; top: 30%; width: 45%; height: 65%; }
@keyframes featherSway { 0%,100% { transform: rotate(-6deg) translateY(0); } 50% { transform: rotate(6deg) translateY(-3px); } }
@keyframes parentBob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes cloudDrift { 0%,100% { transform: translateX(0); } 50% { transform: translateX(6px); } }
/* Gentle "morning light streaming through the sky opening" pulse for the illustrated nest scenes.
   The pulse is a NEGATIVE-z-index pseudo-element so the scene container's layout / stacking
   context and descendants' getBoundingClientRect readings stay clean — animating filter on the
   container itself silently perturbed the training-flight ellipse clamp. */
.chick-scene, .training-zone { position: relative; }
.chick-scene::after, .training-zone::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 42% 55% at 22% 30%, rgba(255,235,180,0.28), rgba(255,235,180,0) 70%);
  mix-blend-mode: screen;
  animation: sunbeamPulse 4.2s ease-in-out infinite;
  z-index: 0;
}
@keyframes sunbeamPulse { 0%,100% { opacity: 0.35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .chick-scene::after, .training-zone::after { animation: none; opacity: 0.35; }
}
.scene-object.done.obj-feather { animation: none; transform: rotate(0); }
.scene-object.done.obj-parent, .scene-object.done.obj-sky { animation: none; }
.scene-caption { position: absolute; left: 18px; right: 18px; top: 18px; padding: 12px 14px; border-radius: 16px; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); text-align: center; font-weight: 800; box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.scene-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.chick-scene {
  min-height: 500px;
  position: relative;
  border-radius: 28px;
  overflow: hidden;
  background: url("assets/nest_interior.webp") center center / cover no-repeat, linear-gradient(180deg,#f2c99a,#8b5a3c);
  aspect-ratio: 3 / 2;
}
/* Chick sits INSIDE the woven-feather nest cup of the new nest_interior illustration
   (nest cup center ≈ 72% x, ~34% from bottom). A soft translucent ellipse shadow anchored
   just below the chick sells the volumetric depth on the wooden plank. */
.chick { position: absolute; left: 72%; bottom: 32%; width: 26%; max-width: 200px; min-width: 100px; aspect-ratio: 17 / 15; height: auto; transform: translateX(-50%); background: url("assets/chick.webp") center bottom / contain no-repeat; filter: drop-shadow(0 12px 14px rgba(0,0,0,.28)); transition: transform .18s ease; }
.chick::before {
  content: ""; position: absolute; left: 50%; bottom: -8%; transform: translateX(-50%);
  width: 96%; height: 14%;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.34) 0%, rgba(0,0,0,.18) 55%, rgba(0,0,0,0) 78%);
  pointer-events: none; z-index: -1;
}
.chick.beak-open { transform: translateX(-50%) translateY(-4px) scale(1.05); }
.chick-body, .chick-head, .chick-eye, .chick-eye::after, .chick-beak { display: none; }
/* Parent flies in from the sky opening (top-left) and hovers above the nest cup to feed.
   Batch-15: landed position tightened to hover just above and slightly left of the chick. */
.parent-bird { position:absolute; top:12%; left:-30%; width:20%; max-width:150px; min-width:90px; aspect-ratio:1/1; height:auto; background: url("assets/parent_food.webp") center center / contain no-repeat; font-size:0; filter:drop-shadow(0 12px 10px rgba(0,0,0,.35)); transition:left 1.2s ease, top .8s ease, transform .18s ease; }
/* parent_food.webp faces LEFT — default (approach from the sky, flying rightward) needs a mirror. */
.parent-bird.arriving { left: 52%; top: 24%; transform: scaleX(-1); }
/* Message bubble sits on the darker upper wall area — add a strong drop shadow for readability. */
.bubble { position:absolute; top:14px; left:14px; right:14px; padding:12px 16px; border-radius:18px; background:rgba(255,255,255,.92); font-weight:800; text-align:center; box-shadow:0 6px 18px rgba(0,0,0,.28); text-shadow:0 1px 0 rgba(255,255,255,.7); }

.training-zone { min-height: 460px; display:grid; place-items:center; text-align:center; border-radius:28px; background: url("assets/nest_interior.webp") center center / cover no-repeat, linear-gradient(180deg,#82d6fa,#e9f7ff 58%,#8b5a3c 59%); overflow:hidden; position:relative; padding:24px; }
.training-zone > div { position:relative; z-index:1; background:rgba(255,255,255,.78); padding:14px 18px; border-radius:20px; box-shadow:0 8px 22px rgba(0,0,0,.18); max-width:min(88%,460px); }
.training-bird { width:150px; height:150px; max-width:min(150px,55%); max-height:min(150px,55%); margin:0 auto; display:block; background: url("assets/swift_left.webp") center center / contain no-repeat; font-size:0; filter:drop-shadow(0 12px 14px rgba(16,42,67,.22)); transition:transform 420ms cubic-bezier(.2,.7,.2,1); will-change:transform; position: relative; }
.training-bird::after {
  /* Batch-15: soft translucent shadow ellipse under the training bird. */
  content: ""; position: absolute; left: 50%; bottom: -16px; transform: translateX(-50%);
  width: 76%; height: 14px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.32) 0%, rgba(0,0,0,.14) 55%, rgba(0,0,0,0) 78%);
  pointer-events: none; z-index: -1;
}
.training-bird.flying { transition:none; }
.hold-button { width:min(230px,75vw); height:86px; border-radius:999px; border:0; background:linear-gradient(145deg,#f8b64e,#db7d10); color:white; font-weight:950; font-size:20px; box-shadow:0 16px 34px rgba(180,105,16,.3); cursor:pointer; user-select:none; touch-action:none; }

.game-wrap { position: relative; min-height: 600px; border-radius: 28px; overflow: hidden; background:#80cef1; }
.game-canvas { display:block; width:100%; height:600px; touch-action:none; }
.game-hud { position:absolute; left:12px; right:12px; top:12px; display:flex; gap:8px; justify-content:space-between; pointer-events:none; }
.hud-pill { padding:9px 12px; border-radius:999px; background:rgba(255,255,255,.9); font-weight:900; box-shadow:0 5px 16px rgba(16,42,67,.14); }
.game-message { position:absolute; left:50%; top:70px; transform:translateX(-50%); max-width:min(90%,560px); padding:12px 16px; border-radius:16px; background:rgba(255,255,255,.92); text-align:center; font-weight:850; transition:opacity .25s ease; }
.game-controls { position:absolute; left:16px; right:16px; bottom:16px; display:flex; justify-content:space-between; align-items:end; gap:14px; }
.joystick { width:132px; height:132px; border-radius:50%; background:rgba(255,255,255,.28); border:2px solid rgba(255,255,255,.72); backdrop-filter:blur(10px); position:relative; touch-action:none; }
.joystick-knob { width:58px; height:58px; border-radius:50%; background:rgba(255,255,255,.92); position:absolute; left:37px; top:37px; box-shadow:0 8px 20px rgba(16,42,67,.25); }
.control-buttons { display:flex; flex-direction:column; gap:10px; }
.round-action { width:92px; height:92px; border-radius:50%; border:0; background:linear-gradient(145deg,#ffbc55,#dc7911); color:white; font-weight:950; box-shadow:0 10px 22px rgba(150,79,8,.3); touch-action:none; cursor:pointer; }
.round-action.secondary { width:72px; height:72px; align-self:flex-end; background:linear-gradient(145deg,#438eb8,#1f5c7c); }

.diary-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); gap:14px; }
.diary-entry { border-radius:20px; padding:18px; background:linear-gradient(145deg,#fffdf6,#f5e8c9); border:1px solid #ebd7a9; min-height:160px; }
.diary-entry.locked { filter:grayscale(1); opacity:.55; }
.diary-date { font-size:12px; color:var(--ink-soft); }
.diary-entry h3 { margin:10px 0 8px; }
.diary-entry p { color:var(--ink-soft); line-height:1.45; }

.encyclopedia-list { display:grid; gap:12px; }
.encyclopedia-item { background:white; border-radius:18px; padding:18px; border-left:7px solid #5cb5df; }
.encyclopedia-item h3 { margin:0 0 7px; }
.encyclopedia-item p { margin:0; color:var(--ink-soft); line-height:1.5; }

.beta-complete { text-align:center; padding:clamp(26px,5vw,60px); }
.beta-complete .big-icon { font-size:90px; }
.beta-complete h1 { font-size:clamp(36px,6vw,64px); margin:10px 0; }
.beta-complete p { font-size:18px; line-height:1.55; color:var(--ink-soft); max-width:760px; margin:0 auto 26px; }
.migration-intro { text-align:center; padding:clamp(26px,5vw,60px); }
.migration-arrival { text-align:center; padding:clamp(36px,6vw,80px); border-radius:28px; }
.migration-arrival .big-icon { font-size:72px; animation:migrationSunRise 1200ms cubic-bezier(.2,.7,.2,1) 1; }
.migration-arrival h1 { font-size:clamp(30px,5vw,52px); margin:12px 0; }
@keyframes migrationSunRise { 0% { transform:translateY(30px); opacity:0; } 100% { transform:translateY(0); opacity:1; } }
@media (prefers-reduced-motion: reduce) {
  .migration-arrival .big-icon { animation:none; }
}

.toast { position:fixed; z-index:100; left:50%; bottom:calc(24px + env(safe-area-inset-bottom)); transform:translateX(-50%) translateY(20px); padding:12px 16px; border-radius:16px; background:#102a43; color:white; font-weight:800; box-shadow:0 16px 34px rgba(0,0,0,.25); opacity:0; pointer-events:none; transition:.25s ease; }
.toast.show { opacity:1; transform:translateX(-50%) translateY(0); }

.footer-note { text-align:center; color:var(--ink-soft); font-size:12px; padding:12px 0 0; }
.sr-only { position:absolute !important; width:1px !important; height:1px !important; padding:0 !important; margin:-1px !important; overflow:hidden !important; clip:rect(0,0,0,0) !important; white-space:nowrap !important; border:0 !important; }

@media (max-width: 860px) {
  .hero { grid-template-columns:1fr; padding-top:20px; }
  .swift-card { min-height:360px; order:-1; }
  .stage-layout { grid-template-columns:1fr; }
  .stage-side { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
  .game-canvas { height:560px; }
}

/* ==== Batch-14 mobile pass: portrait phones ==== */
@media (max-width: 620px) {
  .brand-subtitle { display:none; }
  .brand-title { white-space: normal; line-height: 1.1; font-size: 15px; }
  .brand-mark { width:38px; height:38px; font-size:0; }
  .top-actions { gap: 6px; }
  .top-actions .soft-btn { width:42px; height:42px; overflow:hidden; padding:0; font-size:0; }
  .top-actions .soft-btn::before { content:"☰"; font-size:20px; }
  .icon-btn { width:40px; height:40px; font-size:18px; }
  .form-grid, .choice-grid { grid-template-columns:1fr; }
  .stage-side { grid-template-columns:1fr; }
  .panel { border-radius:20px; padding:14px; }
  .panel h1 { font-size: clamp(20px, 5.4vw, 26px); line-height: 1.2; }
  .main-content { padding:14px max(12px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .screen-heading { margin-bottom: 12px; }
  .screen-heading h1 { font-size: 24px; margin-bottom: 4px; letter-spacing: -.025em; }
  .screen-heading p { font-size: 14px; line-height: 1.4; }

  /* Game panel takes as much viewport height as possible so canvas + HUD + controls
     all fit above the fold. The right-column stats/fact cards render below and are
     revealed by a natural scroll — game is playable without scrolling first. */
  .game-wrap, .stage-card { min-height: 0; }
  .game-wrap { touch-action: none; overscroll-behavior: contain; }
  /* dvh accounts for mobile URL bar; fallback vh for older browsers. */
  .game-canvas {
    height: 420px;
    height: min(calc(100dvh - 280px), 620px);
    min-height: 380px;
  }

  /* HUD: shrink pills so all three + a 48×48 pause button fit on a 328px-wide canvas. */
  .game-hud { left: 8px; right: 8px; top: 8px; gap: 4px; flex-wrap: nowrap; }
  .hud-pill { padding: 6px 8px; font-size: 12px; border-radius: 999px; white-space: nowrap; }
  .hud-pause { min-width: 48px; min-height: 48px; padding: 0 10px; font-size: 18px; }
  .game-message { top: 58px; padding: 8px 12px; font-size: 13px; max-width: 88%; }

  /* Controls: keep joystick + action buttons thumb-reachable but slightly smaller. */
  .game-controls { left: 10px; right: 10px; bottom: 10px; align-items: end; }
  .joystick { width:112px; height:112px; touch-action: none; }
  .joystick-knob { width:52px; height:52px; left:30px; top:30px; }
  .round-action { width:76px; height:76px; touch-action: none; }
  .round-action.secondary { width:62px; height:62px; }
  .control-buttons { gap:8px; }

  /* Scenes: reduce heights so no scroll for tap-only content.
     Batch-14.2 fix: `aspect-ratio: 3/2` combined with the previous `min-height: 320px`
     forced the scenes to a min-width of 480px on any phone — the illustrated card
     spilled ~120px past the right edge of the viewport (body's overflow-x: hidden was
     silently chopping the right side of the illustration + captions). Removing the
     min-height lets the width follow the parent (100%) and the aspect-ratio derives
     the height from that. A taller 4:3 crop on phones keeps the composition readable
     and the chick / egg / feather hotspot % anchors still line up because they are
     relative to the scene box, not to a fixed pixel dimension. */
  .nest-scene, .chick-scene { min-height: 0; aspect-ratio: 4 / 3; }
  .training-zone { min-height: 380px; padding: 16px; }
  .training-zone > div { padding: 12px 14px; max-width: 92%; }
  /* Scene captions must wrap, never truncate, on narrow phones. */
  .scene-caption { left: 10px; right: 10px; top: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.35; white-space: normal; word-break: break-word; }

  /* Beta complete / arrival / intro screens: tighten padding + heading. */
  .beta-complete .big-icon, .migration-arrival .big-icon { font-size: 56px; }
  .beta-complete h1 { font-size: 26px; }
  .migration-arrival h1 { font-size: 22px; }
  .primary-btn.large { min-width: 100%; min-height: 54px; font-size: 16px; padding: 14px 18px; }
  .primary-btn, .action-btn { padding: 12px 18px; }
  .soft-btn { padding: 10px 14px; }
  .hero-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .hero-actions .soft-btn, .hero-actions .primary-btn { width: 100%; }

  /* Diary + encyclopedia lists collapse to one column. */
  .diary-grid { grid-template-columns: 1fr; }
  .diary-entry { min-height: 130px; padding: 14px; }
  .encyclopedia-item { padding: 14px; }

  /* Certificate on mobile: use dvw so image fits without horizontal scroll. */
  .certificate-panel .certificate-frame img { max-width: 100%; }

  /* Stage retry screen: full-width buttons for one-thumb reach. */
  .stage-retry .hero-actions { flex-direction: column; }
  .stage-retry .hero-actions > button { width: 100%; }
}

/* Very narrow phones (iPhone SE / small Android) */
@media (max-width: 400px) {
  .brand-title { font-size: 14px; }
  .brand-mark { width:34px; height:34px; font-size:0; border-radius:11px; }
  .topbar { gap:8px; padding:8px 10px 8px 10px; }
  .icon-btn { width:36px; height:36px; font-size:16px; }
  .top-actions { gap:5px; }
  .top-actions .soft-btn { width:36px; height:36px; }
  .screen-heading h1 { font-size: 22px; }
  .hud-pill { padding: 4px 6px; font-size: 11px; }
  .hud-pause { min-width: 48px; min-height: 48px; padding: 0 8px; font-size: 17px; }
  .game-canvas { height: min(calc(100dvh - 260px), 620px); min-height: 340px; }
  .joystick { width:100px; height:100px; }
  .joystick-knob { width:46px; height:46px; left:27px; top:27px; }
  .round-action { width:70px; height:70px; }
  .round-action.secondary { width:56px; height:56px; }
  .beta-complete h1 { font-size: 22px; }
  .beta-complete p, .migration-intro p, .screen-heading p { font-size: 13px; }
  .field input, .field select { padding: 11px 12px; }
}

/* Landscape phones: canvas stages must remain playable — allow the canvas to be shorter
   but keep controls visible above the fold. */
@media (max-height: 500px) and (orientation: landscape) {
  .game-canvas { height: calc(100dvh - 130px); min-height: 260px; }
  .screen-heading { margin-bottom: 6px; }
  .screen-heading h1 { font-size: 20px; }
  .screen-heading p { display: none; }
  .stage-side { display: none; }
  .main-content { padding-top: 8px; }
  .joystick { width: 96px; height: 96px; }
  .joystick-knob { width: 44px; height: 44px; left: 26px; top: 26px; }
  .round-action { width: 68px; height: 68px; }
  .round-action.secondary { width: 54px; height: 54px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration:.01ms !important; animation-iteration-count:1 !important; scroll-behavior:auto !important; transition-duration:.01ms !important; }
}
