/* 設計語言：漆器沙盤桌（深褐漆色、黃銅細線）＋宣紙（米白、纖維紋）＋朱砂印（直書朱印是這套介面的記號）。
   字體只用系統內建的楷書與黑體，雙擊離線開啟也不缺字。 */
:root {
  --lacquer: #16110d;
  --lacquer-2: #221a14;
  --lacquer-3: #3a2d22;
  --paper: #ebe2cb;
  --paper-2: #f5eedc;
  --paper-edge: #cbbd9c;
  --ink: #1f1a14;
  --muted: #6b5e4c;
  --muted-light: #b9ab92;
  --cinnabar: #b0342a;
  --cinnabar-dark: #86251d;
  --brass: #c9a45c;
  --gold: #c9a45c;
  --jade: #2f6b4f;
  --kai: "DFKai-SB", "BiauKai", "STKaiti", "KaiTi", "Noto Serif TC", serif;
  --sans: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  /* 宣紙纖維：內嵌雜訊，不讀外部圖檔 */
  --fiber: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .28 0 0 0 0 .17 0 0 0 .10 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --paper-bg: var(--fiber), radial-gradient(ellipse 120% 90% at 30% 0%, #f3ecd8 0%, var(--paper) 55%, #e3d8bd 100%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(120, 78, 44, 0.35) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 100% 100%, rgba(90, 30, 20, 0.18) 0%, transparent 70%),
    var(--lacquer);
  background-attachment: fixed;
  color: var(--paper);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  scrollbar-color: #6d5a45 transparent;
  scrollbar-width: thin;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--kai); font-weight: 700; margin: 0; text-wrap: balance; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* ========== 按鈕 ========== */
.btn {
  border: 1px solid var(--lacquer-3);
  background: linear-gradient(180deg, #2b2119, var(--lacquer-2));
  color: var(--paper);
  padding: 6px 14px;
  border-radius: 5px;
  cursor: pointer;
  letter-spacing: 0.08em;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover:not(:disabled) { border-color: var(--brass); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.seal {
  background: linear-gradient(180deg, #bf3d31, var(--cinnabar));
  border-color: var(--cinnabar-dark);
  color: #fbf3e4; font-family: var(--kai); font-size: 17px;
  box-shadow: inset 0 0 0 2px rgba(251, 243, 228, 0.18), 0 2px 6px rgba(0, 0, 0, 0.3);
}
.btn.seal:hover:not(:disabled) { background: linear-gradient(180deg, #cc4538, #b8392e); }
.btn.icon { width: 36px; height: 36px; padding: 0; font-size: 18px; }
.btn.paper { background: var(--paper-2); color: var(--ink); border-color: var(--paper-edge); }
.btn.paper:hover:not(:disabled) { border-color: var(--cinnabar); }

/* 朱印：直書、朱底、內框一圈淡線 */
.seal-mark {
  writing-mode: vertical-rl;
  font-family: var(--kai); font-weight: 700;
  background: var(--cinnabar); color: #fbf1e0;
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px rgba(251, 241, 224, 0.35), 0 3px 8px rgba(0, 0, 0, 0.35);
}

/* ========== 選單 ========== */
.menu { max-width: 1180px; margin: 0 auto; padding-inline: 24px; padding-block: 56px 44px; display: flex; flex-direction: column; gap: 40px; }
.menu-head { display: flex; flex-direction: column; gap: 14px; }
.eyebrow { color: var(--brass); letter-spacing: 0.3em; font-size: 13px; }
.menu-head h1 { display: flex; align-items: center; gap: 22px; }
.h1-main {
  font-size: clamp(46px, 8vw, 84px); letter-spacing: 0.14em; line-height: 1.1;
  background: linear-gradient(180deg, #f8efd9 0%, #d9c49a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 2px 18px rgba(201, 164, 92, 0.12);
}
.h1-seal {
  writing-mode: vertical-rl;
  font-size: clamp(15px, 1.9vw, 20px); letter-spacing: 0.25em; line-height: 1;
  padding: 12px 8px; border-radius: 4px;
  background: var(--cinnabar); color: #fbf1e0;
  box-shadow: inset 0 0 0 2px rgba(251, 241, 224, 0.4), 0 6px 18px rgba(0, 0, 0, 0.4);
  transform: rotate(3deg);
}
.lede { max-width: 62ch; color: var(--muted-light); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 22px; }
.scn-card {
  position: relative;
  background: var(--paper-bg);
  color: var(--ink);
  border-radius: 5px;
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  border: none;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(120, 95, 60, 0.18);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.scn-card:hover { transform: translateY(-4px); box-shadow: 0 18px 36px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(176, 52, 42, 0.35); }
.scn-card:focus-visible { outline: 3px solid var(--brass); outline-offset: 3px; }
.scn-card .cover {
  display: block; margin: -22px -20px 6px; width: calc(100% + 40px); aspect-ratio: 608 / 400; object-fit: cover;
  transition: transform 0.6s ease, filter 0.3s;
  filter: saturate(0.92);
  -webkit-mask-image: linear-gradient(180deg, #000 78%, transparent 100%); mask-image: linear-gradient(180deg, #000 78%, transparent 100%);
}
.scn-card:hover .cover { transform: scale(1.05); filter: saturate(1.05); }
.scn-card .level {
  position: absolute; left: 12px; top: 12px; z-index: 1;
  font-size: 12px; letter-spacing: 0.25em; padding: 1px 8px 1px 10px; border-radius: 2px;
  color: #f6ecd6; background: rgba(22, 17, 13, 0.72); border: 1px solid rgba(201, 164, 92, 0.6);
  backdrop-filter: blur(2px);
}
.scn-card h3 { font-size: 40px; letter-spacing: 0.15em; line-height: 1.2; }
.scn-card .sub { font-family: var(--kai); font-size: 17px; color: var(--cinnabar-dark); }
.scn-card .chap { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.scn-card .meta { font-size: 13px; border-top: 1px solid var(--paper-edge); padding-top: 8px; margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.scn-card .meta b { color: var(--jade); font-weight: 600; }
.scn-card .cleared {
  position: absolute; right: 14px; top: 14px; z-index: 1;
  width: 54px; height: 54px; border: 3px solid var(--cinnabar); border-radius: 6px;
  color: var(--cinnabar); background: rgba(245, 236, 214, 0.9);
  font-family: var(--kai); font-size: 23px; font-weight: 700;
  display: grid; place-items: center; transform: rotate(-10deg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.menu-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; color: var(--muted-light); font-size: 13px; border-top: 1px solid rgba(201, 164, 92, 0.2); padding-top: 18px; }

/* ========== 遊戲 ========== */
.game { display: flex; flex-direction: column; min-height: 100vh; }
.bar {
  display: grid;
  grid-template-columns: minmax(0, auto) 1fr auto;
  align-items: center;
  gap: 22px;
  padding: 10px 18px;
  background: linear-gradient(180deg, #2a2019 0%, var(--lacquer-2) 100%);
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, transparent, rgba(201, 164, 92, 0.55) 20%, rgba(201, 164, 92, 0.55) 80%, transparent) 1;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
}
.bar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bar-title > div { min-width: 0; }
.bar-title h2 { font-size: 26px; letter-spacing: 0.14em; line-height: 1.2; white-space: nowrap; color: #f5ead2; }
.bar-title p { font-size: 12px; color: var(--muted-light); max-width: 30ch; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-status { display: flex; gap: 26px; align-items: center; min-width: 0; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.stat .k { font-size: 11px; color: var(--muted-light); letter-spacing: 0.25em; }
.stat b { font-weight: 600; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 6px; font-size: 16px; }
.stat.grow b { font-weight: 500; font-size: 13.5px; color: var(--brass); }
.pips { display: flex; gap: 3px; margin-top: 4px; }
.pips i { width: 6px; height: 6px; border: 1px solid rgba(201, 164, 92, 0.55); transform: rotate(45deg); }
.pips i.past { background: rgba(201, 164, 92, 0.55); }
.pips i.now { background: var(--cinnabar); border-color: #e0806f; box-shadow: 0 0 6px rgba(224, 96, 80, 0.7); }
.compass { position: relative; width: 30px; height: 30px; color: #a9cadb; flex: none; }
.compass svg { position: absolute; inset: 0; }
.wind .needle { transition: transform 0.6s cubic-bezier(.3, 1.4, .5, 1), opacity 0.3s; }
.bar-actions { display: flex; gap: 8px; }

.stage { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; padding: 18px; align-items: start; }
.mapwrap {
  position: relative;
  overflow-x: auto;
  border-radius: 6px;
  background: #1b140f;
  /* 漆木沙盤桌：外圈深漆、黃銅細線、內陰影 */
  box-shadow:
    0 0 0 5px #120d0a, 0 0 0 6px rgba(201, 164, 92, 0.55), 0 0 0 11px #1d1510, 0 0 0 12px rgba(201, 164, 92, 0.18),
    0 20px 40px rgba(0, 0, 0, 0.6), inset 0 0 40px rgba(0, 0, 0, 0.55);
  margin: 12px;
}
.mapwrap::after { /* 四角黃銅護角 */
  content: ""; position: absolute; inset: 6px; pointer-events: none; z-index: 3;
  background:
    linear-gradient(var(--brass), var(--brass)) top left / 22px 2px no-repeat,
    linear-gradient(var(--brass), var(--brass)) top left / 2px 22px no-repeat,
    linear-gradient(var(--brass), var(--brass)) top right / 22px 2px no-repeat,
    linear-gradient(var(--brass), var(--brass)) top right / 2px 22px no-repeat,
    linear-gradient(var(--brass), var(--brass)) bottom left / 22px 2px no-repeat,
    linear-gradient(var(--brass), var(--brass)) bottom left / 2px 22px no-repeat,
    linear-gradient(var(--brass), var(--brass)) bottom right / 22px 2px no-repeat,
    linear-gradient(var(--brass), var(--brass)) bottom right / 2px 22px no-repeat;
  opacity: 0.75;
}
.view-reset { position: absolute; left: 14px; bottom: 14px; z-index: 4; padding: 4px 12px; font-size: 13px; background: rgba(22, 17, 13, 0.72); border-color: rgba(201, 164, 92, 0.5); }
#map { background: radial-gradient(ellipse 75% 70% at 50% 42%, #5a4632 0%, #3a2c20 45%, #1b140f 100%);
  display: block; width: 100%; min-width: 720px; height: auto; cursor: pointer; touch-action: manipulation; }
.mapwrap.r3d #map { min-width: 0; }

/* 回合橫幅：一道墨色橫帶由中央向兩側展開 */
.turn-banner {
  position: absolute; left: 0; right: 0; top: 42%; transform: translateY(-50%); z-index: 5;
  text-align: center; color: #f6ecd6;
  font-family: var(--kai); font-size: 34px; letter-spacing: 0.4em; text-indent: 0.4em;
  padding: 14px 0;
  background: linear-gradient(90deg, transparent 0%, rgba(14, 10, 8, 0.88) 22%, rgba(14, 10, 8, 0.88) 78%, transparent 100%);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  pointer-events: none; animation: banner 1.4s ease forwards;
}
.turn-banner::before, .turn-banner::after {
  content: ""; position: absolute; left: 15%; right: 15%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--brass) 30%, var(--brass) 70%, transparent);
}
.turn-banner::before { top: 6px; }
.turn-banner::after { bottom: 6px; }
@keyframes banner {
  0% { opacity: 0; clip-path: inset(0 50% 0 50%); }
  18% { opacity: 1; clip-path: inset(0 0 0 0); }
  75% { opacity: 1; clip-path: inset(0 0 0 0); }
  100% { opacity: 0; clip-path: inset(0 0 0 0); }
}

.panel { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 76px; }
.notice { min-height: 1.7em; font-size: 13.5px; color: var(--brass); }
.notice.warn { color: #f0a08f; }
.card { background: var(--paper-bg); color: var(--ink); border-radius: 5px; padding: 14px 16px; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(120, 95, 60, 0.2); }
.unit-card:empty { display: none; }
.idle-cover {
  display: block; width: calc(100% + 32px); margin: -14px -16px 10px; aspect-ratio: 608 / 400; object-fit: cover; border-radius: 5px 5px 0 0;
  -webkit-mask-image: linear-gradient(180deg, #000 80%, transparent 100%); mask-image: linear-gradient(180deg, #000 80%, transparent 100%);
}
/* 還沒有封面圖的戰役：以暗色底代替破圖 */
.cover.none, .idle-cover.none, .m-cover img.none { background: radial-gradient(ellipse 80% 90% at 50% 100%, #7a3a1c 0%, #3a2418 45%, #17110c 100%); }
.idle-goal { font-size: 13.5px; line-height: 1.65; }
.idle-goal b { color: var(--cinnabar); margin-right: 6px; letter-spacing: 0.1em; }
.idle-hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 10px; }
.roster { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--paper-edge); padding-top: 8px; }
.ros { display: grid; grid-template-columns: 36px 1fr 64px 44px; align-items: center; gap: 10px; padding: 5px 6px; border: none; border-radius: 4px; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; transition: background 0.15s; }
.ros:hover, .ros:focus-visible { background: rgba(120, 90, 50, 0.13); }
.ros img, .ros .tk { width: 36px; height: 44px; object-fit: cover; border-radius: 3px; display: grid; place-items: center; color: #fbf6ea; font-family: var(--kai); font-weight: 700; box-shadow: 0 0 0 1px rgba(60, 45, 30, 0.35), 0 2px 5px rgba(0, 0, 0, 0.2); }
.ros .nm { font-size: 14.5px; font-weight: 600; letter-spacing: 0.06em; }
.ros .nm i { font-style: normal; font-size: 11px; color: var(--cinnabar); border: 1px solid var(--cinnabar); border-radius: 2px; padding: 0 3px; margin-left: 6px; vertical-align: 1px; }
.ros .tb { height: 5px; background: #d6c8a8; border-radius: 3px; overflow: hidden; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.15); }
.ros .tb span { display: block; height: 100%; background: linear-gradient(90deg, #3f7a3a, #6aa55c); }
.ros .st { font-size: 12px; color: var(--muted); text-align: right; }
.ros.done { opacity: 0.5; }
.unit-card .head { display: flex; align-items: center; gap: 14px; }
.unit-card .token { width: 50px; height: 50px; border-radius: 7px; color: #fbf6ea; display: grid; place-items: center; font-family: var(--kai); font-size: 27px; font-weight: 700; box-shadow: inset 0 0 0 2px rgba(245, 238, 220, 0.85), 0 3px 8px rgba(0, 0, 0, 0.3); flex: none; }
.unit-card h3 { font-size: 26px; letter-spacing: 0.1em; line-height: 1.2; }
.unit-card .portrait { width: 88px; height: 110px; object-fit: cover; border-radius: 4px; border: 3px solid; flex: none; box-shadow: 0 0 0 1px rgba(201, 164, 92, 0.8), 0 6px 14px rgba(0, 0, 0, 0.3); background: #2a211b; }
.unit-card .look { margin-top: 10px; font-size: 12.5px; line-height: 1.65; color: var(--muted); border-top: 1px solid var(--paper-edge); padding-top: 8px; font-family: var(--kai); font-size: 13.5px; }
.unit-card .kind { font-size: 12.5px; color: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }
.barrow { display: grid; grid-template-columns: 3em 1fr 4.6em; align-items: center; gap: 8px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.barrow .track { height: 7px; background: #d6c8a8; border-radius: 4px; overflow: hidden; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.15); }
.barrow .fill { display: block; height: 100%; border-radius: 4px; }
.barrow .v { text-align: right; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; text-align: center; font-size: 11.5px; color: var(--muted); letter-spacing: 0.15em; }
.stats3 span { border: 1px solid var(--paper-edge); border-radius: 4px; padding: 4px 0 2px; background: rgba(255, 250, 238, 0.35); }
.stats3 b { display: block; font-size: 19px; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: 0; font-family: var(--kai); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 3px; background: #e0d4b8; color: var(--ink); }
.tag.red { background: var(--cinnabar); color: #fbf3e4; }
.tag.green { background: var(--jade); color: #eef6f0; }

.actions { display: flex; flex-direction: column; gap: 10px; }
.actions:empty { display: none; }
.actions .row { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .row.cmds .btn { flex: 1 1 0; min-height: 40px; }
/* 計略牌：朱砂邊、楷書名、剩餘次數像一枚小印 */
.actions .row.abilities { flex-direction: column; }
.ability {
  display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 10px; text-align: left;
  padding: 10px 14px 10px 16px; border-radius: 5px; position: relative;
  background: var(--paper-bg); border: 1px solid var(--paper-edge); color: var(--ink);
  box-shadow: inset 4px 0 0 var(--cinnabar), 0 6px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}
.ability:hover:not(:disabled) { transform: translateX(3px); box-shadow: inset 6px 0 0 var(--cinnabar), 0 8px 20px rgba(0, 0, 0, 0.35); border-color: var(--paper-edge); }
.ability .ab-name { font-family: var(--kai); font-size: 20px; font-weight: 700; letter-spacing: 0.15em; }
.ability .ab-left { font-size: 11.5px; letter-spacing: 0.1em; color: var(--cinnabar); border: 1px solid var(--cinnabar); border-radius: 2px; padding: 0 5px; }
.ability small { grid-column: 1 / -1; font-size: 12px; color: var(--muted); letter-spacing: 0; line-height: 1.5; }
.ability:disabled { filter: grayscale(0.7); }
.preview { background: var(--paper-bg); color: var(--ink); border-left: 4px solid var(--cinnabar); border-radius: 4px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3); }
.preview .vs { font-family: var(--kai); font-size: 20px; letter-spacing: 0.08em; }
.preview .line { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; border-bottom: 1px dotted var(--paper-edge); padding-bottom: 3px; }
.preview .note { color: var(--muted); font-size: 12px; }

/* 游標所在的格子：地形名加幾個性質小籤 */
.tile-info { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted-light); min-height: 24px; }
.tile-info:empty { display: none; }
.tile-info b { font-family: var(--kai); font-size: 15px; color: var(--paper); letter-spacing: 0.1em; }
.tile-info span { padding: 0 7px; border-radius: 10px; background: rgba(201, 164, 92, 0.12); border: 1px solid rgba(201, 164, 92, 0.25); color: #d8c7a0; }
.tile-info i { font-style: normal; margin-left: auto; color: rgba(185, 171, 146, 0.6); font-variant-numeric: tabular-nums; }
.log-wrap { background: rgba(34, 26, 20, 0.85); border: 1px solid rgba(201, 164, 92, 0.18); border-radius: 5px; padding: 8px 12px; }
.log-wrap summary { cursor: pointer; color: var(--muted-light); font-family: var(--kai); font-size: 15px; letter-spacing: 0.3em; list-style: none; display: flex; align-items: center; gap: 8px; }
.log-wrap summary::-webkit-details-marker { display: none; }
.log-wrap summary::before { content: ""; width: 0; height: 0; border-left: 6px solid var(--brass); border-top: 4px solid transparent; border-bottom: 4px solid transparent; transition: transform 0.2s; }
.log-wrap[open] summary::before { transform: rotate(90deg); }
.log { list-style: none; margin: 8px 0 0; padding: 0; max-height: 280px; overflow-y: auto; font-size: 12.5px; display: flex; flex-direction: column; gap: 5px; }
.log li { line-height: 1.5; color: #d9cdb4; padding-left: 10px; border-left: 2px solid rgba(185, 171, 146, 0.25); }
.log li .r { display: inline-block; min-width: 1.6em; text-align: center; color: var(--lacquer); background: var(--muted-light); border-radius: 3px; font-size: 11px; font-variant-numeric: tabular-nums; margin-right: 6px; }
.log li.good { color: #a9d8a0; border-left-color: #5f9e52; }
.log li.bad { color: #f0a08f; border-left-color: #c0503c; }
.log li.event { color: var(--brass); border-left-color: var(--brass); }

/* 桌機：戰場與面板都釘在一個畫面內，沙盤填滿，面板自己捲動 */
@media (min-width: 981px) and (min-height: 560px) {
  .game { height: 100vh; min-height: 0; }
  .stage { min-height: 0; align-items: stretch; }
  .mapcol { min-height: 0; }
  .mapwrap.fill { flex: 1; min-height: 0; overflow: hidden; }
  .mapwrap.fill #map { position: absolute; inset: 0; width: 100%; height: 100%; }
  .panel { position: static; min-height: 0; overflow-y: auto; padding-right: 4px; margin: -4px -4px -4px 0; padding: 4px 8px 4px 4px; }
}

/* ========== 劇情對話 ========== */
.dialog { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 16px; padding-bottom: calc(26px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(180deg, rgba(10, 8, 6, 0.1) 30%, rgba(10, 8, 6, 0.6) 100%); z-index: 20; }
.dialog-card {
  width: min(860px, 100%);
  background: var(--paper-bg);
  color: var(--ink);
  border-radius: 5px;
  padding: 20px 24px 16px;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(120, 95, 60, 0.25), inset 0 0 0 6px rgba(245, 238, 220, 0.5), inset 0 0 0 7px rgba(176, 52, 42, 0.35);
  display: flex; flex-direction: row; align-items: flex-start; gap: 20px;
  animation: rise 0.28s ease;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.dlg-portrait { width: 132px; height: 165px; object-fit: cover; border-radius: 4px; flex: none; box-shadow: 0 0 0 1px rgba(201, 164, 92, 0.9), 0 10px 22px rgba(0, 0, 0, 0.45); margin-top: -46px; border: 4px solid var(--paper-2); background: #2a211b; }
/* 說話的人：直書朱印，貼在台詞左側 */
.dlg-body { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto auto; column-gap: 18px; row-gap: 8px; flex: 1; min-width: 0; }
.dialog .who {
  grid-row: 1 / 4; align-self: start;
  writing-mode: vertical-rl; font-family: var(--kai); font-weight: 700;
  font-size: 21px; letter-spacing: 0.22em; line-height: 1;
  padding: 12px 8px; border-radius: 3px;
  background: var(--cinnabar); color: #fbf1e0;
  box-shadow: inset 0 0 0 2px rgba(251, 241, 224, 0.38), 0 4px 10px rgba(0, 0, 0, 0.3);
  transform: rotate(1.5deg);
}
.dialog[data-kind="narr"] .who { background: #3b3128; }
.dialog[data-kind="note"] .who { background: var(--jade); }
.dialog .text { font-family: var(--kai); font-size: 22px; line-height: 1.8; max-width: 40em; }
.dialog .src { font-size: 12px; color: var(--muted); letter-spacing: 0.1em; }
.dialog .src:empty { display: none; }
.dialog .btn { justify-self: end; grid-column: 2; }

/* ========== 視窗 ========== */
.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at 50% 40%, rgba(20, 14, 10, 0.6), rgba(8, 6, 4, 0.85)); z-index: 30; overflow-y: auto; }
.modal-card {
  position: relative;
  width: min(720px, 100%); background: var(--paper-bg); color: var(--ink); border-radius: 6px; padding: 26px 30px 22px;
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.65), inset 0 0 0 1px rgba(120, 95, 60, 0.25);
  display: flex; flex-direction: column; gap: 16px;
  animation: rise 0.25s ease;
}
#modalBody { display: flex; flex-direction: column; gap: 14px; }
.modal-card h2 { font-size: 34px; letter-spacing: 0.15em; }
.modal-card h4 { margin: 0; font-size: 13px; letter-spacing: 0.3em; color: var(--cinnabar); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.modal-card h4::before { content: ""; width: 8px; height: 8px; background: var(--cinnabar); transform: rotate(45deg); flex: none; }
.modal-card .chap { color: var(--muted); font-size: 13px; }
.modal-card section { display: flex; flex-direction: column; gap: 6px; }
.modal-card ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; }
.modal-card p, .modal-card li { max-width: 64ch; }
.modal-buttons { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; border-top: 1px solid var(--paper-edge); padding-top: 14px; }
/* 視窗題頭：這一場的封面 */
.m-cover { position: relative; margin: -26px -30px 2px; border-radius: 6px 6px 0 0; overflow: hidden; background: #1b140f; }
.m-cover img { display: block; width: 100%; aspect-ratio: 16 / 7; object-fit: cover; }
.m-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10, 7, 5, 0) 35%, rgba(10, 7, 5, 0.88) 100%); }
.m-cover-text { position: absolute; left: 30px; right: 30px; bottom: 16px; z-index: 1; color: #f6ecd6; display: flex; flex-direction: column; gap: 2px; }
.m-cover-text h2 { font-size: 44px; letter-spacing: 0.18em; text-shadow: 0 3px 14px rgba(0, 0, 0, 0.7); }
.m-cover-text .m-sub { font-family: var(--kai); font-size: 18px; color: #e8d6ae; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8); }
.m-level { align-self: flex-start; font-size: 12px; letter-spacing: 0.25em; padding: 1px 8px 1px 10px; border: 1px solid rgba(201, 164, 92, 0.7); color: #f1e2bf; border-radius: 2px; background: rgba(22, 17, 13, 0.5); }
.m-cover.lost img { filter: grayscale(0.85) brightness(0.75); }
.brief { font-size: 15px; line-height: 1.8; }
.orders { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 18px; padding: 14px 0 2px; border-top: 1px solid var(--paper-edge); }
.orders p { font-size: 14px; }
.orders .side { color: var(--jade); font-weight: 600; font-size: 13px; margin-top: 2px; }
.poem { font-family: var(--kai); font-size: 23px; line-height: 1.95; text-align: center; padding: 10px 0; border-top: 1px solid var(--paper-edge); border-bottom: 1px solid var(--paper-edge); letter-spacing: 0.08em; }
.result-seal {
  align-self: flex-end; margin: -58px 6px 0 0; position: relative; z-index: 2;
  font-family: var(--kai); font-size: 40px; font-weight: 700; padding: 2px 18px; border: 4px solid currentColor; border-radius: 6px;
  background: rgba(245, 238, 220, 0.93); transform: rotate(-6deg); letter-spacing: 0.2em; text-indent: 0.2em;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  animation: stamp 0.5s cubic-bezier(.2, 1.4, .4, 1) 0.15s both;
}
.result-seal.win { color: var(--cinnabar); }
.result-seal.lose { color: #4a4238; }
@keyframes stamp { 0% { opacity: 0; transform: scale(1.9) rotate(-14deg); } 100% { opacity: 1; transform: scale(1) rotate(-6deg); } }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 22px; }
.help-grid dt { font-family: var(--kai); font-size: 17px; font-weight: 700; color: var(--cinnabar); letter-spacing: 0.1em; margin-top: 8px; }
.help-grid dd { margin: 0 0 4px; font-size: 14px; line-height: 1.75; }
.help-grid dl { border-top: 1px solid var(--paper-edge); padding-top: 2px; }
.help-grid dl { margin: 0; }
/* 選單載入：卡片依序浮現 */
.cards .scn-card { animation: cardIn 0.5s ease backwards; }
.cards .scn-card:nth-child(2) { animation-delay: 0.05s; } .cards .scn-card:nth-child(3) { animation-delay: 0.1s; }
.cards .scn-card:nth-child(4) { animation-delay: 0.15s; } .cards .scn-card:nth-child(5) { animation-delay: 0.2s; }
.cards .scn-card:nth-child(6) { animation-delay: 0.25s; } .cards .scn-card:nth-child(7) { animation-delay: 0.3s; }
.cards .scn-card:nth-child(8) { animation-delay: 0.35s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

@media (max-width: 980px) {
  .stage { grid-template-columns: 1fr; }
  .panel { position: static; }
  .bar { grid-template-columns: 1fr auto; }
  .bar-status { grid-column: 1 / -1; order: 3; }
}
@media (max-width: 560px) {
  .bar-title p { display: none; }
  .bar-status { gap: 16px; }
  .menu { padding-block: 32px 28px; padding-inline: 16px; }
  .menu-head h1 { gap: 14px; }
  .stage { padding: 10px; }
  .mapwrap { margin: 8px; }
  .dialog .text { font-size: 18px; }
  .dialog .who { font-size: 17px; padding: 10px 6px; }
  .dialog-card { position: relative; padding: 16px 16px 14px; }
  .dialog-card:has(.dlg-portrait:not([hidden])) .dlg-body { padding-right: 58px; }
  .dlg-portrait { position: absolute; right: 12px; top: -40px; width: 64px; height: 80px; margin: 0; border-width: 3px; }
  .dlg-body { column-gap: 12px; }
  .bar { gap: 10px 12px; padding: 8px 12px; }
  .bar-title { gap: 8px; }
  .bar-title h2 { font-size: 22px; letter-spacing: 0.08em; }
  .bar-actions { gap: 6px; }
  .bar-actions .btn { font-size: 14px; padding: 5px 9px; }
  .bar-actions .btn.seal { font-size: 15px; }
  .modal-card { padding: 22px 18px 18px; }
  .m-cover { margin: -22px -18px 2px; }
  .m-cover-text { left: 18px; right: 18px; }
  .m-cover-text h2 { font-size: 34px; }
  .turn-banner { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ========== 演義重演 ========== */
.mapcol { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
body.replaying #btnEnd, body.replaying .log-wrap, body.replaying .unit-card, body.replaying #tileInfo { display: none; }
.caption {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 4;
  width: min(86%, 740px); display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 18px 10px 10px; border-radius: 6px;
  background: linear-gradient(180deg, rgba(28, 21, 15, 0.9), rgba(18, 13, 9, 0.92)); border: 1px solid rgba(201, 164, 92, 0.45);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); color: var(--paper); pointer-events: none;
  backdrop-filter: blur(3px);
}
.caption .cap-face { width: 52px; height: 64px; object-fit: cover; border-radius: 4px; border: 2px solid var(--brass); flex: none; }
.caption .cap-body { min-width: 0; flex: 1; }
.caption p { margin: 0; }
.caption .cap-who { font-family: var(--kai); font-size: 16px; color: var(--brass); letter-spacing: 0.14em; }
.caption .cap-text { font-family: var(--kai); font-size: 21px; line-height: 1.55; white-space: pre-line; }
.caption .cap-src { font-size: 13px; color: var(--muted-light); margin-top: 4px; }
.caption.move .cap-text, .caption.attack .cap-text, .caption.turn .cap-text, .caption.start .cap-text { font-family: var(--sans); font-size: 17px; font-weight: 600; }
.caption.ability .cap-text { font-family: var(--sans); font-size: 17px; font-weight: 600; color: #ffcf8a; }
.caption.note { border-color: rgba(47, 107, 79, 0.8); }
.caption.note .cap-who { color: #8fd0ae; }
.caption.end { border-color: var(--cinnabar); }
.caption.end .cap-who { color: #ff9a8a; font-size: 22px; }

.replay-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 12px 12px;
  padding: 10px 12px; border-radius: 6px; background: linear-gradient(180deg, #2a2019, var(--lacquer-2)); border: 1px solid rgba(201, 164, 92, 0.25);
}
.replay-bar .btn { min-width: 44px; padding: 6px 10px; font-size: 16px; }
.rp-track { position: relative; flex: 1 1 260px; min-width: 200px; padding-bottom: 14px; }
.rp-track input { width: 100%; accent-color: var(--cinnabar); margin: 0; }
.rp-ticks { position: absolute; left: 8px; right: 8px; bottom: 0; height: 12px; pointer-events: none; }
.rp-ticks .tk { position: absolute; top: 2px; width: 2px; height: 8px; transform: translateX(-1px); border-radius: 1px; }
.rp-ticks .tk.say { background: var(--brass); opacity: 0.7; }
.rp-ticks .tk.ab { background: #f09a2a; height: 10px; top: 1px; width: 3px; }
.rp-ticks .tk.rd { background: var(--muted-light); height: 12px; top: 0; width: 1px; }
.rp-ticks .tk.rd i { position: absolute; top: -1px; left: 3px; font-style: normal; font-size: 10px; color: var(--muted-light); line-height: 1; }
.rp-label { font-size: 13px; color: var(--muted-light); min-width: 112px; }
.rp-speed { background: var(--lacquer-3); color: var(--paper); border: 1px solid #5a4636; border-radius: 4px; padding: 5px 6px; font: inherit; font-size: 13px; }
.rp-follow { font-size: 13px; color: var(--muted-light); display: flex; align-items: center; gap: 4px; cursor: pointer; }

.timeline h3 { font-size: 21px; letter-spacing: 0.14em; }
.tl-note { font-size: 12.5px; color: var(--muted); margin: 2px 0 8px; }
.tl-list { list-style: none; margin: 0; padding: 0 4px 0 0; max-height: min(62vh, 640px); overflow-y: auto; position: relative; }
.tl-head { position: sticky; top: 0; z-index: 1; background: #ece3cc; font-size: 12.5px; font-weight: 700; color: var(--cinnabar); letter-spacing: 0.12em; padding: 6px 0 3px; border-bottom: 1px solid var(--paper-edge); }
.tl-item button { display: block; width: 100%; text-align: left; border: none; background: transparent; color: var(--ink); font-size: 13px; line-height: 1.55; padding: 4px 6px 4px 10px; border-left: 3px solid transparent; border-radius: 0 3px 3px 0; cursor: pointer; }
.tl-item button:hover { background: rgba(120, 90, 50, 0.1); }
.tl-item.foe button { color: #3d4a66; }
.tl-item.ability button { color: #9a4a10; font-weight: 600; }
.tl-item.say button { font-family: var(--kai); font-size: 14px; color: #3a2a1c; }
.tl-item.say b { color: var(--cinnabar); margin-right: 4px; }
.tl-item.say small { display: block; font-family: var(--sans); font-size: 11px; color: var(--muted); }
.tl-item.end button { font-weight: 700; color: var(--cinnabar); }
.tl-item.current button { background: rgba(176, 52, 42, 0.12); border-left-color: var(--cinnabar); }
@media (min-width: 981px) and (min-height: 560px) {
  .tl-list { max-height: none; }
  .timeline { display: flex; flex-direction: column; min-height: 0; }
}
@media (max-width: 560px) {
  .caption { bottom: 8px; padding: 8px 10px; gap: 8px; }
  .caption .cap-face { width: 40px; height: 50px; }
  .caption .cap-text { font-size: 16px; }
  .caption.move .cap-text, .caption.attack .cap-text, .caption.ability .cap-text, .caption.turn .cap-text, .caption.start .cap-text { font-size: 14px; }
  .replay-bar { margin: 0 8px 8px; }
}

/* ========== 聲音開關 ========== */
.sound-toggle { display: inline-flex; align-items: center; gap: 6px; }
.snd-ico {
  width: 18px; height: 18px; flex: none; background: currentColor;
  -webkit-mask: var(--snd-on) center / contain no-repeat; mask: var(--snd-on) center / contain no-repeat;
}
.sound-toggle.off .snd-ico { -webkit-mask-image: var(--snd-off); mask-image: var(--snd-off); }
.sound-toggle.off { color: var(--muted-light); }
:root {
  --snd-on: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9h4l5-4v14l-5-4H4z' fill='black'/%3E%3Cpath d='M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12'/%3E%3C/svg%3E");
  --snd-off: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9h4l5-4v14l-5-4H4z' fill='black'/%3E%3Cpath d='M17 9l5 6M22 9l-5 6'/%3E%3C/svg%3E");
}
