:root {
  --bg: #050816;
  --bg-panel: rgba(13, 20, 39, 0.82);
  --bg-panel-strong: rgba(16, 26, 49, 0.94);
  --line: rgba(128, 176, 255, 0.16);
  --line-strong: rgba(128, 176, 255, 0.3);
  --text: #f4f8ff;
  --muted: #91a4ca;
  --accent: #5dd4ff;
  --accent-warm: #ffb357;
  --danger: #ff6177;
  --success: #69e7a4;
  --shadow: 0 24px 50px rgba(0, 0, 0, 0.34);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(93, 212, 255, 0.12), transparent 28%),
    radial-gradient(circle at 85% 15%, rgba(255, 179, 87, 0.14), transparent 25%),
    linear-gradient(180deg, #091022 0%, #040714 100%);
  color: var(--text);
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black, transparent 95%);
  pointer-events: none;
}

button,
input {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease,
    opacity 140ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.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;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  height: 100vh;
  padding: 22px;
}

.content-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  min-height: 0;
}

.content-shell.has-room {
  grid-template-columns: 320px minmax(0, 1fr);
}

.sidebar {
  background: linear-gradient(180deg, rgba(14, 22, 42, 0.96), rgba(8, 14, 30, 0.96));
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 20px 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-crew {
  flex: 1 1 auto;
  min-height: 0;
}

.sidebar-header h2,
.brand-block h1,
.hero-card h2,
.panel h2,
.app-header h2 {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.sidebar-kicker,
.eyebrow,
.label {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--muted);
}

.player-list {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.sidebar-card {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 22px;
  padding: 18px 16px;
}

.room-summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
}

.sidebar-stat strong {
  color: var(--text);
  text-align: right;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.icon-button:disabled {
  opacity: 0.28;
}

.room-code-button {
  width: 100%;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  appearance: none;
}

.room-code-button:hover:not(:disabled) {
  transform: none;
  box-shadow: none;
}

.player-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.player-item.local {
  border-color: rgba(93, 212, 255, 0.28);
  background: rgba(93, 212, 255, 0.08);
}

.player-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05);
}

.player-meta {
  min-width: 0;
}

.player-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-state {
  color: var(--muted);
  font-size: 0.85rem;
}

.player-host {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.72rem;
  background: rgba(255, 179, 87, 0.16);
  color: #ffe0b1;
}

.main-shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  min-width: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-block h1 {
  font-size: clamp(2.4rem, 4vw, 3.8rem);
  text-shadow: 0 8px 26px rgba(93, 212, 255, 0.18);
}

.header-brand {
  flex: 0 0 auto;
}

.header-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 12px;
  min-width: 0;
}

.pause-button {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  flex: 0 0 auto;
}

.metric-pill {
  min-width: 140px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(12, 19, 39, 0.88);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.metric-pill strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.35rem, 1.8vw, 2rem);
}

.score-display {
  display: flex !important;
  align-items: baseline;
  gap: 8px;
}

