:root {
  color-scheme: dark;
  font-family: 'Segoe UI', Tahoma, sans-serif;
}

body {
  margin: 0;
  background: #040b16;
  color: #f3f6fb;
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100dvh;
  padding: 0;
  position: relative;
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 0;
  gap: 0;
  max-width: none;
  min-height: 100dvh;
}

.panel {
  background: rgba(12, 22, 40, 0.85);
  border: 1px solid rgba(54, 92, 168, 0.5);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

#lobby h1 {
  margin-top: 0;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8ea4d7;
}

input {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: none;
  outline: none;
  font-size: 1rem;
}

select {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  background: rgba(20, 30, 48, 0.85);
  color: inherit;
}

button {
  padding: 0.9rem 1.2rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  background: linear-gradient(135deg, #2bdcff, #2ea1ff);
  color: #031223;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
button:focus {
  transform: translateY(-2px);
  box-shadow: 0 15px 30px rgba(43, 220, 255, 0.35);
}

#tutorial ul {
  padding-left: 1.2rem;
}

#tutorial li {
  margin-bottom: 0.5rem;
}

/* #game {
  border: 2px solid rgba(54, 92, 168, 0.45);
  border-radius: 12px;
  background: rgba(5, 10, 19, 0.75);
  display: block;
  margin: 0 auto;
  max-width: 100%;
} */

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  margin: 0;
  border: none;
  border-radius: 0;
  background: #000;
  touch-action: none;
  z-index: 0;
}


#hud {
  position: fixed;
  top: 0.75rem;
  left: 0;
  right: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  gap: 0.75rem;
}

#mute-toggle,
#level,
#leaderboard {
  pointer-events: auto;
}

#level {
  justify-self: start;
  background: rgba(12, 22, 40, 0.8);
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(70, 120, 220, 0.45);
  text-transform: none;
}

#leaderboard {
  justify-self: center;
  align-self: start;
  background: rgba(12, 22, 40, 0.82);
  border-radius: 12px;
  padding: 0.45rem 0.75rem;
  min-width: 180px;
  max-width: min(240px, 50vw);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.26rem;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
}

#mute-toggle {
  justify-self: end;
  align-self: start;
  background: rgba(12, 22, 40, 0.7);
  border-radius: 999px;
  padding: 0.5rem 0.7rem;
  border: 1px solid rgba(90, 140, 220, 0.35);
  color: #f3f6fb;
  font-size: 1.2rem;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

#net-stats {
  position: fixed;
  top: 0.75rem;
  right: 1rem;
  background: rgba(12, 22, 40, 0.78);
  border-radius: 10px;
  padding: 0.4rem 0.65rem;
  color: #dce5ff;
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  pointer-events: none;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
  z-index: 40;
}

#net-stats[hidden] {
  display: none !important;
}

#mute-toggle:hover,
#mute-toggle:focus {
  transform: translateY(-1px);
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.35);
}

#offline-exit-btn {
  justify-self: end;
  align-self: start;
  background: rgba(220, 64, 86, 0.82);
  border: 1px solid rgba(255, 140, 155, 0.55);
  border-radius: 999px;
  padding: 0.55rem 1.05rem;
  color: #fff6f7;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 14px 34px rgba(220, 64, 86, 0.35);
  transition: transform 140ms ease, box-shadow 140ms ease;
}

#offline-exit-btn:hover,
#offline-exit-btn:focus {
  transform: translateY(-1px);
  box-shadow: 0 18px 36px rgba(220, 64, 86, 0.45);
}

#leaderboard .entry {
  display: grid;
  grid-template-columns: 1.4rem 1fr auto;
  align-items: center;
  gap: 0.35rem;
  color: #dce5ff;
  padding: 0.25rem 0.4rem;
  border-radius: 10px;
  background: rgba(18, 28, 46, 0.6);
  border: 1px solid transparent;
}

#leaderboard .entry .entry-rank {
  font-weight: 700;
  text-align: right;
  opacity: 0.8;
}

#leaderboard .entry .entry-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

#leaderboard .entry .entry-score {
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
  text-align: right;
  min-width: 3.2rem;
}

#leaderboard .entry .entry-score.self-score {
  opacity: 1;
  font-weight: 700;
}

.panel-secondary {
  margin-top: 1rem;
  background: rgba(12, 22, 40, 0.68);
  border: 1px solid rgba(54, 92, 168, 0.35);
}

