/* iPad PWA 版面：沿用 app.css 的場景與元件樣式，這裡處理 App 外框、安全區域、橫直向與觸控 */
:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --top: calc(56px + var(--safe-t));
}
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  height: 100%; overflow: hidden; overscroll-behavior: none;
  background: linear-gradient(180deg, #d9e0f6 0%, #efe8f4 55%, #fbf5ea 100%) fixed;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
/* 狀態列為半透明（black-translucent）：頂列延伸到瀏海／狀態列底下，內容往下避開 */
.topbar { height: var(--top); padding-top: var(--safe-t); padding-left: max(12px, var(--safe-l)); padding-right: max(12px, var(--safe-r)); }
.brand img { border-radius: 8px; }

.vlayout {
  height: calc(100% - var(--top)); overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 340px); gap: 14px;
  padding: 12px max(12px, var(--safe-r)) max(12px, var(--safe-b)) max(12px, var(--safe-l));
}
.vlayout .stage-wrap { padding: 0; container-type: size; justify-content: flex-start; min-height: 0; }
.vlayout .stage { width: min(100cqw, calc((100cqh - 32px) * 16 / 9)); }
.vside { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
#panel { overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; min-height: 0; flex: 1; padding-bottom: 8px; -webkit-user-select: text; user-select: text; }
.readonly-note { font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; text-align: center; }
.stage.stale { filter: grayscale(.75) brightness(.97); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: rgba(255, 255, 255, .6); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; font-weight: 700; color: var(--ink-soft); }
.seg button[aria-selected="true"] { background: #fff; color: var(--lav-deep); box-shadow: 0 2px 8px rgba(110, 90, 140, .15); }

/* 直向（或窄螢幕）：場景在上、資訊在下並可捲動 */
@media (orientation: portrait), (max-width: 900px) {
  .vlayout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .vlayout .stage-wrap { container-type: inline-size; }
  .vlayout .stage { width: 100%; }
}

/* 觸控：按鈕最小 44px、按下回饋 */
.icon-btn { min-width: 44px; min-height: 44px; }
.topbar button:active, .seg button:active, .btn:active, .row-btn:active { transform: scale(.97); } /* 場景裡的角色與標籤靠 transform 定位，不能套用 */
.cat, .zone-label, .pair-box { -webkit-touch-callout: none; }

/* 第一次設定 */
.setup { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; overflow: auto;
  padding: max(24px, var(--safe-t)) max(16px, var(--safe-r)) max(24px, var(--safe-b)) max(16px, var(--safe-l));
  background: linear-gradient(180deg, #9fb0ea 0%, #c9bfee 50%, #f6e6ef 100%); }
.setup-card { width: min(560px, 100%); background: rgba(255, 252, 246, .95); border-radius: 26px; padding: 28px; box-shadow: 0 20px 60px rgba(80, 60, 140, .25); display: grid; gap: 12px; text-align: left; -webkit-user-select: text; user-select: text; }
.setup-icon { border-radius: 22px; justify-self: center; box-shadow: 0 8px 20px rgba(80, 60, 140, .25); }
.setup h1 { margin: 0; text-align: center; font-size: 26px; letter-spacing: .06em; }
.setup p { margin: 0; font-size: 16px; line-height: 1.6; }
.setup code { font-family: ui-monospace, Menlo, monospace; background: #f1ecf8; padding: 0 6px; border-radius: 6px; }
.setup textarea { min-height: 88px; border-radius: 12px; border: 1px solid var(--line); padding: 10px; font: 15px/1.4 ui-monospace, Menlo, monospace; resize: vertical; width: 100%; box-sizing: border-box; -webkit-user-select: text; user-select: text; }
.setup .btn { min-height: 48px; font-size: 16px; }
.setup-msg { min-height: 1.6em; font-weight: 700; }
.setup-msg.err { color: var(--bad); }
.setup-msg.ok { color: #3e7a4c; }

/* 更新與訊息提示 */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--safe-b)); z-index: 130;
  display: flex; gap: 12px; align-items: center; padding: 10px 12px 10px 18px; border-radius: 999px;
  background: #4b3f63; color: #fff; box-shadow: 0 10px 30px rgba(60, 40, 90, .35); font-weight: 600; max-width: calc(100% - 32px); }
#msgToast { padding: 10px 18px; }
.toast .btn { min-height: 40px; }
.sheet { max-height: min(80vh, 720px); }
.sheet-body { -webkit-user-select: text; user-select: text; }
.kv dd .btn { margin-top: 4px; }
