:root {
  color-scheme: dark;
  --blue: #287fc0;
  --blue-hover: #216da6;
  --paper: #f4f4f1;
  --paper-2: #e7e8e6;
  --ink: #26292d;
  --muted: #70767c;
  --line: #c8cbce;
  --game-text: #f3f5f7;
  font-family: "Ubuntu", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #101216; }
body { color: var(--ink); font-family: "Ubuntu", sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; }
button, label, summary, select { -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }
.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; }

#view { position: fixed; inset: 0; display: block; width: 100vw; height: 100vh; background: #101216; cursor: crosshair; touch-action: none; }
.screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 18px; overflow: auto; background: rgba(0, 0, 0, 0.48); animation: screen-in 160ms ease-out both; }
.join-panel, .result-panel { width: min(390px, 100%); border: 1px solid #fff; border-radius: 10px; background: var(--paper); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.38); }
.join-header { display: flex; align-items: center; justify-content: space-between; min-height: 79px; padding: 16px 18px 14px; border-bottom: 1px solid var(--line); }
.wordmark { display: flex; align-items: flex-start; gap: 6px; }
.wordmark h1 { margin: 0; color: #202327; font-size: 35px; line-height: 1; letter-spacing: -0.065em; }
.wordmark h1 span { color: var(--blue); }
.wordmark small { margin-top: 2px; padding: 2px 4px; border-radius: 2px; background: #dfe1e2; color: #60666b; font-size: 8px; font-weight: 700; letter-spacing: 0.06em; }
.connection-state { display: flex; align-items: center; gap: 6px; color: #777d82; font-size: 10px; font-weight: 500; }
.connection-state > span { width: 7px; height: 7px; border-radius: 50%; background: #d39b35; }
.connection-state[data-state="online"] { color: #4d6251; }
.connection-state[data-state="online"] > span { background: #52a35f; }
.connection-state[data-state="offline"] { color: #8f4848; }
.connection-state[data-state="offline"] > span { background: #c75252; }

#joinForm { padding: 15px 18px 17px; }
.quick-fields { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(120px, 0.9fr); gap: 7px; }
.field { display: grid; gap: 4px; }
.field > span, .color-fieldset legend { color: #686e74; font-size: 9px; font-weight: 700; letter-spacing: 0.045em; text-transform: uppercase; }
.field input, .field select { width: 100%; height: 39px; border: 1px solid #b8bdc1; border-radius: 4px; outline: 0; background: #fff; color: #25292d; transition: transform 160ms ease, opacity 160ms ease; }
.field input { padding: 0 11px; }
.field select { padding: 0 7px; cursor: pointer; }
.field input:focus, .field select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(40, 127, 192, 0.14); }
.field select:disabled { cursor: wait; opacity: 0.55; }
.room-meta { min-height: 15px; margin: 5px 1px 8px; color: var(--muted); font-size: 9px; }
.color-fieldset { min-width: 0; margin: 0 0 11px; padding: 0; border: 0; }
.color-fieldset legend { margin-bottom: 5px; }
.color-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.color-choice { cursor: pointer; }
.color-choice:nth-child(1) { --swatch: #65d6ff; }
.color-choice:nth-child(2) { --swatch: #7cf29a; }
.color-choice:nth-child(3) { --swatch: #ffd166; }
.color-choice:nth-child(4) { --swatch: #ff7a90; }
.color-choice:nth-child(5) { --swatch: #b99cff; }
.color-choice:nth-child(6) { --swatch: #ff9f68; }
.color-choice:nth-child(7) { --swatch: #5eead4; }
.color-choice:nth-child(8) { --swatch: #f5f7ff; }
.color-choice input { position: absolute; opacity: 0; pointer-events: none; }
.color-choice span { display: block; height: 24px; border: 2px solid #fff; border-radius: 4px; background: var(--swatch); box-shadow: 0 0 0 1px #b8bdc1; transition: transform 160ms ease, opacity 160ms ease; }
.color-choice:hover span { transform: translateY(-1px); }
.color-choice input:checked + span { box-shadow: 0 0 0 2px #30363b; transform: translateY(-1px); }
.color-choice input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.play-button { width: 100%; height: 41px; border: 1px solid #1e6da8; border-radius: 4px; background: var(--blue); color: #fff; cursor: pointer; font-size: 14px; font-weight: 700; letter-spacing: 0.015em; text-shadow: 0 1px rgba(0, 0, 0, 0.18); transition: transform 160ms ease, opacity 160ms ease; }
.play-button:not(:disabled):hover { background: var(--blue-hover); transform: translateY(-1px); }
.play-button:not(:disabled):active { transform: translateY(1px); }
.play-button:disabled { cursor: not-allowed; opacity: 0.52; }
.join-note { min-height: 14px; margin: 5px 0 8px; color: var(--muted); font-size: 9px; text-align: center; }

.settings-panel { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.settings-panel summary { display: flex; align-items: center; justify-content: space-between; min-height: 34px; color: #43484c; cursor: pointer; font-size: 11px; font-weight: 700; list-style: none; }
.settings-panel summary::-webkit-details-marker { display: none; }
.settings-panel summary::before { content: "+"; width: 17px; color: var(--blue); font-size: 16px; font-weight: 400; }
.settings-panel[open] summary::before { content: "−"; }
.settings-panel summary > span { margin-right: auto; }
.settings-panel summary small { color: #858a8e; font-size: 9px; font-weight: 400; }
.toggle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 12px; padding: 2px 0 10px 17px; }
.toggle-grid label { display: flex; align-items: center; min-height: 25px; color: #555b60; cursor: pointer; font-size: 10px; }
.toggle-grid input { width: 14px; height: 14px; margin: 0 6px 0 0; accent-color: var(--blue); }
.controls-help { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px 12px; padding-top: 10px; color: #767c81; font-size: 9px; }
kbd { display: inline-block; min-width: 22px; padding: 2px 4px; border: 1px solid #b8bdc1; border-bottom-width: 2px; border-radius: 3px; background: #fff; color: #454a4f; font-family: inherit; font-size: 8px; font-weight: 700; text-align: center; }

.game-hud { position: fixed; inset: 0; z-index: 10; color: var(--game-text); pointer-events: none; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85); }
.score-panel { position: absolute; top: 16px; left: 14px; display: grid; gap: 2px; font-size: 12px; }
.score-panel > strong { font-size: 17px; }
.score-panel > span { color: rgba(243, 245, 247, 0.82); }
.score-panel b { font-weight: 500; }
.leaderboard-panel { position: absolute; top: 0; right: 0; width: 215px; min-height: 66px; padding: 11px 13px 12px; background: rgba(0, 0, 0, 0.32); }
.leaderboard-panel header, .minimap-panel header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.leaderboard-panel header strong { font-size: 14px; }
.leaderboard-panel header span, .minimap-panel header span { overflow: hidden; color: rgba(255, 255, 255, 0.62); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-list { display: grid; gap: 1px; margin: 7px 0 0; padding: 0; list-style: none; counter-reset: rank; }
.leaderboard-list li { display: grid; grid-template-columns: 15px 6px minmax(0, 1fr) auto; align-items: center; gap: 5px; min-height: 17px; color: rgba(255, 255, 255, 0.86); font-size: 10px; counter-increment: rank; }
.leaderboard-list li::before { content: counter(rank) "."; color: rgba(255, 255, 255, 0.52); text-align: right; }
.leaderboard-list .player-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--player-color, #fff); }
.leaderboard-list .player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-list strong { font-size: 9px; font-weight: 500; }
.leaderboard-list li.is-me { color: #66bfff; font-weight: 700; }
.leaderboard-list li.empty { display: block; color: rgba(255, 255, 255, 0.55); }
.leaderboard-list li.empty::before { content: none; }
.minimap-panel { position: absolute; bottom: 14px; left: 14px; width: 124px; padding: 7px; background: rgba(0, 0, 0, 0.32); }
.minimap-panel header strong { font-size: 9px; }
#minimap { display: block; width: 110px; height: 82px; margin-top: 5px; background: rgba(0, 0, 0, 0.25); }
.network-panel { position: absolute; right: 14px; bottom: 14px; display: grid; justify-items: end; gap: 2px; color: rgba(255, 255, 255, 0.8); font-size: 11px; }
.network-panel b { color: #fff; font-weight: 500; }
.escape-hint { position: absolute; top: 13px; left: 50%; color: rgba(255, 255, 255, 0.48); font-size: 9px; transform: translateX(-50%); }
.escape-hint kbd { border-color: rgba(255, 255, 255, 0.28); border-bottom-width: 1px; background: rgba(0, 0, 0, 0.24); color: rgba(255, 255, 255, 0.68); }

.result-screen { z-index: 30; }
.result-panel { padding: 20px; }
.result-panel h2 { margin: 0 0 4px; font-size: 24px; }
.result-panel > p { margin: 0 0 15px; color: var(--muted); font-size: 11px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 0 0 14px; border: 1px solid var(--line); background: var(--line); }
.result-stats div { padding: 10px 8px; background: #fff; }
.result-stats dt { color: var(--muted); font-size: 9px; }
.result-stats dd { margin: 3px 0 0; font-size: 17px; font-weight: 700; }
.secondary-button { width: 100%; height: 34px; margin-top: 7px; border: 1px solid #b8bdc1; border-radius: 4px; background: #fff; color: #555b60; cursor: pointer; font-size: 10px; transition: transform 160ms ease, opacity 160ms ease; }
.secondary-button:hover { color: #22272b; }
.secondary-button:active { transform: translateY(1px); }

.mobile-controls { position: fixed; inset: 0; z-index: 14; display: none; pointer-events: none; }
.mobile-menu-button { position: absolute; top: 93px; left: max(9px, env(safe-area-inset-left)); min-width: 48px; height: 28px; border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 4px; background: rgba(0, 0, 0, 0.38); color: rgba(255, 255, 255, 0.8); font-size: 8px; font-weight: 700; pointer-events: auto; }
.mobile-zoom { position: absolute; top: 130px; left: max(10px, env(safe-area-inset-left)); display: grid; gap: 7px; pointer-events: auto; }
.mobile-zoom button { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 1px solid rgba(255, 255, 255, 0.38); border-radius: 50%; background: rgba(0, 0, 0, 0.4); color: #fff; font-size: 22px; font-weight: 500; line-height: 1; touch-action: none; transition: transform 160ms ease, opacity 160ms ease; }
.mobile-zoom button:active, .mobile-zoom button.is-active { transform: scale(0.92); background: rgba(40, 127, 192, 0.58); }
.joystick { position: absolute; left: max(15px, env(safe-area-inset-left)); bottom: max(15px, env(safe-area-inset-bottom)); display: grid; place-items: center; width: 106px; height: 106px; pointer-events: auto; touch-action: none; }
.joystick-ring { display: grid; place-items: center; width: 100%; height: 100%; border: 2px solid rgba(255, 255, 255, 0.3); border-radius: 50%; background: rgba(0, 0, 0, 0.24); }
.joystick-knob { width: 43px; height: 43px; border: 2px solid rgba(255, 255, 255, 0.58); border-radius: 50%; background: rgba(40, 127, 192, 0.52); transform: translate(0, 0); transition: transform 160ms ease, opacity 160ms ease; }
.joystick.is-active .joystick-knob { transition: none; }
.mobile-actions { position: absolute; right: max(15px, env(safe-area-inset-right)); bottom: max(17px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 10px; pointer-events: auto; }
.mobile-actions button { display: grid; place-items: center; gap: 1px; width: 67px; height: 67px; border: 2px solid rgba(255, 255, 255, 0.36); border-radius: 50%; background: rgba(0, 0, 0, 0.36); color: #fff; font-size: 8px; font-weight: 700; touch-action: manipulation; transition: transform 160ms ease, opacity 160ms ease; }
.mobile-actions button span { font-size: 17px; }
.mobile-actions .split-action { width: 82px; height: 82px; border-color: rgba(113, 193, 249, 0.72); background: rgba(40, 127, 192, 0.48); }
.mobile-actions button:active { transform: scale(0.94); }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; max-width: min(390px, calc(100% - 30px)); padding: 9px 13px; border-radius: 4px; background: rgba(0, 0, 0, 0.78); color: #fff; font-size: 10px; transform: translateX(-50%); animation: toast-in 160ms ease-out both; }

@keyframes screen-in { from { opacity: 0; transform: scale(0.99); } to { opacity: 1; transform: scale(1); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 5px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 520px) {
  .screen { display: block; padding: 10px; }
  .join-panel, .result-panel { margin: max(3vh, 12px) auto 0; }
  .join-header { min-height: 67px; padding: 12px 14px; }
  .wordmark h1 { font-size: 30px; }
  #joinForm { padding: 12px 14px 14px; }
  .quick-fields { grid-template-columns: minmax(0, 1.35fr) minmax(112px, 0.9fr); }
  .controls-help { gap: 6px 9px; }
  .score-panel { top: 8px; left: 8px; font-size: 9px; }
  .score-panel > strong { font-size: 13px; }
  .leaderboard-panel { width: 154px; padding: 7px 8px 8px; }
  .leaderboard-panel header strong { font-size: 11px; }
  .leaderboard-list { margin-top: 4px; }
  .leaderboard-list li { grid-template-columns: 12px 4px minmax(0, 1fr) auto; gap: 3px; min-height: 14px; font-size: 8px; }
  .leaderboard-list strong { font-size: 7px; }
  .minimap-panel { bottom: 8px; left: 8px; width: 106px; padding: 5px; }
  .joystick-enabled .minimap-panel { bottom: 132px; }
  #minimap { width: 96px; height: 68px; }
  .network-panel { right: 8px; bottom: 116px; font-size: 9px; }
  .escape-hint { display: none; }
  .toast { bottom: 130px; }
}

@media (max-width: 350px) {
  .quick-fields { grid-template-columns: 1fr; }
  .toggle-grid { grid-template-columns: 1fr; }
  .join-panel { margin-top: 5px; }
}

@media (pointer: coarse), (max-width: 900px) and (hover: none) { .mobile-controls:not([hidden]) { display: block; } }
.touch-capable .mobile-controls:not([hidden]) { display: block; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
