/* 首頁：蛋是唯一主角。由上到下：資源列 → 蛋的名字與階段 → 培養架 → 小恐龍與對話 → 生命訊號 → 分頁列 */

/* 首頁剛好填滿一個畫面、不捲動。用 svh（最小視窗高度）：網址列展開或收合都不會跳動 */
body[data-view="incubate"] .app { height: 100vh; height: 100svh; overflow: hidden; }
.view--incubate { gap: 8px; padding: 8px 0 10px; }

/* ---------- 蛋的名字與孵化階段 ---------- */
.eggtitle { display: flex; flex-direction: column; align-items: center; gap: 5px; position: relative; z-index: 2; }
.eggtitle__name {
  font-family: var(--font-display); font-weight: 700; font-size: 17px; line-height: 1.2; letter-spacing: 0.22em; padding-left: 0.22em;
  background: var(--metal); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.eggtitle__meta { display: flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.16em; color: var(--silver); }
.pips { display: flex; gap: 6px; }
.pips i { width: 7px; height: 7px; transform: rotate(45deg); border: 1px solid var(--rose-metal); transition: background 0.4s ease, box-shadow 0.4s ease; }
.pips i.is-on { background: var(--crimson); border-color: var(--rose-light); box-shadow: 0 0 8px rgba(194, 31, 60, 0.9); }

/* ---------- 培養架與蛋 ---------- */
.stage { position: relative; flex: 1; min-height: 0; container-type: size; }
.incubator {
  position: absolute; left: 50%; top: 50%; aspect-ratio: 1;
  width: min(128vw, 50vh);            /* 不支援容器單位的舊瀏覽器 */
  width: min(130cqw, 139cqh);         /* 依培育區的實際寬高縮放：蛋永遠完整、盡量大 */
  transform: translate(-50%, -53%);   /* 素材的視覺中心在畫布 53% 的高度 */
}
.incubator__layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.incubator__layer--cradle { filter: brightness(0.8) saturate(0.85); } /* 架子退後一步，讓蛋最亮 */
.incubator__slot { position: absolute; inset: 0; }

/* 蛋背後的呼吸光：隨孵化進度變亮 */
.incubator__halo {
  position: absolute; left: 51.5%; top: 43%; width: 70%; aspect-ratio: 1; margin: -35% 0 0 -35%;
  border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, rgba(255, 217, 196, 0.75), rgba(232, 150, 160, 0.3) 45%, transparent 72%);
  opacity: calc(0.3 + 0.55 * var(--p, 0));
  animation: halo 4s ease-in-out infinite;
}
.incubator.is-ready .incubator__halo { animation-duration: 1.4s; opacity: 1; }
@keyframes halo { 0%, 100% { transform: scale(0.92); } 50% { transform: scale(1.06); } }

