/* ===== 全域 ===== */
:root {
  --pixel-font: 'Press Start 2P', 'Cubic 11', monospace;
  --ui-font: 'Microsoft JhengHei', 'PingFang TC', system-ui, sans-serif;
  --brand-orange: #F69403;
  --panel-bg: #1c1832;
  --panel-border: #4a3f7a;
  --text-main: #f2eefc;
  --text-dim: #9a8fc4;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  background: #12101f;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;       /* iOS 長按選單/放大鏡 */
  overscroll-behavior: none;         /* 下拉刷新/邊緣回彈 */
  -webkit-tap-highlight-color: transparent;
}
body { position: fixed; inset: 0; } /* 徹底鎖住視口，防任何捲動位移 */

#game-root { position: relative; width: 100%; height: 100%; }
#game-container { width: 100%; height: 100%; }
#game-container canvas {
  image-rendering: pixelated; image-rendering: crisp-edges;
  touch-action: none; /* 畫布上禁止瀏覽器縮放/捲動手勢 */
}

/* 覆蓋層：跟 canvas 對齊，事件預設穿透 */
#overlay-container {
  position: absolute; inset: 0;
  pointer-events: none;
  font-family: var(--ui-font);
  color: var(--text-main);
  z-index: 10;
}
#overlay-container > * { pointer-events: auto; }

/* ===== 像素風面板基底 ===== */
.pixel-panel {
  background: var(--panel-bg);
  border: 3px solid var(--panel-border);
  border-radius: 4px;
  box-shadow: 0 0 0 3px #0d0b18, 0 6px 18px rgba(0,0,0,.6);
  image-rendering: pixelated;
}

.pixel-btn {
  display: inline-block;
  font-family: var(--ui-font);
  font-weight: bold;
  font-size: 15px;
  color: #1a1408;
  background: var(--brand-orange);
  border: 3px solid #b56c00;
  border-radius: 4px;
  box-shadow: 0 3px 0 #7d4a00;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform .05s;
}
.pixel-btn:active { transform: translateY(3px); box-shadow: none; }
.pixel-btn.secondary {
  color: var(--text-main); background: #35305c;
  border-color: var(--panel-border); box-shadow: 0 3px 0 #211c40;
}

/* ===== 對話框 ===== */
#dialog-box {
  position: absolute; left: 50%; bottom: 4%;
  transform: translateX(-50%);
  width: min(92%, 560px);
  padding: 14px;
  display: flex; gap: 12px; align-items: flex-start;
}
#dialog-box .portrait {
  flex: 0 0 auto;
  width: 72px; height: 72px;
  border: 3px solid var(--panel-border);
  border-radius: 4px;
  background: #0d0b18;
  image-rendering: pixelated;
}
#dialog-box .dialog-body { flex: 1; min-width: 0; }
#dialog-box .speaker {
  font-size: 13px; color: var(--brand-orange);
  font-weight: bold; margin-bottom: 6px; letter-spacing: 1px;
}
#dialog-box .text {
  font-size: 15px; line-height: 1.6; min-height: 48px;
  word-break: break-word;
}
#dialog-box .next-hint {
  text-align: right; font-size: 12px; color: var(--text-dim);
  margin-top: 6px; animation: bounce-hint 1s infinite;
}
@keyframes bounce-hint { 0%,100% { transform: translateY(0);} 50% { transform: translateY(3px);} }

/* ===== 裝備卡 ===== */
#equip-cards {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(92%, 400px);
  max-height: 80%;
  overflow-y: auto;
  padding: 16px;
}
#equip-cards h3 {
  font-size: 15px; color: var(--brand-orange);
  margin-bottom: 12px; text-align: center; letter-spacing: 2px;
}
.equip-card {
  display: flex; align-items: center; gap: 12px;
  background: #241f42;
  border: 2px solid var(--panel-border);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.equip-card img {
  width: 48px; height: 48px;
  image-rendering: pixelated;
  background: #0d0b18;
  border-radius: 4px;
  flex: 0 0 auto;
}
.equip-card .info { flex: 1; min-width: 0; }
.equip-card .name { font-size: 14px; font-weight: bold; }
.equip-card .price { font-size: 13px; color: var(--brand-orange); margin-top: 4px; }
.equip-card .add-btn {
  flex: 0 0 auto;
  font-size: 13px; padding: 8px 12px;
}
.equip-card .add-btn.added {
  background: #3a7d44; border-color: #26562e; box-shadow: 0 3px 0 #1a3d20; color: #eaffea;
}
#equip-cards .close-row { text-align: center; margin-top: 6px; }

/* ===== HUD（背包鈕 / 進度 / 音效） ===== */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
#hud .hud-left, #hud .hud-right { display: flex; gap: 8px; align-items: center; }
.hud-chip {
  font-size: 13px; font-weight: bold;
  background: rgba(28,24,50,.92);
  border: 2px solid var(--panel-border);
  border-radius: 4px;
  padding: 8px 12px;
  color: var(--text-main);
  cursor: pointer;
}
.hud-chip .badge {
  display: inline-block; min-width: 18px; text-align: center;
  background: var(--brand-orange); color: #1a1408;
  border-radius: 9px; font-size: 11px; padding: 1px 4px; margin-left: 4px;
}

/* ===== 背包面板 ===== */
#backpack-panel {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(92%, 400px);
  max-height: 82%;
  display: flex; flex-direction: column;
  padding: 16px;
}
#backpack-panel h3 { font-size: 15px; color: var(--brand-orange); text-align: center; margin-bottom: 12px; letter-spacing: 2px; }
#backpack-panel .bp-list { overflow-y: auto; flex: 1; }
.bp-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 4px; border-bottom: 1px solid #2e2853;
}
.bp-item img { width: 36px; height: 36px; image-rendering: pixelated; }
.bp-item .name { flex: 1; font-size: 14px; }
.bp-item .price { font-size: 13px; color: var(--brand-orange); }
.bp-item .rm { font-size: 12px; color: var(--text-dim); background: none; border: none; cursor: pointer; padding: 6px; }
#backpack-panel .bp-total { text-align: right; font-size: 14px; font-weight: bold; padding: 10px 4px; }
#backpack-panel .bp-actions { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
#backpack-panel .bp-empty { text-align: center; color: var(--text-dim); font-size: 14px; padding: 30px 0; }

