:root {
  --bg-1: #0a0e1a;
  --bg-2: #0f1626;
  --accent: #00d9ff;
  --accent-2: #ffa500;
  --accent-3: #ff006e;
  --text: #f8fafc;
  --muted: #94a3b8;
  --panel: rgba(15, 22, 38, 0.9);
  --danger: #ff3860;
  --line: rgba(255, 255, 255, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 0%, #18274a, var(--bg-1) 55%),
    linear-gradient(130deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

html,
body {
  height: 100%;
}

.bg-shapes::before,
.bg-shapes::after {
  content: "";
  position: fixed;
  inset: auto;
  z-index: -1;
  border-radius: 30%;
  filter: blur(12px);
  opacity: 0.28;
  animation: drift 20s infinite ease-in-out alternate;
  will-change: transform;
}

.bg-shapes::before {
  width: 40vw;
  height: 40vw;
  background: #2ed9ff;
  top: -12vw;
  right: -8vw;
}

.bg-shapes::after {
  width: 34vw;
  height: 34vw;
  background: #f4b75d;
  bottom: -12vw;
  left: -7vw;
}

@keyframes drift {
  from {
    transform: translateY(-6px);
  }
  to {
    transform: translateY(6px);
  }
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  background: rgba(6, 10, 20, 0.75);
  backdrop-filter: blur(3px);
  will-change: opacity;
}

.auth-gate-card {
  width: min(460px, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(12, 18, 36, 0.92);
  padding: 1rem;
  text-align: center;
}

.auth-gate-card h2 {
  margin: 0 0 0.4rem;
}

.auth-gate-card p {
  margin: 0 0 0.8rem;
  color: var(--muted);
}

body.auth-locke2 .app-shell {
  filter: blur(6px);
  pointer-events: none;
  user-select: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.auth {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: 1px;
}

h2 {
  margin-top: 0;
}

.subtitle {
  margin-top: 0.25rem;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;2px);
  will-change: opacity
  backdrop-filter: blur(4px);
}

.modes-panel {
  margin-top: 1rem;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.8rem;
}
.hidden {
  display: none !important;
}

.category-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.category-btn.active {
  border: 1px solid var(--accent);
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8rem;
}

.menu-category {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 0.45rem;
}

.menu-category .tabs {
  margin-bottom: 0.2rem;
}

.menu-category .leaderboard-list {
  max-height: 340px;
  overflow: auto;
  padding-right: 0.3rem;
}

.menu-category h3 {
  margin: 0;
}

.menu-category p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.settings-jump {
  background: linear-gradient(125deg, #21466a, #1f5f6b);
}

.menu-footer {
  margin-top: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

#customRoomPanel {
  margin-top: 0.8rem;
}

.custom-room-info {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.public-rooms-list {
  list-style: none;
  padding-left: 0;
  max-height: 280px;
  overflow: auto;
}

.public-room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin: 0.4rem 0;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.public-room-item span {
  font-size: 0.92rem;
  color: var(--text);
}

body.lobby-state .category-tabs,
body.lobby-state .menu-grid,
body.lobby-state .menu-footer,
body.lobby-state #customRoomPanel,
body.lobby-state .modes-panel > h2 {
  display: none;
}

body.lobby-state .modes-panel {
  background: transparent;
  border-color: transparent;
  padding: 0;
}

body.lobby-state #quickLobbyPanel {
  margin-top: 0;
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.lobby-header h3 {
  margin: 0;
}

.lobby-meta {
  display: flex;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: nowrap;
}

#quickLobbyPanel .exit-btn {
  position: static;
  top: auto;
  left: auto;
  z-index: 1;
  padding: 0.5rem 0.8rem;
}

#quickLobbyPanel .exit-btn.small {
  font-size: 0.95rem;
}

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.9rem;
  margin-top: 0.9rem;
  align-items: stretch;
}

.lobby-column {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.lobby-column h4 {
  margin: 0;
  letter-spacing: 0.5px;
}

.lobby-players {
  list-style: none;
  padding-left: 0;
  margin: 0;
  overflow: auto;
  flex: 1;
}

.lobby-players li {
  margin: 0.35rem 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.16);
}

.lobby-center {
  justify-content: center;
  text-align: center;
}

.countdown-big {
  font-size: clamp(2.6rem, 6vw, 4.2rem);
  font-weight: 800;
  letter-spacing: 1px;
  padding: 0.4rem 0;
}

.lobby-info {
  margin: 0;
  color: var(--muted);
}

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1;
  min-height: 0;
}

.chat-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  overflow: auto;
  flex: 1;
  padding: 0.55rem 0.6rem;
}

.chat-list li {
  margin: 0.35rem 0;
  color: var(--text);
  word-break: break-word;
}

.chat-flag {
  opacity: 0.9;
  margin-right: 0.25rem;
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
}

.chat-input-row input {
  flex: 1;
}

@media (max-width: 980px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
  .lobby-meta {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  object-fit: cover;
  background: rgba(255, 255, 255, 0.1);
}

button,
input {
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
}

button {
  cursor: pointer;
  background: linear-gradient(135deg, #0066ff, #0099ff);
  color: white;
  padding: 0.7rem 1rem;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-weight: 500;
  box-shadow: 0 4px 15px rgba(0, 102, 255, 0.2);
  border: 1px solid rgba(0, 217, 255, 0.3);
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 102, 255, 0.35);
  border-color: rgba(0, 217, 255, 0.6);
}

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

.danger-btn {
  background: linear-gradient(135deg, #ff3860, #ff006e);
  box-shadow: 0 4px 15px rgba(255, 56, 96, 0.2);
  border-color: rgba(255, 56, 96, 0.3);
}

.danger-btn:hover {
  box-shadow: 0 6px 20px rgba(255, 56, 96, 0.35);
  border-color: rgba(255, 56, 96, 0.6);
}

.mode-btn.active,
.leader-tab.active {
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 217, 255, 0.2), inset 0 0 8px rgba(0, 217, 255, 0.1);
  background: linear-gradient(135deg, rgba(0, 102, 255, 0.1), rgba(0, 217, 255, 0.1));
}

.mode-btn.with-count {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.mode-population {
  min-width: 1.8rem;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.08rem 0.42rem;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.85rem;
}

.layout {
  margin-top: 1rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: 320px minmax(320px, 1fr) 280px;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.row {
  display: flex;
  gap: 0.5rem;
}

input {
  width: 100%;
  background: rgba(0, 102, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(0, 217, 255, 0.2);
  padding: 0.7rem 0.8rem;
  transition: all 0.2s ease;
}

input:focus {
  outline: none;
  border-color: rgba(0, 217, 255, 0.6);
  background: rgba(0, 102, 255, 0.15);
  box-shadow: 0 0 10px rgba(0, 217, 255, 0.2);
}

input.capturing-key {
  border-color: var(--accent);
  box-shadow: 0 0 15px rgba(0, 217, 255, 0.4), inset 0 0 8px rgba(0, 217, 255, 0.15);
  background: rgba(0, 217, 255, 0.15);
}

.room-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.status-box {
  margin-top: 0.8rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.status-box p {
  margin: 0.35rem 0;
}

.players-list,
.leaderboard-list {
  margin: 0;
  padding-left: 1.1rem;
}

.players-list li,
.leaderboard-list li {
  margin: 0.35rem 0;
}

.players-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.game-panel {
  position: relative;
  display: grid;
  grid-template-columns: 170px minmax(220px, 360px) 160px 230px;
  gap: 1rem;
  align-items: start;
  padding-top: 3.2rem;
}

.exit-btn {
  position: absolute;
  top: -0.6rem;
  left: -3.2rem;
  z-index: 2;
}
.game-side {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6rem;
}
.next-canvas-list {
  display: grid;
  gap: 0.45rem;
}

.next-mini,
.hold-mini {
  width: 100%;
  max-width: 102px;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 8, 18, 0.9);
}

.alive-panel {
  max-height: 720px;
  overflow: auto;
}

.alive-panel h3 {
  margin: 0 0 0.5rem;
}

.compact-list {
  padding-left: 0;
  list-style: none;
}

.compact-list li {
  display: block;
  margin: 0.35rem 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.9rem;
}

#gameCanvas {
  border: 2px solid var(--accent);
  border-radius: 16px;
  width: 100%;
  max-width: 360px;
  height: auto;
  background: rgba(4, 6, 14, 0.95);
  justify-self: center;
  box-shadow: 0 0 30px rgba(0, 217, 255, 0.25), inset 0 0 20px rgba(0, 217, 255, 0.1);
  transition: box-shadow 0.3s ease;
}

.hud {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.clear-feed {
  display: grid;
  gap: 0.35rem;
}

.clear-item {
  border: 1px solid rgba(89, 240, 194, 0.25);
  border-radius: 10px;
  background: rgba(89, 240, 194, 0.08);
  padding: 0.4rem 0.5rem;
}

.clear-item strong {
  display: block;
  font-size: 0.92rem;
}

.clear-item span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.hold-box h3 {
  margin: 0 0 0.5rem;
}

.hud-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
}

.hud-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

.hud-card strong {
  font-size: 1.05rem;
  margin-top: 0.2rem;
}

.help {
  margin-top: 0.7rem;
  color: var(--muted);
  grid-column: 1 / 5;
}

kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.15rem 0.35rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.admin-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 0.6rem;
}

.metrics-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.8rem;
}

.metrics-table th,
.metrics-table td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 0.45rem 0.2rem;
  font-size: 0.92rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.profile-editor {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.keybind-grid {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.profile-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid var(--line);
  object-fit: cover;
  background: rgba(255, 255, 255, 0.08);
}

.profile-stats {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6rem;
  background: rgba(255, 255, 255, 0.04);
}

.profile-stats p {
  margin: 0 0 0.4rem;
}

.profile-stats ol {
  margin: 0;
  padding-left: 1rem;
}

.toggle input {
  width: auto;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .game-panel {
    grid-template-columns: 1fr;
  }
  .help,
  #backToMenuBtn {
    grid-column: 1 / -1;
  }
}

body.menu-state #gameScene {
  display: none;
}

body.playing-state .modes-panel {
  display: none;
}

body.playing-state #gameScene {
  grid-template-columns: 1fr;
}

