:root {
  color-scheme: dark;
  --panel-bg: linear-gradient(180deg, rgba(6, 12, 22, 0.9), rgba(8, 16, 28, 0.76));
  --panel-border: rgba(152, 186, 255, 0.2);
  --text: #eff6ff;
  --muted: #a7bddb;
  --blue: #4ec9ff;
  --orange: #ff8c77;
  --accent: #8fd6ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(32, 78, 138, 0.28), transparent 42%),
    radial-gradient(circle at bottom, rgba(14, 90, 54, 0.22), transparent 34%),
    #051019;
  color: var(--text);
  font-family: Inter, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.18;
  pointer-events: none;
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.topbar,
.topbar-actions,
.hud-strip,
.invite-row,
.field-grid,
.action-cluster,
.settings-grid,
.player-head,
.stat-row,
.panel-head,
.invite-head {
  display: flex;
}

.topbar {
  position: absolute;
  inset: 16px 20px auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 5;
}

.back-link,
.ghost-btn,
.status-pill,
.panel,
.hud-band,
.touch-controls button {
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 34px rgba(1, 6, 14, 0.34);
  backdrop-filter: blur(12px);
}

.back-link,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(7, 14, 24, 0.74);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}

.brand-block {
  min-width: 0;
}

.brand-block strong,
.panel-head h1,
.panel-head h2,
.setup-panel h1,
.info-panel h2 {
  font-family: "Space Grotesk", Inter, sans-serif;
}

.eyebrow,
.label,
.mini-status,
.helper-copy,
.status-copy,
.help-block p,
.player-role,
.event-time {
  color: var(--muted);
}

.eyebrow,
.label {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand-block .eyebrow {
  margin-bottom: 2px;
}

.brand-block strong {
  display: block;
  font-size: 1.1rem;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(7, 14, 24, 0.82);
  font-weight: 700;
}

.status-pill[data-tone='online'] {
  border-color: rgba(112, 255, 183, 0.34);
  color: #8ffbc7;
}

.status-pill[data-tone='busy'] {
  border-color: rgba(255, 214, 102, 0.34);
  color: #ffe18d;
}

.status-pill[data-tone='offline'] {
  color: #d8e6fb;
}

.status-pill.ghost {
  color: #d3e7ff;
}

.hud-band,
.panel {
  background: var(--panel-bg);
}

.hud-band {
  position: absolute;
  left: 50%;
  top: 82px;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 420px));
  min-width: min(680px, calc(100vw - 440px));
  padding: 14px 18px;
  border-radius: 24px;
  z-index: 4;
}

.score-chip {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  font-size: clamp(1.35rem, 2vw, 1.85rem);
  font-weight: 800;
}

