:root {
  --ink: #121614;
  --muted: #68706b;
  --paper: #f5f6f2;
  --panel: #ffffff;
  --line: #dce0da;
  --acid: #d6ff38;
  --acid-dark: #b6df1c;
  --red: #ef4d45;
  --red-dark: #c52f2a;
  --blue: #3484ee;
  --blue-dark: #1762c4;
  --court: #2d8b61;
  --court-dark: #226d4c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--paper); }
button, input, select { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(18, 22, 20, .25); outline-offset: 2px; }
.is-hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.topbar { height: 68px; padding: 0 clamp(18px, 4vw, 64px); background: var(--ink); color: white; display: flex; align-items: center; justify-content: space-between; }
.brand { color: white; text-decoration: none; display: flex; align-items: center; gap: 11px; font-weight: 900; font-size: 15px; }
.brand img { border-radius: 7px; }
.connection { display: flex; align-items: center; gap: 8px; color: #aeb6b0; font-size: 12px; font-weight: 750; text-transform: uppercase; }
.connection span, .status-dot { width: 8px; height: 8px; background: #f1b544; border-radius: 50%; }
.connection.online span, .status-dot { background: var(--acid); box-shadow: 0 0 0 3px rgba(214,255,56,.13); }

.home-view { min-height: calc(100vh - 68px); display: grid; grid-template-columns: minmax(0, 1fr) minmax(390px, 520px); align-items: center; gap: clamp(40px, 7vw, 110px); padding: 48px clamp(22px, 7vw, 120px); }
.eyebrow { margin: 0 0 14px; color: #58605b; text-transform: uppercase; font-size: 11px; font-weight: 850; }
.public-browser { align-self: stretch; min-height: 560px; display: flex; flex-direction: column; min-width: 0; }
.public-browser-heading { min-height: 90px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding-bottom: 18px; border-bottom: 2px solid var(--ink); }
.public-browser-heading .eyebrow { margin-bottom: 4px; }
.public-browser-heading h1 { margin: 0; font-size: clamp(30px, 4vw, 52px); line-height: 1; text-transform: uppercase; }
.public-browser-heading > span { color: var(--muted); font-size: 10px; font-weight: 850; text-transform: uppercase; padding-bottom: 4px; }
.public-room-list { flex: 1; min-height: 390px; max-height: 590px; overflow-y: auto; border-bottom: 1px solid var(--line); }
.public-empty { height: 100%; min-height: 390px; display: grid; place-content: center; justify-items: center; color: var(--muted); text-align: center; }
.public-empty strong { margin-top: 14px; color: var(--ink); font-size: 14px; }
.public-empty > span:last-child { margin-top: 4px; font-size: 11px; }
.empty-pitch { position: relative; display: block; width: 90px; height: 48px; border: 2px solid #b9c0ba; }
.empty-pitch::before { content: ""; position: absolute; left: 50%; top: 0; height: 100%; border-left: 1px solid #b9c0ba; }
.empty-pitch i { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%); border: 1px solid #b9c0ba; border-radius: 50%; }
.public-room { min-height: 84px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 18px; align-items: center; padding: 13px 10px; border-bottom: 1px solid var(--line); }
.public-room:hover { background: white; }
.public-room-main { min-width: 0; }
.public-room-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.public-room-meta { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 7px; color: var(--muted); font-size: 9px; text-transform: uppercase; font-weight: 750; }
.public-room-status { min-width: 70px; text-align: right; }
.public-room-status strong { display: block; font-size: 12px; font-variant-numeric: tabular-nums; }
.public-room-status span { color: var(--muted); font-size: 8px; font-weight: 800; text-transform: uppercase; }
.public-join { min-width: 72px; height: 36px; border: 1px solid var(--ink); border-radius: 3px; background: transparent; font-size: 10px; font-weight: 850; }
.public-join:hover { background: var(--ink); color: white; }

.setup-panel, .join-panel { position: relative; z-index: 1; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 18px 60px rgba(18, 22, 20, .08); padding: clamp(24px, 3vw, 38px); border-radius: 6px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 28px; }
.panel-heading h2 { margin: 0; font-size: 28px; }
.panel-heading .eyebrow { margin-bottom: 5px; }
.step-badge { color: #b5bab6; font-size: 12px; font-weight: 800; border: 1px solid var(--line); padding: 7px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field > span:first-child, .select-setting > span { font-size: 11px; font-weight: 850; text-transform: uppercase; color: #49504c; }
input, select { width: 100%; height: 44px; color: var(--ink); border: 1px solid #cdd2cd; background: white; border-radius: 3px; padding: 0 12px; }
input::placeholder { color: #999f9a; }
.segments { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid #cdd2cd; border-radius: 3px; padding: 3px; }
.segments.two { grid-template-columns: repeat(2, 1fr); }
.segments input { position: absolute; opacity: 0; pointer-events: none; }
.segments label { text-align: center; padding: 8px 3px; color: var(--muted); font-size: 12px; font-weight: 750; cursor: pointer; }
.segments input:checked + label { background: var(--ink); color: white; border-radius: 2px; }
.primary-button, .start-button { width: 100%; border: 0; border-radius: 3px; background: var(--acid); color: var(--ink); min-height: 50px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; font-weight: 900; }
.primary-button:hover, .start-button:hover { background: var(--acid-dark); }
.join-divider { display: flex; align-items: center; gap: 12px; margin: 19px 0 13px; color: #8a918c; font-size: 11px; text-transform: uppercase; }
.join-divider::before, .join-divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.join-row { display: grid; grid-template-columns: 1fr 92px; gap: 8px; }
.join-row input { text-transform: uppercase; font-weight: 800; }
.secondary-button { border: 1px solid var(--ink); background: white; font-weight: 800; border-radius: 3px; }
.secondary-button:hover { background: var(--ink); color: white; }
.form-error { min-height: 16px; color: #bd2922; font-size: 12px; margin: 9px 0 0; }

.join-view { min-height: calc(100vh - 68px); display: grid; place-items: center; padding: 28px; background: var(--court-dark); background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px); background-size: 48px 48px; }
.join-panel { width: min(440px, 100%); text-align: center; }
.join-panel > img { border-radius: 10px; margin-bottom: 20px; }
.join-panel h1 { font-size: 29px; margin: 0 0 9px; }
.join-panel > p:not(.eyebrow):not(.form-error) { color: var(--muted); margin: 0 0 26px; }
.join-panel .field { text-align: left; }
.join-panel > a { display: inline-block; color: var(--muted); font-size: 13px; margin-top: 18px; }

.room-view { min-height: calc(100vh - 68px); padding: 22px clamp(14px, 3vw, 46px) 32px; }
.room-toolbar { max-width: 1500px; margin: 0 auto 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.room-identity { display: flex; align-items: center; gap: 12px; }
.room-identity small { display: block; font-size: 9px; font-weight: 850; color: var(--muted); }
.room-identity strong { font-size: 16px; }
.room-actions { display: flex; gap: 8px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); background: white; border-radius: 3px; font-size: 20px; }
.invite-button { height: 42px; border: 1px solid var(--line); background: white; border-radius: 3px; display: flex; align-items: center; gap: 12px; padding: 0 12px; font-size: 12px; }
.invite-button strong { border-left: 1px solid var(--line); padding-left: 12px; letter-spacing: 1px; }
.copy-icon { color: var(--muted); }
.game-layout { max-width: 1500px; margin: auto; display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 18px; align-items: start; }
.game-column { min-width: 0; }
.scoreboard { height: 70px; display: grid; grid-template-columns: 1fr 150px 1fr; background: var(--ink); color: white; border-radius: 5px 5px 0 0; overflow: hidden; }
.team-score { display: flex; align-items: center; gap: 18px; padding: 0 30px; font-size: 12px; font-weight: 850; }
.team-score strong { font-size: 34px; }
.team-score.red { justify-content: flex-end; background: linear-gradient(90deg, rgba(239,77,69,.13), transparent); }
.team-score.blue { justify-content: flex-start; background: linear-gradient(90deg, transparent, rgba(52,132,238,.13)); }
.match-clock { display: flex; flex-direction: column; align-items: center; justify-content: center; border-inline: 1px solid #343936; }
.match-clock small { color: var(--acid); font-weight: 900; font-size: 9px; }
.match-clock strong { font-size: 23px; font-variant-numeric: tabular-nums; }
.court-wrap { position: relative; width: 100%; aspect-ratio: 1.84; min-height: 300px; max-height: calc(100vh - 270px); background: var(--court-dark); overflow: hidden; box-shadow: inset 0 0 50px rgba(0,0,0,.12); }
#gameCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
.court-message { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(340px, calc(100% - 40px)); color: white; background: rgba(16,20,18,.9); border-left: 4px solid var(--acid); padding: 16px 18px; text-align: left; pointer-events: none; }
.court-message strong, .court-message span { display: block; }
.court-message strong { font-size: 15px; }
.court-message span { margin-top: 5px; color: #bbc4be; font-size: 11px; line-height: 1.4; }
.goal-flash { position: absolute; inset: 0; display: grid; place-items: center; color: white; font-size: clamp(50px, 9vw, 110px); font-weight: 950; }
.goal-flash[data-team="red"] { background: rgba(239,77,69,.9); }
.goal-flash[data-team="blue"] { background: rgba(52,132,238,.9); }
.powerup-bar { min-height: 60px; display: flex; align-items: center; gap: 14px; padding: 9px 18px; background: var(--ink); color: white; }
.powerup-bar-label { flex-shrink: 0; color: var(--acid); font-size: 9px; font-weight: 850; text-transform: uppercase; }
.powerup-slots, .powerup-active { display: flex; gap: 8px; }
.powerup-slot { position: relative; min-width: 42px; height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 9px; border: 1px solid #343936; border-radius: 4px; background: #1b201d; color: white; }
.powerup-slot .powerup-slot-icon { min-width: 18px; font-size: 17px; line-height: 1; }
.powerup-slot strong { font-size: 10px; font-weight: 800; white-space: nowrap; }
.powerup-slot small { position: absolute; top: -6px; left: -6px; width: 15px; height: 15px; display: grid; place-items: center; border-radius: 3px; background: #343936; color: #cfd6d1; font-size: 8px; font-weight: 850; }
.powerup-slot:disabled { opacity: .4; cursor: default; }
.powerup-slot.filled { border-color: var(--tint); box-shadow: 0 0 14px -7px var(--tint); }
.powerup-slot.filled small { background: var(--tint); color: var(--ink); }
.powerup-slot.filled:hover { background: #242a27; }
.powerup-chip { position: relative; overflow: hidden; padding: 6px 9px; border: 1px solid var(--tint); border-radius: 3px; background: #1b201d; font-size: 9px; font-weight: 800; white-space: nowrap; }
.powerup-chip::after { content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 2px; background: var(--tint); transform-origin: left; animation: powerup-deplete var(--life) linear forwards; }
@keyframes powerup-deplete { to { transform: scaleX(0); } }
.powerup-bar-hint { margin-left: auto; color: #8b938d; font-size: 9px; font-weight: 800; text-transform: uppercase; }
.touch-powerups { display: none; }
.game-footer { min-height: 76px; padding: 11px 18px; display: flex; align-items: center; gap: 24px; background: white; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 5px 5px; }
.control-hint { display: flex; align-items: center; gap: 9px; }
.control-hint > span:last-child { display: flex; flex-direction: column; }
.control-hint strong { font-size: 11px; }
.control-hint small { color: var(--muted); font-size: 9px; }
kbd { min-width: 19px; height: 19px; padding: 0 4px; display: inline-grid; place-items: center; border: 1px solid #cbd0cb; border-bottom-width: 2px; border-radius: 3px; background: #f5f6f2; font-size: 9px; font-family: inherit; font-weight: 850; }
.keys { display: flex; flex-direction: column; align-items: center; line-height: 0; }
.keys > span { display: flex; }
.space-key { min-width: 53px; }
.possession-note { margin-left: auto; font-size: 10px; font-weight: 850; text-transform: uppercase; color: var(--muted); }

.room-sidebar { min-height: 500px; background: white; border: 1px solid var(--line); border-radius: 5px; display: flex; flex-direction: column; overflow: hidden; }
.sidebar-tabs { height: 49px; display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.sidebar-tabs button { border: 0; border-bottom: 2px solid transparent; background: white; color: var(--muted); font-size: 11px; font-weight: 850; }
.sidebar-tabs button.active { color: var(--ink); border-bottom-color: var(--ink); }
.sidebar-tabs span { background: var(--paper); padding: 2px 6px; margin-left: 4px; border-radius: 20px; }
.tab-panel { padding: 14px; }
.team-block { margin-bottom: 15px; }
.team-heading { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; font-weight: 850; text-transform: uppercase; padding: 5px 3px; }
.team-heading i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; }
.red-block .team-heading i { background: var(--red); }
.blue-block .team-heading i { background: var(--blue); }
.roster { display: flex; flex-direction: column; gap: 5px; min-height: 42px; }
.roster:empty::after { content: "Empty slot"; height: 42px; border: 1px dashed var(--line); display: flex; align-items: center; padding: 0 12px; color: #a2a8a3; font-size: 11px; }
.player-row { height: 42px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); padding: 0 9px; border-radius: 3px; }
.player-avatar { width: 25px; height: 25px; display: grid; place-items: center; color: white; border-radius: 50%; font-size: 10px; font-weight: 900; }
.red-block .player-avatar { background: var(--red); }
.blue-block .player-avatar { background: var(--blue); }
.spectator-block .player-avatar { background: var(--muted); }
.player-row strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.player-row em { margin-left: auto; color: #838a85; font-size: 8px; font-style: normal; font-weight: 850; }
.team-move-actions { display: flex; gap: 5px; margin-left: 4px; }
.team-move-button { width: 20px; height: 20px; padding: 0; border: 2px solid white; border-radius: 50%; box-shadow: 0 0 0 1px #c8cdc8; }
.team-move-button.red { background: var(--red); }
.team-move-button.blue { background: var(--blue); }
.team-move-button:hover { box-shadow: 0 0 0 2px var(--ink); }
.player-row.own { border-color: #8a918b; }
.player-row:not(.locked) { cursor: pointer; }
.team-help { color: var(--muted); font-size: 10px; line-height: 1.4; text-align: center; margin: 20px 8px 0; }
.chat-panel { min-height: 430px; padding: 0; display: flex; flex-direction: column; }
.chat-messages { height: 382px; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); }
.chat-empty strong, .chat-empty span { display: block; }
.chat-empty strong { color: var(--ink); font-size: 12px; }
.chat-empty span { margin-top: 4px; font-size: 10px; }
.chat-message { min-width: 0; }
.chat-message-head { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.chat-team-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.chat-message[data-team="red"] .chat-team-dot { background: var(--red); }
.chat-message[data-team="blue"] .chat-team-dot { background: var(--blue); }
.chat-message-head strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.chat-message-head time { margin-left: auto; color: #929893; font-size: 8px; font-variant-numeric: tabular-nums; }
.chat-message p { margin: 0; color: #3f4641; font-size: 11px; line-height: 1.45; overflow-wrap: anywhere; }
.chat-message.own p { color: var(--ink); font-weight: 650; }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { height: 38px; min-width: 0; font-size: 11px; }
.chat-form button { border: 0; border-radius: 3px; background: var(--ink); color: white; padding: 0 13px; font-size: 10px; font-weight: 850; }
.chat-form button:hover { background: #2c332f; }
.sidebar-action { margin-top: auto; padding: 14px; border-top: 1px solid var(--line); }
.start-button:disabled { cursor: default; background: #e5e8e3; color: #939994; }
.settings-list { display: flex; flex-direction: column; gap: 18px; }
.settings-list > label { display: flex; flex-direction: column; gap: 7px; }
.settings-list label > span { display: flex; justify-content: space-between; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.settings-list output { color: var(--muted); }
input[type="range"] { appearance: none; height: 4px; background: #dfe3de; border: 0; padding: 0; border-radius: 0; accent-color: var(--ink); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--ink); }
.select-setting select { height: 36px; font-size: 11px; }
.host-lock { color: var(--muted); font-size: 10px; line-height: 1.4; margin-top: 20px; }
.touch-controls { display: none; }
.toast { position: fixed; left: 50%; bottom: 25px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: white; padding: 11px 16px; border-radius: 3px; font-size: 12px; transition: .2s; z-index: 10; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .home-view { grid-template-columns: 1fr; padding-block: 42px; }
  .public-browser { min-height: 420px; }
  .public-room-list, .public-empty { min-height: 300px; }
  .public-room-list { max-height: 420px; }
  .setup-panel { width: 100%; }
  .game-layout { grid-template-columns: 1fr; }
  .room-sidebar { min-height: 0; }
  .room-sidebar .tab-panel { max-height: none; }
}

@media (pointer: coarse), (max-width: 720px) {
  .topbar { height: 58px; }
  .room-view { padding: 12px 8px 24px; }
  .invite-button > span:first-child { display: none; }
  .scoreboard { height: 58px; grid-template-columns: 1fr 112px 1fr; }
  .team-score { padding: 0 12px; gap: 8px; }
  .team-score strong { font-size: 26px; }
  .court-wrap { min-height: 250px; max-height: none; }
  .game-footer, .powerup-bar { display: none; }
  .touch-powerups { display: flex; flex-direction: column-reverse; gap: 8px; }
  .powerup-slot.compact { min-width: 50px; width: 50px; height: 50px; justify-content: center; padding: 0; border-radius: 50%; }
  .powerup-slot.compact small { top: -2px; left: -2px; }
  .touch-controls { display: flex; justify-content: space-between; align-items: flex-end; padding: 14px 14px 2px; touch-action: none; }
  .touch-pad { width: 134px; height: 104px; display: grid; grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(2, 42px); gap: 5px; }
  .touch-pad button, .touch-kick { border: 1px solid #cdd2cd; background: white; box-shadow: 0 2px 0 #cdd2cd; font-weight: 900; user-select: none; -webkit-user-select: none; }
  .touch-pad button[data-key="up"] { grid-column: 2; }
  .touch-pad button[data-key="left"] { grid-column: 1; grid-row: 2; }
  .touch-pad button[data-key="down"] { grid-column: 2; grid-row: 2; }
  .touch-pad button[data-key="right"] { grid-column: 3; grid-row: 2; }
  .touch-kick { width: 76px; height: 76px; border-radius: 50%; background: var(--acid); }
}

@media (max-width: 560px) {
  .home-view { padding: 30px 15px; gap: 30px; }
  .public-browser { min-height: 380px; }
  .public-browser-heading h1 { font-size: 30px; }
  .public-room { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .public-room-status { display: none; }
  .setup-panel { padding: 21px 16px; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .field-wide { grid-column: auto; }
  .room-toolbar { align-items: center; }
  .room-identity small { display: none; }
  .scoreboard { grid-template-columns: 1fr 100px 1fr; }
  .team-score span { display: none; }
  .match-clock strong { font-size: 19px; }
  .court-message { padding: 12px; }
}
