/* ========== 3D 夜市模式樣式（2D 模式下不影響任何既有畫面）========== */

/* ----- 右上角 2D / 3D 切換 ----- */
#view-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 1000;
  display: flex;
  padding: 4px;
  gap: 4px;
  background: rgba(34, 9, 12, 0.82);
  border: 1.5px solid rgba(255, 209, 102, 0.55);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45), 0 0 14px rgba(255, 138, 61, 0.25);
}
#view-toggle button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #ffe9b0;
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
#view-toggle button:hover:not(.active) { background: rgba(255, 209, 102, 0.14); }
#view-toggle button:focus-visible { outline: 2px solid #ffd166; outline-offset: 2px; }
#view-toggle button.active {
  color: #3a1608;
  background: linear-gradient(135deg, #ffe082, #f59e3d);
  box-shadow: 0 0 12px rgba(255, 176, 74, 0.6);
}
#view-toggle button.loading { opacity: 0.6; cursor: progress; }
#view-toggle button.loading::after { content: " …"; }

/* ----- 提示 toast（載入失敗等）----- */
#view-toast {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 1001;
  max-width: 320px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fff8e7;
  background: rgba(60, 10, 14, 0.92);
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 10px;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}
#view-toast.show { opacity: 1; transform: none; }

/* ----- 3D 舞台：2D 模式完全隱藏 ----- */
#stage3d { display: none; }

body.mode-3d #stage3d {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 12px;
  overflow: hidden;
}
#stage3d .stage3d-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#stage3d-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

/* 3D 模式：2D 格子隱藏（DOM 仍持續被 game.js 更新，切回 2D 無縫接軌） */
body.mode-3d #board > .tile { visibility: hidden; }
body.mode-3d #board { padding: 0; }

/* ===== 以下為 HUD / 資訊欄覆蓋層（由 controls.js 負責的區塊）===== */

/* --- 3D 模式版面：棋盤改寬比例、燈籠列隱藏（場景裡已有燈籠）--- */
body.mode-3d .lantern-row { display: none; }
body.mode-3d #board {
  aspect-ratio: 16 / 10;
  max-width: 100%;
  /* 隱藏的 2D 格子不能把列撐高，否則寬比例會失效 */
  grid-template-rows: repeat(6, minmax(0, 1fr));
}
body.mode-3d #board > .tile { min-height: 0; }

/* --- .board-center → 頂部置中的半透明 HUD 橫幅（純 CSS 重新排版，DOM 不動）--- */
body.mode-3d .board-center {
  grid-area: auto;                 /* 脫離 grid 區塊，改以整個 #board 為定位基準 */
  position: absolute;
  z-index: 3;                      /* 高於 #stage3d（z-index: 1） */
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 640px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "dice status"
    "dice info";
  align-items: center;
  gap: 4px 12px;
  padding: 8px 12px;
  text-align: left;
  background: rgba(24, 6, 9, 0.62);
  border: 1px solid rgba(255, 209, 102, 0.42);
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 224, 150, 0.14);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;            /* 不擋住鏡頭拖曳 */
}
body.mode-3d .board-center h1 { display: none; }
body.mode-3d .board-center #dice-display { grid-area: dice; }
body.mode-3d .board-center .dice {
  width: 46px;
  height: 46px;
  font-size: 24px;
  border-width: 2px;
  border-radius: 10px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}
body.mode-3d .board-center #game-status {
  grid-area: status;
  font-size: 14px;
  padding: 0;
  background: none;
  line-height: 1.35;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
body.mode-3d .board-center #current-tile-info {
  grid-area: info;
  width: auto;
  min-height: 0;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.35;
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 209, 102, 0.22);
}
body.mode-3d #current-tile-info .info-name { font-size: 13px; }
body.mode-3d #current-tile-info .info-detail {
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- controls.js 的覆蓋層容器 --- */
.hud3d {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: inherit;
  color: #fff8e7;
}

