/* ===== 黑白棋 — 樣式 =====
 * 視覺摘要：胡桃木深棕底、黃銅細框與金色重點、象牙白文字；棋子是黑曜石與象牙大理石。
 * 控制項（按鈕、開關、滑桿、分段選單）一律自製，圓潤但偏沉穩的「棋室」質感。
 */
:root {
  --bg: #2a1f17; --bg2: #35271d; --panel: rgba(58, 42, 30, .96); --panel-solid: #3b2b1e; --panel-hi: #4b3626;
  --line: rgba(226, 180, 90, .5); --line-hi: rgba(240, 205, 130, .9);
  --brass: #c89b3c; --brass-hi: #ecc77a; --brass-lo: #8a6a24;
  --text: #fbf3e2; --muted: #dccdb0; --faint: #b5a588;
  --good: #7ed6a0; --bad: #e8786a; --info: #8fc9ee;
  --radius: 14px; --side-w: 300px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", "Noto Serif CJK TC", Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.5; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 3px solid var(--brass-hi); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: grid; grid-template-columns: 0 1fr; height: 100dvh; }
#app[data-side="open"][data-in-game="1"] { grid-template-columns: var(--side-w) 1fr; }
#view { grid-column: 2; grid-row: 1; position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #3a2a1e; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
#gl:focus-visible { outline: 3px solid var(--brass-hi); outline-offset: -3px; border-radius: 0; }

#modal-root { position: fixed; top: 0; left: 0; width: 0; height: 0; z-index: 100; }

/* ---------- 側欄：摘要 + 聊天室 ---------- */
#side { grid-column: 1; grid-row: 1; min-width: 0; display: none; flex-direction: column; background: linear-gradient(180deg, #4a3526, #3a2a1e); border-right: 1px solid var(--line); overflow: hidden; z-index: 30; padding-left: var(--safe-l); }
#app[data-in-game="1"] #side { display: flex; }
#app[data-side="closed"] #side { display: none; }
.icon-btn.side-close { display: none; position: absolute; top: 8px; right: 8px; z-index: 2; }
.side-backdrop { position: fixed; inset: 0; z-index: 45; background: rgba(6, 4, 2, .5); }
.side-title { font-family: var(--serif); font-size: 15px; letter-spacing: .12em; color: var(--brass-hi); padding: 14px 16px 6px; font-weight: 700; }
#summary { flex: 0 1 auto; min-height: 0; overflow-y: auto; padding-bottom: 8px; }
.scoreboard { display: grid; gap: 8px; padding: 4px 12px; }
.pl-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px; background: rgba(255, 236, 200, .1); border: 1px solid transparent; transition: border-color .2s, background .2s; }
.pl-row.turn { border-color: var(--brass); background: rgba(200, 155, 60, .13); box-shadow: 0 0 0 1px rgba(236, 199, 122, .25) inset; }
.pl-row .nm { min-width: 0; }
.pl-row .nm b { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-row .nm small { color: var(--muted); font-size: 12px; }
.pl-row .cnt { font-family: var(--serif); font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 1.6ch; text-align: right; }
.tag { display: inline-block; padding: 0 7px; margin-left: 6px; border-radius: 9px; font-size: 11px; line-height: 17px; background: var(--brass-lo); color: #fff6df; vertical-align: 1px; }
.tag.off { background: #6a4b44; } .tag.ready { background: #2f7a4f; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-right: 5px; }
.dot.off { background: #c05b4d; }
.disc-ico { width: 34px; height: 34px; border-radius: 50%; flex: none; box-shadow: 0 2px 4px rgba(0, 0, 0, .55), inset 0 -3px 5px rgba(0, 0, 0, .25); }
.disc-ico.b { background: radial-gradient(circle at 34% 28%, #6a6e79 0, #23252b 38%, #08090b 78%); }
.disc-ico.w { background: radial-gradient(circle at 34% 28%, #ffffff 0, #f0ead9 42%, #bdb49d 90%); }
.disc-ico.sm { width: 22px; height: 22px; }
.status-line { padding: 8px 16px 2px; color: var(--text); font-weight: 600; min-height: 2.4em; }
.timer-line { margin: 4px 14px; height: 7px; border-radius: 4px; background: rgba(0, 0, 0, .35); overflow: hidden; }
.timer-line i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--brass), var(--brass-hi)); transform-origin: left; }
.timer-line.low i { background: linear-gradient(90deg, #c4503f, #f08a6a); }
.side-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
.history-box { margin: 4px 12px 0; color: var(--muted); font-size: 13px; }
.history-box summary { cursor: pointer; padding: 4px 0; }
.history { list-style: none; margin: 4px 0 0; padding: 0; max-height: 128px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 3px 8px; font-variant-numeric: tabular-nums; }
.history li { display: flex; align-items: center; gap: 6px; }
.history li em { color: var(--faint); font-style: normal; margin-left: auto; }

.chatbox { flex: 1 1 0; min-height: 150px; display: flex; flex-direction: column; border-top: 1px solid var(--line); background: rgba(0, 0, 0, .16); }
.chat-list { list-style: none; margin: 0; padding: 0 12px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.chat-list li { font-size: 14px; word-break: break-word; }
.chat-list li b { color: var(--brass-hi); margin-right: 6px; font-weight: 600; }
.chat-list li.sys { color: var(--muted); font-size: 12.5px; }
.chat-list li.spec b { color: var(--info); }
.chat-quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px 0; }
.chat-quick button { border: 1px solid var(--line); background: rgba(0, 0, 0, .25); border-radius: 14px; padding: 2px 10px; font-size: 12.5px; color: var(--text); cursor: pointer; }
.chat-quick button:hover { border-color: var(--brass); }
.chat-form { display: flex; gap: 8px; padding: 8px 12px calc(10px + var(--safe-b)); }

input[type="text"] { flex: 1; min-width: 0; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #2a1d13; color: var(--text); padding: 0 12px; font: inherit; }
input[type="text"]::placeholder { color: var(--faint); }
input[type="text"]:focus { outline: none; border-color: var(--brass-hi); box-shadow: 0 0 0 3px rgba(236, 199, 122, .22); }

/* ---------- 按鈕 ---------- */
.btn { appearance: none; border: 1px solid var(--line-hi); background: linear-gradient(180deg, #8a6339, #66452a); color: #fff8e8; border-radius: 12px; min-height: 44px; padding: 0 18px; font-weight: 700; letter-spacing: .04em; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 2px 0 #120c08, 0 5px 12px rgba(0, 0, 0, .35); transition: transform .08s, filter .15s, border-color .15s; }
.btn:hover { filter: brightness(1.13); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #120c08; }
.btn.primary { background: linear-gradient(180deg, #e2b457, #b98626); color: #271a07; border-color: #f1d189; text-shadow: 0 1px 0 rgba(255, 255, 255, .25); }
.btn.danger { background: linear-gradient(180deg, #c9604f, #96382c); border-color: #f0a090; color: #fff4ef; }
.btn.ghost { background: rgba(88, 62, 38, .85); box-shadow: none; border-color: var(--line); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.big { min-height: 58px; font-size: 19px; padding: 0 28px; border-radius: 16px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; filter: none; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { position: relative; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line-hi); background: linear-gradient(180deg, #f6dd9c, #d3a64a); color: #3a2410; border-color: #fff0c4; display: inline-grid; place-items: center; cursor: pointer; backdrop-filter: blur(6px); box-shadow: 0 0 0 2px rgba(58, 36, 16, .75), 0 3px 10px rgba(0, 0, 0, .45); }
.icon-btn { color: #2b1800; background: linear-gradient(180deg, #fff3b8, #ffd24d 55%, #f0a91f); border-color: #fffbe0; box-shadow: inset 0 1px 0 #fff, inset 0 -3px 5px rgba(150, 90, 0, .3), 0 0 0 2px rgba(58, 36, 16, .8), 0 0 16px rgba(255, 214, 90, .6), 0 4px 10px rgba(0, 0, 0, .45); transition: transform .12s, filter .12s; }
.icon-btn svg, .btn svg { filter: drop-shadow(0 1px 0 rgba(255, 255, 255, .35)); stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(1px) scale(.96); }
.icon-btn:focus-visible, .lobby-pill:focus-visible { outline: 3px solid #fff3c4; outline-offset: 2px; }
.icon-btn svg { width: 24px; height: 24px; }
/* 左上角「返回遊戲大廳」膠囊（只在首頁），與其他遊戲的返回鈕同位置、同圓角膠囊造型 */
.lobby-pill { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 16px 0 10px; border-radius: 999px; text-decoration: none; font-weight: 800; font-size: 15px; letter-spacing: .04em; color: #2b1800; background: linear-gradient(180deg, #fff3b8, #ffd24d 55%, #f0a91f); border: 1px solid #fffbe0; box-shadow: inset 0 1px 0 #fff, inset 0 -3px 5px rgba(150, 90, 0, .3), 0 0 0 2px rgba(58, 36, 16, .8), 0 0 16px rgba(255, 214, 90, .6), 0 4px 10px rgba(0, 0, 0, .45); transition: transform .12s, filter .12s; }
.lobby-pill[hidden] { display: none; }
.lobby-pill:hover { filter: brightness(1.08); transform: translateY(-1px); }
.lobby-pill:active { transform: translateY(1px) scale(.97); }
.lobby-pill svg { width: 22px; height: 22px; }
@media (max-width: 380px) { .lobby-pill { padding: 0 12px 0 6px; font-size: 14px; } }
.icon-btn.small { width: 36px; height: 36px; box-shadow: none; }
.icon-btn[aria-pressed="true"] { background: #8a5a22; color: #fff3d0; }
.badge { position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #e0533f; color: #fff; font: 700 11px/18px var(--font); font-style: normal; text-align: center; }

/* ---------- 浮動介面 ---------- */
.hud-top { position: absolute; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); display: flex; align-items: center; gap: 10px; z-index: 30; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#app:not([data-in-game="1"]) #side-toggle { display: none; }
.turn-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; border-radius: 22px; border: 1px solid var(--line-hi); background: rgba(84, 58, 36, .94); backdrop-filter: blur(6px); font-weight: 700; box-shadow: 0 3px 10px rgba(0, 0, 0, .4); max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-chip.mine { border-color: var(--brass-hi); box-shadow: 0 0 0 3px rgba(236, 199, 122, .2), 0 3px 10px rgba(0, 0, 0, .4); }
.hud-bottom { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); z-index: 15; display: flex; gap: 8px; }
.hint-btn[aria-pressed="true"] { background: linear-gradient(180deg, #e2b457, #b98626); color: #271a07; }
.confirm-bar { position: absolute; left: 50%; bottom: calc(66px + var(--safe-b)); transform: translateX(-50%); z-index: 16; display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 14px; background: rgba(28, 20, 14, .94); border: 1px solid var(--brass-hi); font-weight: 600; white-space: nowrap; }
.toasts { position: absolute; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: min(92vw, 520px); }
.toast { padding: 9px 16px; border-radius: 12px; background: rgba(70, 50, 34, .97); border: 1px solid var(--line-hi); box-shadow: 0 6px 18px rgba(0, 0, 0, .5); font-weight: 600; animation: tin .22s ease-out; text-align: center; }
.toast.bad { border-color: #e8786a; } .toast.good { border-color: #7ed6a0; }
.toast.out { opacity: 0; transform: translateY(-6px); transition: .35s; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }
.boot { position: absolute; inset: 0; z-index: 90; display: grid; place-content: center; justify-items: center; gap: 16px; background: #3a2a1e; transition: opacity .4s; }
.boot.gone { opacity: 0; pointer-events: none; }
.boot-disc { width: 54px; height: 54px; border-radius: 50%; background: linear-gradient(90deg, #101114 50%, #f2ecdc 50%); animation: spin 1.1s linear infinite; box-shadow: 0 6px 16px rgba(0, 0, 0, .6); }
@keyframes spin { to { transform: rotateY(360deg); } }

/* 棋盤佔滿高度（左右有空位）時，提示鈕與確認列放到左下角，不蓋住棋盤 */
#view[data-fit="side"] .hud-bottom { left: calc(14px + var(--safe-l)); transform: none; }
#view[data-fit="side"] .confirm-bar { left: calc(14px + var(--safe-l)); transform: none; bottom: calc(64px + var(--safe-b)); white-space: normal; max-width: 210px; flex-wrap: wrap; }

/* ---------- 畫面卡片 ---------- */
.screens { position: absolute; inset: 0; z-index: 25; display: grid; place-items: center; padding: calc(64px + var(--safe-t)) 16px calc(16px + var(--safe-b)); overflow-y: auto; pointer-events: none; background: radial-gradient(ellipse at center, rgba(10, 7, 4, .15), rgba(10, 7, 4, .66)); }
.screens:not(:has(.screen.on)) { display: none; }
.screen { display: none; pointer-events: auto; }
.screen.on { display: block; animation: cin .28s ease-out; }
@keyframes cin { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.card { width: min(560px, 100%); max-height: 100%; overflow-y: auto; border-radius: 22px; padding: 26px 26px 22px; background: linear-gradient(180deg, rgba(92, 66, 44, .97), rgba(66, 47, 32, .98)); border: 1px solid var(--line-hi); box-shadow: 0 0 0 5px rgba(0, 0, 0, .28), 0 24px 60px rgba(0, 0, 0, .65), inset 0 1px 0 rgba(255, 230, 170, .12); }
.card.wide { width: min(860px, 100%); }
.card h1 { font-family: var(--serif); font-size: clamp(34px, 7vw, 52px); letter-spacing: .14em; text-align: center; color: var(--brass-hi); text-shadow: 0 3px 0 rgba(0, 0, 0, .4); font-weight: 900; }
.card h1 span { display: inline-block; width: .8em; height: .8em; border-radius: 50%; vertical-align: -.05em; margin: 0 .1em; }
.card h1 .b { background: radial-gradient(circle at 34% 28%, #6a6e79, #08090b 75%); } .card h1 .w { background: radial-gradient(circle at 34% 28%, #fff, #bdb49d 90%); }
.card h2.title { font-family: var(--serif); font-size: 26px; letter-spacing: .1em; color: var(--brass-hi); margin-bottom: 4px; }
.sub { color: var(--muted); text-align: center; margin: 6px 0 18px; }
.menu { display: grid; gap: 12px; margin-top: 6px; }
.menu .btn { width: 100%; }
.foot-note { margin-top: 14px; text-align: center; color: var(--faint); font-size: 13px; }
.sec-title { font-weight: 700; color: var(--brass-hi); letter-spacing: .08em; margin: 18px 0 8px; font-size: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head .btn { margin-left: auto; }

.levels { display: grid; gap: 8px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn { appearance: none; flex: 1 1 auto; min-height: 42px; padding: 6px 14px; border-radius: 11px; border: 1px solid var(--line); background: rgba(88, 62, 38, .8); cursor: pointer; font-weight: 600; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; }
.seg-btn small { color: var(--muted); font-weight: 400; font-size: 12px; }
.seg-btn:hover { border-color: var(--brass); }
.seg-btn.on { background: linear-gradient(180deg, #e2b457, #b98626); color: #261a07; border-color: #f1d189; }
.seg-btn.on small { color: #4a3510; }
.seg.levels-seg { display: grid; grid-template-columns: 1fr; }
.seg.levels-seg .seg-btn { flex-direction: row; justify-content: flex-start; gap: 12px; text-align: left; padding: 8px 14px; }
.seg.levels-seg .seg-btn b { min-width: 3.6em; font-size: 17px; }
.seg.levels-seg .seg-btn small { font-size: 13px; }
.seg-btn .stars { letter-spacing: 2px; color: var(--brass); margin-left: auto; font-size: 13px; }
.seg-btn.on .stars { color: #4a3510; }

.row { display: flex; align-items: center; gap: 14px; padding: 10px 2px; border-bottom: 1px solid rgba(206, 160, 70, .13); min-height: 52px; }
.row:last-child { border-bottom: none; }
.row-label { flex: 1; font-weight: 600; }
.row-label small { display: block; color: var(--muted); font-weight: 400; font-size: 12.5px; }
.sw { appearance: none; width: 54px; height: 30px; border-radius: 15px; border: 1px solid var(--line-hi); background: #3a2a1d; position: relative; cursor: pointer; flex: none; transition: background .18s; padding: 0; }
.sw-knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #bfb59d); box-shadow: 0 2px 4px rgba(0, 0, 0, .5); transition: transform .18s; }
.sw[aria-checked="true"] { background: linear-gradient(180deg, #d6a844, #a87818); }
.sw[aria-checked="true"] .sw-knob { transform: translateX(24px); }
.slider-row { gap: 12px; }
.slider-row .row-label { flex: 0 0 5.5em; }
.sl { position: relative; flex: 1; height: 34px; cursor: pointer; touch-action: none; display: flex; align-items: center; }
.sl-rail { position: absolute; left: 0; right: 0; height: 8px; border-radius: 4px; background: #3a2a1d; border: 1px solid var(--line); overflow: hidden; }
.sl-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--brass-lo), var(--brass-hi)); }
.sl-knob { position: absolute; top: 50%; width: 22px; height: 22px; border-radius: 50%; transform: translate(-50%, -50%); background: radial-gradient(circle at 35% 30%, #fff3d4, #c89b3c); box-shadow: 0 2px 5px rgba(0, 0, 0, .55); }
.sl-val { width: 3.2em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 大廳 */
.lobby-grid { display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px; }
.lobby-grid > section { min-width: 0; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-weight: 600; color: var(--muted); font-size: 13px; }
.field .inline { display: flex; gap: 8px; }
.room-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 40vh; overflow-y: auto; }
.room-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: rgba(255, 236, 200, .1); border: 1px solid var(--line); }
.room-item .code { font-family: var(--serif); font-size: 22px; font-weight: 800; letter-spacing: .12em; color: var(--brass-hi); }
.room-item .meta { min-width: 0; font-size: 13px; color: var(--muted); }
.room-item .meta b { display: block; color: var(--text); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item .acts { display: flex; gap: 6px; }
.empty { text-align: center; color: var(--faint); padding: 22px 8px; border: 1px dashed var(--line); border-radius: 12px; }
.net-note { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; background: rgba(255, 236, 200, .1); border: 1px solid var(--line); color: var(--muted); font-size: 13.5px; margin-bottom: 12px; }
.net-note.bad { border-color: #b8564a; color: #f1b7ad; }
.invite-card { padding: 14px; border-radius: 14px; border: 1px solid var(--brass-hi); background: rgba(200, 155, 60, .1); margin-bottom: 14px; }
.invite-card h3 { font-family: var(--serif); color: var(--brass-hi); margin-bottom: 6px; }

/* 房間面板 */
.room-panel { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); z-index: 18; width: min(680px, calc(100% - 20px)); border-radius: 18px; padding: 12px 14px; background: rgba(72, 52, 36, .96); border: 1px solid var(--line-hi); box-shadow: 0 16px 40px rgba(0, 0, 0, .6); max-height: 62%; overflow-y: auto; }
.room-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.room-code { font-family: var(--serif); font-weight: 800; letter-spacing: .16em; font-size: 24px; color: var(--brass-hi); }
.seat-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.seat { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px; background: rgba(255, 236, 200, .1); border: 1px dashed var(--line); }
.seat.taken { border-style: solid; }
.seat b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat small { color: var(--muted); }
.room-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.room-more { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 4px; }
.room-more summary { cursor: pointer; padding: 8px 0; color: var(--brass-hi); font-weight: 600; }
.spec-line { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* 結算層：疊在棋盤上方，不換頁 */
.result-layer { position: absolute; inset: 0; z-index: 40; display: grid; justify-items: center; align-items: start; overflow-y: auto; padding: 16px; background: radial-gradient(ellipse at center, rgba(8, 5, 3, .42), rgba(8, 5, 3, .78)); animation: cin .35s ease-out; }
.result-card { margin: auto; width: min(460px, 100%); text-align: center; border-radius: 24px; padding: 26px 22px 20px; background: linear-gradient(180deg, rgba(96, 69, 46, .98), rgba(68, 48, 33, .98)); border: 1px solid var(--brass-hi); box-shadow: 0 0 0 6px rgba(0, 0, 0, .3), 0 28px 70px rgba(0, 0, 0, .7); }
.result-card h2 { font-family: var(--serif); font-size: 38px; letter-spacing: .12em; color: var(--brass-hi); }
.result-card.lose h2 { color: #d9a99e; } .result-card.draw h2 { color: #cfd8e6; }
.result-card .why { color: var(--muted); margin-top: 4px; min-height: 1.5em; }
.final { display: flex; justify-content: center; align-items: center; gap: 22px; margin: 18px 0; }
.final .side { display: grid; justify-items: center; gap: 6px; }
.final .side .disc-ico { width: 52px; height: 52px; }
.final .side b { font-family: var(--serif); font-size: 40px; line-height: 1; }
.final .side small { color: var(--muted); max-width: 8em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.final .win .disc-ico { box-shadow: 0 0 0 4px rgba(236, 199, 122, .6), 0 4px 10px rgba(0, 0, 0, .6); }
.final .vs { color: var(--faint); font-family: var(--serif); }
.result-actions { display: grid; gap: 10px; margin-top: 6px; }
.result-actions .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-note { color: var(--faint); font-size: 13px; margin-top: 8px; min-height: 1.2em; }

/* 彈窗 */
.veil { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: calc(14px + var(--safe-t)) 14px calc(14px + var(--safe-b)); background: rgba(6, 4, 2, .7); opacity: 0; transition: opacity .16s; }
.veil.in { opacity: 1; }
.modal { width: min(520px, 100%); max-height: 100%; display: flex; flex-direction: column; border-radius: 20px; background: linear-gradient(180deg, #644730, #4a3424); border: 1px solid var(--line-hi); box-shadow: 0 28px 70px rgba(0, 0, 0, .75); }
.modal.small { width: min(400px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 6px 20px; }
.modal-head h2 { flex: 1; font-family: var(--serif); font-size: 21px; letter-spacing: .1em; color: var(--brass-hi); }
.modal-body { padding: 4px 20px 12px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 10px 20px 18px; flex-wrap: wrap; }
.modal-text { color: var(--text); padding: 6px 0 4px; }
.how h3 { color: var(--brass-hi); margin: 14px 0 4px; font-size: 15px; letter-spacing: .08em; }
.how p { color: var(--text); margin: 4px 0; font-size: 15px; }
.how p.muted { color: var(--muted); }

/* ---------- 窄螢幕：側欄變左側抽屜 ---------- */
@media (max-width: 899px) {
  #app[data-side="open"][data-in-game="1"] { grid-template-columns: 0 1fr; }
  #side { position: absolute; left: 0; top: 0; bottom: 0; width: min(88vw, 340px); box-shadow: 14px 0 36px rgba(0, 0, 0, .55); z-index: 50; }
  #app[data-in-game="1"] #side { display: flex; }
  #app[data-side="closed"] #side { display: none; }
  .icon-btn.side-close { display: inline-grid; }
  .lobby-grid { grid-template-columns: 1fr; }
  .card { padding: 20px 16px 16px; }
  .seat-list { gap: 6px; }
  .seat { grid-template-columns: auto 1fr; gap: 8px; padding: 6px 8px; }
  .seat .disc-ico { width: 26px; height: 26px; }
  .room-panel { padding: 10px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .screens { padding-top: calc(56px + var(--safe-t)); }
  .card { padding: 14px 18px; }
  .card h1 { font-size: 28px; }
  .menu { grid-template-columns: repeat(3, 1fr); } .menu .btn.big { min-height: 48px; font-size: 16px; padding: 0 10px; }
  .sub { margin: 2px 0 10px; }
  .seg.levels-seg { grid-template-columns: 1fr 1fr; gap: 6px 8px; }
  .seg.levels-seg .seg-btn { padding: 5px 10px; min-height: 40px; } .seg.levels-seg .seg-btn small { display: none; }
  .room-panel { max-height: 80%; }
  .result-card { padding: 14px 18px; } .final { margin: 8px 0; } .result-card h2 { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
body.reduce-motion * { animation-duration: .01ms !important; transition-duration: .01ms !important; }

.lv { display: flex; align-items: baseline; gap: 12px; width: 100%; }
.lv small { color: inherit; opacity: .78; }
.lv .stars { margin-left: auto; }

/* ---------- 自訂卷軸（原生的全部隱藏，由 scrollbar.js 畫滑塊） ---------- */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { display: none; width: 0; height: 0; }
#sb-layer { position: fixed; inset: 0; z-index: 300; pointer-events: none; }
.sb-track { position: fixed; width: 8px; margin-left: 0; border-radius: 4px; display: none; pointer-events: auto; background: rgba(0, 0, 0, .12); opacity: .75; transition: opacity .15s; touch-action: none; }
.sb-track:hover { opacity: 1; }
.sb-thumb { width: 100%; border-radius: 4px; background: linear-gradient(90deg, #f0cd82, #c89b3c); box-shadow: 0 0 0 1px rgba(60, 40, 10, .45); cursor: grab; }
.sb-thumb.drag { cursor: grabbing; filter: brightness(1.15); }
.sb-host { overscroll-behavior: contain; }

/* 浮在木桌上的控制要夠亮：奶油黃銅底、深色字 */
.turn-chip { background: linear-gradient(180deg, #f6e4b4, #e0bd6c); color: #3a2410; border-color: #fff0c4; box-shadow: 0 0 0 2px rgba(58, 36, 16, .7), 0 3px 10px rgba(0, 0, 0, .45); }
.hud-bottom .btn, .hud-bottom .btn.ghost { background: linear-gradient(180deg, #f6dd9c, #d3a64a); color: #3a2410; border-color: #fff0c4; box-shadow: 0 0 0 2px rgba(58, 36, 16, .7), 0 3px 10px rgba(0, 0, 0, .45); text-shadow: none; }

/* 設定：選項列在窄螢幕改成「標題＋說明一整列、選項按鈕在下一列」，避免標題被擠成直排 */
@media (max-width: 560px) {
  .row:has(.seg) { flex-wrap: wrap; row-gap: 8px; }
  .row:has(.seg) .row-label { flex: 1 1 100%; }
  .row:has(.seg) .seg { flex: 1 1 100%; }
}
/* 棋盤下方的投降鈕維持紅色（上面的亮黃規則會把它蓋成黃色） */
.hud-bottom .btn.danger { background: linear-gradient(180deg, #e0705f, #b04232); color: #fff8f4; border-color: #ffc2b6; text-shadow: 0 1px 0 rgba(0, 0, 0, .25); }

/* 彈窗在矮螢幕要被限制在畫面內，內容區才會出現捲動（否則彈窗會長到畫面外、按鈕按不到） */
.veil { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
.veil > .modal { max-height: 100%; min-height: 0; justify-self: center; align-self: center; width: min(520px, 100%); }
.veil > .modal.small { width: min(400px, 100%); }
.modal-body { flex: 1 1 auto; min-height: 0; }

/* ---------- 語言切換鈕（放在設定鈕旁，造型同 .icon-btn）---------- */
.lang-toggle { position: relative; flex: none; width: 44px; height: 44px; min-width: 44px; padding: 0; border-radius: 50%; display: inline-grid; place-items: center; cursor: pointer; font: 800 15px/1 var(--font); letter-spacing: 0; color: #2b1800; background: linear-gradient(180deg, #fff3b8, #ffd24d 55%, #f0a91f); border: 1px solid #fffbe0; box-shadow: inset 0 1px 0 #fff, inset 0 -3px 5px rgba(150, 90, 0, .3), 0 0 0 2px rgba(58, 36, 16, .8), 0 0 16px rgba(255, 214, 90, .6), 0 4px 10px rgba(0, 0, 0, .45); transition: transform .12s, filter .12s; -webkit-appearance: none; appearance: none; }
.lang-toggle:hover { filter: brightness(1.08); transform: translateY(-1px); }
.lang-toggle:active { transform: translateY(1px) scale(.96); }
.lang-toggle:focus-visible { outline: 3px solid #fff3c4; outline-offset: 2px; }
.hud-right { flex: none; }
.turn-chip { flex: 0 1 auto; min-width: 0; }

/* Inputs can shrink before English action labels wrap. */
.inline { min-width: 0; flex-wrap: wrap; }
.inline input { min-width: 0; flex: 1 1 140px; }
.inline .btn { flex-shrink: 0; }
