:root {
  color-scheme: dark;
  --bg: #101718;
  --panel: #172021;
  --surface: #1b2829;
  --line: #314141;
  --text: #eaf0e9;
  --muted: #a1b4af;
  --lime: #cdf27d;
  --lime-bg: #50673b;
  --orange: #ff9777;
  --blue: #9cc8d3;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at 58% 0%, #253431 0%, transparent 63%), var(--bg); }
button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .42; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--lime); outline-offset: 3px; }
button, input { min-height: 44px; border-radius: 8px; }
input { min-width: 0; color: var(--text); border: 1px solid var(--line); background: #10191a; padding: 10px 12px; }
input::placeholder { color: #91a4a0; }
button { border: 1px solid transparent; padding: 8px 12px; color: var(--text); background: none; font-weight: 650; font-size: .875rem; }
.primary { background: var(--lime); color: #1d2b10; }
.primary:hover:not(:disabled) { background: #dfffaa; }
.secondary { background: #263536; border-color: #405452; }
.secondary:hover:not(:disabled), .subtle:hover:not(:disabled) { background: #334544; }
.subtle { color: var(--muted); }
.wide { width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.topbar { border-bottom: 1px solid #354543; background: #111a1be5; }
.top-inner { max-width: 1440px; display: flex; justify-content: space-between; align-items: center; margin: auto; min-height: 66px; padding: 0 26px; }
.brand, .top-end { display: flex; align-items: center; gap: 12px; }
.brand { font-size: 1.03rem; font-weight: 800; }
.brand-mark { width: 33px; height: 33px; display: grid; place-items: center; border-radius: 8px; border: 1px solid #657b45; background: #2b3b29; color: var(--lime); font-size: 1.25rem; }
.connection { color: var(--muted); font-size: .875rem; display: inline-flex; align-items: center; gap: 7px; }
.connection i, .presence i { width: 7px; height: 7px; background: var(--lime); border-radius: 50%; flex: 0 0 auto; }
.connection.offline i, .presence.offline i { background: var(--orange); }
.shell { max-width: 1440px; margin: auto; padding: 26px; }
.panel { border: 1px solid var(--line); background: var(--panel); border-radius: 14px; box-shadow: 0 12px 32px #0002; }
.lobby { max-width: 1060px; margin: clamp(14px, 7vh, 88px) auto; padding: clamp(20px, 5.5vw, 70px); display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1fr); align-items: center; gap: clamp(28px, 7vw, 96px); }
.eyebrow { margin: 0 0 8px; color: var(--lime); font-size: .875rem; font-weight: 750; letter-spacing: .1em; }
h1, h2, p { overflow-wrap: anywhere; }
h1, h2 { margin: 0; }
.lobby h1 { font-size: clamp(3.1rem, 7vw, 6rem); font-weight: 900; letter-spacing: -.075em; line-height: 1.1; }
.lobby h1 span { color: var(--lime); }
.intro { color: var(--muted); margin: 18px 0 29px; line-height: 1.65; }
label { display: block; margin-bottom: 7px; font-size: .875rem; font-weight: 680; }
#nickname { width: 100%; margin-bottom: 10px; }
.join-row { margin-top: 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.invite-create { margin-top: 8px; }
#room-code { text-transform: uppercase; letter-spacing: .13em; }
.lobby-preview { min-width: 0; align-self: center; }
.preview-heading { color: var(--muted); display: flex; justify-content: space-between; font-size: .875rem; margin-bottom: 11px; }
.preview-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: #111a1b; }
.preview-grid span { display: grid; place-items: center; background: #263536; border-radius: 3px; aspect-ratio: 1; font-weight: 800; line-height: 1; }
.preview-grid span.plane { background: #58733d; }
.preview-grid span.head { background: #728b4c; color: #f0ffd4; }
.preview-grid span.wreck { background: #624137; }
.preview-grid span.miss { color: var(--blue); }
.preview-grid span.hit, .preview-grid span.destroy { color: var(--orange); }
.legend { margin-top: 13px; display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: .875rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 14px; height: 14px; line-height: 14px; text-align: center; display: inline-block; font-style: normal; font-weight: 850; }
.legend-plane { background: var(--lime-bg); border: 1px solid #819760; border-radius: 3px; }
.legend-miss { color: var(--blue); }
.legend-hit, .legend-destroy { color: var(--orange); }
.match-header { padding: 18px 21px; display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 15px; }
.match-header h1 { font-size: clamp(1.5rem, 3vw, 2.25rem); }
#match-note { margin: 6px 0 0; color: var(--muted); font-size: .95rem; min-height: 1.35em; }
.room-tools { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.room-code-label { display: grid; gap: 2px; padding-right: 8px; }
.room-code-label span { color: var(--muted); font-size: .875rem; }
.room-code-label strong { color: var(--lime); letter-spacing: .12em; font-family: ui-monospace, monospace; font-size: 1.1rem; }
.match-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(250px, .78fr); gap: 15px; align-items: start; }
.match-grid[data-phase="WAITING"] .waiting, .match-grid[data-phase="PREPARING"] .mine { grid-column: span 2; }
.match-grid[data-phase="PREPARING"] .mine .board { max-width: 510px; margin-inline: auto; }
.match-grid[data-phase="PREPARING"] .mine #placement { max-width: 510px; margin-inline: auto; }
.board-panel, .waiting, .sidebar { padding: 16px; min-width: 0; }
.board-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.board-heading h2 { font-size: 1.1rem; }
.board-heading span { color: var(--muted); font-size: .875rem; }
.board { display: grid; grid-template-columns: minmax(14px, .52fr) repeat(10, minmax(0, 1fr)); gap: 2px; user-select: none; touch-action: manipulation; }
.axis { display: grid; place-items: center; min-height: 18px; color: var(--muted); font-size: .78rem; font-family: ui-monospace, monospace; }
.cell { display: grid; place-items: center; min-height: 0; aspect-ratio: 1; padding: 0; border: 1px solid #3a4d4b; border-radius: 3px; background: #243333; color: #e3f4cb; line-height: 1; font-size: clamp(.75rem, 2.1vw, 1.05rem); }
.cell:disabled { opacity: 1; }
.cell:not(:disabled):hover { background: #3d5350; }
.cell.plane { background: #51683e; border-color: #778f57; }
.cell.head { background: #6b854a; color: #fbffde; }
.cell.wreck { background: #4c3732; border-color: #775045; }
.cell.miss { color: var(--blue); }
.cell.hit, .cell.destroy { color: var(--orange); }
.cell.selected { outline: 2px solid var(--lime); outline-offset: -2px; z-index: 1; background: #4a603c; }
.cell.valid-preview { border-color: var(--lime); }
.cell.invalid-preview { border-color: var(--orange); }
.cell.active-plane { box-shadow: inset 0 0 0 1px var(--lime); }
.cell:focus-visible { position: relative; z-index: 2; }
.helper { color: var(--muted); font-size: .875rem; line-height: 1.5; }
#placement-note { margin: 13px 0 8px; }
.plane-slots, .button-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 7px; }
.plane-slots button { padding-inline: 4px; font-weight: 500; }
.plane-slots button[aria-pressed="true"] { border-color: var(--lime); color: var(--lime); }
.shot-controls { display: flex; gap: 8px; justify-content: space-between; align-items: center; margin-top: 11px; }
.shot-controls button { white-space: nowrap; }
.waiting { padding: clamp(18px, 4.5vw, 48px); min-height: 290px; }
.waiting-icon { font-size: 2rem; color: var(--lime); margin-bottom: 11px; }
.waiting p { color: var(--muted); line-height: 1.6; }
#invite-url { width: 100%; }
.pilots { margin-bottom: 13px; }
.pilot { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 8px; padding: 8px 0; align-items: center; }
.pilot + .pilot { border-top: 1px solid var(--line); }
.pilot strong { min-width: 0; overflow-wrap: anywhere; }
.presence { display: flex; gap: 5px; align-items: center; color: var(--muted); font-size: .875rem; }
.pilot small { color: var(--muted); font-size: .875rem; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.tabs button[aria-selected="true"] { color: var(--lime); box-shadow: inset 0 -2px var(--lime); border-radius: 0; }
.stream { height: clamp(180px, 32vh, 380px); overflow: auto; overscroll-behavior: contain; padding: 10px 0; }
.stream p { margin: 0 0 10px; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.55; }
.stream strong { color: var(--lime); }
.stream .empty { color: var(--muted); font-size: .875rem; }
.log-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 8px; }
.log-entry b { color: var(--blue); }
.log-entry b[data-result="HIT"], .log-entry b[data-result="PLANE_DESTROYED"] { color: var(--orange); }
#chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.error { color: #ffb59e; line-height: 1.5; margin: 9px 0 0; }
.banner { background: #412b25; border: 1px solid #7a4d42; border-radius: 8px; padding: 10px 13px; margin: 0 0 12px; }
dialog { color: var(--text); background: var(--panel); border: 1px solid #536562; border-radius: 14px; max-width: min(490px, calc(100vw - 28px)); padding: 21px; }
dialog::backdrop { background: #060d0dc9; }
dialog li { margin-bottom: 9px; line-height: 1.6; color: var(--muted); }
dialog ol { padding-left: 24px; }
dialog .close { float: right; min-width: 44px; font-size: 1.35rem; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 3; max-width: calc(100vw - 20px); padding: 10px 14px; border: 1px solid #667c49; background: #223125; color: var(--lime); border-radius: 9px; }
@media (max-width: 1050px) {
  .match-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar { grid-column: span 2; }
  .match-grid[data-phase="WAITING"], .match-grid[data-phase="PREPARING"] { grid-template-columns: minmax(0, 1fr) minmax(235px, .7fr); }
  .match-grid[data-phase="WAITING"] > *, .match-grid[data-phase="PREPARING"] > * { grid-column: auto !important; }
}
@media (max-width: 680px) {
  .match-grid, .match-grid[data-phase="WAITING"], .match-grid[data-phase="PREPARING"] { grid-template-columns: minmax(0, 1fr); }
  .sidebar { grid-column: auto; }
  .enemy { order: -1; }
  .top-inner { min-height: 57px; padding-inline: 12px; }
  .shell { padding: 12px; }
  .lobby { margin: 12px auto; grid-template-columns: minmax(0, 1fr); gap: 25px; }
  .lobby-preview { width: min(100%, 400px); justify-self: center; }
  .match-header { align-items: start; flex-direction: column; padding: 13px; gap: 9px; }
  .room-tools { justify-content: flex-start; }
  .board-panel, .waiting, .sidebar { padding: 10px; }
}
@media (orientation: landscape) and (max-width: 950px) and (max-height: 530px) {
  .match-grid[data-phase="PLAYING"], .match-grid[data-phase="FINISHED"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar { grid-column: 1 / -1; }
}
