:root {
  color-scheme: dark;
  --bg: #101a17;
  --panel: #1b2b25;
  --line: #405347;
  --ink: #f5f0df;
  --soft: #b6c8bc;
  --gold: #f0c875;
  --green: #214f40;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; color: var(--ink); background: radial-gradient(ellipse at 82% 0%, #233d31, transparent 57%), var(--bg); }
[hidden] { display: none !important; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled { opacity: .53; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, canvas:focus-visible, summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
a { color: inherit; text-decoration: none; }
.wrap { width: min(1190px, calc(100% - 58px)); margin-inline: auto; }
.top { min-height: 76px; display: flex; justify-content: space-between; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.brand, .account { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 750; }
.brand-ball { display: grid; place-items: center; width: 35px; aspect-ratio: 1; background: radial-gradient(circle at 34% 26%, #62746a, #101815 67%); border: 1px solid #687c70; border-radius: 50%; color: var(--gold); font: 800 17px Georgia, serif; }
main { padding-block: 36px 10px; }
h1 { margin: 4px 0 15px; font-size: clamp(35px, 5.2vw, 65px); line-height: 1.15; letter-spacing: -.05em; overflow-wrap: anywhere; }
h2 { font-size: 20px; margin: 0; }
p { line-height: 1.65; }
.kind { margin: 0 0 5px; font-weight: 750; color: var(--gold); font-size: 12px; letter-spacing: .13em; }
.welcome { display: grid; grid-template-columns: minmax(0, 1fr) minmax(255px, 355px); align-items: center; gap: clamp(25px, 7vw, 95px); padding: 18px 0; }
.welcome-copy > p:not(.kind) { max-width: 430px; color: var(--soft); margin: 0 0 18px; }
.demo { max-width: 620px; width: 100%; height: auto; display: block; }
.panel { background: linear-gradient(150deg, #25382e, var(--panel) 70%); border: 1px solid var(--line); border-radius: 18px; padding: clamp(17px, 3vw, 30px); }
.sign-in { padding: clamp(19px, 3.2vw, 35px); }
.switch { display: flex; padding: 4px; background: var(--bg); border-radius: 11px; gap: 4px; }
.switch button { flex: 1; border-color: transparent; padding-block: 9px; }
.switch button[aria-pressed="true"] { background: #355142; color: var(--ink); }
form { display: grid; gap: 9px; margin-top: 21px; }
form label, .controls label { font-size: 13px; font-weight: 700; }
form input { background: #111f19; color: var(--ink); border: 1px solid #52685b; border-radius: 9px; min-height: 45px; width: 100%; padding: 9px 11px; }
form input::placeholder { color: #a0b1a6; }
#auth-form label:not(:first-child) { margin-top: 6px; }
form > .primary { margin-top: 6px; }
.primary, .quiet { border: 1px solid transparent; border-radius: 8px; padding: 11px 15px; min-height: 41px; font-size: 14px; font-weight: 750; color: var(--ink); background: #2e4639; white-space: nowrap; }
.primary { color: #242214; background: var(--gold); }
.primary:hover:enabled { background: #ffda92; }
.quiet { border-color: #506657; background: transparent; color: var(--soft); }
.quiet:hover:enabled { background: #345042; color: var(--ink); }
.compact { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.status { background: #423b2a; border: 1px solid #8a754f; color: #ffe2a6; border-radius: 9px; padding: 9px 12px; margin: 0 0 15px; overflow-wrap: anywhere; }
.lobby-grid, .game-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(235px, 300px); gap: 16px; align-items: start; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.room-list { display: grid; gap: 8px; margin-top: 14px; }
.room-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; background: #16241e; border: 1px solid #42564a; border-radius: 11px; padding: 11px 12px; }
.room-item strong { display: block; overflow-wrap: anywhere; }
.room-item small, .empty { color: var(--soft); font-size: 13px; }
.enter-code { border-top: 1px solid var(--line); padding-top: 19px; }
.input-row, .room-head, .room-intro { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.room-intro { margin-top: 22px; }
.room-intro h1 { font-size: clamp(28px, 4vw, 46px); }
.badge { border: 1px solid #63795d; border-radius: 30px; padding: 6px 11px; font-size: 12px; color: #d7edbd; background: #263d30; white-space: nowrap; }
.table-card { border: 1px solid var(--line); background: #192922; border-radius: 18px; overflow: hidden; }
.table-wrap { background: radial-gradient(ellipse, #293e31, #131c18); padding: clamp(3px, 1.4vw, 15px); }
#table { display: block; width: 100%; aspect-ratio: 1064/584; touch-action: none; outline-offset: -3px; }
#table.aim { cursor: crosshair; }
.controls { display: grid; grid-template-columns: 90px minmax(50px, 1fr) 105px; align-items: center; gap: 12px; padding: 15px 20px; }
.controls input { accent-color: var(--gold); width: 100%; margin: 0; }
.controls output { color: var(--gold); margin-inline-start: 4px; }
.score-panel { padding: 17px; }
.score-panel > button { width: 100%; margin: 4px 0; }
.score-row { padding: 8px; margin-top: 8px; display: grid; grid-template-columns: 11px minmax(0, 1fr) 24px; align-items: center; gap: 8px; min-height: 39px; border: 1px solid #42564a; border-radius: 8px; }
.score-row.active { border-color: var(--gold); background: #343825; }
.score-row .name { font-size: 13px; overflow-wrap: anywhere; }
.score-row strong { text-align: center; font-variant-numeric: tabular-nums; }
.score-ball { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.score-ball.blue { background: #80c4d2; }
.eight-pockets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin: 8px 0; }
.eight-pockets span { grid-column: 1 / -1; color: var(--gold); font-size: 11px; font-weight: 750; }
.eight-pockets button { min-height: 27px; padding: 3px 1px; border: 1px solid #596b55; border-radius: 6px; background: #17251d; color: var(--soft); font-size: 10px; }
.eight-pockets button[aria-pressed="true"] { color: #262014; background: var(--gold); border-color: var(--gold); font-weight: 800; }
.game-note { color: var(--soft); font-size: 13px; margin: 13px 0 8px; }
details { color: var(--soft); font-size: 12px; border-top: 1px solid var(--line); margin-top: 13px; padding-top: 11px; }
summary { cursor: pointer; }
details p { margin-bottom: 0; }
.footer { padding-block: 20px; font-size: 13px; color: var(--soft); }
.landscape-hint { display: none; color: var(--soft); font-size: 11px; margin: 3px 0 8px; }
@media (orientation: landscape) and (max-height: 560px) and (max-width: 950px) {
  body.in-game { height: 100dvh; min-height: 0; overflow: hidden; }
  body.in-game .top, body.in-game .footer { display: none; }
  body.in-game main { height: 100dvh; padding: 0; }
  body.in-game .wrap { width: 100%; margin-inline: 0; }
  body.in-game #game { position: relative; height: 100dvh; min-height: 0; }
  body.in-game #game:fullscreen, body.in-game #game.fullscreen-fallback { position: fixed; inset: 0; z-index: 20; width: 100vw; height: 100dvh; background: #101a17; }
  body.in-game #game:fullscreen .room-head, body.in-game #game.fullscreen-fallback .room-head { position: fixed; z-index: 32; inset: max(5px, env(safe-area-inset-top)) max(7px, env(safe-area-inset-right)) auto auto; min-height: 0; }
  body.in-game #game:fullscreen #back, body.in-game #game:fullscreen #invite,
  body.in-game #game.fullscreen-fallback #back, body.in-game #game.fullscreen-fallback #invite { display: none; }
  body.in-game #game:fullscreen #fullscreen, body.in-game #game.fullscreen-fallback #fullscreen { min-height: 28px; padding: 5px 10px; font-size: 11px; color: #f6f0dd; background: #14221ddb; border-color: #80907d; }
  body.in-game .room-head .compact { min-height: 27px; padding: 4px 8px; font-size: 10px; }
  .room-intro { display: none; }
  .landscape-hint { display: none; }
  body.in-game .game-grid { height: 100%; grid-template-columns: minmax(0, 1fr) 164px; gap: 5px; align-items: center; padding: 30px 6px 4px; }
  .table-card, .score-panel { border-radius: 10px; }
  .table-wrap { padding: 2px; }
  body.in-game #table { width: 100%; max-height: calc(100dvh - 40px); height: auto; object-fit: contain; margin-inline: auto; }
  body.in-game .controls { position: fixed; z-index: 4; right: max(6px, env(safe-area-inset-right)); bottom: max(6px, env(safe-area-inset-bottom)); width: 152px; grid-template-columns: minmax(0, 1fr) 58px; padding: 7px; gap: 4px 6px; font-size: 10px; border: 1px solid #627665; border-radius: 9px; background: #14221deF; }
  body.in-game .controls label { grid-column: 1; grid-row: 1; }
  body.in-game .controls input { grid-column: 1; grid-row: 2; }
  body.in-game .controls .primary { grid-column: 2; grid-row: 1 / 3; min-height: 32px; padding: 4px; font-size: 10px; }
  body.in-game .score-panel { padding: 8px; }
  .score-panel h2 { font-size: 14px; }
  .score-row { margin-top: 5px; min-height: 30px; padding: 4px; gap: 4px; grid-template-columns: 8px minmax(0, 1fr) 15px; }
  .score-row .name { font-size: 10px; }
  .game-note { font-size: 10px; line-height: 1.35; margin: 6px 0; max-height: 42px; overflow: auto; }
  .eight-pockets { gap: 2px; margin: 5px 0; }
  .eight-pockets span { font-size: 9px; }
  .eight-pockets button { min-height: 22px; font-size: 9px; }
  .score-panel > button { min-height: 30px; padding: 4px; font-size: 10px; }
  details { font-size: 10px; margin-top: 5px; padding-top: 5px; }
  details p { max-height: 52px; overflow: auto; }
  .footer { padding-block: 4px; font-size: 10px; }
  body.in-game #game:fullscreen .game-grid, body.in-game #game.fullscreen-fallback .game-grid { display: grid; width: 100%; height: 100%; grid-template-columns: minmax(0, 1fr); place-items: center; gap: 0; padding: 0; }
  body.in-game #game:fullscreen .table-card, body.in-game #game.fullscreen-fallback .table-card { position: relative; width: min(100vw, calc(100dvh * 1.8219)); max-width: 100vw; aspect-ratio: 1064 / 584; border: 0; border-radius: 0; overflow: visible; background: transparent; }
  body.in-game #game:fullscreen .table-wrap, body.in-game #game.fullscreen-fallback .table-wrap { width: 100%; height: 100%; padding: 0; background: transparent; }
  body.in-game #game:fullscreen #table, body.in-game #game.fullscreen-fallback #table { width: 100%; height: 100%; max-height: none; aspect-ratio: 1064 / 584; object-fit: fill; margin: 0; }
  body.in-game #game:fullscreen .score-panel, body.in-game #game.fullscreen-fallback .score-panel { display: contents; }
  body.in-game #game:fullscreen .score-panel > h2, body.in-game #game:fullscreen .score-row,
  body.in-game #game.fullscreen-fallback .score-panel > h2, body.in-game #game.fullscreen-fallback .score-row { display: none; }
  body.in-game #game:fullscreen .game-note, body.in-game #game.fullscreen-fallback .game-note { position: fixed; z-index: 31; inset: max(7px, env(safe-area-inset-top)) auto auto max(7px, env(safe-area-inset-left)); width: min(45vw, 310px); margin: 0; padding: 6px 9px; border: 1px solid #8a9b7c9c; border-radius: 8px; color: #fff5df; background: #14221ddb; font-size: 11px; line-height: 1.3; }
  body.in-game #game:fullscreen .controls, body.in-game #game.fullscreen-fallback .controls { position: absolute; z-index: 30; inset: auto auto max(9px, env(safe-area-inset-bottom)) 50%; transform: translateX(-50%); width: min(270px, 58vw); grid-template-columns: minmax(0, 1fr) 62px; padding: 6px 9px; gap: 3px 9px; border: 1px solid #9bab8c99; border-radius: 10px; background: #14221dde; box-shadow: 0 2px 12px #0005; font-size: 10px; }
  body.in-game #game:fullscreen .controls label, body.in-game #game.fullscreen-fallback .controls label { grid-column: 1; grid-row: 1; }
  body.in-game #game:fullscreen .controls input, body.in-game #game.fullscreen-fallback .controls input { grid-column: 1; grid-row: 2; }
  body.in-game #game:fullscreen .controls .primary, body.in-game #game.fullscreen-fallback .controls .primary { grid-column: 2; grid-row: 1 / 3; min-height: 34px; padding: 4px; font-size: 11px; }
  body.in-game #game:fullscreen #eight-pockets, body.in-game #game.fullscreen-fallback #eight-pockets { position: fixed; z-index: 31; inset: max(42px, calc(env(safe-area-inset-top) + 34px)) auto auto 50%; transform: translateX(-50%); width: min(250px, 60vw); padding: 6px; border: 1px solid #9bab8c99; border-radius: 9px; background: #14221def; }
  body.in-game #game:fullscreen #eight-pockets span, body.in-game #game.fullscreen-fallback #eight-pockets span { grid-column: 1 / -1; text-align: center; color: #fff2d2; }
  body.in-game #game:fullscreen #sit, body.in-game #game:fullscreen #rematch, body.in-game #game:fullscreen #leave,
  body.in-game #game.fullscreen-fallback #sit, body.in-game #game.fullscreen-fallback #rematch, body.in-game #game.fullscreen-fallback #leave { position: fixed; z-index: 31; left: 50%; top: max(42px, calc(env(safe-area-inset-top) + 34px)); transform: translateX(-50%); width: auto; min-height: 30px; padding: 5px 10px; font-size: 11px; white-space: nowrap; }
}
@media (max-width: 720px) {
  .wrap { width: calc(100% - 28px); }
  .top { min-height: 60px; }
  main { padding-top: 23px; }
  .welcome, .lobby-grid, .game-grid { grid-template-columns: 1fr; gap: 12px; }
  .welcome { padding-top: 4px; }
  .demo { max-height: 155px; object-fit: contain; object-position: left; }
  .controls { grid-template-columns: minmax(62px, auto) minmax(38px, 1fr) 70px; padding: 9px 10px; gap: 8px; }
  .room-intro { margin-top: 15px; }
  .account { gap: 5px; font-size: 12px; }
  .brand { white-space: nowrap; font-size: 14px; gap: 7px; }
  .brand-ball { width: 29px; }
}