.team {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.98rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.team.blue {
  color: var(--blue);
  justify-self: start;
}

.team.orange {
  color: var(--orange);
  justify-self: end;
}

.hud-strip {
  margin-top: 8px;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.92rem;
}

.status-copy {
  margin: 10px 0 0;
  line-height: 1.5;
}

.panel {
  position: absolute;
  top: 184px;
  width: min(340px, calc(100vw - 40px));
  padding: 18px;
  border-radius: 26px;
  z-index: 4;
  display: grid;
  gap: 16px;
  transition: transform 180ms ease, opacity 180ms ease;
}

.setup-panel {
  left: 20px;
}

.info-panel {
  right: 20px;
}

.panel.panel-hidden {
  opacity: 0;
  pointer-events: none;
}

.setup-panel.panel-hidden {
  transform: translateX(calc(-100% - 18px));
}

.info-panel.panel-hidden {
  transform: translateX(calc(100% + 18px));
}

.panel-head {
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.setup-panel h1,
.info-panel h2 {
  margin: 0;
  font-size: 1.3rem;
}

.field-grid,
.settings-grid {
  flex-direction: column;
  gap: 12px;
}

.field-grid label,
.advanced-panel label,
.slider-field,
.toggle-field {
  display: grid;
  gap: 8px;
}

label span,
.mini-status {
  font-size: 0.9rem;
}

input,
button,
summary {
  border-radius: 16px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid rgba(122, 158, 219, 0.22);
  background: rgba(4, 10, 18, 0.78);
  color: var(--text);
  padding: 0.9rem 1rem;
}

input::placeholder {
  color: rgba(208, 224, 245, 0.5);
}

.action-cluster {
  flex-wrap: wrap;
  gap: 10px;
}

button {
  min-height: 46px;
  padding: 0 16px;
  background: rgba(7, 14, 24, 0.82);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

button.primary {
  background: linear-gradient(135deg, rgba(42, 142, 255, 0.92), rgba(102, 203, 255, 0.84));
  color: #03111f;
}

button.secondary {
  background: rgba(9, 20, 32, 0.92);
}

button:hover {
  transform: translateY(-1px);
}

.invite-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: 20px;
  background: rgba(7, 14, 24, 0.64);
  border: 1px solid rgba(122, 158, 219, 0.18);
}

.invite-head,
.invite-row {
  align-items: center;
  gap: 10px;
}

.invite-row {
  flex-wrap: wrap;
}

.invite-row input {
  flex: 1 1 220px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.toggle-field button {
  width: 100%;
}

.advanced-panel {
  padding-top: 4px;
}

.advanced-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
}

.player-cards,
.event-list {
  display: grid;
  gap: 12px;
}

.player-card,
.event-card,
.help-block {
  padding: 14px 15px;
  border-radius: 18px;
  background: rgba(5, 12, 21, 0.72);
  border: 1px solid rgba(122, 158, 219, 0.14);
}

.player-name {
  font-weight: 800;
  font-size: 1rem;
}

.player-role {
  font-size: 0.86rem;
}

.player-head {
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.inline-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(12, 23, 39, 0.82);
  border: 1px solid rgba(122, 158, 219, 0.18);
  font-size: 0.78rem;
  font-weight: 700;
}

.player-stats {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.stat-row {
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
}

.meter {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(78, 201, 255, 0.92), rgba(162, 233, 255, 0.92));
}

.meter-fill.orange {
  background: linear-gradient(90deg, rgba(255, 140, 119, 0.92), rgba(255, 190, 132, 0.92));
}

.meter-fill.boost {
  background: linear-gradient(90deg, rgba(255, 210, 92, 0.92), rgba(255, 240, 158, 0.92));
}

.event-card {
  display: grid;
  gap: 6px;
}

.event-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.event-title {
  font-weight: 800;
}

.event-card p,
.help-block p {
  margin: 0;
  line-height: 1.5;
}

.help-block {
  gap: 8px;
}

.touch-controls {
  position: absolute;
  inset: auto 14px 14px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  z-index: 4;
}

.left-pad,
.right-pad {
  display: grid;
  gap: 8px;
}

.left-pad {
  grid-template-columns: repeat(3, 56px);
  grid-template-areas:
    '. up .'
    'left down right';
}

.left-pad button[data-key='w'] { grid-area: up; }
.left-pad button[data-key='a'] { grid-area: left; }
.left-pad button[data-key='s'] { grid-area: down; }
.left-pad button[data-key='d'] { grid-area: right; }

.touch-controls button {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: rgba(5, 12, 21, 0.8);
  color: #f5fbff;
  font-weight: 800;
}

.right-pad button {
  width: 102px;
}

.hidden {
  display: none !important;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(18px);
  min-width: min(86vw, 420px);
  max-width: min(86vw, 520px);
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(5, 12, 21, 0.92);
  border: 1px solid rgba(122, 158, 219, 0.22);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  z-index: 6;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1200px) {
  .hud-band {
    width: min(760px, calc(100vw - 40px));
    min-width: 0;
  }

  .panel {
    top: 220px;
    width: min(320px, calc(100vw - 40px));
  }
}

@media (max-width: 980px) {
  .topbar {
    inset: 12px 12px auto;
    flex-wrap: wrap;
  }

  .hud-band {
    top: 128px;
    width: calc(100vw - 24px);
  }

  .panel {
    top: auto;
    bottom: 86px;
    width: calc(100vw - 24px);
    max-height: min(58vh, 520px);
    overflow: auto;
  }

  .setup-panel {
    left: 12px;
  }

  .info-panel {
    right: 12px;
  }

  .setup-panel.panel-hidden,
  .info-panel.panel-hidden {
    transform: translateY(calc(100% + 20px));
  }
}

@media (max-width: 720px) {
  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions > * {
    flex: 1 1 140px;
  }

  .score-chip {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 8px;
  }

  .team.blue,
  .team.orange {
    justify-self: center;
  }

  .hud-strip {
    font-size: 0.84rem;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .touch-controls {
    bottom: 16px;
  }
}
