/* =========================================================
   四國軍棋 · 樣式
   隊伍配色：南（紅）＋北（橙）＝暖色隊；東（藍）＋西（綠）＝冷色隊
   ========================================================= */
:root {
  color-scheme: dark;
  --bg: #1b2226;
  --panel: #242c31;
  --line: rgba(255, 255, 255, .1);
  --ink: #ece6da;
  --muted: #a9b1b4;
  --gold: #e0b45a;
  --s: #c0392b;   /* 南 紅 */
  --e: #2e6fbf;   /* 東 藍 */
  --n: #d9822b;   /* 北 橙 */
  --w: #2f8f5b;   /* 西 綠 */
  --paper: #efe2c2;
  --wood: #6b4a2b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: radial-gradient(ellipse at 50% -20%, #2c3a40, var(--bg) 60%); color: var(--ink);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.center { text-align: center; }
.c-s { color: #ff7b6b; } .c-e { color: #6fa8ff; } .c-n { color: #ffb066; } .c-w { color: #6fd39b; }

.screen { min-height: 100dvh; max-width: 620px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 10px) 14px calc(env(safe-area-inset-bottom) + 14px); }

/* ---------- 按鈕 ---------- */
.btn { min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 15px; font-weight: 600; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--s); border-color: var(--s); color: #fff; }
.btn.danger { color: #ff9a8a; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .45; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 20px; flex: none; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

/* ---------- 主選單 ---------- */
.home-top { text-align: center; position: relative; padding: 10px 0 6px; }
.home-top .back { position: absolute; left: 0; top: 6px; color: var(--muted); text-decoration: none; font-size: 30px; padding: 0 8px; }
.home-top h1 { margin: 10px 0 2px; font-size: 30px; letter-spacing: .3em; padding-left: .3em; font-family: "Kaiti TC", "BiauKai", "DFKai-SB", serif; }
.home-top p { margin: 0; color: var(--muted); font-size: 13px; }
.emblem { position: relative; width: 64px; height: 64px; margin: 0 auto; }
.emblem i { position: absolute; width: 22px; height: 22px; border-radius: 5px; }
.emblem .e-s { left: 21px; bottom: 0; background: var(--s); }
.emblem .e-n { left: 21px; top: 0; background: var(--n); }
.emblem .e-e { right: 0; top: 21px; background: var(--e); }
.emblem .e-w { left: 0; top: 21px; background: var(--w); }
.cards { display: grid; gap: 12px; margin-top: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.card h2 { margin: 0 0 6px; font-size: 18px; }
.card .btn.primary { width: 100%; margin-top: 10px; }
.card.big { text-align: left; border-color: var(--gold); }
.card.big strong { display: block; font-size: 17px; color: var(--gold); }
.card.big small { color: var(--muted); }
.field { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }
.field input, .join-row input { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: #1b2226; color: var(--ink); font: inherit; font-size: 16px; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.join-row input { margin: 0; letter-spacing: .3em; text-align: center; }
.feedback { min-height: 18px; margin: 8px 0 0; font-size: 13px; color: #ffb3a7; }
.seg-label { font-size: 13px; color: var(--muted); margin: 8px 0 6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: #1b2226; font-weight: 600; cursor: pointer; }
.seg small { font-weight: 400; font-size: 11px; color: var(--muted); }
.seg input:checked + span { border-color: var(--gold); color: var(--gold); background: rgba(224, 180, 90, .08); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--s); }
.rules summary { font-weight: 700; font-size: 17px; cursor: pointer; }
.rules h3 { font-size: 14.5px; margin: 14px 0 4px; color: var(--gold); }
.rules p { margin: 4px 0; font-size: 13.5px; line-height: 1.7; color: #d3d0c8; }

/* ---------- 等待室 ---------- */
.bar { display: flex; align-items: center; gap: 10px; }
.bar h2 { margin: 0; font-size: 18px; }
.room-code { text-align: center; margin: 16px 0 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.room-code small { color: var(--muted); }
.room-code strong { display: block; font-size: 40px; letter-spacing: .25em; color: var(--gold); font-variant-numeric: tabular-nums; }
.seat-map { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto auto auto; gap: 8px; margin: 14px auto; max-width: 380px; }
.seat { min-height: 76px; border-radius: 14px; border: 2px solid var(--line); background: var(--panel); padding: 6px; font-size: 13px; line-height: 1.4; }
.seat b { display: block; font-size: 16px; }
.seat.mine { box-shadow: 0 0 0 3px rgba(255, 255, 255, .5); }
.seat.taken { background: #2c363c; }
.s-n { grid-column: 2; grid-row: 1; border-color: var(--n); }
.s-w { grid-column: 1; grid-row: 2; border-color: var(--w); }
.s-e { grid-column: 3; grid-row: 2; border-color: var(--e); }
.s-s { grid-column: 2; grid-row: 3; border-color: var(--s); }
.seat-center { grid-column: 2; grid-row: 2; display: grid; place-items: center; color: var(--muted); font-size: 13px; border: 1px dashed var(--line); border-radius: 14px; }

/* ---------- 對局 ---------- */
#game { padding-left: 2px; padding-right: 2px; display: flex; flex-direction: column; gap: 6px; height: 100dvh; }
#game .game-top, #game .status, #game .controls { margin: 0 4px; }
.game-top { display: flex; gap: 6px; align-items: center; }
.chips { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; min-width: 0; }
.chip { border-radius: 9px; border: 1px solid var(--line); background: var(--panel); padding: 3px 5px; font-size: 11px; line-height: 1.35; min-width: 0; position: relative; }
.chip b { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip i { font-style: normal; color: var(--muted); white-space: nowrap; }
.chip.turn { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.chip.out { opacity: .4; text-decoration: line-through; }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 3px; vertical-align: 1px; }
.status { margin: 0; min-height: 20px; font-size: 13.5px; text-align: center; color: var(--ink); }
.board-wrap { flex: 1; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; border-radius: 10px; }
.board-wrap.zoom { overflow: auto; display: block; -webkit-overflow-scrolling: touch; }
.board { position: relative; flex: none; }
#lines, #labels, #marks, #pieces { position: absolute; inset: 0; width: 100%; height: 100%; }
#labels, #marks { pointer-events: none; }
.controls { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.controls .btn { font-size: 14px; padding: 0 6px; }

/* 棋子：寬度約佔格子的 95%，兩個字橫排（例如「軍長」） */
.pc {
  position: absolute; width: 5.6%; height: 3.4%; transform: translate(-50%, -50%);
  border-radius: 3px; display: grid; place-items: center;
  color: #fff; font-weight: 500; line-height: 1; white-space: nowrap; letter-spacing: 0;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(255, 255, 255, .25);
  transition: left .28s ease, top .28s ease, opacity .3s;
}
.pc.one { font-size: 1.45em; letter-spacing: 0; }   /* 只有一個字元時（英文模式的數字）放大 */
.pc.s0 { background: var(--s); } .pc.s1 { background: var(--e); } .pc.s2 { background: var(--n); } .pc.s3 { background: var(--w); }
.pc.hidden { background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, .12) 0 2px, transparent 2px 5px); }
.pc.sel { outline: 2px solid #fff; outline-offset: 1px; z-index: 3; }
.pc.dying { opacity: 0; }
.pc.noted { color: rgba(255, 255, 255, .95); font-weight: 400; outline: 1.5px dashed rgba(255, 255, 255, .9); outline-offset: -3px; }
.board { -webkit-touch-callout: none; }
.note-sel { display: block; width: 100%; margin: 4px 0 6px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: #1b2226; color: var(--ink); font: inherit; font-size: 16px; }
.pc.flagged { box-shadow: 0 0 0 2px #ffe27a, 0 1px 2px rgba(0, 0, 0, .45); }
.tgt { position: absolute; width: 2.4%; height: 2.4%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(255, 230, 120, .95); box-shadow: 0 0 0 2px rgba(0, 0, 0, .35); }
.tgt.atk { width: 6.1%; height: 3.9%; border-radius: 4px; background: transparent; box-shadow: 0 0 0 2.5px #ffe066, 0 0 8px #ffe066; }
.lab { position: absolute; transform: translate(-50%, -50%); width: 30%; text-align: center; color: var(--ink); line-height: 1.3; }
.lab b { display: block; font-size: 2.1em; font-family: "Kaiti TC", "BiauKai", "DFKai-SB", serif; }
.lab span { display: block; font-size: 1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lab small { display: block; font-size: .9em; color: var(--muted); }
.lab.turn small { color: var(--gold); font-weight: 700; }
.lab.out { opacity: .45; }
:root { --sl: #ff7b6b; --el: #6fa8ff; --nl: #ffb066; --wl: #6fd39b; }

/* 戰況 */
.log { list-style: none; padding: 0; margin: 0 0 6px; max-height: 60vh; overflow: auto; font-size: 13.5px; line-height: 1.6; }
.log li { padding: 6px 2px; border-bottom: 1px solid var(--line); }

/* 對話框 */
dialog { width: min(420px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlg { padding: 18px; }
.dlg h2 { margin: 0 0 10px; }
.kicker { margin: 0; color: var(--gold); font-size: 12px; letter-spacing: .3em; }
#endTitle { font-size: 26px; margin: 6px 0; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 80px); transform: translateX(-50%); max-width: 90vw; padding: 9px 14px; border-radius: 12px; background: rgba(10, 12, 14, .92); border: 1px solid var(--line); font-size: 13.5px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; text-align: center; }
.toast.show { opacity: 1; }

/* ---------- 語言切換（繁 / 简 / EN） ---------- */
.lang-toggle { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.lang-toggle b { color: var(--gold); }
.home-top .lang-toggle { position: absolute; right: 0; top: 8px; }
.en-only { display: none; }
body.lang-en .en-only { display: block; }
body.lang-en .zh-only { display: none; }
.rules ul { padding-left: 1.2em; margin: 4px 0; font-size: 13.5px; line-height: 1.7; color: #d3d0c8; }
/* 英文模式：棋子顯示數字／字母，用無襯線粗體比較清楚 */
body.lang-en .pc { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 600; }
body.lang-en .lab b { font-family: system-ui, sans-serif; font-size: 1.5em; }
/* 簡體：改用簡體字型，避免「军长」一個字用一種字型 */
html:lang(zh-Hans) body, html:lang(zh-Hans) .pc { font-family: "PingFang SC", "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif; }
html:lang(zh-Hans) .home-top h1, html:lang(zh-Hans) .lab b { font-family: "Kaiti SC", "STKaiti", "KaiTi", serif; }

/* ---------- 電腦／平板橫向：棋盤在左邊吃滿高度，資訊與按鈕放右側 ---------- */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  #game.screen { max-width: none; padding: 14px 18px; display: grid; grid-template-columns: minmax(0, 1fr) 280px; grid-template-rows: auto auto 1fr auto; column-gap: 20px; row-gap: 12px; }
  #game .board-wrap { grid-column: 1; grid-row: 1 / -1; }
  #game .game-top { grid-column: 2; grid-row: 1; flex-direction: column; align-items: stretch; margin: 0; }
  #game .game-top .icon-btn { align-self: flex-start; }
  #game .chips { grid-template-columns: 1fr; gap: 8px; }
  #game .chip { padding: 8px 12px; font-size: 13px; }
  #game .chip b { font-size: 16px; }
  #game .status { grid-column: 2; grid-row: 2; text-align: left; font-size: 15px; line-height: 1.6; margin: 0; }
  #game .controls { grid-column: 2; grid-row: 4; grid-auto-flow: row; margin: 0; }
  #game .controls .btn { font-size: 15px; min-height: 48px; }
}
