* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, sans-serif;
}

.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen.hidden {
  display: none;
}

/* ============================================
   Welcome Screen
   ============================================ */
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#welcome-screen {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(68, 68, 255, 0.06) 0%, transparent 50%);
  gap: clamp(2rem, 5vh, 4rem);
}

.welcome-chips {
  display: flex;
  gap: clamp(0.6rem, 1.2vw, 1rem);
  margin-top: -0.8em;
}

.welcome-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-family: 'Orbitron', monospace;
  font-weight: 500;
  font-size: clamp(10px, 1.3vw, 14px);
  color: rgba(224, 224, 255, 0.55);
  padding: clamp(0.4rem, 0.8vh, 0.6rem) clamp(0.8rem, 1.4vw, 1.2rem);
  border: 1px solid rgba(224, 224, 255, 0.15);
  border-radius: var(--radius-md);
  background: rgba(224, 224, 255, 0.06);
}

.welcome-chip-icon {
  font-style: normal;
  font-size: 1.8em;
  line-height: 1;
}

.welcome-chip-icon--grey {
  filter: grayscale(1);
}

#welcome-screen h1 {
  font-size: clamp(2.5rem, 7vh, 6rem);
  filter: drop-shadow(0 0 24px rgba(0, 200, 255, 0.35));
  animation: fadeDown 0.6s ease-out both;
}

#new-game-btn {
  padding: clamp(0.8rem, 1.6vh, 1.5rem) clamp(2.5rem, 5vw, 7rem);
  font-size: clamp(1rem, 2.2vh, 1.8rem);
  letter-spacing: 0.08em;
  animation: fadeUp 0.6s 0.3s ease-out both, btnPulse 2.5s 1s ease-in-out infinite;
}

#welcome-footer {
  position: absolute;
  bottom: clamp(1.2rem, 3vh, 2.5rem);
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 16px);
  animation: fadeUp 0.6s 0.6s ease-out both;
}

#version-label {
  color: rgba(224, 224, 255, 0.15);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: clamp(11px, 1.2vw, 13px);
  font-weight: 500;
  letter-spacing: 0.06em;
}

#github-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(224, 224, 255, 0.2);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: clamp(11px, 1.2vw, 13px);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-decoration: none;
  transition: color 0.3s ease, filter 0.3s ease;
}

#github-link:hover {
  color: rgba(224, 224, 255, 0.5);
  filter: drop-shadow(0 0 6px rgba(0, 200, 255, 0.2));
}

/* ============================================
   Lobby Screen
   ============================================ */
#lobby-screen {
  background:
    radial-gradient(ellipse at 50% 20%, rgba(68, 68, 255, 0.06) 0%, transparent 50%);
  gap: 0;
  padding: 4vh 2rem 4vh;
}

/* Entrance animations */
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

#lobby-screen h1 {
  font-size: clamp(2rem, 5vh, 5rem);
  filter: drop-shadow(0 0 18px rgba(0, 200, 255, 0.3));
  animation: fadeDown 0.6s ease-out both;
}

#qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: auto;
  animation: fadeUp 0.6s 0.15s ease-out both, qrGlow 3s 1s ease-in-out infinite;
}

@keyframes qrGlow {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(0, 200, 255, 0.08)); }
  50%      { filter: drop-shadow(0 0 16px rgba(0, 200, 255, 0.18)); }
}

#qr-label {
  margin: clamp(4px, 0.8vh, 10px) 0 0;
  font-size: clamp(12px, 1.8vh, 20px);
  color: rgba(0, 200, 255, 0.7);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

#qr-code {
  width: clamp(140px, 24vh, 300px);
  height: clamp(140px, 24vh, 300px);
  border: 1px solid rgba(0, 200, 255, 0.15);
  border-radius: clamp(8px, 1vh, 16px);
  background: #fff;
  padding: clamp(6px, 1vh, 14px);
  box-shadow: 0 0 24px rgba(0, 200, 255, 0.08);
}

