:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --bg: #0f1412;
  --panel: rgba(19, 25, 23, 0.82);
  --panel-strong: rgba(27, 35, 32, 0.94);
  --line: rgba(238, 244, 233, 0.14);
  --text: #f2f7ed;
  --muted: #aab7ae;
  --green: #70d767;
  --lime: #d6f264;
  --red: #ef6249;
  --amber: #f2c35e;
  --cyan: #64c9d8;
  --violet: #a88cff;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  background:
    linear-gradient(rgba(15, 20, 18, 0.62), rgba(15, 20, 18, 0.78)),
    url("assets/arcade-bg.png") center / cover no-repeat fixed,
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    radial-gradient(circle at 16% 10%, rgba(100, 201, 216, 0.22), transparent 25rem),
    radial-gradient(circle at 88% 82%, rgba(239, 98, 73, 0.16), transparent 28rem),
    radial-gradient(circle at 48% 105%, rgba(214, 242, 100, 0.12), transparent 24rem),
    linear-gradient(145deg, #0f1412, #151817 52%, #101816);
  background-size:
    auto,
    cover,
    32px 32px,
    32px 32px,
    auto,
    auto,
    auto,
    auto;
  color: var(--text);
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(120deg, transparent 0 42%, rgba(255, 255, 255, 0.045) 50%, transparent 58%),
    radial-gradient(circle at center, transparent 0, rgba(0, 0, 0, 0.36) 72%);
  mix-blend-mode: screen;
}

button {
  min-width: 0;
  font: inherit;
  border: 1px solid var(--line);
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    rgba(242, 247, 237, 0.07);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

button:hover,
button:focus-visible {
  border-color: rgba(242, 195, 94, 0.78);
  background: rgba(242, 195, 94, 0.14);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 0 0 4px rgba(242, 195, 94, 0.08);
  outline: 2px solid rgba(242, 195, 94, 0.42);
  outline-offset: 2px;
}

button:active {
  transform: translateY(1px) scale(0.98);
}

.game-shell {
  position: relative;
  z-index: 1;
  width: min(96vw, 1180px);
  max-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 12px;
}

.game-shell::before {
  position: absolute;
  inset: 4px;
  z-index: -1;
  content: "";
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(15, 20, 18, 0.52), rgba(15, 20, 18, 0.26)),
    rgba(6, 9, 8, 0.18);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.045),
    0 30px 120px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(3px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #97ecf5;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(100, 201, 216, 0.42);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5.2vw, 3.8rem);
  line-height: 0.95;
  letter-spacing: 0;
  color: transparent;
  background: linear-gradient(110deg, #f2f7ed 0%, var(--lime) 42%, #97ecf5 92%);
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow: 0 16px 50px rgba(112, 215, 103, 0.22);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(500px, 0.96fr) 360px;
  gap: 12px;
  align-items: stretch;
  min-height: 0;
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 10px;
  min-width: 0;
  min-height: 0;
}

.icon-button {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 1.12rem;
  backdrop-filter: blur(10px);
}

.name-button {
  max-width: 128px;
  height: 46px;
  padding: 0 14px;
  overflow: hidden;
  color: #101411;
  background: linear-gradient(135deg, var(--lime), var(--green) 70%, #8ce5ee);
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button.is-muted {
  color: var(--muted);
  background: rgba(242, 247, 237, 0.04);
}

.hud {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.hud > div,
.settings,
.profile-board,
.player-card,
.leaderboard,
.controls {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 48%),
    var(--panel);
  border-radius: 8px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 18px 60px rgba(0, 0, 0, 0.28);
}

.hud > div::before,
.settings::before,
.profile-board::before,
.player-card::before,
.leaderboard::before,
.controls::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  content: "";
  background: linear-gradient(var(--cyan), var(--lime));
  opacity: 0.62;
}

.hud > div {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px 14px;
}

.label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0;
}

.hud strong {
  font-size: clamp(1.2rem, 2.4vw, 1.9rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(214, 242, 100, 0.16);
}

.settings {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 8px;
}

.profile-board {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 8px;
}

.player-card,
.leaderboard {
  padding: 12px 14px;
}

.player-card {
  display: grid;
  gap: 8px;
}

.player-card label,
.leaderboard-head h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0;
}

.player-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.player-row input {
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(238, 244, 233, 0.18);
  border-radius: 8px;
  color: var(--text);
  background: rgba(7, 11, 10, 0.42);
  font: inherit;
  outline: none;
}

.player-row input:focus {
  border-color: rgba(214, 242, 100, 0.62);
  box-shadow: 0 0 0 3px rgba(214, 242, 100, 0.1);
}

.player-row button {
  min-width: 64px;
  min-height: 40px;
  padding: 0 12px;
}

.leaderboard {
  display: grid;
  gap: 8px;
}

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

.leaderboard-head span {
  min-width: 42px;
  padding: 3px 8px;
  border: 1px solid rgba(100, 201, 216, 0.22);
  border-radius: 999px;
  color: #b9f3f8;
  background: rgba(100, 201, 216, 0.08);
  font-size: 0.72rem;
  font-weight: 750;
  text-align: center;
}

.leaderboard ol {
  display: grid;
  gap: 5px;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.username-dialog {
  width: min(92vw, 390px);
  padding: 0;
  border: 1px solid rgba(238, 244, 233, 0.18);
  border-radius: 10px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 46%),
    rgba(16, 22, 20, 0.96);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.52);
}