body.playing-state #gameScene .left-column,
body.playing-state #gameScene .settings-panel,
body.playing-state #gameScene .admin-panel {
  display: none;
}

body.playing-state #gameScene .game-panel {
  max-width: 1260px;
  margin: 0 auto;
}

body.playing-state {
  overflow: hidden;
}

body.playing-state .app-shell {
  height: 100vh;
  overflow: hidden;
}

body.playing-state #gameCanvas {
  width: min(42vh, 45vw);
  max-width: 360px;
  max-height: calc(100vh - 220px);
}

body.settings-state .modes-panel {
  display: none;
}

body.settings-state #gameScene {
  grid-template-columns: 1fr;
}

body.settings-state #gameScene .left-column,
body.settings-state #gameScene .game-panel,
body.settings-state #gameScene .admin-panel {
  display: none;
}

body.settings-state #gameScene .settings-panel {
  max-width: 680px;
  margin: 0 auto;
}

.countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  font-size: clamp(3rem, 12vw, 8rem);
  font-weight: 700;
  color: white;
  z-index: 40;
}

.result-card {
  background: rgba(12, 18, 36, 0.82);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  min-width: 300px;
  max-width: 420px;
  text-align: center;
  font-size: 0.95rem;
}

.result-card h2 {
  margin: 0 0 0.6rem;
  font-size: 1.8rem;
}

.result-card p {
  margin: 0.45rem 0;
}

.result-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}
