/* style.css — 圍棋・十二峰：寫實棋室
   深胡桃木環境 / 蜜色棋盤（程式繪製）/ 自然窗光 / 低反光棋子 / 米白資訊面板 / 青銅主按鈕
   行動優先：base 390×844，相容 360×640、768×1024、1440×900 */

:root {
  /* 胡桃木——更深的黑胡桃 + 蜜色暖底 */
  --walnut-0: #100c08;
  --walnut-1: #1c1611;
  --walnut-2: #2a211a;
  --walnut-3: #3c2f25;
  --walnut-4: #503c2e;
  --walnut-grain: rgba(0, 0, 0, 0.28);

  /* 米白資訊面板——比舊版更暖（象牙 → 蜜紙）*/
  --panel: #f6f0e3;
  --panel-ink: #2f261a;
  --panel-muted: #6a5c47;
  --panel-line: #d6cbb5;

  /* 青銅——更立體（左上反光、右下陰影）*/
  --bronze: #b07a3a;
  --bronze-hi: #d29a52;
  --bronze-lo: #7e541a;
  --bronze-deep: #4a2e0e;
  --bronze-ink: #fff5e0;

  /* 暖紅——危險鍵，比舊版更收斂 */
  --danger: #a83c30;
  --danger-hi: #c45040;
  --danger-lo: #6e2018;

  /* 蜜色——用於獎勵框、棋盤裝飾與窗光 */
  --honey-1: #ecd084;
  --honey-2: #dcb15e;
  --line-ink: #432f1e;

  --radius: 12px;
  --tap: 44px;
  --shadow-soft: 0 8px 22px rgba(0, 0, 0, 0.35);
  --shadow-deep: 0 14px 32px rgba(0, 0, 0, 0.46);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  color: #ece4d6;
  background:
    /* 左上窗光（暖蜜色高光）*/
    radial-gradient(900px 540px at 12% -10%, rgba(255, 220, 150, 0.16), transparent 60%),
    /* 右下暗角（室內夕落陰影）*/
    radial-gradient(900px 600px at 110% 110%, rgba(0, 0, 0, 0.55), transparent 55%),
    /* 胡桃木基底：直紋 → 帶狀陰影 */
    linear-gradient(180deg, var(--walnut-2) 0%, var(--walnut-1) 50%, var(--walnut-0) 100%);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* 胡桃木牆面紋理（純 CSS，內含細密木紋、年輪紋、暖光斑點） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    /* 年輪粗紋（70–80px 距，深色窄帶）*/
    repeating-linear-gradient(90deg,
      transparent 0px, rgba(0, 0, 0, 0.18) 70px, transparent 73px,
      rgba(255, 220, 160, 0.025) 88px, transparent 118px),
    /* 直紋細密（4px 一線）*/
    repeating-linear-gradient(90deg,
      transparent 0px, rgba(0, 0, 0, 0.06) 3px, transparent 7px,
      rgba(255, 220, 160, 0.022) 11px, transparent 19px),
    /* 暖光斑點（左上加亮）*/
    radial-gradient(50% 40% at 12% 8%, rgba(255, 210, 140, 0.10), transparent 70%);
  opacity: 0.85;
}

#app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 12px calc(18px + var(--safe-bottom));
}

.screen[hidden] { display: none; }

h1, h2, h3 { margin: 0; font-weight: 700; }
p { margin: 0; }
button { font-family: inherit; }

/* ---------- 按鈕 ---------- */
.btn {
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.06s ease, filter 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
  overflow: hidden;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--bronze-hi); outline-offset: 2px; }

/* 青銅銅扣按鈕（主行動，例如：開始對局、確認落子、再戰一局） */
.btn-bronze {
  color: var(--bronze-ink);
  background:
    linear-gradient(180deg, #f0c074 0%, var(--bronze-hi) 35%, var(--bronze) 70%, var(--bronze-lo) 100%);
  border: 1px solid var(--bronze-lo);
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 200, 0.55), /* 銅面高光 */
    inset 0 -2px 0 rgba(0, 0, 0, 0.25),     /* 銅底陰影 */
    0 2px 0 var(--bronze-deep),             /* 厚實銅邊 */
    0 8px 18px rgba(0, 0, 0, 0.45),         /* 環境陰影 */
    0 0 0 0.5px rgba(255, 215, 145, 0.35);  /* 金邊微光 */
}
.btn-bronze::before {
  /* 拉絲紋理（一道橫向拋光線）*/
  content: "";
  position: absolute;
  top: 30%;
  left: 8%;
  right: 8%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 245, 220, 0.5), transparent);
  pointer-events: none;
}
.btn-bronze:hover { filter: brightness(1.06); }
.btn-bronze:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 200, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25),
    0 1px 0 var(--bronze-deep),
    0 3px 8px rgba(0, 0, 0, 0.4);
}