#recent-absorbs h2,
#personal-stats h2 {
  margin-top: 0;
}

#absorb-log,
#personal-stats-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

#absorb-log li,
#personal-stats-list li {
  line-height: 1.3;
  color: #c9d8ff;
}

#quick-rematch {
  margin-top: 0.75rem;
  align-self: flex-start;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.95rem;
  background: linear-gradient(135deg, #2bdcff, #4a7dff);
  color: #041027;
  border: none;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

#quick-rematch:hover,
#quick-rematch:focus {
  transform: translateY(-1px);
  box-shadow: 0 18px 32px rgba(75, 125, 255, 0.35);
}

#leaderboard .entry.self {
  background: linear-gradient(135deg, rgba(63, 107, 255, 0.55), rgba(99, 172, 255, 0.65));
  border-color: rgba(110, 189, 255, 0.6);
  color: #041027;
  box-shadow: 0 12px 28px rgba(90, 160, 255, 0.35);
}

#leaderboard .entry.self .entry-name,
#leaderboard .entry.self .entry-rank {
  color: inherit;
}

@media (max-width: 768px) {
  #hud {
    top: 0.5rem;
    padding: 0.6rem 0.65rem;
    font-size: 0.82rem;
    gap: 0.5rem;
  }

  #level {
    width: 2.2rem;
    height: 2.2rem;
    font-size: 0.9rem;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.34);
  }

  #leaderboard {
    padding: 0.35rem 0.5rem;
    min-width: 140px;
    font-size: 0.7rem;
    border-radius: 10px;
    gap: 0.22rem;
  }

  #leaderboard .entry {
    padding: 0.18rem 0.28rem;
    border-radius: 8px;
    grid-template-columns: 1.1rem 1fr auto;
    gap: 0.25rem;
  }

  #leaderboard .entry .entry-score {
    min-width: 2.4rem;
  }

  #mute-toggle {
    padding: 0.45rem 0.62rem;
    font-size: 1.1rem;
  }

  .panel-secondary {
    margin-top: 0.75rem;
    padding: 1rem;
  }

  #quick-rematch {
    width: 100%;
    text-align: center;
  }

  #toast-container {
    top: 0.6rem;
  }
}

#high-scores {
  margin-top: 1.5rem;
}

#high-score-list {
  padding-left: 1.25rem;
  margin: 0;
  list-style-position: outside;
}

.secondary-action {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(90, 140, 220, 0.4);
  background: rgba(18, 28, 46, 0.7);
  color: #f3f6fb;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35);
}

.secondary-action:hover,
.secondary-action:focus {
  transform: translateY(-1px);
  background: rgba(28, 42, 64, 0.78);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4);
}

#status-message {
  z-index: 1000;
  pointer-events: none;
  text-align: center;
  min-width: 220px;
}

#toast-container {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
  z-index: 1200;
  pointer-events: none;
}

.toast {
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 18px 40px rgba(1, 8, 20, 0.45);
  opacity: 0;
  transform: translateY(-10px) scale(0.98);
  transition: opacity 180ms ease, transform 180ms ease;
  border: 1px solid rgba(80, 120, 200, 0.4);
  background: linear-gradient(135deg, rgba(12, 22, 40, 0.92), rgba(14, 30, 52, 0.92));
  color: #f3f6fb;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-info {
  border-color: rgba(59, 158, 255, 0.55);
  box-shadow: 0 16px 40px rgba(59, 158, 255, 0.25);
}

.toast-success {
  border-color: rgba(76, 217, 149, 0.6);
  box-shadow: 0 16px 40px rgba(76, 217, 149, 0.25);
}

.toast-warning {
  border-color: rgba(255, 196, 86, 0.7);
  box-shadow: 0 16px 40px rgba(255, 196, 86, 0.35);
  color: #fff6e5;
}

#connection-warning {
  position: fixed;
  bottom: 1.6rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.85rem;
  align-items: center;
  padding: 0.85rem 1.25rem;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(26, 14, 44, 0.92), rgba(44, 20, 68, 0.9));
  color: #fdf2ff;
  border: 1px solid rgba(255, 188, 126, 0.7);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
  z-index: 1400;
  pointer-events: auto;
}

#connection-warning[hidden] {
  display: none !important;
}

#connection-warning button {
  border: 1px solid rgba(255, 220, 170, 0.6);
  background: rgba(255, 168, 92, 0.9);
  color: #38121d;
  border-radius: 12px;
  padding: 0.45rem 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

