/* avatar.css — 頭像 phase 1a (頭像及服飾收藏方案 v3 §2, §4.1–§4.3), added 2026-11-21. Loaded after game.css.
   The composed avatar is a <canvas> sized to its box x devicePixelRatio (js/avatar_render.js): full body = the manifest body_box crop (314 x 660 at the
   512 x 768 canvas, aspect 0.476), head = the square head_box crop. Static: no flashing, motion only under
   html:not([data-motion="reduce"]). Tap targets are 48 px or more. */

.av-img { display: block; }
.av-img.av-full { height: 100%; width: auto; max-width: 100%; object-fit: contain; }
.av-img.av-head { width: 100%; height: 100%; object-fit: cover; }
.av-ph { display: block; }
.av-ph.av-full { height: 100%; aspect-ratio: 314 / 660; margin: 0 auto;
  background: radial-gradient(ellipse 38% 22% at 50% 24%, rgba(34, 49, 74, .08) 98%, transparent 100%),
              radial-gradient(ellipse 22% 36% at 50% 66%, rgba(34, 49, 74, .06) 98%, transparent 100%); }
.av-ph.av-head { width: 100%; height: 100%; border-radius: 50%; background: rgba(34, 49, 74, .06); }

/* ---------- top bar (§4.2): avatar head inside the XP ring, the pet as a small stamp bottom-left ---------- */
.g-avatar-art.is-av { background: #fff8ea; }
.g-avatar-art.is-av .av-img { width: 100%; height: 100%; }
.g-avatar-pet { position: absolute; left: -5px; bottom: -3px; width: 24px; height: 24px; border-radius: 50%; overflow: hidden; background: #fff;
  border: 2px solid var(--g-panel-line); display: grid; place-items: center; pointer-events: none; }
.g-avatar-pet .pet-art { width: 22px !important; height: 22px !important; object-fit: contain; }

/* ---------- 主頁天台 (§4.1): avatar centre-left, pet on the right by stage ---------- */
/* the avatar's head stays right of the side bubbles (they end at 84 px) */
.g-scene.has-av { --av-h: min(250px, 62cqw); --av-x: 37%; --av-base: 160px; }
.g-av { position: absolute; z-index: 3; left: var(--av-x); bottom: var(--av-base); height: var(--av-h); width: calc(var(--av-h) * 0.476);
  margin-left: calc(var(--av-h) * -0.238); padding: 0; border: 0; background: none; border-radius: 40% 40% 12% 12%; }
.g-av .av-img { height: 100%; width: 100%; filter: drop-shadow(0 8px 8px rgba(31, 41, 51, .2)); }
.g-av:active { transform: translateY(2px); }
html:not([data-motion="reduce"]) .g-av .av-img { animation: g-breathe 3.6s ease-in-out infinite; }
/* pet: stage 1–2 at the avatar's feet, 3 side by side, 4 behind (and gently floating) */
.g-scene.has-av .g-pet { --pw: min(140px, 36cqw); left: 72%; bottom: calc(var(--av-base) - 6px); width: var(--pw); margin-left: calc(var(--pw) / -2); }
.g-scene.has-av.st3 .g-pet { --pw: min(196px, 50cqw); left: 71%; }
.g-scene.has-av.st4 .g-pet { --pw: min(210px, 54cqw); left: 69%; bottom: calc(var(--av-base) + 60px); z-index: 2; }
html:not([data-motion="reduce"]) .g-scene.has-av.st4 .g-pet:not(.resting) .pet-art { animation: av-float 4s ease-in-out infinite; }
@keyframes av-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.g-scene.has-av .g-zz { left: calc(72% + 30px); bottom: calc(var(--av-base) + min(130px, 34cqw)); }
.g-scene.has-av .g-ff { left: calc(72% + min(36px, 9cqw)); bottom: calc(var(--av-base) + min(150px, 40cqw)); }
.g-scene.has-av.st4 .g-ff { bottom: calc(var(--av-base) + 60px + min(190px, 50cqw)); }
/* ground decor moves out of the avatar's way (bottom-left corner, smaller) */
.g-scene.has-av .g-decor.ground { left: 1%; width: 19%; bottom: calc(var(--av-base) - 4px); }

/* ---------- 守護卡 (§4.3): avatar centre-left, pet centre-right, about 60% of the card height each ---------- */
.pet-screen .scene.has-av::after { left: 18%; right: 14%; }
.pet-screen .scene-av { position: absolute; z-index: 2; left: 35%; bottom: 7%; height: 60%; aspect-ratio: 314 / 660; transform: translateX(-50%); pointer-events: none; }
.pet-screen .scene-av .av-img { height: 100%; width: 100%; filter: drop-shadow(0 5px 6px rgba(31, 41, 51, .18)); }
.pet-screen .scene.has-av .scene-pet { left: 65%; bottom: 15%; height: 57%; }
.pet-screen .scene.has-av .scene-decor.ground { left: 4%; bottom: 6%; width: 17%; }
/* high decor stays top-right; the pet stands in front of it (a kite or lantern may tuck behind the pet) */
.pet-screen .scene.has-av .scene-decor.high { right: 3%; top: 24%; width: 17%; z-index: 1; }
.pet-screen .scene.has-av .scene-pet { z-index: 3; }
.pet-screen .scene.has-av .scene-zz { right: 14%; top: 20%; }

/* 我的形象 card on the 寵物 tab */
.pet-screen .av-card { display: flex; align-items: center; gap: 12px; }
.pet-screen .av-card h4 { margin: 0 0 2px; }
.pet-screen .av-card p { margin: 0; }
.pet-screen .av-card .g-btn { flex-shrink: 0; min-height: 48px; padding: 8px 16px; font-size: 16px; }
.av-card-head { width: 64px; height: 64px; flex-shrink: 0; border-radius: 50%; overflow: hidden; background: #fff8ea; border: 3px solid var(--g-panel-line); }

/* ---------- 設計我的形象 ---------- */
.screen.av-screen { padding: 12px 16px 24px; }
.av-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.av-top h2 { margin: 4px 0 2px; font-size: 22px; }
.av-top p { margin: 0; }
.av-top h2:focus:not(:focus-visible) { outline: none; }
.av-tabs button:focus-visible, .av-opt:focus-visible { outline: 3px solid var(--g-primary-edge); outline-offset: 2px; }
.av-skip { min-height: 48px; padding: 8px 16px; font-size: 16px; flex-shrink: 0; }
.av-stick { position: sticky; top: 0; z-index: 4; margin: 0 -16px; padding: 8px 16px 6px; background: var(--g-bg); }
.av-preview { height: min(280px, 34dvh); margin: 0 0 8px; border-radius: var(--g-radius-lg); border: 3px solid var(--g-panel-line);
  background: radial-gradient(ellipse 60% 18% at 50% 92%, rgba(122, 82, 54, .14), transparent 70%), linear-gradient(180deg, #e9f3fb 0%, #fdf6ea 78%);
  display: flex; justify-content: center; align-items: flex-end; padding: 10px 0 12px; }
.av-preview .av-img, .av-preview .av-ph { height: 100%; }
.av-tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 4px; }
.av-tabs button { min-height: 48px; padding: 4px 2px; border-radius: 14px; border: 2px solid var(--g-neutral-edge); background: #fff; color: var(--g-ink-soft);
  font-size: 16px; font-weight: 800; box-shadow: 0 3px 0 var(--g-neutral-edge); }
.av-tabs button.on { background: var(--g-primary); border-color: var(--g-primary-edge); color: var(--g-ink); box-shadow: 0 3px 0 var(--g-primary-edge); }
.av-tabs button:active { transform: translateY(3px); box-shadow: none; }
.av-panel { min-height: 120px; }
.av-slot h4 { margin: 8px 0 6px; font-size: 16px; }
.av-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.av-grid.swatches { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
.av-opt { position: relative; min-height: 92px; min-width: 48px; padding: 8px 4px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border-radius: 18px; border: 3px solid var(--g-panel-line); background: #fff; color: var(--g-ink); font-weight: 700; box-shadow: 0 3px 0 var(--g-panel-line); }
.av-opt:active { transform: translateY(3px); box-shadow: none; }
.av-opt.on { border-color: var(--g-primary-edge); background: #fff6d8; box-shadow: 0 3px 0 var(--g-primary-edge); }
.av-opt small { font-size: 14px; line-height: 1.2; text-align: center; }
.av-opt .av-head, .av-opt .av-ph.av-head { width: 60px; height: 60px; border-radius: 50%; background: #fdf6ea; }
.av-opt.round { min-height: 72px; }
.av-opt.labelled { min-height: 88px; }
.av-swatch { width: 48px; height: 48px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(34, 49, 74, .18); }
.av-thumb { display: block; width: 64px; height: 56px; object-fit: contain; }
.av-thumb.av-ph { border-radius: 12px; background: rgba(34, 49, 74, .06); }
.av-none { width: 56px; height: 56px; display: grid; place-items: center; font-size: 32px; color: var(--g-ink-soft); }
.av-tick { position: absolute; top: 4px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--g-primary-edge); color: #fff;
  font-style: normal; font-size: 14px; line-height: 22px; text-align: center; }
.av-note { margin: 10px 0 0; }
.av-actions { position: sticky; bottom: 0; z-index: 5; display: flex; gap: 10px; margin: 14px -16px 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(253, 246, 234, .96); border-top: 2px solid var(--g-panel-line); }
.av-actions .g-btn { min-height: 56px; }
.av-actions .grow { flex: 1; }
.av-skipnote { margin: 8px 0 0; }