.score-target {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.score-pill strong {
  color: #ffffff;
}

.status-pill {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(12, 19, 39, 0.88);
  border: 1px solid var(--line);
  font-weight: 700;
}

.hero-screen,
.room-screen {
  flex: 1 1 auto;
  min-height: 0;
}

.hero-screen {
  display: grid;
  place-items: center;
}

.room-screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-card,
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.hero-card {
  width: min(720px, 100%);
  padding: 34px;
}

.menu-card {
  width: min(1080px, 100%);
  padding: 34px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.menu-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.menu-panel {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 24px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.create-panel .wide-button {
  margin-top: auto;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.stat-tile {
  padding: 18px;
  border-radius: 20px;
  background: rgba(9, 14, 28, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-tile span {
  color: var(--muted);
  font-size: 0.92rem;
}

.stat-tile strong {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
}

.field-error {
  margin: 12px 0 0;
  color: #ffb8c3;
  font-size: 0.92rem;
}

.hero-copy,
.panel-copy,
.hint,
#gameover-reason {
  color: var(--muted);
  line-height: 1.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

.field.compact {
  margin-top: 0;
}

.field span {
  color: var(--muted);
  font-size: 0.88rem;
}

input {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.24);
  color: var(--text);
  padding: 15px 16px;
  outline: none;
}

input:focus {
  border-color: rgba(93, 212, 255, 0.58);
  box-shadow: 0 0 0 4px rgba(93, 212, 255, 0.14);
}

.hero-actions,
.join-row,
.lobby-actions,
.gameover-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.hero-actions {
  margin-top: 18px;
}

.join-row {
  margin-top: 18px;
}

.join-row .field {
  flex: 1;
}

.menu-join-row {
  margin-top: auto;
  align-items: flex-end;
}

.menu-join-row .field {
  margin-top: 0;
}

.primary-button,
.secondary-button {
  border-radius: 18px;
  padding: 14px 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.wide-button {
  width: 100%;
  justify-content: center;
}

.primary-button {
  background: linear-gradient(135deg, #61d4ff, #2f8eff);
  color: #041426;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--line);
}

.score-card strong,
.gameover-score strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.4rem, 2vw, 2.3rem);
}

.panel-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.panel {
  padding: 22px;
}

.lobby-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
}

.lobby-copy-block {
  display: flex;
  flex-direction: column;
}

.mode-highlights {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.mode-highlight {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(6, 11, 24, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.mode-highlight span {
  color: var(--muted);
  font-size: 0.88rem;
}

.mode-highlight strong {
  display: block;
  margin-top: 6px;
  font-size: 1.4rem;
}

.mode-selector {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  min-height: 122px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  text-align: left;
}

.mode-card.active {
  background: rgba(93, 212, 255, 0.12);
  border-color: rgba(93, 212, 255, 0.4);
  box-shadow: 0 0 0 1px rgba(93, 212, 255, 0.14) inset;
}

.mode-title {
  font-weight: 800;
  font-size: 1.05rem;
}

.mode-copy {
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.92rem;
}

.lobby-actions {
  margin-top: 16px;
}

.stage-panel {
  flex: 1;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
}

.stage-sizing-shell {
  width: 100%;
  height: 100%;
  display: grid;
  min-height: 0;
  align-items: start;
  justify-items: center;
}

.stage-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  padding: 0;
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(8, 13, 26, 0.96), rgba(3, 6, 16, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: var(--shadow);
}

.playfield {
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
  touch-action: none;
}

.stage-frame[data-native-cursor="true"] .playfield {
  cursor: default;
}

.stage-frame[data-native-cursor="true"],
.stage-frame[data-native-cursor="true"] * {
  cursor: default;
}

.miss-flash-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.miss-flash {
  position: absolute;
  top: 0;
  width: 240px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle at center top, rgba(255, 96, 122, 0.72), rgba(255, 96, 122, 0));
  filter: blur(10px);
}

.pause-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  background: rgba(4, 8, 20, 0.76);
  backdrop-filter: blur(14px);
  border-radius: 18px;
  z-index: 2;
}

.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(320px, 100%);
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 6, 16, 0.7);
  backdrop-filter: blur(10px);
}

.confirm-card {
  width: min(440px, 100%);
  padding: 28px;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(15, 23, 44, 0.98), rgba(8, 14, 30, 0.98));
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.confirm-actions > * {
  flex: 1 1 0;
}

#marker-layer,
#cursor-layer,
#fx-layer,
.cursor,
.cursor * {
  pointer-events: none;
}

.gameover-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.complete-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.result-row {
  display: flex;
  gap: 18px;
  align-items: baseline;
  justify-content: space-between;
  min-width: min(360px, 100%);
}

.result-row span {
  color: var(--muted);
}

.result-row strong {
  font-size: 1.15rem;
}

.gameover-score {
  min-width: 180px;
  text-align: right;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 97, 119, 0.26);
  background: rgba(29, 10, 15, 0.92);
  color: #ffd0d6;
  box-shadow: var(--shadow);
}

.is-online {
  color: #d7fff0;
  border-color: rgba(105, 231, 164, 0.22);
}

.is-offline {
  color: #ffd0d6;
  border-color: rgba(255, 97, 119, 0.22);
}

@media (max-width: 1200px) {
  .app-shell {
    padding: 16px;
    gap: 16px;
  }

  .content-shell {
    gap: 16px;
  }

  .content-shell.has-room {
    grid-template-columns: 280px minmax(0, 1fr);
  }

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

  .metric-pill {
    min-width: 120px;
  }
}

@media (max-width: 920px) {
  html,
  body {
    overflow: auto;
  }

  .content-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .panel-stack {
    height: auto;
  }

  .stage-panel {
    min-height: 520px;
  }

  .playfield {
    width: 100%;
  }

  .app-header,
  .header-actions,
  .header-metrics {
    flex-direction: column;
    align-items: stretch;
  }

  .lobby-panel,
  .complete-panel,
  .gameover-panel,
  .join-row,
  .menu-join-row {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-selector {
    grid-template-columns: 1fr;
  }

  .stats-grid,
  .mode-highlights {
    grid-template-columns: 1fr;
  }
}