#join-url {
  font-size: clamp(0.7rem, 1.4vh, 1.1rem);
  color: var(--text-secondary);
  margin-top: 0.3rem;
  letter-spacing: 0.02em;
}

#player-list {
  display: flex;
  gap: clamp(0.6rem, 1.2vw, 1.2rem);
  justify-content: center;
  margin-top: auto;
  min-height: clamp(50px, 8vh, 90px);
  animation: fadeIn 0.4s 0.3s ease-out both;
}

.player-card {
  justify-content: center;
  padding: clamp(0.6rem, 1.2vh, 1rem) clamp(1.2rem, 2vw, 2.2rem);
  font-size: clamp(0.9rem, 2vh, 1.4rem);
  min-width: clamp(100px, 12vw, 180px);
}

.player-card.empty {
  background: transparent;
  border: 2px dashed rgba(255, 255, 255, 0.1);
  box-shadow: none;
  color: var(--text-secondary);
  opacity: 0.35;
}

@keyframes slotPopIn {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.08); opacity: 1; }
  80%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

.player-card.join-pop {
  animation: slotPopIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

#start-btn {
  margin-top: auto;
  padding: clamp(0.7rem, 1.4vh, 1.3rem) clamp(2rem, 4vw, 6rem);
  font-size: clamp(1rem, 2vh, 1.6rem);
  letter-spacing: 0.08em;
  animation: fadeUp 0.5s 0.45s ease-out both;
}

#start-btn:disabled {
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: not-allowed;
}

#start-btn:not(:disabled) {
  animation: fadeUp 0.5s 0.45s ease-out both, btnPulse 2.5s 1.2s ease-in-out infinite;
}

/* ============================================
   Game Screen
   ============================================ */
#game-screen {
  position: relative;
  padding: 0;
  background: var(--bg-primary);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#countdown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(6rem, 15vh, 14rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow:
    0 0 30px rgba(68, 68, 255, 0.9),
    0 0 60px rgba(68, 68, 255, 0.5),
    0 0 120px rgba(68, 68, 255, 0.2);
  background:
    radial-gradient(ellipse at 50% 50%, rgba(68, 68, 255, 0.08) 0%, transparent 60%),
    rgba(6, 6, 15, 0.8);
  z-index: 10;
}

#countdown-overlay.hidden {
  display: none;
}

/* ============================================
   Game Toolbar (fullscreen + pause)
   ============================================ */
#game-toolbar {
  position: absolute;
  top: clamp(10px, 1.5vh, 20px);
  right: clamp(10px, 1.5vw, 20px);
  z-index: 50;
  display: flex;
  gap: clamp(6px, 0.8vh, 10px);
}

#game-toolbar.hidden {
  display: none;
}

#game-toolbar button {
  width: clamp(36px, 4vh, 52px);
  height: clamp(36px, 4vh, 52px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

#game-toolbar button.hidden {
  display: none;
}

#game-toolbar button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.8);
  border-color: rgba(255, 255, 255, 0.3);
}

#fullscreen-btn svg {
  stroke: rgba(255, 255, 255, 0.5);
  transition: stroke 0.2s ease;
}

#fullscreen-btn:hover svg {
  stroke: rgba(255, 255, 255, 0.8);
}

#pause-btn .pause-icon::before,
#pause-btn .pause-icon::after {
  width: clamp(3px, 0.4vh, 5px);
  height: clamp(12px, 1.6vh, 18px);
  border-radius: 1px;
}

#pause-btn:hover .pause-icon::before,
#pause-btn:hover .pause-icon::after {
  background: rgba(255, 255, 255, 0.8);
}

#pause-overlay {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 15;
  background: var(--overlay-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlayFadeIn 0.3s ease both;
}

#pause-overlay h1 {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(1.6rem, 4vh, 3.5rem);
  font-weight: 900;
  letter-spacing: 0.15em;
  color: var(--text-primary);
  margin-bottom: clamp(1.5rem, 3vh, 3rem);
}

#pause-buttons {
  display: flex;
  gap: clamp(0.8rem, 1.5vw, 1.5rem);
}