#connection-warning button:hover,
#connection-warning button:focus {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(255, 168, 92, 0.4);
}

#death-modal::backdrop {
  background: rgba(7, 10, 20, 0.75);
}

#death-modal {
  border: none;
  border-radius: 14px;
  padding: 1.5rem 2rem;
  background: rgba(10, 16, 28, 0.95);
  color: #f3f6fb;
  min-width: min(90vw, 420px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

#death-modal h2 {
  margin-top: 0;
  color: #ffc371;
}

#modal-high-scores {
  padding-left: 1.2rem;
  margin: 0 0 1rem;
}

#modal-high-scores li {
  margin-bottom: 0.3rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

#play-again-btn {
  padding: 0.8rem 1.4rem;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  background: linear-gradient(135deg, #2bdcff, #2ea1ff);
  color: #081018;
  cursor: pointer;
}

#touch-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 1.5rem;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 1.5rem;
  gap: 1rem;
  pointer-events: none;
  z-index: 4;
}

#joystick {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(12, 22, 40, 0.72);
  border: 2px solid rgba(54, 92, 168, 0.6);
  position: relative;
  pointer-events: auto;
  touch-action: none;
}

#joystick-knob {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2bdcff, #2ea1ff);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.08s ease;
}

#boost-button {
  pointer-events: auto;
  padding: 1rem 1.5rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #ff5f6d, #ffc371);
  color: #1a1325;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.35);
  text-transform: uppercase;
  touch-action: none;
}

#boost-button.active {
  transform: scale(0.95);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

@media (pointer: coarse) {
  #touch-controls.active {
    display: flex;
  }
}

@media (max-width: 768px) {
  body {
    padding: 0;
    align-items: stretch;
  }

  .app-shell {
    flex-grow: 1;
    padding: 0;
    gap: 0;
    max-width: none;
  }

  #game[hidden] + #hud,
  #hud[hidden] {
    display: none !important;
  }

  #lobby,
  #game,
  #touch-controls {
    margin: 0 auto;
  }

  #game {
    max-width: none;
    width: 100%;
    height: 100dvh;
  }
}

body:not(.in-game) #game,
body:not(.in-game) #hud,
body:not(.in-game) #touch-controls {
  display: none !important;
}

body:not(.in-game) #desktop-controls {
  display: none;
}

body.in-game #lobby {
  display: none;
}

#mute-toggle {
  
  border: none;
  background: rgba(12, 22, 40, 0.65);
  color: #dce5ff;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1rem;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s ease;
}

#mute-toggle:active {
  transform: scale(0.95);
}

#mute-toggle.muted {
  background: rgba(30, 40, 58, 0.65);
  color: rgba(220, 229, 255, 0.55);
}

body.in-game #hud {
  top: 1rem;
  right: 1rem;
}

#desktop-controls {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(8, 14, 28, 0.7);
  border: 1px solid rgba(90, 120, 180, 0.35);
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.35);
  color: #dce5ff;
  backdrop-filter: blur(12px);
  z-index: 5;
 
}

@media (pointer: coarse) {
  #desktop-controls {
    display: none;
  }
}

body:not(.in-game) {
  justify-content: stretch;
  align-items: stretch;
  overflow-y: auto;
}

body:not(.in-game) .app-shell {
  padding: 0;
  gap: 0;
  overflow-y: auto;
}

body:not(.in-game) #lobby {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1.25rem;
  max-width: 640px;
  border-radius: 0;
  border: none;
  box-shadow: none;
  padding: calc(1.75rem + env(safe-area-inset-top, 0px)) 1.5rem calc(1.75rem + env(safe-area-inset-bottom, 0px));
  background: none;
}

body:not(.in-game) #high-scores {
  background: transparent;
  padding: 0;
}
#background-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: -2;
}

#background-layer .star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  opacity: 0.3;
  animation: twinkle 6s ease-in-out infinite;
  will-change: transform;
}

#background-layer .planet {
  position: absolute;
  border-radius: 50%;
  filter: blur(0.5px);
  opacity: 0.25;
  background: radial-gradient(circle at 30% 30%, rgba(120, 170, 255, 0.8), transparent 70%);
  will-change: transform;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.3); }
}
#level {
  font-size: 1rem;
  background: rgba(12, 22, 40, 0.75);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #dce5ff;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: minmax(80px, 1fr) minmax(140px, auto) minmax(80px, 1fr);
  align-items: start;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  gap: 0.5rem;
}
