/* ========== 楚河漢界 · 樣式 ========== */
:root {
  --ink: #14100d;
  --ink2: #1d1814;
  --ink3: #2a221c;
  --line: rgba(232, 196, 120, .16);
  --gold: #e3b562;
  --gold2: #f6d995;
  --red: #c9342b;
  --red2: #ff5a48;
  --jade: #4fbf8f;
  --text: #f3e8d6;
  --muted: #a8977f;
  --wood1: #f0cf95;
  --wood2: #d9a75f;
  --wood-line: #6b3f1a;
  --serif: "Noto Serif TC", "LXGW WenKai TC", "Songti TC", "PMingLiU", serif;
  --kai: "LXGW WenKai TC", "Noto Serif TC", "Kaiti TC", "DFKai-SB", serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #3a2516 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 110%, #2a1712 0%, transparent 60%),
    var(--ink);
  color: var(--text);
  font-family: var(--kai);
  overflow-x: hidden;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

/* 背景光暈 */
.bg-orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bg-orbs i { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .32; animation: orb 22s ease-in-out infinite alternate; }
.bg-orbs i:nth-child(1) { width: 380px; height: 380px; background: #b5422c; left: -120px; top: 20%; }
.bg-orbs i:nth-child(2) { width: 320px; height: 320px; background: #b88632; right: -100px; top: 55%; animation-delay: -8s; }
.bg-orbs i:nth-child(3) { width: 260px; height: 260px; background: #6b2f22; left: 40%; top: -120px; animation-delay: -14s; }
@keyframes orb { to { transform: translate(60px, -40px) scale(1.2); } }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }
#vignette { position: fixed; inset: 0; pointer-events: none; z-index: 55; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(220, 30, 20, .55) 100%); }
#vignette.flash { animation: vig 1.1s ease-out; }
@keyframes vig { 0% { opacity: 0; } 12% { opacity: 1; } 100% { opacity: 0; } }

.view { position: relative; z-index: 1; }

/* ========== 共用元件 ========== */
.card {
  background: linear-gradient(180deg, rgba(48, 36, 27, .82), rgba(29, 23, 19, .9));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 230, 180, .06);
  backdrop-filter: blur(6px);
}
.card h2 { margin: 0 0 14px; font-size: 20px; display: flex; align-items: center; gap: 10px; font-family: var(--serif); }
.card h2 b {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 17px;
  color: var(--red); background: radial-gradient(circle at 35% 30%, #fff6e2, #eed29e 70%, #c99a57);
  box-shadow: 0 2px 0 #9a6b33, 0 4px 10px rgba(0, 0, 0, .4);
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); letter-spacing: .05em; }
input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, .28); outline: none; font-size: 16px; transition: border-color .2s, box-shadow .2s;
}
input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(227, 181, 98, .18); }
input::placeholder { color: #7a6a57; }

.btn {
  border: 1px solid var(--line); background: rgba(255, 255, 255, .05); border-radius: 12px;
  padding: 11px 18px; font-size: 16px; transition: transform .12s, filter .2s, background .2s; white-space: nowrap;
}
.btn:active { transform: scale(.96); }
.btn.primary {
  border: 0; color: #2a1405; font-weight: 700;
  background: linear-gradient(180deg, var(--gold2), var(--gold) 55%, #b9873a);
  box-shadow: 0 4px 0 #8a5e22, 0 8px 18px rgba(227, 181, 98, .25);
}
.btn.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a5e22; }
.btn.red { background: linear-gradient(180deg, #e8574a, var(--red)); color: #fff; border: 0; box-shadow: 0 4px 0 #7d1c16; }
.btn.big { width: 100%; padding: 14px; font-size: 18px; letter-spacing: .1em; }
.btn.sm { padding: 6px 12px; font-size: 14px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; pointer-events: none; }

.seg { display: flex; background: rgba(0, 0, 0, .3); border-radius: 12px; padding: 4px; gap: 4px; border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 9px; font-size: 15px; color: var(--muted); transition: all .2s; display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button.on { background: linear-gradient(180deg, #4b3726, #3a2a1d); color: var(--gold2); box-shadow: inset 0 1px 0 rgba(255, 220, 160, .15), 0 2px 6px rgba(0, 0, 0, .4); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.red { background: var(--red2); box-shadow: 0 0 8px var(--red2); }
.dot.blk { background: #222; border: 1px solid #888; }

/* ========== 大廳 ========== */
#lobby { max-width: 980px; margin: 0 auto; padding: calc(18px + var(--safe-t)) 14px calc(30px + var(--safe-b)); }
.hero { text-align: center; padding: 18px 0 22px; position: relative; }
.hero-pieces { display: flex; justify-content: center; gap: 18px; margin-bottom: 10px; }
.hp {
  width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; font: 900 30px var(--serif);
  background: radial-gradient(circle at 35% 30%, #fff7e4, #f1d7a3 60%, #cf9d5c);
  box-shadow: 0 4px 0 #8f6332, 0 10px 22px rgba(0, 0, 0, .5); position: relative;
  animation: bob 3.4s ease-in-out infinite;
}
.hp::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; border: 2px solid currentColor; opacity: .6; }
.hp.red { color: var(--red); }
.hp.blk { color: #1c1c1c; animation-delay: -1.7s; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }
.brand {
  margin: 0; font: 900 clamp(44px, 12vw, 76px)/1.1 var(--serif); letter-spacing: .08em;
  filter: drop-shadow(0 4px 14px rgba(227, 181, 98, .3));
}
.brand span {
  display: inline-block; animation: rise .8s cubic-bezier(.2, 1.4, .4, 1) both;
  background: linear-gradient(180deg, #fff1cc 10%, var(--gold) 55%, #9a6a2b);
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
}
.brand span:nth-child(2) { animation-delay: .08s; }
.brand span:nth-child(4) { animation-delay: .16s; }
.brand span:nth-child(5) { animation-delay: .24s; }
.brand i { font-style: normal; color: var(--red); -webkit-text-fill-color: var(--red); margin: 0 .1em; }
@keyframes rise { from { opacity: 0; transform: translateY(30px) scale(.6); filter: blur(6px); } }
.tagline { color: var(--muted); margin: 8px 0 0; letter-spacing: .12em; font-size: 14px; }

.me-card { margin-bottom: 14px; padding: 14px 18px; }
.me-card .field { margin: 0; }
.lobby-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .lobby-grid { grid-template-columns: 1fr 1.15fr; align-items: start; } }

.join-row { display: flex; gap: 10px; margin-bottom: 18px; }
.code-input { font: 700 22px/1 ui-monospace, Menlo, monospace; letter-spacing: .35em; text-align: center; }
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.list-head h3 { margin: 0; font-size: 15px; color: var(--muted); font-weight: 400; }
.room-list { display: flex; flex-direction: column; gap: 10px; max-height: 52vh; overflow: auto; padding-right: 2px; }
.room-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; text-align: left; width: 100%;
  background: rgba(0, 0, 0, .22); border: 1px solid var(--line); transition: transform .15s, border-color .2s, background .2s;
  animation: slidein .35s ease both;
}
.room-item:hover { border-color: rgba(227, 181, 98, .45); background: rgba(227, 181, 98, .06); }
.room-item:active { transform: scale(.98); }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } }
.room-item .ri-main { flex: 1; min-width: 0; }
.room-item .ri-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item .ri-sub { font-size: 13px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item .ri-sub .r { color: #ff8a7a; }
.tag { font-size: 12px; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.tag.waiting { background: rgba(79, 191, 143, .15); color: var(--jade); border: 1px solid rgba(79, 191, 143, .35); }
.tag.playing { background: rgba(255, 90, 72, .12); color: #ff8b7d; border: 1px solid rgba(255, 90, 72, .35); }
.tag.over { background: rgba(255, 255, 255, .06); color: var(--muted); border: 1px solid var(--line); }
.empty { color: var(--muted); text-align: center; padding: 26px 0; font-size: 14px; }
.foot { text-align: center; color: #6e604f; font-size: 12px; margin-top: 24px; letter-spacing: .2em; }

/* ========== 房間 ========== */
#room { height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-t); }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; flex: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .25); font-size: 20px; display: grid; place-items: center; flex: none; }
.icon-btn:active { transform: scale(.92); }
#backBtn { font-size: 28px; line-height: 1; padding-bottom: 4px; }
.room-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
#roomName { font-size: 15px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-chip { border: 1px dashed rgba(227, 181, 98, .5); background: rgba(227, 181, 98, .08); border-radius: 99px; padding: 2px 12px; font-size: 13px; color: var(--gold2); }
.code-chip b { font-family: ui-monospace, Menlo, monospace; letter-spacing: .12em; font-size: 15px; }
.code-chip small { opacity: .7; margin-left: 4px; }
.net { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.net.ok { background: var(--jade); box-shadow: 0 0 8px var(--jade); }
.net.bad { background: #e0a030; box-shadow: 0 0 8px #e0a030; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.stage { flex: 1; min-height: 0; display: flex; justify-content: center; gap: 18px; padding: 0 8px calc(6px + var(--safe-b)); }
.play-col {
  --bw: min(calc(100vw - 28px), calc((100dvh - 268px - var(--safe-t) - var(--safe-b)) * .9), 620px);
  width: var(--bw); display: flex; flex-direction: column; gap: 8px; min-height: 0;
}

/* 玩家卡 */
.pcard {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 14px; flex: none;
  background: rgba(0, 0, 0, .25); border: 1px solid var(--line); position: relative; transition: border-color .3s, box-shadow .3s;
  min-height: 54px;
}
.pcard.turn { border-color: rgba(227, 181, 98, .7); box-shadow: 0 0 0 1px rgba(227, 181, 98, .3), 0 0 22px rgba(227, 181, 98, .18); }
.pcard .av {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; font: 900 20px var(--serif);
  background: radial-gradient(circle at 35% 30%, #fff7e4, #f1d7a3 60%, #cf9d5c); box-shadow: 0 2px 0 #8f6332; position: relative;
}
.pcard .av.r { color: var(--red); }
.pcard .av.b { color: #1d1d1d; }
.pcard .av .on { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; background: #6b6b6b; border: 2px solid var(--ink2); }
.pcard .av .on.y { background: var(--jade); }
.pcard .who { flex: 1; min-width: 0; }
.pcard .nm { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.pcard .nm small { color: var(--muted); font-size: 12px; flex: none; }
.pcard .caps { display: flex; gap: 1px; margin-top: 2px; min-height: 18px; flex-wrap: wrap; }
.pcard .caps i {
  width: 17px; height: 17px; border-radius: 50%; font: normal 900 11px/17px var(--serif); text-align: center;
  background: radial-gradient(circle at 35% 30%, #fff3dc, #dcbd86); animation: pop .4s cubic-bezier(.3, 1.8, .5, 1);
}
.pcard .caps i.r { color: var(--red); }
.pcard .caps i.b { color: #222; }
.pcard .think { font-size: 12px; color: var(--gold); display: none; }
.pcard.turn .think { display: inline; }
.pcard .think::after { content: "…"; animation: dots 1.2s steps(4) infinite; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }
.clock {
  font: 700 20px/1 ui-monospace, Menlo, monospace; padding: 7px 10px; border-radius: 10px; background: rgba(0, 0, 0, .35);
  min-width: 74px; text-align: center; color: var(--muted); flex: none; transition: color .2s, background .2s;
}
.pcard.turn .clock { color: var(--gold2); background: rgba(227, 181, 98, .12); }
.clock.low { color: #fff !important; background: var(--red) !important; animation: lowpulse 1s infinite; }
@keyframes lowpulse { 50% { box-shadow: 0 0 18px var(--red2); } }
.pcard .sit { margin-left: auto; }
.bubble {
  position: absolute; left: 54px; top: -6px; transform: translateY(-100%); background: #fff4dd; color: #2a1a0a; padding: 6px 12px;
  border-radius: 14px; font-size: 14px; max-width: 70%; z-index: 20; box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
  animation: bubble 3.6s ease forwards; pointer-events: none; word-break: break-word;
}
.bubble::after { content: ""; position: absolute; left: 14px; bottom: -6px; border: 6px solid transparent; border-top-color: #fff4dd; border-bottom: 0; }
.pcard.me .bubble { top: auto; bottom: -6px; transform: translateY(100%); }
.pcard.me .bubble::after { bottom: auto; top: -6px; border-top: 0; border-bottom: 6px solid #fff4dd; }
@keyframes bubble { 0% { opacity: 0; scale: .7; } 8% { opacity: 1; scale: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }

/* 棋盤 */
.board-wrap { position: relative; width: var(--bw); flex: none; }
.board-wrap.shake { animation: shake .45s cubic-bezier(.36, .07, .19, .97); }
.board-wrap.shake2 { animation: shake2 .6s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake { 20%, 60% { transform: translate(-4px, 2px); } 40%, 80% { transform: translate(4px, -2px); } }
@keyframes shake2 { 10%, 50%, 90% { transform: translate(-8px, 3px) rotate(-.4deg); } 30%, 70% { transform: translate(8px, -3px) rotate(.4deg); } }
.board {
  position: relative; width: 100%; aspect-ratio: 9 / 10; border-radius: 14px; container-type: inline-size; user-select: none;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 245, 210, .45), transparent 60%),
    repeating-linear-gradient(92deg, rgba(120, 70, 20, .07) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(88deg, rgba(90, 50, 10, .06) 0 1px, transparent 1px 23px),
    linear-gradient(160deg, var(--wood1), var(--wood2));
  box-shadow: 0 0 0 6px #5a3214, 0 0 0 8px #2b170a, 0 0 0 9px rgba(227, 181, 98, .4), 0 24px 50px rgba(0, 0, 0, .65), inset 0 0 40px rgba(110, 60, 15, .35);
  touch-action: manipulation; cursor: pointer;
}
#boardSvg, .layer { position: absolute; inset: 0; }
#boardSvg svg { width: 100%; height: 100%; display: block; }
.layer { pointer-events: none; }

/* 棋子 */
.pc {
  position: absolute; width: 10.6%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%;
  display: grid; place-items: center; font: 900 6.2cqw/1 var(--serif);
  background: radial-gradient(circle at 34% 28%, #fffaf0 0%, #f6e2b8 35%, #e6c487 70%, #c99a58 100%);
  box-shadow: 0 .55cqw 0 #8b5d2c, 0 .9cqw 1.6cqw rgba(0, 0, 0, .45), inset 0 -.3cqw .6cqw rgba(120, 70, 20, .3);
  transition: left .32s cubic-bezier(.3, .9, .35, 1.05), top .32s cubic-bezier(.3, .9, .35, 1.05), transform .2s, box-shadow .2s;
  z-index: 2; will-change: left, top;
}
.pc::before { content: ""; position: absolute; inset: 9%; border-radius: 50%; border: .35cqw solid currentColor; opacity: .55; }
.pc::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; background: linear-gradient(160deg, rgba(255, 255, 255, .45), transparent 40%); }
.pc.r { color: #c22a20; text-shadow: 0 1px 0 rgba(255, 255, 255, .5); }
.pc.b { color: #161616; text-shadow: 0 1px 0 rgba(255, 255, 255, .45); }
.pc.sel { transform: translate(-50%, -62%) scale(1.12); z-index: 5; box-shadow: 0 1.6cqw 0 #8b5d2c, 0 3cqw 3cqw rgba(0, 0, 0, .5), 0 0 0 .5cqw var(--gold2), 0 0 3cqw var(--gold); animation: selpulse 1.2s ease-in-out infinite; }
@keyframes selpulse { 50% { box-shadow: 0 1.6cqw 0 #8b5d2c, 0 3cqw 3cqw rgba(0, 0, 0, .5), 0 0 0 .5cqw var(--gold2), 0 0 5cqw var(--gold2); } }
.pc.moving { z-index: 6; transform: translate(-50%, -60%) scale(1.18); box-shadow: 0 2.2cqw 0 #8b5d2c, 0 4cqw 4cqw rgba(0, 0, 0, .45); }
.pc.land { animation: land .32s ease-out; }
@keyframes land { 0% { transform: translate(-50%, -50%) scale(1.16); } 50% { transform: translate(-50%, -50%) scale(.94); } 100% { transform: translate(-50%, -50%) scale(1); } }
.pc.checked { animation: kingdanger .9s ease-in-out infinite; }
@keyframes kingdanger { 50% { box-shadow: 0 .55cqw 0 #8b5d2c, 0 0 0 .6cqw var(--red2), 0 0 5cqw var(--red2); } }
.pc.dying { transition: transform .5s cubic-bezier(.5, -0.4, .7, .4), opacity .5s; transform: translate(-50%, -50%) scale(1.5) rotate(40deg); opacity: 0; z-index: 7; }
.pc.nope { animation: nope .35s; }
@keyframes nope { 25% { margin-left: -1cqw; } 75% { margin-left: 1cqw; } }
.pc.enter { animation: enter .5s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes enter { from { opacity: 0; transform: translate(-50%, -50%) scale(.3); } }

/* 標記 */
.mk { position: absolute; transform: translate(-50%, -50%); }
.mk.hint { width: 3.4%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, #3cdc9a 0%, #1f9e69 60%, transparent 70%); box-shadow: 0 0 2cqw rgba(60, 220, 154, .9); animation: hint 1.1s ease-in-out infinite; }
@keyframes hint { 50% { transform: translate(-50%, -50%) scale(1.35); } }
.mk.cap { width: 12.4%; aspect-ratio: 1; border-radius: 50%; border: .6cqw solid var(--red2); box-shadow: 0 0 3cqw var(--red2), inset 0 0 2cqw var(--red2); animation: capring 1s ease-in-out infinite; z-index: 3; }
@keyframes capring { 50% { transform: translate(-50%, -50%) scale(1.08); opacity: .7; } }
.mk.from, .mk.to { width: 11.6%; aspect-ratio: 1; }
.mk.from::before, .mk.to::before {
  content: ""; position: absolute; inset: 0;
  --c: rgba(40, 110, 220, .9);
  background:
    linear-gradient(var(--c), var(--c)) top left / 26% .6cqw no-repeat, linear-gradient(var(--c), var(--c)) top left / .6cqw 26% no-repeat,
    linear-gradient(var(--c), var(--c)) top right / 26% .6cqw no-repeat, linear-gradient(var(--c), var(--c)) top right / .6cqw 26% no-repeat,
    linear-gradient(var(--c), var(--c)) bottom left / 26% .6cqw no-repeat, linear-gradient(var(--c), var(--c)) bottom left / .6cqw 26% no-repeat,
    linear-gradient(var(--c), var(--c)) bottom right / 26% .6cqw no-repeat, linear-gradient(var(--c), var(--c)) bottom right / .6cqw 26% no-repeat;
}
.mk.from::before { --c: rgba(40, 110, 220, .5); }
.mk.from::after { content: ""; position: absolute; inset: 38%; border-radius: 50%; background: rgba(40, 110, 220, .35); }
.mk.ring { width: 11%; aspect-ratio: 1; border-radius: 50%; border: .8cqw solid var(--gold2); animation: ringout .6s ease-out forwards; z-index: 1; }
@keyframes ringout { from { opacity: .9; transform: translate(-50%, -50%) scale(.6); } to { opacity: 0; transform: translate(-50%, -50%) scale(2.1); } }

.floaty { position: absolute; font-size: 9cqw; animation: floaty 2.2s ease-out forwards; z-index: 9; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .4)); }
@keyframes floaty { 0% { opacity: 0; transform: translate(-50%, 0) scale(.3); } 15% { opacity: 1; transform: translate(-50%, -20%) scale(1.3); } 100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), -260%) scale(1) rotate(var(--rot)); } }

.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20; text-align: center;
  background: rgba(20, 14, 10, .88); border: 1px solid rgba(227, 181, 98, .45); border-radius: 18px; padding: 18px 22px; width: min(86%, 360px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .6); backdrop-filter: blur(4px); animation: popin .35s cubic-bezier(.2, 1.5, .4, 1);
}
.banner h3 { margin: 0 0 6px; font: 900 22px var(--serif); color: var(--gold2); }
.banner p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.banner .code { font: 700 34px/1.2 ui-monospace, Menlo, monospace; letter-spacing: .2em; color: var(--gold2); margin: 4px 0 12px; }
.banner .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
@keyframes popin { from { opacity: 0; transform: translate(-50%, -50%) scale(.8); } }
@keyframes pop { from { transform: scale(0); } }

/* 動作列 */
.actions { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; flex: none; }
.act {
  position: relative; border: 1px solid var(--line); background: rgba(0, 0, 0, .25); border-radius: 12px; padding: 6px 0 5px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; transition: transform .12s, background .2s;
}
.act i { font: normal 900 18px/1.2 var(--serif); color: var(--gold); }
.act span { font-size: 11px; color: var(--muted); }
.act:active { transform: scale(.92); background: rgba(227, 181, 98, .12); }
.act:disabled { opacity: .35; pointer-events: none; }
.act.pending i { animation: blink 1s infinite; }
.badge { position: absolute; top: -5px; right: -3px; background: var(--red); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; animation: pop .3s cubic-bezier(.3, 1.8, .5, 1); }

.emote-pop {
  position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); z-index: 40; display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 6px; padding: 10px; background: rgba(30, 22, 16, .96); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 16px 40px rgba(0, 0, 0, .6);
  animation: emin .25s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes emin { from { opacity: 0; transform: translate(-50%, 20px) scale(.9); } }
.emote-pop button { font-size: 30px; border: 0; background: transparent; padding: 6px 10px; border-radius: 12px; transition: transform .15s; }
.emote-pop button:active { transform: scale(1.3); }

/* 側欄：聊天 / 棋譜 */
.side {
  width: 330px; display: flex; flex-direction: column; background: rgba(20, 15, 12, .82); border: 1px solid var(--line); border-radius: 18px;
  overflow: hidden; min-height: 0; max-height: calc(100dvh - 76px);
}
.side-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.side-tabs button { flex: 1; border: 0; background: transparent; padding: 12px; color: var(--muted); font-size: 15px; position: relative; }
.side-tabs button.on { color: var(--gold2); }
.side-tabs button.on::after { content: ""; position: absolute; left: 30%; right: 30%; bottom: 0; height: 2px; background: var(--gold); border-radius: 2px; }
.side-close { flex: 0 0 48px !important; display: none; }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.msg { max-width: 85%; animation: slidein .25s ease; }
.msg .mn { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg .mt { background: rgba(255, 255, 255, .07); padding: 7px 11px; border-radius: 4px 14px 14px 14px; font-size: 15px; word-break: break-word; display: inline-block; }
.msg.r .mn { color: #ff8b7d; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg.mine .mt { background: linear-gradient(180deg, #6b4a24, #533818); border-radius: 14px 4px 14px 14px; }
.msg.sys { align-self: center; max-width: 100%; font-size: 12px; color: var(--muted); background: rgba(227, 181, 98, .07); border-radius: 99px; padding: 3px 12px; text-align: center; }
.quick { display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px 0; flex: none; scrollbar-width: none; }
.quick button { flex: none; border: 1px solid var(--line); background: rgba(255, 255, 255, .04); border-radius: 99px; padding: 5px 11px; font-size: 13px; color: var(--muted); }
.chat-form { display: flex; gap: 8px; padding: 10px; flex: none; }
.chat-form .btn { padding: 10px 14px; }
.move-list { margin: 0; padding: 10px 12px; overflow-y: auto; flex: 1; list-style: none; counter-reset: mv; font-size: 15px; }
.move-list li { display: grid; grid-template-columns: 34px 1fr 1fr; padding: 5px 6px; border-radius: 8px; counter-increment: mv; }
.move-list li::before { content: counter(mv) "."; color: #6e604f; font-size: 13px; }
.move-list li:nth-child(odd) { background: rgba(255, 255, 255, .03); }
.move-list .mr { color: #ff8b7d; }
.move-list .mb { color: #d8cdbd; }
.move-list .last { color: var(--gold2); font-weight: 700; text-shadow: 0 0 8px rgba(227, 181, 98, .5); }
.move-list .ck::after { content: " 將"; font-size: 11px; color: var(--red2); }

/* 手機：側欄改成底部抽屜 */
@media (max-width: 979px) {
  .side {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; height: 62dvh; max-height: none; z-index: 45; border-radius: 20px 20px 0 0;
    transform: translateY(105%); transition: transform .32s cubic-bezier(.3, .9, .3, 1); padding-bottom: var(--safe-b); background: rgba(24, 18, 14, .98);
    box-shadow: 0 -20px 50px rgba(0, 0, 0, .6);
  }
  .side.open { transform: none; }
  .side-close { display: block; }
}
@media (min-width: 980px) {
  .play-col { --bw: min(calc(100vw - 380px), calc((100dvh - 268px) * .9), 640px); }
  #aChat, #aMoves { display: none; }
  .actions { grid-template-columns: repeat(5, 1fr); }
}
@media (max-height: 640px) and (max-width: 979px) {
  .act span { display: none; }
  .act { padding: 8px 0; }
  .play-col { --bw: min(calc(100vw - 28px), calc((100dvh - 236px - var(--safe-t) - var(--safe-b)) * .9), 620px); }
}

/* 大字特效：將軍 / 絕殺 */
#bigText { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 58; gap: 4vmin; }
#bigText span {
  font: 900 min(26vmin, 190px)/1 var(--serif); color: #fff3d6; display: inline-block;
  -webkit-text-stroke: .02em #6b0d07; text-shadow: 0 0 .15em var(--red2), 0 0 .4em rgba(255, 60, 30, .8), .04em .06em 0 #5a0a05;
  animation: stamp 1.5s cubic-bezier(.2, 1.4, .4, 1) both;
}
#bigText span:nth-child(2) { animation-delay: .1s; }
#bigText.gold span { color: #fff8e0; -webkit-text-stroke-color: #7a5210; text-shadow: 0 0 .15em var(--gold2), 0 0 .5em rgba(255, 200, 80, .8), .04em .06em 0 #5a3a05; }
@keyframes stamp {
  0% { opacity: 0; transform: scale(3) rotate(-12deg); filter: blur(10px); }
  22% { opacity: 1; transform: scale(.92) rotate(2deg); filter: blur(0); }
  32% { transform: scale(1.04); }
  75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.15); filter: blur(4px); }
}

/* 結果畫面 */
.result { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: rgba(8, 5, 3, .55); backdrop-filter: blur(3px); animation: fadein .4s; padding: 20px; }
@keyframes fadein { from { opacity: 0; } }
.result .rbox { text-align: center; animation: popin2 .6s cubic-bezier(.2, 1.4, .4, 1); width: min(100%, 380px); }
@keyframes popin2 { from { opacity: 0; transform: scale(.6) translateY(30px); } }
.result .seal {
  width: 150px; height: 150px; margin: 0 auto 16px; border-radius: 22px; display: grid; place-items: center; font: 900 76px var(--serif);
  color: #fff4dc; background: linear-gradient(145deg, #e04434, #9a1d14); box-shadow: 0 0 0 6px rgba(255, 255, 255, .08), 0 20px 50px rgba(200, 40, 20, .5);
  transform: rotate(-8deg); border: 4px double rgba(255, 230, 200, .65); animation: sealin .7s cubic-bezier(.2, 1.6, .4, 1) .15s both;
}
.result.lose .seal { background: linear-gradient(145deg, #555, #252525); box-shadow: 0 20px 50px rgba(0, 0, 0, .6); color: #ccc; }
.result.draw .seal { background: linear-gradient(145deg, #c79a45, #7a5520); }
@keyframes sealin { from { opacity: 0; transform: rotate(-30deg) scale(2.4); } }
.result h2 { font: 900 34px var(--serif); margin: 0 0 6px; letter-spacing: .2em; color: var(--gold2); }
.result.lose h2 { color: #cfc3b3; }
.result p { color: var(--muted); margin: 0 0 20px; }
.result .row { display: flex; gap: 10px; justify-content: center; }
.result .row .btn { flex: 1; }

/* 彈窗 */
.modal-back { position: fixed; inset: 0; z-index: 80; background: rgba(5, 3, 2, .6); display: grid; place-items: center; padding: 20px; animation: fadein .2s; backdrop-filter: blur(2px); }
.modal { width: min(100%, 360px); background: linear-gradient(180deg, #33261c, #221a14); border: 1px solid rgba(227, 181, 98, .3); border-radius: 20px; padding: 22px; box-shadow: 0 30px 60px rgba(0, 0, 0, .6); animation: popin2 .35s cubic-bezier(.2, 1.4, .4, 1); }
.modal h3 { margin: 0 0 8px; font: 900 21px var(--serif); color: var(--gold2); }
.modal p { margin: 0 0 16px; color: var(--text); line-height: 1.6; }
.modal input { margin-bottom: 16px; }
.modal .row { display: flex; gap: 10px; }
.modal .row .btn { flex: 1; }

#toasts { position: fixed; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: 92%; }
.toast { background: rgba(30, 22, 16, .96); border: 1px solid rgba(227, 181, 98, .35); padding: 10px 18px; border-radius: 99px; font-size: 15px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: toast 2.8s ease forwards; text-align: center; }
.toast.err { border-color: rgba(255, 90, 72, .6); color: #ffb3a8; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-14px) scale(.9); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; transform: translateY(-8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .05s !important; }
}
.banner.mini { top: 12%; padding: 12px 16px; }
.banner.mini h3 { font-size: 17px; color: #ffb3a8; }
.banner.mini p { font-size: 13px; margin-bottom: 8px; }
@media (max-width: 979px) { .stage { align-items: center; } .play-col { justify-content: center; } }