#pause-continue-btn {
  padding: clamp(0.6rem, 1.2vh, 1.2rem) clamp(2rem, 4vw, 4rem);
  font-size: clamp(0.85rem, 1.6vh, 1.2rem);
  letter-spacing: 0.06em;
}

#pause-newgame-btn {
  padding: clamp(0.6rem, 1.2vh, 1.2rem) clamp(2rem, 4vw, 4rem);
  font-size: clamp(0.85rem, 1.6vh, 1.2rem);
  letter-spacing: 0.06em;
}

/* ============================================
   Results Overlay
   ============================================ */
#results-screen {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  background: radial-gradient(ellipse at 50% 30%, var(--winner-glow, rgba(255, 215, 0, 0.06)) 0%, transparent 60%),
              var(--overlay-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlayFadeIn 0.5s ease both;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#results-screen h1 {
  font-size: clamp(1.6rem, 4vh, 3.5rem);
  letter-spacing: 0.15em;
  margin-bottom: clamp(1rem, 3vh, 3rem);
  filter: drop-shadow(0 0 24px rgba(0, 200, 255, 0.35));
}

#results-list {
  display: flex;
  flex-direction: column;
  gap: clamp(0.4rem, 0.8vh, 0.8rem);
  width: 90%;
  max-width: 700px;
}

.result-row {
  gap: 1rem;
  padding: clamp(0.6rem, 1.2vh, 1.2rem) clamp(1rem, 2vw, 2rem);
}

.result-rank {
  font-size: clamp(1.2rem, 2.5vh, 2.2rem);
  font-weight: 700;
  width: 4rem;
  flex-shrink: 0;
}

.result-info {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  min-width: 0;
}

.result-name {
  font-size: clamp(1.2rem, 2.5vh, 2.2rem);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
}

.result-stats {
  display: flex;
  gap: 1.5rem;
  font-size: clamp(1rem, 2.2vh, 1.8rem);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.result-stats span {
  white-space: nowrap;
}

#results-buttons {
  display: flex;
  gap: clamp(0.8rem, 1.5vw, 1.5rem);
  margin-top: clamp(1.5rem, 3vh, 3rem);
}

#play-again-btn {
  padding: clamp(0.6rem, 1.2vh, 1.2rem) clamp(2rem, 4vw, 4rem);
  font-size: clamp(0.85rem, 1.6vh, 1.2rem);
  letter-spacing: 0.06em;
  animation: resultsBtnIn 0.5s 0.6s ease-out both, btnPulse 2.5s 1.5s infinite;
}

#new-game-results-btn {
  padding: clamp(0.6rem, 1.2vh, 1.2rem) clamp(2rem, 4vw, 4rem);
  font-size: clamp(0.85rem, 1.6vh, 1.2rem);
  letter-spacing: 0.06em;
  animation: resultsBtnIn 0.5s 0.7s ease-out both;
}

/* ============================================
   Mobile Screen Hint
   ============================================ */
#mobile-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.8rem, 2vh, 1.5rem);
  background:
    radial-gradient(ellipse at 50% 40%, rgba(68, 68, 255, 0.08) 0%, transparent 60%),
    var(--bg-primary);
  text-align: center;
  padding: 2rem;
}

#mobile-hint .mobile-hint-icon {
  font-size: 3rem;
  line-height: 1;
}

#mobile-hint h2 {
  font-size: clamp(1.3rem, 5vw, 2rem);
  letter-spacing: 0.06em;
}

#mobile-hint p {
  font-size: clamp(0.85rem, 3vw, 1rem);
  color: var(--text-secondary);
  line-height: 1.6;
}

#mobile-hint button {
  margin-top: 1rem;
  padding: 0.5rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'Orbitron', sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.2s ease;
}

#mobile-hint button:hover {
  border-color: rgba(68, 68, 255, 0.4);
  color: var(--text-primary);
}

/* Show only on phone-sized screens */
@media (max-width: 768px) and (orientation: portrait) {
  #mobile-hint { display: flex; }
}

@media (max-width: 568px) and (orientation: landscape) {
  #mobile-hint { display: flex; }
}