.egg { position: absolute; inset: 0; transform: translate(var(--egg-x, 1.5%), var(--egg-y, 0.8%)); }
/* 蛋穩穩坐進培養架：往下放一點，底部加接觸陰影與托盤反光 */
.egg[data-art="weather"], .egg[data-art="keepsake"] { --egg-y: 3.6%; }
.egg::before { content: ''; position: absolute; left: 39%; right: 39%; top: 66.5%; height: 4.5%; border-radius: 50%; background: radial-gradient(closest-side, #000c, #0006 55%, transparent); filter: blur(1px); }
.egg::after { content: ''; position: absolute; left: 34%; right: 34%; top: 66%; height: 6%; border-radius: 50%; background: radial-gradient(closest-side, var(--egg-glow, #ffd9c4)66, transparent); opacity: var(--glow, .12); mix-blend-mode: screen; }
.egg__layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.egg__wobble, .egg__body { position: absolute; inset: 0; transform-origin: 50% 68.5%; }
.egg__body { animation: egg-breathe 3.6s ease-in-out infinite; }
.egg__layer--glow { mix-blend-mode: screen; opacity: var(--glow, 0.12); animation: egg-pulse var(--pulse, 3s) ease-in-out infinite; }
.egg__layer--cracks { opacity: 0; transition: opacity 0.6s ease, clip-path 0.8s ease; clip-path: inset(0 0 100% 0); }

/* 孵化階段越高，蛋的反應越明顯 */
.egg[data-stage="1"] .egg__wobble { animation: egg-stir 4s ease-in-out infinite; }
.egg[data-stage="2"] .egg__wobble { animation: egg-stir 2.2s ease-in-out infinite; }
.egg[data-stage="2"] .egg__layer--cracks { opacity: 0.85; clip-path: inset(0 0 45% 0); }
.egg[data-stage="3"] .egg__wobble, .egg[data-stage="4"] .egg__wobble { animation: egg-shake 0.5s ease-in-out infinite; }
.egg[data-stage="3"] .egg__layer--cracks, .egg[data-stage="4"] .egg__layer--cracks { opacity: 1; clip-path: inset(0); }
.egg.is-hatching .egg__wobble { animation: none; }
.egg.is-hatching .egg__body { animation: egg-open 0.9s ease-in forwards; }

@keyframes egg-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.012, 1.025); } }
@keyframes egg-pulse { 0%, 100% { transform: scale(0.97); } 50% { transform: scale(1.03); } }
@keyframes egg-stir { 0%, 86%, 100% { transform: rotate(0); } 90% { transform: rotate(-2.5deg); } 94% { transform: rotate(2.5deg); } 98% { transform: rotate(-1deg); } }
@keyframes egg-shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
@keyframes egg-open { to { transform: scale(1.25); opacity: 0; } }

/* 點蛋：先壓下去再彈回來 */
.incubator__slot.is-press { animation: press 0.36s cubic-bezier(0.3, 1.5, 0.5, 1); transform-origin: 51.5% 66%; }
@keyframes press { 0% { transform: scale(1); } 30% { transform: scale(0.94, 0.96); } 65% { transform: scale(1.04, 1.03); } 100% { transform: scale(1); } }
/* 能量抵達：蛋亮一下 */
.incubator__slot.is-fed .egg__layer--glow { animation: fed 0.6s ease-out; }
@keyframes fed { 30% { opacity: 0.9; } }

/* 能量抵達時的光點 */
.spark {
  position: absolute; left: 51.5%; top: 43%; width: 7px; height: 7px; margin: -3.500px; border-radius: 50%; pointer-events: none;
  background: #fff; box-shadow: 0 0 10px 3px rgba(255, 190, 180, 0.9);
  animation: spark 0.6s ease-out forwards;
}
@keyframes spark { from { transform: translate(0, 0) scale(1); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; } }

/* 進入新階段：一圈光環向外擴散 */
.incubator__ring {
  position: absolute; left: 51.5%; top: 43%; width: 44%; aspect-ratio: 1; margin: -22% 0 0 -22%;
  border-radius: 50%; border: 2px solid var(--rose-light); opacity: 0; pointer-events: none;
  box-shadow: 0 0 24px rgba(255, 217, 196, 0.9), inset 0 0 24px rgba(255, 217, 196, 0.5);
}
.incubator__ring.is-on { animation: ring 0.9s ease-out; }
@keyframes ring { 0% { opacity: 0.95; transform: scale(0.7); } 100% { opacity: 0; transform: scale(1.9); } }

.incubator__flare {
  position: absolute; left: 51.5%; top: 43%; width: 80%; aspect-ratio: 1; margin: -40% 0 0 -40%; border-radius: 50%; opacity: 0; pointer-events: none;
  background: radial-gradient(closest-side, #fff 0%, var(--egg-glow) 35%, transparent 100%);
}
.incubator__flare.is-on { animation: egg-flare 1.1s ease-out forwards; }
@keyframes egg-flare { 0% { opacity: 0; transform: scale(0.4); } 40% { opacity: 0.95; } 100% { opacity: 0; transform: scale(1.7); } }

/* 蛋本身是按鈕 */
.egg-hit { position: absolute; z-index: 4; left: 33%; top: 19%; width: 38%; height: 49%; border: 0; border-radius: 50%; background: none; padding: 0; }

.float-gain {
  position: absolute; z-index: 5; left: 64%; top: 22%; pointer-events: none; opacity: 0;
  font-family: var(--font-mono); font-size: 20px; font-weight: 500; color: #fff;
  text-shadow: 0 0 10px rgba(255, 138, 156, 0.95), 0 0 2px rgba(109, 15, 34, 1);
}
.float-gain.is-on { animation: gain 0.9s ease-out; }
@keyframes gain { 0% { opacity: 0; transform: translateY(10px) scale(0.8); } 25% { opacity: 1; transform: translateY(0) scale(1.1); } 100% { opacity: 0; transform: translateY(-36px) scale(1); } }

/* 從能量膠囊飛向蛋的能量球 */
.orb {
  position: fixed; z-index: 30; left: 0; top: 0; width: 14px; height: 14px; margin: -7px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 35% 30%, #fff, #ff8a9c 45%, var(--crimson));
  box-shadow: 0 0 14px 4px rgba(255, 110, 135, 0.8);
}

/* 緩緩上升的光點 */
.motes { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.motes i {
  position: absolute; bottom: 18%; width: 4px; height: 4px; border-radius: 50%;
  background: var(--rose-light); box-shadow: 0 0 8px 2px rgba(248, 220, 205, 0.6);
  opacity: 0; animation: mote 7s linear infinite;
}
.motes i:nth-child(1) { left: 16%; animation-delay: 0s; }
.motes i:nth-child(2) { left: 30%; animation-delay: 2.1s; width: 3px; height: 3px; }
.motes i:nth-child(3) { left: 44%; animation-delay: 4.4s; }
.motes i:nth-child(4) { left: 58%; animation-delay: 1.2s; width: 3px; height: 3px; }
.motes i:nth-child(5) { left: 72%; animation-delay: 3.3s; }
.motes i:nth-child(6) { left: 86%; animation-delay: 5.5s; width: 3px; height: 3px; }
.motes i:nth-child(7) { left: 24%; animation-delay: 6.1s; width: 2px; height: 2px; }
.motes i:nth-child(8) { left: 66%; animation-delay: 0.6s; width: 2px; height: 2px; }
@keyframes mote { 0% { opacity: 0; transform: translate(0, 0); } 15% { opacity: 0.9; } 85% { opacity: 0.6; } 100% { opacity: 0; transform: translate(10px, -46cqh); } }

/* 階段完成的短暫提示 */
.banner {
  position: absolute; z-index: 6; left: 50%; top: 4%; transform: translateX(-50%); pointer-events: none; opacity: 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px; white-space: nowrap; padding: 6px 0;
}
.banner::before, .banner::after { content: ''; position: absolute; top: 50%; width: 46px; height: 1px; background: linear-gradient(90deg, transparent, #e7d4f2cc); }
.banner::before { right: calc(100% + 10px); }
.banner::after { left: calc(100% + 10px); transform: scaleX(-1); }
.banner__en { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.34em; color: #cdb8dc; }
.banner__zh { font-family: var(--font-display); font-weight: 400; font-size: 17px; letter-spacing: 0.24em; color: #fbf3ff; text-shadow: 0 0 12px #c9a8ffcc, 0 0 2px #fff; }
.banner__zh::before, .banner__zh::after { content: '✦'; margin: 0 8px; font-size: 9px; color: #e7cdf2; vertical-align: middle; }
.banner.is-on { animation: banner 2.2s ease both; }
@keyframes banner { 0% { opacity: 0; transform: translateX(-50%) translateY(6px); filter: blur(3px); } 18% { opacity: 1; transform: translateX(-50%) translateY(0); filter: blur(0); } 78% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) translateY(-6px); } }

/* 右側浮動按鈕 */
.side { position: absolute; z-index: 5; right: 0; top: 2px; display: flex; flex-direction: column; gap: 10px; }
.fab {
  position: relative; width: 48px; height: 48px; border-radius: 50%; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 1px solid rgba(210, 163, 145, 0.6); background: rgba(22, 14, 18, 0.78);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.fab svg { width: 18px; height: 18px; display: block; fill: none; stroke: var(--rose-light); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.fab__label { font-size: 9px; line-height: 1; letter-spacing: 0.08em; color: var(--pearl); }
.fab:active { transform: scale(0.94); }
.fab.is-nudge { animation: nudge 0.5s ease; }
@keyframes nudge { 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

/* ---------- 地板：角色活動區 ---------- */
/* 圖層順序（後→前）：背景 → 培養架後景 → 蛋 → 培養架前景 → 角色（地板）→ 對話框 */
.floor { position: relative; z-index: 4; height: var(--actor); margin-top: calc(var(--actor) * -0.42); pointer-events: none; --actor: clamp(100px, 29vw, 128px); }
.floor > * { pointer-events: auto; }

/* 小恐龍引導員 */
.guide { position: absolute; left: -6px; bottom: 0; width: calc(var(--actor) * 0.74); border: 0; background: none; padding: 0; }
.mascot { position: relative; display: block; width: 100%; height: auto; transform-origin: 50% 92%; animation: dino-idle 3.2s ease-in-out infinite; }
.guide__shadow, .actor__shadow {
  position: absolute; left: 18%; right: 18%; bottom: 3%; height: 12%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.55), transparent);
}
.guide__alert { /* 對話框收起時，提醒玩家小恐龍有話要說 */
  position: absolute; right: 4%; top: 0; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--font-mono); font-size: 12px; font-weight: 500; color: #fff;
  background: var(--crimson); border: 1px solid var(--rose-light);
  animation: alert 1.4s ease-in-out infinite;
}
@keyframes alert { 50% { transform: translateY(-3px) scale(1.1); } }

/* 對話框：有事才出現，幾秒後自動收起 */
.bubble {
  position: absolute; z-index: 2; left: calc(var(--actor) * 0.56); bottom: calc(var(--actor) * 0.62); max-width: min(66vw, 280px);
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 8px 13px 9px; border: 0; border-radius: 16px 16px 16px 4px;
  background: #f7eee7; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(201, 160, 147, 0.9);
  transform-origin: 0 100%; opacity: 0; transform: scale(0.6); visibility: hidden;
  transition: opacity 0.2s ease, transform 0.28s cubic-bezier(0.3, 1.5, 0.5, 1), visibility 0s 0.28s;
}
.bubble.is-open { opacity: 1; transform: scale(1); visibility: visible; transition-delay: 0s; }
.bubble__text { font-family: var(--font-display); font-size: 13.500px; line-height: 1.5; color: #3a1620; }
.bubble__cta { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; color: #a3213b; }

/* 小恐龍的四種狀態 */
@keyframes dino-idle { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.02, 0.98); } }
.guide[data-mood="happy"] .mascot { animation: dino-happy 0.5s ease-in-out 3; }
@keyframes dino-happy { 0%, 100% { transform: translateY(0) scale(1.03, 0.97); } 50% { transform: translateY(-12px) scale(0.97, 1.04); } }
.guide[data-mood="remind"] .mascot { animation: dino-remind 0.42s ease-in-out 3; }
@keyframes dino-remind { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg); } 75% { transform: rotate(9deg); } }
.guide[data-mood="cheer"] .mascot { animation: dino-cheer 0.7s ease-in-out infinite; }
@keyframes dino-cheer { 0%, 100% { transform: translateY(0) scale(1.04, 0.96); } 45% { transform: translateY(-9px) scale(0.97, 1.04); } }
.guide.is-hop .mascot { animation: dino-happy 0.5s ease-in-out 1; }

/* 小湘：會自己走動的角色。外層負責水平位移，中層負責左右翻面，內層是逐格播放的圖 */
.actor {
  position: absolute; left: 0; bottom: 0; width: var(--actor); height: var(--actor); pointer-events: none !important;
  transition: transform 0s linear; will-change: transform;
}
.actor__flip { position: absolute; inset: 0; transform-origin: 50% 92%; }
.actor__flip[data-dir="left"] { transform: scaleX(-1); }
.actor__sprite { position: absolute; inset: 0; transform-origin: 50% 92%; animation:hd-breathe 5s ease-in-out infinite; animation-play-state:paused; }
.resident-lanes[data-active="true"] .actor:not([data-state="walk"]) .actor__sprite { animation-play-state:running; }
@keyframes hd-breathe { 50% { transform:scale(1.004,1.007); } }
@media(prefers-reduced-motion:reduce) { .actor__sprite { animation:none!important; } }
.actor__layer { position: absolute; inset: 0; background-repeat: no-repeat; background-size: 100% 100%; transform-origin:50% 91.6268%; }
.actor__sprite.is-swap { animation: actor-swap 0.24s ease-out; }
@keyframes actor-swap { 0% { transform: scale(1.04, 0.9); } 100% { transform: scale(1); } }
.actor__shadow { left: 26%; right: 26%; }
.actor.is-cheer .actor__sprite { animation: dino-happy 0.5s ease-in-out 2; }
.actor__emote { /* 看蛋時頭上冒出的小光點 */
  position: absolute; left: 50%; top: 2%; width: 10px; height: 10px; margin-left: -5px; transform: rotate(45deg); opacity: 0;
  background: var(--rose-light); box-shadow: 0 0 10px 2px rgba(248, 220, 205, 0.8);
}
.actor__emote.is-on { animation: emote 1.6s ease-out 0.3s; }
@keyframes emote { 0% { opacity: 0; transform: translateY(6px) rotate(45deg) scale(0.4); } 25% { opacity: 1; transform: translateY(-4px) rotate(45deg) scale(1); } 100% { opacity: 0; transform: translateY(-18px) rotate(45deg) scale(0.8); } }

/* ---------- 生命訊號：一條精簡的儀表 ---------- */
.vitals { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 16px; }
.vitals__id { display: flex; flex-direction: column; gap: 3px; }
.vitals__en { font-family: var(--font-mono); font-size: 9px; line-height: 1; letter-spacing: 0.2em; color: var(--hud); }
.vitals__zh { font-family: var(--font-display); font-size: 12px; line-height: 1; letter-spacing: 0.16em; color: var(--rose-metal); }
.vitals__meter { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ecg { position: relative; height: 14px; overflow: hidden; }
.ecg__line { position: absolute; top: 0; left: 0; width: 200%; height: 100%; animation: ecg var(--ecg-dur, 2.5s) linear infinite; }
.ecg__line path { fill: none; stroke: #ff6a82; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
@keyframes ecg { to { transform: translateX(-50%); } }
.bar { height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar__fill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--crimson-deep), var(--crimson) 60%, #ff8a9c); transition: width 0.5s cubic-bezier(0.3, 1, 0.4, 1); }
.vitals__num { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; font-family: var(--font-mono); line-height: 1; }
.vitals__value { font-size: 18px; color: var(--ivory); }
.vitals__max { font-size: 11px; color: var(--silver); }
.vitals__bpm { font-size: 9px; letter-spacing: 0.14em; color: var(--hud); }

/* 矮螢幕（瀏覽器工具列佔掉高度時）：縮小角色與輔助元素，不縮蛋 */
@media (max-height: 640px) {
  .view--incubate { gap: 5px; padding-top: 4px; }
  .eggtitle__name { font-size: 15px; }
  .floor { --actor: clamp(84px, 25vw, 104px); }
  .vitals { padding: 6px 12px; }
  .fab { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .motes, .orb { display: none; }
}
