/* 控件在滚动区域内保留完整的焦点与选中轮廓。 */
#gm, .overlay, .gm-card, .card { box-sizing: border-box; }
#gm { padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); overflow: auto; overscroll-behavior: contain; }
#gm .gm-card { max-width: 100%; max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow: auto; scrollbar-gutter: stable; }
#gm .gm-head { flex-wrap: wrap; gap: 10px; }
#gm .gm-head h2 { min-width: 0; overflow-wrap: anywhere; }
#gm .gm-x { flex: none; margin-left: auto; }
#gm .gm-body, #gm .me-side, #gm .me-row { min-width: 0; }
#gm .me-opts { padding: 8px; box-sizing: border-box; scrollbar-gutter: stable; overscroll-behavior: contain; }
#gm .me-sw { padding: 5px; gap: 10px; }
#gm .me-sw button { flex: 0 0 32px; width: 32px; height: 32px; box-sizing: border-box; }
#gm .me-tabs { padding: 5px; gap: 8px; }
#gm .me-tabs button, #gm .me-chips button { position: relative; }
#gm .me-buy { height: auto; min-height: 46px; flex-wrap: wrap; }
#gm .me-buy span { min-width: 0; overflow-wrap: anywhere; }
#gm .me-grid { height: clamp(280px, 55dvh, 460px); }
body .spots { box-sizing: border-box; max-width: calc(100% - 24px); padding: 8px; gap: 4px; overflow: visible; }
body .spots button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 0; position: relative; }
body .spots button[data-key]::after, body .spots button[data-kbd]::after { position: static; flex: none; margin: 0; }
.hud-r { min-width: 0; }
.hud-r > * { box-sizing: border-box; max-width: 100%; }
button, a { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; transition: background-color .16s ease, border-color .16s ease, color .16s ease; }
#gm, .overlay:not([hidden]), .pk-wrap { animation: ui-appear .18s ease-out; }
#gm .gm-card, .overlay > .card { animation: ui-rise .2s ease-out; }
@keyframes ui-appear { from { opacity: 0; } to { opacity: 1; } }
@keyframes ui-rise { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
#sceneTransition { position: fixed; inset: 0; z-index: 9; pointer-events: none; background: #090b18; animation: scene-fade .32s ease-in-out both; }
@keyframes scene-fade { 0%, 100% { opacity: 0; } 45%, 55% { opacity: .8; } }
@media (max-width: 720px) {
  #gm .me-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: clamp(150px, 27dvh, 240px) minmax(240px, 38dvh); height: auto; }
  #gm .me-card .gm-body { padding: 10px 12px 12px; }
  #gm .me-card .gm-row { margin: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  #gm .me-tabs button { padding: 8px 10px; }
  body .spots { width: max-content; max-width: calc(100% - 20px); gap: 0; }
  body .spots button { padding: 9px 8px; font-size: 11px; }
  .hud { padding-inline: 10px; }
  .hud .brand { padding: 7px 10px; }
}
@media (max-width: 440px) {
  body .spots { width: calc(100% - 20px); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-radius: 20px; }
  .hint, #fps { display: none; }
  .portal { bottom: calc(env(safe-area-inset-bottom, 0px) + 105px); box-sizing: border-box; }
  .hud-r { gap: 5px; }
  .hud-r .mapbtn { padding: 8px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  #gm, #gm .gm-card, .overlay, .overlay > .card, .pk-wrap, #sceneTransition { animation: none; }
  button, .bubble { transition: none; }
}

.lock { box-sizing: border-box; max-width: calc(100% - 24px); text-align: center; }
#gm .me-stage, #gm .me-opts { min-width: 0; }
#gm .me-wait { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 12px; padding: 16px; text-align: center; }
#gm .me-wait button { pointer-events: auto; max-width: 100%; }
#gm .me-chips button { max-width: 100%; overflow-wrap: anywhere; }
#gm .gm-head small { flex-basis: 100%; order: 3; line-height: 1.5; }
#pkWrap iframe { margin-top: calc(58px + env(safe-area-inset-top, 0px)); height: calc(100% - 58px - env(safe-area-inset-top, 0px)); }
#pkWrap .pk-x { max-width: calc(100% - 28px); box-sizing: border-box; }
@media (max-width: 380px) {
  #cam .cam-bar { gap: 10px; }
}
@media (max-width: 440px) {
  #cam:not(.side) .cam-bar { width: calc(100% - 24px); grid-template-columns: 44px 64px minmax(0, 1fr) 48px; gap: 8px; }
  #cam:not(.side) .cam-shut { width: 64px; height: 64px; }
  #cam:not(.side) .cam-roll { width: 42px; height: 42px; }
  #cam:not(.side) .cam-flip { width: 48px; height: 48px; }
  #cam:not(.side) .cam-zoom { gap: 0; padding: 2px; }
  #cam:not(.side) .cam-zoom button { width: 25px; height: 30px; padding: 0; flex: none; }
  #cam:not(.side) .cam-zoom b { font-size: 10px; }
}
.site-failure { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 18px; padding: 24px; box-sizing: border-box; background: #121014; color: #f3eef1; font: 16px/1.7 system-ui, sans-serif; text-align: center; }
.site-failure p { max-width: 560px; }
.site-failure button { border: 0; border-radius: 999px; padding: 12px 24px; background: #ff2e88; color: #fff; font: inherit; }
#gm .gm-head { position: sticky; top: 0; z-index: 3; background: #1c1420; }
/* 相机工具栏按实际文字宽度排列；横屏固定一列，避免生成隐式第二列。 */
#cam { box-sizing: border-box; padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
#cam .cam-tools { position: fixed; display: flex; gap: 8px; top: calc(env(safe-area-inset-top, 0px) + 12px); left: max(16px, env(safe-area-inset-left, 0px)); right: calc(max(16px, env(safe-area-inset-right, 0px)) + 48px); }
#cam .cam-tools .cam-style { position: relative; inset: auto; display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-width: 0; max-width: 100%; height: 40px; padding: 0 12px; white-space: nowrap; }
#cam .cam-keys { top: calc(env(safe-area-inset-top, 0px) + 62px); }
#cam.side .cam-bar { grid-template-columns: 76px; grid-template-rows: repeat(4, auto); gap: 8px; }
#cam.side .cam-bar > * { grid-column: 1; }
#cam.side .cam-shut { width: 64px; height: 64px; }
#cam.side .cam-flip { width: 48px; height: 48px; }
#cam.side .cam-roll { width: 42px; height: 42px; }
#cam.side .cam-zoom { gap: 0; padding: 2px; }
#cam.side .cam-zoom button { width: 26px; height: 26px; padding: 0; }
@supports (height: 100dvh) { .floor canvas#c { height: min(calc(84.5dvh - 66px), calc(180vw - 108px), 1080px); } }
.pk-loading { position: absolute; inset: 58px 0 0; z-index: 1; display: grid; place-items: center; padding: 24px; text-align: center; background: #0d0908; font: 600 14px/1.6 system-ui, sans-serif; }
#pkWrap.ready .pk-loading { display: none; }
#pkWrap iframe { opacity: 0; transition: opacity .18s ease; }
#pkWrap.ready iframe { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #pkWrap iframe { transition: none; } }
.kart-on .hud, .kart-on .hint { visibility: hidden; }
.cam-on #touchHelp, .kart-on #touchHelp { display: none; }
#kartHud { box-sizing: border-box; max-width: calc(100% - 24px); flex-wrap: wrap; justify-content: center; gap: 8px; white-space: nowrap; top: calc(env(safe-area-inset-top, 0px) + 12px); }
@media (max-width: 560px) {
  body .kart-pad { gap: 8px; }
  body .kart-pad button { width: 64px; height: 64px; box-sizing: border-box; padding: 0; font-size: 13px; }
}
/* v5：相機主要操作維持底部橫排；短橫屏用兩行，不把按鈕堆到螢幕外。 */
body #cam .cam-bar2 { width: max-content; box-sizing: border-box; max-width: calc(100% - 24px); justify-content: center; flex-wrap: wrap; gap: 8px; }
body #cam .cam-bar2 > button { box-sizing: border-box; flex: 0 0 auto; min-width: 44px; }
body #cam .cam-bar2 .cam-shut { width: 64px; height: 64px; margin: 0 4px; }
body #cam .cam-bar2 .cam-roll { width: 44px; height: 44px; }
body #cam .cam-bar2 .cb { min-width: 48px; height: 56px; padding: 4px 8px; font-size: 12px; }
body #cam .cam-scenes { width: max-content; box-sizing: border-box; max-width: calc(100% - 24px); gap: 8px; padding: 12px 2px 4px; overflow-x: auto; }
body #cam .cs { flex: 0 0 clamp(64px, 20vw, 150px); box-sizing: border-box; }
body #cam .cam-arrow { width: 44px; height: 52px; }
body #cam .cam-frame .lab { font-size: 10px; gap: 8px; overflow-wrap: anywhere; }
body #cam.side .cam-bar2 { left: 50%; right: auto; top: auto; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); flex-direction: row; gap: 8px; }
body #cam.side .cam-bar2 .cb { min-width: 52px; height: 44px; font-size: 11px; }
body #cam.side .cam-bar2 .cam-shut { width: 48px; height: 48px; }
body #cam.side .cam-scenes { display: flex; }
body #cam.side .cam-scenes[hidden] { display: none; }
#leadSync { box-sizing: border-box; position: fixed; z-index: 44; top: max(80px, calc(env(safe-area-inset-top) + 64px)); left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid #65465e; border-radius: 12px; background: #1c1420; color: #fff; font: 12px/1.5 system-ui,sans-serif; }
#leadSync[hidden] { display: none; }
#leadSync button { min-width: 32px; min-height: 36px; border: 0; border-radius: 8px; background: #762348; color: #fff; cursor: pointer; }
@media (max-width: 400px) { body #cam .cam-bar2 { width: calc(100% - 24px); gap: 5px; } body #cam .cam-bar2 .cam-roll { position: absolute; right: 0; bottom: 86px; } body #cam .cam-bar2 .cb { padding: 4px; } }
@media (prefers-reduced-motion: reduce) { body #cam .cs, body #cam .cam-tip, body #cam .cam-fade { transition: none; } }
.cam-on #leadSync { top: max(8px, env(safe-area-inset-top)); max-width: calc(100% - 120px); font-size: 11px; padding: 4px 8px; }

/* 捏人使用獨立、不透明的合成層，避免模糊背景與 WebGL 在拖動、滾動時互相重繪。 */
#gm.me-overlay { background: #100d16; backdrop-filter: none; -webkit-backdrop-filter: none; animation: none; }
#gm.me-overlay .me-card { animation: none; }
#gm .me-stage { contain: layout paint; isolation: isolate; background: #17121c; }

/* 合照背景固定兩欄，為長標籤和快捷鍵留出獨立空間。 */
#gm .kol-scenes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; padding: 8px 0; }
#gm .kol-scenes .gm-btn { position: relative; min-width: 0; min-height: 72px; box-sizing: border-box; padding: 18px 44px 18px 20px; border-radius: 18px; text-align: left; line-height: 1.5; white-space: normal; overflow-wrap: anywhere; }
#gm .kol-scenes .gm-btn::after { top: 8px; right: 8px; }
@media (max-width: 560px) {
  #gm .kol-scenes { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  #gm .kol-scenes .gm-btn { min-height: 56px; padding: 14px 44px 14px 18px; }
}

/* 平板、桌面視窗與分割畫面使用同一組可伸縮布局。 */
.hud { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.hud-r { flex-wrap: wrap; justify-content: flex-end; max-width: 100%; row-gap: 10px; }
#gm .gm-card { overscroll-behavior: contain; }
#gm .gm-body { overflow-wrap: anywhere; }
#gm .gm-x { min-width: 44px; min-height: 44px; }
#gm .gm-x::after { top: 2px; right: 2px; transform: translate(25%, -30%); }
#gm .me-side { overflow: hidden; }
#gm .me-tabs button { min-height: 40px; }
#gm .me-card .gm-row { position: sticky; bottom: 0; background: #1c1420; padding-top: 10px; padding-bottom: max(12px, env(safe-area-inset-bottom)); z-index: 2; }
@media (any-pointer: coarse), (hover: none) {
  .hud .mapbtn, .hud .pill, body .spots button, .portal a { min-height: 44px; box-sizing: border-box; }
  .hud .brand { min-height: 44px; box-sizing: border-box; }
  #gm .me-chips button, #gm .me-tabs button, #gm .gm-btn { min-height: 44px; }
  #gm .me-sw button { width: 44px; height: 44px; flex-basis: 44px; }
  #gm .me-tabs { gap: 6px; }
  #gm .me-tabs button { flex: 1 0 48px; padding: 8px; font-size: 12px; }
  /* 觸控滑動時不對全屏街景反覆套用模糊濾鏡。 */
  #gm { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(10,8,12,.88); }
  .hud .brand, .hud .mapbtn, .hud .pill, body .spots { backdrop-filter: none; -webkit-backdrop-filter: none; background-color: rgba(18,16,20,.94); }
}
@media (min-width: 721px) and (max-width: 1100px) {
  #gm .me-grid { grid-template-columns: minmax(230px, .85fr) minmax(0, 1.15fr); height: clamp(320px, 54dvh, 540px); }
  .hud-r { gap: 6px; }
  .hud-r .mapbtn { padding-inline: 10px; }
}
@media (max-width: 720px) {
  .hud-r { flex: 1 1 100%; gap: 6px; }
  .hud-r .mapbtn { flex: 0 0 auto; }
}
@media (max-height: 500px) and (min-width: 650px) {
  .hud .brand { padding: 6px 10px; }
  .hud-r .mapbtn { padding: 6px 10px; }
  #gm .gm-head { padding-top: 8px; }
  #gm .me-grid { grid-template-columns: minmax(180px, .8fr) minmax(0, 1.2fr); grid-template-rows: minmax(180px, 1fr); height: 54dvh; }
}
@media (any-pointer: coarse), (hover: none) {
  .hud-r > * { min-height: 44px; }
  .hud-r > button { min-width: 44px; }
}
@media (max-width: 720px) {
  /* 餘珠與品牌同一行，五個操作鍵另佔一行，避免相機掉到第三行。 */
  body .hud-r { gap: 6px; }
  .hud #pkChip { position: absolute; right: max(16px, env(safe-area-inset-right)); top: calc(env(safe-area-inset-top, 0px) + 12px); min-height: 44px; align-items: center; padding-inline: 8px; }
  .hud #pkChip b { font-size: 16px; }
  .hud .brand { gap: 6px; padding: 8px 10px; }
  .hud .brand img { height: 17px; }
  .hud .brand span { font-size: 12px; }
}