/* 右下角：重置視角 / 自動環繞 */
.hud3d-btns {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  gap: 6px;
  z-index: 4;
}
.hud3d-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #ffe9b0;
  background: rgba(34, 9, 12, 0.78);
  border: 1.5px solid rgba(255, 209, 102, 0.5);
  border-radius: 999px;
  padding: 6px 11px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: background 160ms ease, color 160ms ease, transform 120ms ease;
}
.hud3d-btn:hover { background: rgba(80, 22, 18, 0.88); }
.hud3d-btn:active { transform: translateY(1px); }
.hud3d-btn:focus-visible { outline: 2px solid #ffd166; outline-offset: 2px; }
.hud3d-btn.on {
  color: #3a1608;
  background: linear-gradient(135deg, #ffe082, #f59e3d);
  box-shadow: 0 0 12px rgba(255, 176, 74, 0.6);
}

/* 左下角：購買 / 租金 / 破產小提示（往上堆疊） */
.hud3d-toasts {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: min(46%, 320px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  z-index: 4;
}
.hud3d-toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 7px 12px 7px 10px;
  font-size: 13px;
  line-height: 1.35;
  background: rgba(34, 9, 12, 0.86);
  border: 1px solid rgba(255, 209, 102, 0.42);
  border-left: 4px solid var(--pc, #ffd166);
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateX(-12px);
  transition: opacity 220ms ease, transform 220ms ease;
}
.hud3d-toast.show { opacity: 1; transform: none; }
.hud3d-toast.danger { background: rgba(90, 10, 14, 0.9); }
.hud3d-toast-icon { font-size: 18px; flex: none; }
.hud3d-toast-text b { color: #ffd166; }

/* 中央偏下：抽獎 / 命運卡翻面 */
.hud3d-cardstage {
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  z-index: 5;
  perspective: 800px;
}
.hud3d-card {
  width: 220px;
  height: 140px;
  opacity: 0;
  transform: translateY(16px) scale(0.9);
  transition: opacity 240ms ease, transform 240ms ease;
}
.hud3d-card.flipped { opacity: 1; transform: none; }
.hud3d-card.leaving { opacity: 0; transform: translateY(-14px) scale(0.95); }
.hud3d-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 600ms cubic-bezier(0.2, 0.8, 0.3, 1.2) 120ms;
}
.hud3d-card.flipped .hud3d-card-inner { transform: rotateY(180deg); }
.hud3d-card-face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55), 0 0 18px rgba(255, 176, 74, 0.35);
}
.hud3d-card-back {
  background: repeating-linear-gradient(45deg, #b91c1c 0 10px, #991616 10px 20px);
  border: 3px solid #ffd166;
}
.hud3d-card.destiny .hud3d-card-back {
  background: repeating-linear-gradient(45deg, #5b21b6 0 10px, #4c1d95 10px 20px);
}
.hud3d-card-bigicon { font-size: 52px; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5)); }
.hud3d-card-front {
  transform: rotateY(180deg);
  gap: 6px;
  padding: 10px 14px;
  color: #3a1a0a;
  background: linear-gradient(180deg, #fffdf7, #f6e2b8);
  border: 3px solid #e09a2c;
}
.hud3d-card-kind { font-size: 12px; font-weight: 800; color: #a04010; letter-spacing: 1px; }
.hud3d-card-text { font-size: 15px; font-weight: 800; line-height: 1.35; }
.hud3d-card-who {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--pc, #a04010);
  padding: 2px 10px;
  border-radius: 999px;
}

/* 勝利大彈窗（只有它可點擊；在 3D 畫面內，不會擋到下方的 #controls） */
.hud3d-win {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 84px 12px 12px;          /* 讓出頂部 HUD 橫幅 */
  background: radial-gradient(circle at 50% 55%, rgba(255, 176, 74, 0.18), rgba(0, 0, 0, 0.55) 70%);
  pointer-events: auto;
  opacity: 0;
  transition: opacity 300ms ease;
}
.hud3d-win.show { opacity: 1; }
.hud3d-win-panel {
  max-width: 340px;
  width: 100%;
  padding: 18px 20px 20px;
  text-align: center;
  background: linear-gradient(160deg, rgba(60, 10, 12, 0.95), rgba(110, 22, 26, 0.95));
  border: 2px solid #ffd166;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 0 0 28px rgba(255, 176, 74, 0.45), inset 0 0 0 3px var(--pc, transparent);
  transform: scale(0.85);
  transition: transform 380ms cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.hud3d-win.show .hud3d-win-panel { transform: none; }
.hud3d-win-trophy { font-size: 48px; line-height: 1; animation: hud3d-bob 1.6s ease-in-out infinite; }
.hud3d-win-title {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 800;
  color: #fffaf0;
  text-shadow: 0 0 8px #ffd166, 0 0 18px #ff8a3d;
}
.hud3d-win-sub { margin-top: 4px; font-size: 13px; color: #ffe9b0; }
.hud3d-win-btn {
  margin-top: 14px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  padding: 10px 22px;
  color: #3a1608;
  background: linear-gradient(135deg, #ffe082, #f59e3d);
  border: 1.5px solid #9a4a12;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 3px 0 #6e3109, 0 6px 14px rgba(0, 0, 0, 0.35);
}
.hud3d-win-btn:hover { filter: brightness(1.06); }
.hud3d-win-btn:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
@keyframes hud3d-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@media (prefers-reduced-motion: reduce) {
  .hud3d-card, .hud3d-card-inner, .hud3d-toast, .hud3d-win, .hud3d-win-panel { transition: none; }
  .hud3d-win-trophy { animation: none; }
}

/* --- 響應式 --- */
@media (max-width: 900px) {
  /* 單欄時棋盤在最上方，往下讓出右上角 position:fixed 的 #view-toggle */
  #app { padding-top: 46px; }
  body.mode-3d #board { aspect-ratio: 4 / 3; }
}
@media (max-width: 500px) {
  #app { padding-top: 50px; }
  body.mode-3d #board { aspect-ratio: 1 / 1; }
  body.mode-3d .board-center {
    top: 6px;
    width: calc(100% - 12px);
    gap: 3px 8px;
    padding: 6px 8px;
  }
  body.mode-3d .board-center .dice { width: 36px; height: 36px; font-size: 19px; }
  body.mode-3d .board-center #game-status { font-size: 12.5px; }
  body.mode-3d .board-center #current-tile-info { font-size: 11px; padding: 3px 6px; }
  body.mode-3d #current-tile-info .info-name { font-size: 12px; }
  body.mode-3d #current-tile-info .info-detail { -webkit-line-clamp: 1; }
  .hud3d-btns { right: 6px; bottom: 6px; gap: 4px; }
  .hud3d-btn { padding: 7px 9px; font-size: 15px; }
  .hud3d-btn-label { display: none; }   /* 只留圖示；aria-label 仍可讀 */
  .hud3d-toasts { left: 6px; bottom: 6px; max-width: calc(100% - 100px); }
  .hud3d-toast { font-size: 12px; padding: 5px 9px 5px 8px; }
  .hud3d-toast:nth-last-child(n + 3) { display: none; }  /* 小螢幕最多疊 2 個 */
  .hud3d-cardstage { top: 56%; }
  .hud3d-card { width: 180px; height: 116px; }
  .hud3d-card-text { font-size: 13px; }
  .hud3d-card-bigicon { font-size: 40px; }
  .hud3d-win { padding-top: 72px; }
  .hud3d-win-panel { padding: 14px 14px 16px; }
  .hud3d-win-title { font-size: 20px; }
  .hud3d-win-trophy { font-size: 38px; }
}

/* 寬螢幕：側欄往下讓出右上角固定的 #view-toggle（2D / 3D 皆適用） */
@media (min-width: 901px) {
  #sidebar { padding-top: 48px; }
}