/* 幽靈按鈕（在胡桃木背景上的次要行動） */
.btn-ghost {
  color: #e9dcc4;
  background: linear-gradient(180deg, rgba(255, 240, 200, 0.08), rgba(255, 240, 200, 0.04));
  border-color: rgba(220, 180, 100, 0.32);
}
.btn-ghost:hover { background: linear-gradient(180deg, rgba(255, 240, 200, 0.14), rgba(255, 240, 200, 0.08)); }

/* 米白面板按鈕（棋室內的次主行動，例如：Pass/棋譜回顧/認輸） */
.btn-panel {
  color: var(--panel-ink);
  background:
    linear-gradient(180deg, #fbf5e6 0%, #efe5cc 100%);
  border-color: #cbbda2;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    inset 0 -1px 0 rgba(120, 90, 40, 0.18),
    0 2px 0 #a9987c,
    0 6px 14px rgba(0, 0, 0, 0.32);
}
.btn-panel:hover { filter: brightness(1.04); }
.btn-panel:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    inset 0 -1px 0 rgba(120, 90, 40, 0.18),
    0 1px 0 #a9987c,
    0 3px 8px rgba(0, 0, 0, 0.32);
}

/* 危險按鈕（紅銅，僅確認認輸） */
.btn-danger {
  color: #fff3ee;
  background:
    linear-gradient(180deg, #d8634f 0%, var(--danger-hi) 35%, var(--danger) 70%, var(--danger-lo) 100%);
  border: 1px solid var(--danger-lo);
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 210, 0.5),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25),
    0 2px 0 #4a180e,
    0 6px 14px rgba(0, 0, 0, 0.4);
}
.btn-danger:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 210, 0.4),
    0 1px 0 #4a180e,
    0 3px 8px rgba(0, 0, 0, 0.32);
}
.btn-danger-soft {
  color: #8c3328;
  background: linear-gradient(180deg, #f7e3dc, #ecd4ca);
  border: 1px solid #d4a294;
  box-shadow: 0 2px 0 #a87868, 0 4px 10px rgba(0, 0, 0, 0.25);
}

.btn-large { width: 100%; min-height: 52px; font-size: 17px; padding: 12px 16px; }
.btn-sm { min-height: 44px; padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: grayscale(0.3); }

/* ---------- 面板（米白資訊卡：像一道木匾內裱的紙） ---------- */
.panel {
  background:
    linear-gradient(180deg, #fbf6ea 0%, #f1e8d3 60%, #e8dec4 100%);
  color: var(--panel-ink);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 #fff,
    inset 0 -1px 0 rgba(120, 90, 40, 0.12),
    var(--shadow-soft),
    /* 木匾外框：左上一抹青銅色 */
    0 0 0 1px rgba(160, 110, 50, 0.18);
  position: relative;
}
.panel::before {
  /* 紙張細紋（左上微亮）*/
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(80% 60% at 10% 0%, rgba(255, 240, 200, 0.45), transparent 60%);
}

/* ================= 畫面一：棋院 ================= */
.academy-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.brand h1 {
  font-size: clamp(24px, 6.4vw, 34px);
  letter-spacing: 3px;
  color: #f3e4c6;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
.subtitle { color: #b9a582; font-size: 13px; letter-spacing: 4px; margin-top: 2px; }

.player-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  background: linear-gradient(180deg, rgba(58, 47, 37, 0.95), rgba(35, 28, 22, 0.95));
  border: 1px solid rgba(200, 160, 100, 0.35);
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}
.player-chip-img { width: 42px; height: 50px; border-radius: 8px; object-fit: cover; }
.player-chip-meta { display: flex; flex-direction: column; line-height: 1.25; }
.player-chip-name { font-size: 14px; color: #f3e7d0; }
.player-chip-level { font-size: 12px; color: #c8a96e; }

.xpbar {
  position: relative;
  margin: 12px 0 6px;
  height: 22px;
  border-radius: 999px;
  background: #120e0a;
  border: 1px solid rgba(200, 160, 100, 0.3);
  overflow: hidden;
}
.xpbar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8a5e24, #d9a94f);
  transition: width 0.4s ease;
}
.xpbar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #f6ead0;
  text-shadow: 0 1px 2px #000;
}

.resume-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #3a2f1d, #2c2415);
  border: 1px solid #8a6a34;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
}
.resume-text { display: flex; flex-direction: column; gap: 2px; font-size: 14px; color: #eedfb8; }
.resume-text span { color: #c7b184; font-size: 13px; }
.resume-actions { display: flex; gap: 8px; }
/* [hidden] 防呆：display:flex 不得蓋掉 hidden 屬性（修復幻影橫幅根因） */
.resume-banner[hidden] { display: none; }

.section-title {
  margin: 14px 2px 10px;
  font-size: 16px;
  letter-spacing: 2px;
  color: #dcc79a;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.char-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--walnut-3), var(--walnut-2));
  border: 1px solid rgba(200, 160, 100, 0.22);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.38);
  cursor: pointer;
  text-align: left;
  color: #ecdfc6;
  min-height: var(--tap);
}
.char-card:hover { border-color: rgba(220, 180, 110, 0.55); }
.char-card.is-locked { opacity: 0.62; cursor: not-allowed; }
.char-card.is-locked:hover { border-color: rgba(200, 160, 100, 0.22); }

.char-card-top { display: flex; gap: 8px; align-items: flex-start; }
.char-portrait {
  width: 58px;
  height: 70px;
  border-radius: 8px;
  object-fit: cover;
  background: #d8d2c4;
  flex: 0 0 auto;
}
.char-name { font-size: 15px; font-weight: 700; }
.char-alias { font-size: 12px; color: #c6b084; }
.char-diff {
  display: inline-block;
  margin-top: 3px;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(169, 118, 58, 0.25);
  border: 1px solid rgba(200, 144, 72, 0.4);
  color: #e8c890;
}
.char-blurb { font-size: 12px; line-height: 1.5; color: #cdbd9d; }
.char-meta {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  color: #b7a580;
  border-top: 1px dashed rgba(220, 190, 140, 0.22);
  padding-top: 6px;
}
.char-lockmask {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #e2c98f;
}

/* ================= 畫面二：開局設定 ================= */
.setup-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.setup-head h2 { font-size: 20px; color: #f0e0bd; letter-spacing: 2px; }
.btn-back { min-height: 44px; }

.setup-room {
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 12px;
}
.setup-portrait {
  flex: 0 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #d8d2c4;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(200, 160, 100, 0.3);
}
.setup-portrait img { display: block; width: 110px; height: 132px; object-fit: cover; }

.setup-info { padding: 12px 14px; flex: 1 1 auto; min-width: 0; }
.setup-info h3 { font-size: 19px; }
.epithet { color: var(--bronze-lo); font-size: 13px; margin: 2px 0 6px; letter-spacing: 1px; }
.blurb { font-size: 13px; line-height: 1.6; }
.meta-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 10px 0 6px;
  font-size: 13px;
}
.meta-list dt { color: var(--panel-muted); }
.meta-list dd { margin: 0; font-weight: 600; }
.strength-note {
  margin-top: 8px;
  font-size: 11.5px;
  color: #8a744a;
  border-top: 1px dashed var(--panel-line);
  padding-top: 6px;
}

.setup-options { padding: 14px; }
fieldset {
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  margin: 0 0 12px;
  padding: 10px 12px 12px;
}
legend { font-size: 14px; font-weight: 700; padding: 0 6px; color: #5b4628; }

.size-options { display: flex; gap: 8px; }
.size-opt { flex: 1 1 0; cursor: pointer; }
.size-opt input { position: absolute; opacity: 0; pointer-events: none; }
.size-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1.5px solid var(--panel-line);
  background: #fffdf6;
  min-height: 56px;
  font-size: 15px;
  color: var(--panel-ink);
}
.size-card small { font-size: 11px; color: var(--panel-muted); }
.size-opt input:checked + .size-card {
  border-color: var(--bronze);
  background: #f6e8cd;
  box-shadow: 0 0 0 2px rgba(169, 118, 58, 0.25);
}
.size-opt input:focus-visible + .size-card { outline: 2px solid var(--bronze-hi); outline-offset: 2px; }

.rules-list { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.7; }
.rules-list li::marker { color: var(--bronze); }

.single-tap-opt {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--panel-muted);
  margin-bottom: 12px;
  cursor: pointer;
}
.single-tap-opt input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--bronze); flex: 0 0 auto; }

/* ================= 畫面三：對局 ================= */
.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.vs { display: flex; align-items: center; gap: 8px; min-width: 0; }
.vs-portrait {
  width: 36px;
  height: 44px;
  border-radius: 7px;
  object-fit: cover;
  background: #d8d2c4;
  flex: 0 0 auto;
}
.vs-portrait.player-side { outline: 1.5px solid rgba(220, 190, 120, 0.5); }
.vs-meta { display: flex; flex-direction: column; min-width: 0; }
.vs-title { font-size: 14px; font-weight: 700; white-space: nowrap; }
.vs-vs { color: #c0a872; font-weight: 400; margin: 0 2px; }
.vs-sub { font-size: 11.5px; color: #b39f78; }

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  margin-bottom: 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, #33281d, #261e15);
  border: 1px solid rgba(200, 160, 100, 0.3);
  font-size: 13.5px;
  min-height: 38px;
}
.status-wait { color: #e2bf7c; font-variant-numeric: tabular-nums; }
.status-wait::before {
  content: "";
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--bronze-hi);
  animation: pulse 1s infinite ease-in-out;
}
@keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* 棋室：窗光 + 棋盤檯 */
.board-room {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 14px 10px;
  border-radius: 18px;
  background:
    radial-gradient(140% 90% at 82% 0%, rgba(255, 232, 180, 0.14), transparent 55%),
    linear-gradient(180deg, #2c231b, #201a14);
  border: 1px solid rgba(200, 160, 100, 0.22);
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.55), 0 12px 28px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
/* 斜射自然窗光 */
.window-light {
  position: absolute;
  top: -40%;
  right: -10%;
  width: 70%;
  height: 130%;
  background: linear-gradient(115deg, rgba(255, 240, 205, 0.16), rgba(255, 240, 205, 0.03) 45%, transparent 70%);
  transform: skewX(-12deg);
  pointer-events: none;
}

.board-frame {
  position: relative;
  width: min(94vw, 52vh, 560px);
  aspect-ratio: 1 / 1;
  padding: 2.4%;
  border-radius: 14px;
  background: linear-gradient(160deg, #4a382a, #2e2219);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.6),
    inset 0 1px 2px rgba(255, 220, 170, 0.25),
    inset 0 -3px 8px rgba(0, 0, 0, 0.5);
}
#board {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  touch-action: manipulation;
}

.game-controls { margin-top: 10px; }

.confirm-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #f5edd9, #e6dac0);
  color: #4d3c24;
  border: 1px solid #c8b488;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
}
.confirm-hint { font-size: 13.5px; font-weight: 600; flex: 1 1 auto; min-width: 120px; }
.confirm-bar .btn { min-height: 44px; }

.action-bar { display: flex; gap: 8px; }
.action-bar .btn { flex: 1 1 0; padding: 10px 6px; font-size: 14px; }

.captures-bar {
  display: flex;
  justify-content: space-around;
  margin-top: 8px;
  font-size: 12.5px;
  color: #c4b189;
}
.captures-bar strong { color: #ecd9a8; }

/* ================= 畫面四：終局 ================= */
.endgame-head { margin: 6px 0 12px; }
.endgame-head h2 { font-size: 24px; letter-spacing: 3px; color: #f2e2bd; text-align: center; }

.endgame-card { padding: 16px; text-align: center; }
.endgame-verdict { font-size: 22px; font-weight: 800; color: #5b4628; letter-spacing: 2px; }
.endgame-reason { font-size: 13.5px; color: var(--panel-muted); margin-top: 4px; }

.score-box { margin-top: 12px; }
.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.score-table th, .score-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--panel-line);
  text-align: center;
}
.score-table thead th { color: var(--panel-muted); font-weight: 600; }
.score-total th, .score-total td { font-weight: 800; border-bottom: none; color: #4a3517; }
.score-margin { margin-top: 8px; font-size: 14px; font-weight: 700; color: var(--bronze-lo); }

.reward-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  padding: 10px;
  border-radius: 10px;
  background: linear-gradient(180deg, #f2e3bd, #e2c98d);
  border: 1px solid #c6a45c;
  font-size: 15px;
  color: #5b4316;
}
.reward-box strong { font-size: 19px; }

.endgame-board { margin-top: 12px; padding: 12px; }
.endgame-board h3 { font-size: 15px; margin-bottom: 8px; color: #5b4628; text-align: center; }
.final-board-frame {
  width: min(80vw, 380px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: 2.4%;
  border-radius: 10px;
  background: linear-gradient(160deg, #4a382a, #2e2219);
}
#final-board { display: block; width: 100%; height: 100%; border-radius: 5px; }

.endgame-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.endgame-actions .btn { flex: 1 1 30%; }

/* ================= 覆層 ================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(8, 6, 4, 0.72);
  backdrop-filter: blur(2px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 28px);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  padding: 14px;
}
.modal-sm { max-width: 340px; text-align: center; }
.modal-sm p { font-size: 13.5px; color: var(--panel-muted); margin: 8px 0 4px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal-head h3 { font-size: 17px; color: #4d3c24; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal-actions .btn { flex: 1 1 0; }

.review-board-frame {
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: 2.4%;
  border-radius: 10px;
  background: linear-gradient(160deg, #4a382a, #2e2219);
}
#review-board { display: block; width: 100%; height: 100%; border-radius: 5px; }
.review-step { text-align: center; font-size: 13px; color: var(--panel-muted); margin: 8px 0; }
.review-nav { display: flex; gap: 6px; }
.review-nav .btn { flex: 1 1 0; padding: 8px 4px; font-size: 13px; min-height: 44px; }
.review-note { font-size: 11.5px; color: #9a8662; text-align: center; margin: 8px 0; }
#btn-review-continue { width: 100%; }

/* ================= 輕提示 ================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: 90vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(28, 22, 15, 0.95);
  border: 1px solid rgba(220, 180, 110, 0.4);
  color: #f6e9cc;
  font-size: 13.5px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.toast[hidden] { display: none; }

/* ================= 矮螢幕：先收肖像與裝飾 ================= */
@media (max-height: 700px) {
  .board-frame { width: min(92vw, 42vh, 460px); }
  .board-room { padding: 8px; }
  .window-light { opacity: 0.55; }
  .captures-bar { margin-top: 5px; }
}
@media (max-height: 640px) {
  .vs-portrait { display: none; }
  .brand .subtitle { display: none; }
  .board-frame { width: min(90vw, 40vh, 430px); }
}

/* ================= 窄螢幕 360 ================= */
@media (max-width: 360px) {
  #app { padding-left: 8px; padding-right: 8px; }
  .char-grid { gap: 8px; }
  .char-portrait { width: 50px; height: 60px; }
  .char-blurb { display: none; }
  .setup-portrait img { width: 92px; height: 110px; }
  .action-bar .btn { font-size: 13px; padding-left: 4px; padding-right: 4px; }
}

/* ================= 平板 768 ================= */
@media (min-width: 720px) {
  .char-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .char-portrait { width: 66px; height: 80px; }
  .board-frame { width: min(72vw, 58vh, 620px); }
  .setup-portrait img { width: 140px; height: 168px; }
  .setup-info { padding: 16px 18px; }
}

/* ================= 桌面 1024+：棋盤＋右側欄 ================= */
@media (min-width: 1024px) {
  #app { max-width: 1280px; padding: 22px 20px; }

  #screen-game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas:
      "head head"
      "status side"
      "board side";
    column-gap: 18px;
    align-items: start;
  }
  #screen-game .game-head { grid-area: head; }
  #screen-game .status-strip { grid-area: status; margin-top: 4px; }
  #screen-game .board-room { grid-area: board; }
  #screen-game .game-controls {
    grid-area: side;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
  }
  #screen-game .action-bar { flex-direction: column; }
  #screen-game .action-bar .btn { width: 100%; }
  #screen-game .confirm-bar { flex-wrap: nowrap; }
  #screen-game .captures-bar { flex-direction: column; gap: 6px; align-items: flex-start; }
  .board-frame { width: min(60vw, 72vh, 760px); }

  .char-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  /* 開局設定桌面排版 */
  #screen-setup .setup-options { max-width: 760px; margin-left: auto; margin-right: auto; }
  .setup-room { max-width: 760px; margin-left: auto; margin-right: auto; }

  /* 終局桌面：並排結果卡與最終棋盤 */
  #screen-endgame {
    display: grid;
    grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
  }
  #screen-endgame .endgame-head { grid-column: 1 / -1; }
  #screen-endgame .endgame-actions { grid-column: 1 / -1; justify-content: center; }
  #screen-endgame .endgame-actions .btn { flex: 0 1 200px; }
}

@media (min-width: 1024px) and (max-height: 900px) {
  .board-frame { width: min(56vw, 68vh, 720px); }
}

/* 尊重減少動態 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
