:root {
  color-scheme: dark;
  --ink: #f9f1ff;
  --muted: #b6aec4;
  --panel: #21142c;
  --panel-2: #101925;
  --stroke: #61416b;
  --pink: #ff5d96;
  --green: #61f0a8;
  --amber: #ffc857;
  --danger: #ff4f64;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 18% 18%, rgba(97, 240, 168, 0.14), transparent 18rem),
    radial-gradient(circle at 82% 8%, rgba(255, 93, 150, 0.18), transparent 20rem),
    linear-gradient(145deg, #0a0e1a 0%, #171026 44%, #071622 100%);
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0 20px;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 14px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr) minmax(240px, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 72px;
}

.brand,
.room-tools,
.scoreboard,
.control-pill,
.touch-controls {
  background: rgba(16, 25, 37, 0.86);
  border: 2px solid var(--stroke);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  min-width: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  background:
    linear-gradient(var(--pink), var(--pink)) 9px 4px / 14px 4px no-repeat,
    linear-gradient(var(--pink), var(--pink)) 6px 8px / 20px 16px no-repeat,
    linear-gradient(#16111b, #16111b) 11px 12px / 4px 4px no-repeat,
    linear-gradient(#16111b, #16111b) 20px 12px / 4px 4px no-repeat,
    linear-gradient(var(--green), var(--green)) 7px 25px / 6px 4px no-repeat,
    linear-gradient(var(--green), var(--green)) 20px 25px / 6px 4px no-repeat;
  image-rendering: pixelated;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.2rem, 3vw, 2.1rem);
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand p,
.title-lockup p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.scoreboard {
  min-height: 72px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.score-slot {
  min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.score-slot.empty {
  display: block;
  text-align: center;
  color: var(--muted);
}

.score-avatar {
  width: 30px;
  height: 30px;
  image-rendering: pixelated;
}

.score-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-value {
  color: var(--amber);
  font-size: 1.4rem;
}

.score-vs {
  color: var(--green);
  font-size: 0.86rem;
}

.room-tools {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
}

.room-tools input,
.join-card input {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: #0b1019;
  border: 2px solid #3f304b;
  outline: none;
  padding: 10px 12px;
}

.room-tools input:focus,
.join-card input:focus {
  border-color: var(--green);
}

.room-tools button,
.join-card button,
#ready-button {
  color: #120d16;
  background: var(--green);
  border: 0;
  padding: 10px 14px;
  min-height: 42px;
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}

.room-tools button:disabled,
.join-card button:disabled,
#ready-button:disabled {
  cursor: not-allowed;
  color: #756d7a;
  background: #302837;
}

.arena-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 0;
  border: 3px solid #7b4f86;
  background: #050914;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.5), 0 18px 44px rgba(0, 0, 0, 0.32);
  overflow: hidden;
}

#game {
  width: 100%;
  height: 100%;
  min-height: 0;
}

#game canvas {
  display: block;
  image-rendering: pixelated;
}

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  opacity: 0.13;
  background: repeating-linear-gradient(0deg, transparent 0 5px, #ffffff 5px 6px);
  mix-blend-mode: overlay;
}

.status-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  width: min(380px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 14px;
  color: var(--ink);
  text-align: center;
  background: rgba(9, 12, 22, 0.82);
  border: 2px solid rgba(249, 241, 255, 0.18);
}

.status-panel.is-compact {
  left: 16px;
  top: auto;
  bottom: 16px;
  width: min(460px, calc(100% - 32px));
  transform: none;
  justify-items: start;
  gap: 4px;
  padding: 10px 12px;
  text-align: left;
  pointer-events: none;
}

.status-panel.is-compact #ready-button {
  display: none;
}

.status-panel strong {
  color: var(--green);
  font-size: 1.35rem;
  text-transform: uppercase;
}

.status-panel span {
  color: var(--muted);
  font-size: 0.86rem;
}

.controls-row {
  display: grid;
  gap: 10px;
}

.keyboard-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.control-pill {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  color: var(--muted);
}

kbd {
  min-width: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  color: var(--ink);
  background: #1b1025;
  border: 2px solid #4c3658;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.32);
}

#ready-button {
  justify-self: center;
  min-width: 190px;
  border: 2px solid #152318;
}

#ready-button.is-ready {
  background: var(--amber);
}

.touch-controls {
  display: none;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 10px;
  padding: 10px;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-key {
  min-width: 0;
  min-height: 64px;
  color: var(--ink);
  background: #1b1025;
  border: 2px solid #4c3658;
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.32);
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.touch-key-space {
  color: #120d16;
  background: var(--green);
  border-color: #214d38;
}

.touch-key.is-active {
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.32);
  filter: brightness(1.18);
}

.join-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 6, 14, 0.78);
  backdrop-filter: blur(4px);
}

.join-overlay.hidden {
  display: none;
}

.join-card {
  width: min(520px, 100%);
  display: grid;
  gap: 12px;
  padding: 18px;
  background: var(--panel);
  border: 3px solid #895f93;
  box-shadow: 0 0 0 4px #05070f, 0 24px 60px rgba(0, 0, 0, 0.45);
}

.title-lockup {
  display: grid;
  grid-template-columns: 68px 1fr 68px;
  gap: 12px;
  align-items: center;
  text-align: center;
}

.title-lockup img {
  width: 68px;
  height: 68px;
  image-rendering: pixelated;
}

.title-lockup h2 {
  margin: 0;
  font-size: clamp(1.7rem, 7vw, 3rem);
  line-height: 1;
  text-transform: uppercase;
}

.join-card label {
  color: var(--green);
  text-transform: uppercase;
  font-weight: 700;
}

.join-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
}

@media (max-width: 860px) {
  .shell {
    width: min(100vw - 18px, 760px);
    padding-top: 9px;
    gap: 9px;
  }

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

  .room-tools {
    grid-template-columns: 1fr;
  }

  .keyboard-hints {
    display: none;
  }

  .touch-controls {
    display: grid;
  }

  .arena-wrap {
    border-width: 2px;
  }

  .status-panel.is-compact {
    left: 8px;
    top: 8px;
    bottom: auto;
    width: auto;
    max-width: calc(100% - 16px);
    padding: 6px 8px;
    gap: 0;
  }

  .status-panel.is-compact strong {
    font-size: 0.78rem;
    line-height: 1;
  }

  .status-panel.is-compact span {
    display: none;
  }
}

@media (max-width: 520px) {
  .scoreboard {
    grid-template-columns: 1fr;
  }

  .score-vs {
    display: none;
  }

  .title-lockup {
    grid-template-columns: 48px 1fr 48px;
  }

  .title-lockup img {
    width: 48px;
    height: 48px;
  }

  .status-panel {
    width: min(320px, calc(100% - 24px));
    padding: 10px;
  }

  .status-panel strong {
    font-size: 1.05rem;
  }

  .touch-controls {
    gap: 7px;
    padding: 8px;
  }

  .touch-key {
    min-height: 56px;
    padding: 8px 6px;
  }
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}