.username-dialog::backdrop {
  background: rgba(4, 8, 7, 0.66);
  backdrop-filter: blur(5px);
}

.username-modal {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.modal-eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.username-modal h2 {
  margin: 0;
  font-size: 1.6rem;
  line-height: 1;
}

.username-modal label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.username-modal input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(238, 244, 233, 0.18);
  border-radius: 8px;
  color: var(--text);
  background: rgba(7, 11, 10, 0.5);
  font: inherit;
  outline: none;
}

.username-modal input:focus {
  border-color: rgba(214, 242, 100, 0.68);
  box-shadow: 0 0 0 3px rgba(214, 242, 100, 0.11);
}

.username-modal input:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
}

#usernameHelp {
  min-height: 1.4em;
  margin: 0;
  color: #dbe4d9;
  font-size: 0.86rem;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal-actions button {
  min-height: 42px;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 26px;
  color: #dbe4d9;
  font-size: 0.88rem;
}

.leaderboard .rank {
  color: var(--amber);
  font-weight: 850;
}

.leaderboard .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard .score {
  color: var(--lime);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.segmented {
  min-width: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}

.segmented button {
  min-height: 38px;
  padding: 0 10px;
  color: var(--muted);
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.055);
}

.segmented button.is-active {
  color: #101411;
  border-color: rgba(214, 242, 100, 0.72);
  background: linear-gradient(135deg, var(--lime), var(--green) 70%, #8ce5ee);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 10px 26px rgba(112, 215, 103, 0.22);
  font-weight: 800;
}

.play-area {
  position: relative;
  width: 100%;
  height: min(68vh, calc(100vh - 184px));
  min-height: 460px;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(238, 244, 233, 0.2);
  border-radius: 8px;
  background: #111715;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    inset 0 0 50px rgba(214, 242, 100, 0.035),
    0 0 0 1px rgba(112, 215, 103, 0.08),
    0 28px 110px rgba(0, 0, 0, 0.46),
    0 0 44px rgba(100, 201, 216, 0.08);
  touch-action: none;
}

.play-area::before {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  content: "";
  border-radius: inherit;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.08), transparent 22%, transparent 78%, rgba(255, 255, 255, 0.06)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.16));
}

.play-area::after {
  position: absolute;
  inset: 10px;
  z-index: 1;
  pointer-events: none;
  content: "";
  border: 1px solid rgba(214, 242, 100, 0.1);
  border-radius: 6px;
  box-shadow:
    inset 0 0 22px rgba(100, 201, 216, 0.055),
    0 0 20px rgba(214, 242, 100, 0.045);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.flash {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: rgba(214, 242, 100, 0.08);
}

.flash.is-strong {
  background: rgba(242, 195, 94, 0.12);
}

.flash.is-active {
  animation: flash 150ms ease-out;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(circle at center, rgba(214, 242, 100, 0.11), transparent 18rem),
    rgba(10, 14, 13, 0.74);
  backdrop-filter: blur(7px) saturate(1.1);
}

.overlay.is-visible {
  display: grid;
}

.overlay h2 {
  max-width: 12ch;
  margin: 0;
  font-size: clamp(2.25rem, 10vw, 5.4rem);
  line-height: 0.95;
  letter-spacing: 0;
  color: transparent;
  background: linear-gradient(120deg, #ffffff, var(--lime) 52%, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow: 0 18px 60px rgba(214, 242, 100, 0.18);
}

.overlay p {
  min-height: 1.5em;
  max-width: 28rem;
  margin: 0;
  color: #dbe4d9;
  font-size: clamp(0.95rem, 3.6vw, 1.12rem);
}

.overlay button {
  min-width: 136px;
  min-height: 44px;
  padding: 0 18px;
  color: #101411;
  border-color: rgba(214, 242, 100, 0.84);
  background: linear-gradient(135deg, var(--lime), var(--green) 72%, #8ce5ee);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 16px 40px rgba(112, 215, 103, 0.25);
  font-weight: 800;
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
}

.hint {
  min-width: 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 650;
}

.dpad {
  width: 158px;
  height: 108px;
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 48px);
  gap: 6px;
}

.dpad button {
  width: 48px;
  height: 48px;
  font-weight: 800;
  color: #dff8dd;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    rgba(100, 201, 216, 0.08);
}

.dpad [data-dir="up"] {
  grid-column: 2;
}

.dpad [data-dir="left"] {
  grid-column: 1;
}

.dpad [data-dir="down"] {
  grid-column: 2;
}

.dpad [data-dir="right"] {
  grid-column: 3;
}

@keyframes flash {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@media (max-width: 620px) {
  body {
    place-items: start center;
  }

  .game-shell {
    width: 100vw;
    padding: 10px;
    gap: 10px;
  }

  .topbar {
    align-items: center;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .name-button {
    max-width: 104px;
    height: 42px;
  }

  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .hud > div {
    min-height: 58px;
    padding: 10px;
  }

  .settings,
  .profile-board,
  .controls {
    grid-template-columns: 1fr;
  }

  .dpad {
    justify-self: center;
  }
}

@media (max-width: 980px) {
  .game-shell {
    width: min(96vw, 760px);
    max-height: none;
    padding: 10px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-rows: auto;
  }

  .hud {
    grid-template-columns: repeat(4, 1fr);
  }

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

  .play-area {
    height: auto;
    min-height: 0;
  }
}

@media (max-width: 620px) {
  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .settings,
  .profile-board,
  .controls {
    grid-template-columns: 1fr;
  }
}