/* ===== 結算清單 + 優惠券 ===== */
#summary-panel {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(92%, 420px);
  max-height: 88%;
  display: flex; flex-direction: column;
  padding: 16px;
  overflow-y: auto;
}
#summary-panel h3 { font-size: 15px; color: var(--brand-orange); text-align: center; margin-bottom: 12px; letter-spacing: 2px; }
.sm-list { flex: 0 1 auto; }
.sm-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid #2e2853;
  cursor: pointer;
}
.sm-check {
  flex: 0 0 auto; width: 22px; height: 22px;
  border: 2px solid var(--brand-orange); border-radius: 4px;
  color: var(--brand-orange); font-size: 14px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
}
.sm-item .name { flex: 1; font-size: 14px; }
.sm-item .price { font-size: 13px; color: var(--brand-orange); }
.sm-item.off { opacity: .35; }
.sm-item.off .sm-check { color: transparent; border-color: var(--text-dim); }
.sm-total { text-align: right; font-size: 14px; padding: 10px 4px; }
.sm-total b { color: var(--brand-orange); font-size: 16px; }

.sm-coupon-wrap { margin: 8px 0 12px; }
.sm-coupon {
  border: 3px dashed var(--brand-orange);
  border-radius: 6px;
  background: linear-gradient(160deg, #2b2010, #1c1832);
  padding: 14px;
  text-align: center;
}
.sm-coupon .c-head { font-size: 16px; font-weight: bold; color: #ffd54f; letter-spacing: 2px; }
.sm-coupon .c-body { font-size: 15px; font-weight: bold; margin: 8px 0; color: var(--text-main); }
.sm-coupon .c-meta { font-size: 11px; color: var(--text-dim); line-height: 1.6; }
.sm-coupon .c-foot {
  margin-top: 8px; font-size: 12px; color: #1a1408;
  background: var(--brand-orange); border-radius: 3px;
  display: inline-block; padding: 4px 10px; font-weight: bold;
}
.sm-coupon.locked {
  border-color: var(--panel-border);
  color: var(--text-dim); font-size: 13px;
  background: #17132a;
}

/* ===== 提示 toast ===== */
#toast {
  position: absolute; left: 50%; top: 14%;
  transform: translateX(-50%);
  background: rgba(28,24,50,.95);
  border: 2px solid var(--brand-orange);
  border-radius: 4px;
  color: var(--text-main);
  font-size: 14px; font-weight: bold;
  padding: 10px 18px;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none !important;
}
#toast.show { opacity: 1; }

/* ===== 虛擬手把（觸控裝置）===== */
#gamepad {
  position: absolute; left: 0; right: 0;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 14px;
  pointer-events: none;
}
#gamepad .gp-dpad {
  pointer-events: auto;
  position: relative; width: 132px; height: 132px;
  display: grid;
  grid-template-areas: ". up ." "left . right" ". down .";
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
  opacity: .82;
}
#gamepad .gp-up { grid-area: up; } #gamepad .gp-down { grid-area: down; }
#gamepad .gp-left { grid-area: left; } #gamepad .gp-right { grid-area: right; }
#gamepad .gp-btn {
  display: flex; align-items: center; justify-content: center;
  background: rgba(28,24,50,.9);
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text-main); font-size: 16px; font-weight: bold;
  user-select: none; touch-action: none;
}
#gamepad .gp-btn.on, #gamepad .gp-btn:active {
  background: var(--brand-orange); color: #1a1408; border-color: #b56c00;
}
#gamepad .gp-ab {
  pointer-events: auto;
  display: flex; gap: 14px; align-items: flex-end;
  opacity: .85;
}
#gamepad .gp-a, #gamepad .gp-b {
  width: 58px; height: 58px; border-radius: 50%;
  font-size: 20px;
}
#gamepad .gp-a { background: rgba(246,148,3,.92); color: #1a1408; border-color: #b56c00; margin-bottom: 18px; }
#gamepad .gp-b { background: rgba(53,48,92,.92); }

/* ===== 遮罩 ===== */
#dim-mask {
  position: absolute; inset: 0;
  background: rgba(8,6,16,.55);
}
