:root {
  color-scheme: dark;
  --mat: #233d32;
  --text: #edf2e7;
  --muted: #b1c2b2;
  --wood: #e9c796;
  --line: #87683f;
  --red: #b34432;
  --sans: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { background: var(--mat); color: var(--text); font: 14px var(--sans); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .5; }
button:focus-visible, input:focus-visible { outline: 2px solid #e4bc74; outline-offset: 3px; }
[hidden] { display: none !important; }
.game-app {
  --rail: 240px;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "board tools" "board actions";
  gap: 20px;
  padding: 12px;
}
.toolbar { grid-area: tools; display: flex; flex-direction: column; align-items: stretch; gap: 20px; min-width: 0; min-height: 0; }
.room-tools, .view-tools { display: flex; align-items: center; gap: 4px; }
.room-tools { flex: 0 0 auto; }
.view-tools { flex: 0 0 auto; justify-content: flex-start; }
.toolbar-button, .icon-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 40px; padding: 9px 12px; background: transparent; border: 0; border-radius: 6px; }
.toolbar-button { font-size: 13px; color: #d1decb; }
.icon-button { width: 40px; height: 40px; padding: 11px; color: var(--muted); }
.toolbar-button:hover, .icon-button:hover { background: #ffffff0c; color: #fff; }
.icon-button[aria-pressed="true"] { color: var(--text); }
.toolbar-button svg, .icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
#sound-toggle[aria-pressed="false"] .sound-waves, #sound-toggle[aria-pressed="true"] .sound-off { display: none; }
#room-button-label { font-variant-numeric: tabular-nums; }
.connection { width: 16px; height: 32px; display: grid; place-items: center; margin-right: 2px; }
.connection i { display: block; width: 5px; height: 5px; background: #ddbc76; border-radius: 50%; }
.connection.connected i { background: #a2c7a1; }
.connection.disconnected i { background: #e79c80; }
.players { display: flex; flex-direction: column; align-items: stretch; gap: 16px; min-width: 0; padding: 0 12px; }
.player { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: 14px; }
.player.active { color: #fff; }
.player-piece { display: inline-block; width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0; }
.player-piece.black { background: #131b16; box-shadow: inset 0 0 0 1px #8c9a8040; }
.player-piece.white { background: #f0eee0; }
.player-piece.red { background: #c7543d; }
.player-piece.ink { background: #121e19; box-shadow: inset 0 0 0 1px #9eac9360; }
.player-piece.neutral { background: transparent; border: 1px solid var(--muted); }
.player.active .player-piece { outline: 1px solid #beccac; outline-offset: 3px; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.you-label { font-size: 11px; margin-left: 6px; color: #c4d6be; }
.tabletop { grid-area: board; display: grid; place-items: center; min-height: 0; min-width: 0; }
.board-frame {
  width: min(calc(100vw - var(--rail) - 44px), calc(100dvh - 24px));
  aspect-ratio: 1;
  padding: 8px;
  background: #b68f5d;
  border-radius: 4px;
  box-shadow: 0 14px 32px #0b1d1640;
}
.board-surface { width: 100%; height: 100%; position: relative; background: var(--wood); border-radius: 1px; }
.board-lines, .board-cells { position: absolute; inset: 0; width: 100%; height: 100%; }
.board-lines line { stroke: var(--line); stroke-width: 1.15; opacity: .85; }
.board-lines circle { fill: #725631; }
.cell { position: absolute; width: 6.5714286%; height: 6.5714286%; padding: 0; transform: translate(-50%, -50%); border: 0; background: transparent; display: grid; place-items: center; border-radius: 50%; }
.cell[aria-disabled="true"] { cursor: default; }
.cell:focus-visible { outline: 1.5px solid #294b33; outline-offset: -4px; }
.piece { width: 58%; height: 58%; border-radius: 50%; position: relative; display: block; animation: stone-in .12s ease-out; }
.piece.black { background: radial-gradient(circle at 32% 24%, #484d43, #1d251e 52%, #131a14); box-shadow: 1px 2px 3px #4c351a40; }
.piece.white { background: radial-gradient(circle at 32% 24%, #fffdf4, #efecdd 65%, #d7d1bd); box-shadow: 1px 2px 3px #4c351a35; }
.cell.last .piece::after { content: ""; position: absolute; width: 13%; height: 13%; top: 43.5%; left: 43.5%; background: var(--red); border-radius: 50%; }
.cell.winning .piece { outline: 2px solid var(--red); outline-offset: 2px; }
.board-cells.is-playable .cell.empty:hover::after { content: ""; width: 58%; height: 58%; border: 1px solid #334e3550; border-radius: 50%; background: #334e3520; }
.gamebar { grid-area: actions; display: flex; flex-direction: column; align-items: stretch; gap: 12px; min-width: 0; padding: 0 12px 4px; }
.turn-panel { font-size: 18px; color: var(--muted); line-height: 1.5; }
.turn-panel.your-turn { color: #f5f3dd; }
.turn-panel.finished { color: #f3cf98; }
.game-actions { display: grid; gap: 8px; }
.game-actions .button { min-height: 40px; padding: 9px 14px; font-size: 14px; }
.rematch-status { margin: 0; color: #d8d6ae; line-height: 1.6; font-size: 13px; }
.button { min-height: 44px; padding: 11px 16px; border: 0; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 500; transition: background .12s ease-out; }
.primary { background: #365944; color: #fffdf0; }
.primary:hover:not(:disabled) { background: #294935; }
.game-actions .primary { background: #d4dfc5; color: #20372b; }
.game-actions .primary:hover:not(:disabled) { background: #e6eddc; }
.secondary { background: #e5e8db; color: #344b38; }
.secondary:hover:not(:disabled) { background: #d5decd; }
.quiet { background: #ffffff08; color: #b8c9b4; }
.quiet:hover:not(:disabled) { background: #ffffff12; color: #fff; }
.danger { background: #a74735; color: #fff8f2; }
.danger:hover:not(:disabled) { background: #943a2a; }
.modal { color-scheme: light; width: calc(100% - 32px); max-width: 340px; max-height: calc(100dvh - 40px); overflow-y: auto; border: 0; border-radius: 12px; padding: 24px; background: #f2efe4; color: #263c2e; box-shadow: 0 20px 60px #071c1460; }
.modal::backdrop { background: #112a2260; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -4px -8px 20px 0; }
.modal h2 { font: 600 18px var(--sans); margin: 0; }
.modal .icon-button { color: #5e735e; }
.modal .icon-button:hover { background: #264b3210; color: #263c2e; }
.field-label { display: block; font-size: 13px; margin-bottom: 8px; }
.field { width: 100%; height: 44px; border: 1px solid #bbc7b3; border-radius: 6px; background: #fffdf5; color: #263c2e; padding: 0 12px; font-size: 14px; }
.field::placeholder { color: #61745d; }
.field:focus { border-color: #4a6a4d; }
.create-button { width: 100%; margin-top: 12px; }
.lobby-screen { width: 360px; max-width: calc(100vw - 48px); }
.game-selector { display: flex; gap: 8px; margin-bottom: 32px; }
.game-option { flex: 1; padding: 18px 16px; background: transparent; border: 1px solid #829d85; border-radius: 6px; color: #d3dfcf; font-size: 20px; }
.game-option.selected { background: #d4dfc5; border-color: #d4dfc5; color: #20372b; }
.game-option:hover:not(.selected) { background: #ffffff08; }
.game-app.in-lobby { grid-template-columns: 1fr; grid-template-areas: "board"; grid-template-rows: 1fr; }
.in-lobby .toolbar { position: absolute; top: 12px; right: 12px; }
.in-lobby .room-tools { display: none; }
.lobby-screen .primary { background: #d4dfc5; color: #20372b; }
.lobby-screen .primary:hover:not(:disabled) { background: #e6eddc; }
.lobby-screen .join-form { border-color: #718c723d; }
.chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 12px; }
.chat-panel h2 { font-size: 13px; font-weight: 500; color: var(--muted); margin: 0 0 12px; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #68876d transparent; padding: 4px 4px 12px 0; }
.chat-message { margin-bottom: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.chat-author { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.chat-message.own .chat-author { color: #dbdca8; }
.chat-text { white-space: pre-wrap; font-size: 14px; }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) 42px; gap: 6px; }
.chat-input { height: 40px; min-width: 0; width: 100%; padding: 0 10px; border: 1px solid #78927866; border-radius: 6px; background: #1b3128; color: var(--text); }
.chat-input::placeholder { color: #b1c2b2; }
.chat-send { border: 0; border-radius: 6px; background: #d4dfc5; color: #20372b; font-size: 12px; }
.rules-modal { max-width: 440px; }
.rules-modal p { font-size: 14px; line-height: 1.8; margin: 16px 0 0; }
.rank-order { font-weight: 600; }
.game-app[data-game="banqi"] .board-frame { width: min(calc(100vw - var(--rail) - 44px), calc((100dvh - 24px) * 2)); aspect-ratio: 2; padding: 12px; }
.game-app[data-game="banqi"] .cell { width: 12.5%; height: 25%; transform: none; border-radius: 0; }
.game-app[data-game="banqi"] .board-lines line { stroke-width: 1.4; }
.dark-piece { display: grid; place-items: center; width: 76%; height: auto; aspect-ratio: 1; border-radius: 50%; background: #f3d7a5; border: 2px solid #af8150; box-shadow: 2px 4px 5px #65431d33, inset 0 0 0 4px #dfb77e; font: 600 clamp(24px, 3.2vw, 62px)/1 "KaiTi", "STKaiti", "SimSun", serif; }
.dark-piece.red { color: #a23526; }
.dark-piece.ink { color: #232e26; }
.dark-piece.covered { background: #a47848; border-color: #8a6036; box-shadow: 2px 4px 5px #65431d33, inset 0 0 0 4px #bb905c; }
.dark-piece.covered::before { content: ""; position: absolute; inset: 19%; border: 2px solid #d2aa72; border-radius: 50%; }
.dark-piece.covered::after { content: ""; position: absolute; inset: 32%; border: 1px solid #d2aa72; border-radius: 50%; }
.cell.selected .dark-piece { outline: 3px solid #375b3d; outline-offset: 4px; }
.cell.destination.empty::after { content: ""; width: 16%; height: 16%; border-radius: 50%; background: #36543c90; }
.cell.destination:not(.empty) .dark-piece { outline: 2px dashed #36543c; outline-offset: 4px; }
.game-app[data-game="banqi"] .cell.last .piece::after { width: 7%; height: 7%; left: 46.5%; top: 84%; background: #36543c; }
.game-app[data-game="banqi"] .board-cells.is-playable .cell.empty:hover::after { width: 16%; height: 16%; }
.join-form { display: flex; gap: 8px; margin-top: 24px; padding-top: 24px; border-top: 1px solid #d2d9c9; }
.join-form .field { min-width: 0; }
.join-form .button { white-space: nowrap; }
.code-field { text-transform: uppercase; font-variant-numeric: tabular-nums; letter-spacing: 2px; }
.code-field::placeholder { letter-spacing: 0; }
.copy-code { width: 100%; background: transparent; border: 0; padding: 12px 0; color: #263c2e; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#room-id { font-family: "Cascadia Code", Consolas, monospace; font-size: 26px; letter-spacing: 3px; }
.copy-label { font-size: 12px; color: #536a4c; }
.leave-button { width: 100%; margin-top: 20px; }
.confirm-modal p { font-size: 14px; line-height: 1.7; color: #52644c; margin: 16px 0 0; }
.confirm-actions { display: flex; gap: 10px; margin-top: 24px; }
.confirm-actions > * { flex: 1; }
.toast { position: fixed; bottom: max(72px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 10; width: max-content; max-width: calc(100% - 32px); color: #eef3e8; background: #142c23; box-shadow: 0 4px 18px #081c1540; padding: 12px 16px; border-radius: 6px; font-size: 13px; line-height: 1.6; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.noscript { position: fixed; inset: 40% 0 auto; text-align: center; background: #263f33; padding: 20px; }
@keyframes stone-in { from { transform: scale(.9); } to { transform: scale(1); } }
@media (hover: none) { .board-cells.is-playable .cell.empty:hover::after { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
