:root {
  --bg: #12141a;
  --panel: #1b1e27;
  --panel2: #232733;
  --line: #333a49;
  --ink: #e7e9ef;
  --muted: #9aa2b4;
  --accent: #57c7ff;
  --me: #ffcf5c;
  --danger: #ff6b6b;
  --poison: #7a4bd6;
  --ok: #55d6a0;
  --revive: #ff8fb0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
#topbar h1 { font-size: 18px; margin: 0; letter-spacing: 2px; }
#status { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; flex: 1; }
#status span { font-size: 13px; }
#round-badge { font-weight: 700; color: var(--accent); }
#phase-badge { color: var(--muted); }
#me-hp b { color: var(--me); }
#new-game {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
#new-game:hover { border-color: var(--accent); }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 12px;
  padding: 12px;
  align-items: start;
}

/* ── 地圖 ── */
#board-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
#poison-legend { font-size: 12px; color: var(--muted); margin-bottom: 8px; min-height: 18px; }
#board {
  position: relative;
  width: 100%;
  overflow-x: auto;
}
#board-inner { position: relative; }
.room {
  position: absolute;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel2);
  padding: 3px 4px;
  font-size: 11px;
  line-height: 1.2;
  overflow: hidden;
  cursor: default;
  transition: background .12s, border-color .12s;
}
.room .rid { font-weight: 700; color: var(--muted); }
.room .rname { display: block; color: var(--ink); font-size: 11px; }
.room .rfn { display: block; color: var(--accent); font-size: 10px; }
.room.me { border-color: var(--me); background: #3a3416; box-shadow: 0 0 0 2px var(--me) inset; }
.room.me .rid { color: var(--me); }
.room.poisoned { background: #2e1d47; }
.room.poisoned::after { content: "☠"; position: absolute; top: 2px; right: 3px; color: var(--poison); font-size: 12px; }
.room.battle { outline: 2px dashed var(--danger); outline-offset: -2px; }
.room.revive { border-bottom: 3px solid var(--revive); }
.room.pickable { cursor: pointer; border-color: var(--ok); background: #1d3a2e; }
.room.pickable:hover { background: #275041; }
.room.pathnode { box-shadow: 0 0 0 2px var(--accent) inset; }
.floor-band {
  position: absolute; left: 0; right: 0;
  border-top: 1px dashed #2a2f3c;
  font-size: 10px; color: #5a6274;
  pointer-events: none;
}
.floor-band.poison { background: rgba(122,75,214,0.12); }
.floor-band .flabel { position: absolute; left: 2px; top: 2px; }

/* ── 側欄 ── */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.panel h2 { font-size: 14px; margin: 0 0 8px; color: var(--accent); }
#hand-cards { display: flex; flex-wrap: wrap; gap: 6px; min-height: 26px; }
.card-chip {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 5px;
  padding: 3px 8px; font-size: 12px;
}
.card-chip.gun { border-color: var(--danger); }
.card-chip.consumable { border-color: var(--ok); }
.hand-empty { color: var(--muted); font-size: 12px; }

#action-body { display: flex; flex-direction: column; gap: 10px; }
.field { border-top: 1px solid var(--line); padding-top: 8px; }
.field:first-child { border-top: none; padding-top: 0; }
.field label.head { display: block; font-weight: 700; margin-bottom: 4px; color: var(--ink); font-size: 13px; }
.field .hint { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; }
button.opt, .btnrow button {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 9px; cursor: pointer; font-size: 12px;
}
button.opt:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #06263a; border-color: var(--accent); font-weight: 700; }
button.primary:disabled { background: var(--panel2); color: var(--muted); border-color: var(--line); cursor: not-allowed; font-weight: 400; }
button.warn { border-color: var(--danger); color: var(--danger); }
select, input[type=number] {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 5px; padding: 4px 6px; font-size: 12px;
}
input[type=number] { width: 56px; }
.path-draft { font-size: 12px; color: var(--me); margin: 4px 0; min-height: 16px; word-break: break-all; }
.path-err { color: var(--danger); font-size: 12px; }
.path-ok { color: var(--ok); font-size: 12px; }
.checkline { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 2px 0; }
.gene-inputs { display: flex; gap: 10px; align-items: center; }
.gene-inputs label { font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.sum-ok { color: var(--ok); }
.sum-bad { color: var(--danger); }

#public-log, #full-log { font-size: 12px; line-height: 1.5; max-height: 220px; overflow-y: auto; }
#public-log div, #full-log div { padding: 1px 0; border-bottom: 1px solid #20242f; }
#full-log { max-height: 300px; color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ── overlay ── */
#overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
#overlay.hidden { display: none; }
#overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; width: min(560px, 92vw); max-height: 86vh; overflow-y: auto;
}
#overlay-card h2 { margin-top: 0; color: var(--accent); }
#overlay-body { font-size: 13px; line-height: 1.6; }
#overlay-body .hp-change { color: var(--me); font-weight: 700; margin: 8px 0; }
#overlay-body ul { padding-left: 18px; margin: 6px 0; }
#overlay-continue {
  margin-top: 16px; background: var(--accent); color: #06263a; border: none;
  padding: 8px 20px; border-radius: 7px; font-weight: 700; cursor: pointer; font-size: 14px;
}
.rank-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.rank-table th, .rank-table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
.rank-table tr.me-row { background: #3a3416; }
.rank-table .shadow { color: var(--muted); }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  #side { order: 2; }
}

/* ── 回放（上帝視角）─────────────────────────────────────────────── */
.replay-nav { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.replay-board {
  overflow-x: auto; margin: 10px 0 14px;
  border: 1px solid #2a3242; border-radius: 6px; padding: 8px; background: #0e131b;
}
.room.replay { font-size: 10px; cursor: default; }
.room.replay .chips {
  position: absolute; left: 2px; right: 2px; bottom: 2px;
  display: flex; flex-wrap: wrap; gap: 2px;
}
.room.replay .chip {
  font-size: 9px; line-height: 1.3; padding: 0 3px; border-radius: 3px;
  background: #3b82f6; color: #fff; white-space: nowrap;
}
.room.replay .chip.mine { background: #facc15; color: #1a1a1a; font-weight: 700; }
.room.replay .chip.shadow { background: #6b21a8; }
.room.replay .chip.thru { background: #334155; color: #94a3b8; opacity: .7; }

.replay-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.replay-table th, .replay-table td {
  border-bottom: 1px solid #232a36; padding: 5px 6px; text-align: left; vertical-align: top;
}
.replay-table th { color: #93a3b8; font-weight: 600; }
.replay-table tr.is-me { background: rgba(250, 204, 21, .08); }
.replay-table tr.is-me td:first-child { color: #facc15; font-weight: 700; }
.replay-table .path { font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: #cbd5e1; }
.replay-table .ev { color: #94a3b8; }
.replay-table .up { color: #4ade80; }
.replay-table .down { color: #f87171; }
.replay-table .dead { color: #a78bfa; }

/* ── 樓梯／廊橋連線 ────────────────────────────────────────────────── */
.link {
  position: absolute; height: 0; pointer-events: none;
  transform-origin: 0 0; z-index: 5;
}
.link.stair  { border-top: 2px dashed #eab308; opacity: .75; }
.link.bridge { border-top: 3px solid  #38bdf8; opacity: .8; }

/* ── 抽卡／丟棄勾選 ────────────────────────────────────────────────── */
label.check {
  display: flex; align-items: flex-start; gap: 7px;
  padding: 5px 6px; border-radius: 5px; cursor: pointer; font-size: 12px;
}
label.check:hover { background: #1b2230; }
label.check input { margin-top: 2px; }
.link.chute  { border-top: 3px dotted #4ade80; opacity: .85; }

/* ── 抽卡結果 ──────────────────────────────────────────────────────── */
.drew-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.drew-card {
  background: #1d4ed8; color: #fff; border-radius: 5px;
  padding: 4px 8px; font-size: 12px; font-weight: 600;
}
.drew-card em { font-style: normal; font-weight: 400; opacity: .8; margin-left: 4px; }
.tag-new {
  background: #1d4ed8; color: #fff; border-radius: 3px;
  padding: 0 4px; font-size: 10px; margin-left: 4px;
}
.room.replay .chip.fight { background: #dc2626; font-size: 11px; padding: 0 4px; }

/* ── 事件標記：戰鬥／亂鬥／暗影相遇分開顯示 ─────────────────────────── */
.room .chips { position: absolute; right: 3px; bottom: 2px; display: flex; gap: 2px; }
.chip.ev-fight  { background: #dc2626; }
.chip.ev-brawl  { background: #f97316; }
.chip.ev-shadow { background: #7c3aed; }
.chip.ev-fight, .chip.ev-brawl, .chip.ev-shadow {
  color: #fff; border-radius: 3px; padding: 0 3px; font-size: 10px; line-height: 1.4;
}
/* 屬性被道具加成時標色 */
b.buffed { color: #4ade80; }

/* ═══════════════════════════════════════════════════════════════════
   UI 優化：毒氣改綠色、加大對比、狀態列分區
   （放最後以覆蓋前面的規則）
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --poison: #3ddc84;          /* 毒氣＝綠色 */
  --poison-bg: rgba(61, 220, 132, 0.10);
  --poison-room: #16301f;
}

.room.poisoned { background: var(--poison-room); box-shadow: inset 0 0 0 1px rgba(61,220,132,.35); }
.room.poisoned::after { content: "☠"; color: var(--poison); font-weight: 700; }
.floor-band.poison { background: var(--poison-bg); }
.floor-band.poison .flabel { color: var(--poison); font-weight: 700; }
#poison-legend { color: var(--muted); line-height: 1.7; font-size: 12px; }

/* 狀態列：分成獨立徽章，一眼看得出來 */
#topbar { gap: 12px; }
#topbar-actions { display: flex; gap: 8px; }
#status span {
  background: var(--panel2); border: 1px solid var(--line);
  padding: 3px 9px; border-radius: 999px; font-size: 13px; white-space: nowrap;
}
#round-badge { border-color: var(--accent) !important; }
#me-hp { font-variant-numeric: tabular-nums; }
#me-hp b { font-size: 15px; }
#sound-toggle {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
#sound-toggle:hover { border-color: var(--accent); }
#sound-toggle.muted { color: var(--muted); opacity: .65; }

/* 房間：加大字級與對比 */
.room { font-size: 11px; }
.room .rid { font-weight: 700; letter-spacing: .3px; }
.room .rname { display: block; opacity: .95; }
.room .rfn { color: var(--accent); font-size: 10px; }
.room.me { box-shadow: 0 0 0 2px var(--me), 0 0 12px rgba(255,207,92,.35); }
.room.pickable { cursor: pointer; }
.room.pickable:hover { filter: brightness(1.35); }

/* 面板：標題更清楚、區塊間距拉開 */
.panel h2 { font-size: 14px; letter-spacing: .5px; }
.field { margin-bottom: 12px; }
.field .head {
  display: block; font-weight: 700; margin-bottom: 5px;
  color: var(--accent); font-size: 13px;
}
.hint { color: var(--muted); font-size: 12px; line-height: 1.65; }
button.primary {
  font-size: 14px; font-weight: 700; padding: 10px 14px; width: 100%;
  margin-top: 4px;
}
button.opt { font-size: 12px; }
button.opt:hover { border-color: var(--accent); }

/* 血量變化：數字放大 */
.hp-change { font-size: 14px; line-height: 1.9; }
.hp-change b { font-size: 17px; }
.up { color: var(--ok); font-weight: 700; }
.down { color: var(--danger); font-weight: 700; }
.dead { color: #a78bfa; font-weight: 700; }

/* 覆蓋層：加寬、可捲動 */
#overlay-card { max-width: 860px; max-height: 88vh; overflow-y: auto; }

/* ═══════════════════════════════════════════════════════════════════
   通道視覺、可抽卡房間、目的地選取（放最後以覆蓋前面規則）
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --pick: #4aa8ff;            /* 可到達＝藍 */
  --cards: #e0b34a;           /* 可抽卡＝琥珀 */
  --stair: #eab308;
  --bridge: #38bdf8;
  --chute: #3ddc84;
}

/* ── 通道 ── */
.link { height: 0; border: 0; }
.link.stair {
  border-top: 3px dashed var(--stair);
  opacity: .55; filter: drop-shadow(0 0 3px rgba(234,179,8,.35));
}
.link.bridge {
  border-top: 4px solid var(--bridge);
  opacity: .7; filter: drop-shadow(0 0 5px rgba(56,189,248,.45));
}
.link.chute {
  border-top: 3px dotted var(--chute);
  opacity: .7; filter: drop-shadow(0 0 4px rgba(61,220,132,.4));
}
.link-dot {
  position: absolute; width: 7px; height: 7px; border-radius: 50%;
  transform: translate(-50%, -50%); z-index: 6; pointer-events: none;
  border: 1px solid rgba(0,0,0,.55);
}
.link-dot.stair  { background: var(--stair); }
.link-dot.bridge { background: var(--bridge); width: 9px; height: 9px; }
.link-dot.chute  { background: var(--chute); }
.link-arrow {
  position: absolute; z-index: 6; pointer-events: none;
  width: 0; height: 0;
  border-left: 9px solid var(--chute);
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
.lg {
  display: inline-block; width: 20px; height: 0; vertical-align: middle;
  margin-right: 4px; position: relative; top: -2px;
}
.lg-stair  { border-top: 3px dashed var(--stair); }
.lg-bridge { border-top: 4px solid var(--bridge); }
.lg-chute  { border-top: 3px dotted var(--chute); }

/* ── 可抽卡房間 ── */
.room.has-cards {
  background: #2a2416;
  box-shadow: inset 0 0 0 1px rgba(224,179,74,.45);
}
.room.has-cards.poisoned { background: #253018; }
.card-dot {
  position: absolute; top: 3px; right: 5px;
  color: var(--cards); font-size: 13px; line-height: 1; text-shadow: 0 0 4px rgba(224,179,74,.5);
}

/* ── 可到達／已選目的地：藍 ── */
.room.pickable {
  box-shadow: inset 0 0 0 2px var(--pick), 0 0 10px rgba(74,168,255,.25);
  cursor: pointer;
}
.room.pickable:hover { box-shadow: inset 0 0 0 2px #8ecbff, 0 0 16px rgba(74,168,255,.5); }
.room.chosen {
  box-shadow: inset 0 0 0 3px var(--pick), 0 0 20px rgba(74,168,255,.75) !important;
  background: #16283d !important;
}
.room.pathnode { box-shadow: inset 0 0 0 2px rgba(74,168,255,.5); }
.room.me { box-shadow: 0 0 0 2px var(--me), 0 0 12px rgba(255,207,92,.4) !important; }

/* ── 目的地清單 ── */
.dest-list { display: flex; flex-direction: column; gap: 5px; margin: 8px 0; }
.dest-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.dest-floor {
  min-width: 30px; font-size: 11px; color: var(--muted); font-weight: 700;
}
button.dest-btn { display: inline-flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
button.dest-btn em { font-style: normal; font-size: 10px; color: var(--muted); }
button.dest-btn.has-cards { border-color: rgba(224,179,74,.6); }
button.dest-btn.via-laser em { color: var(--danger); }
button.dest-btn:hover { border-color: var(--pick); background: #16283d; }

/* ── 結算面板的血量表 ── */
.hp-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 8px 0 12px; }
.hp-table th, .hp-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.hp-table th { color: var(--muted); font-weight: 600; }
.hp-table tr.me-row { background: rgba(255,207,92,.09); }
.hp-table tr.me-row td:first-child { color: var(--me); font-weight: 700; }
.hp-table tr.shadow td { color: #a78bfa; }
.hp-table td b { font-variant-numeric: tabular-nums; }
.hpbar {
  display: inline-block; width: 54px; height: 7px; border-radius: 4px;
  background: #2b3140; margin-right: 6px; overflow: hidden; vertical-align: middle;
}
.hpbar i { display: block; height: 100%; background: linear-gradient(90deg,#ff6b6b,#ffcf5c,#55d6a0); }
.pub-list { margin: 4px 0 6px 18px; padding: 0; }
.pub-list li { margin: 2px 0; font-size: 12px; line-height: 1.6; }
