/* ===========================================
   P2P Shooter POC — Styles
   Retro Maze Combat — Unified Orange/Dark Theme
   =========================================== */

/* ---- CSS Custom Properties (fallback defaults, overridden by ThemeManager) ---- */
:root {
  /* Backgrounds (darkest to lightest) */
  --bg-deep: #07070f;
  --bg-dark: #0a0a1a;
  --bg-panel: #0d0d1a;
  --bg-elevated: #1a1a2e;

  /* Primary Accent — Orange */
  --accent: #ff6b00;
  --accent-hover: #cc5500;
  --accent-glow: rgba(255, 107, 0, 0.3);
  --accent-dim: rgba(255, 107, 0, 0.08);

  /* Borders */
  --border-dark: #2a2a4a;
  --border-subtle: #1a1a2e;

  /* Text */
  --text-primary: #c8c8e0;
  --text-muted: #888;
  --text-dim: #555;
  --text-dark: #333;

  /* Player Colors */
  --p1: #00d4ff;
  --p2: #ff4444;

  /* Status */
  --status-ok: #2ecc71;
  --status-error: #e74c3c;

  /* Button text on filled accent buttons */
  --btn-text: #000;

  /* Overlay / modal text */
  --overlay-text: #fff;

  /* Author credit link */
  --author-link: #00d4ff;

  /* Keyboard hint widget */
  --key-border: #444;
  --key-text: #ccc;

  /* Leave-cancel button hover background */
  --leave-cancel-hover: #222240;

  /* Mobile shoot button */
  --shoot-btn-bg: #c0392b;
  --shoot-btn-border: #e74c3c;
  --shoot-btn-text: #fff;

  /* Shared animation curves */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Maze card — overridden per-theme by ThemeManager */
  --card-bg:            rgba(14,14,30,.7);
  --card-border:        rgba(255,255,255,.06);
  --card-hover-bg:      rgba(20,20,42,.9);
  --card-hover-border:  rgba(255,255,255,.12);
  --card-shimmer-color: rgba(255,255,255,.04);

  /* Touch controls — overridden by light themes for visibility */
  --touch-area-bg:        transparent;
  --joystick-base-bg:     rgba(255,255,255,0.06);
  --joystick-base-border: rgba(255,255,255,0.2);
  --joystick-knob-bg:     rgba(255,255,255,0.55);
  --joystick-knob-border: rgba(255,255,255,0.85);
}

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

/* ---- Base ---- */
body {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  background: var(--bg-deep);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
  transition: background 0.5s var(--ease-out), color 0.4s var(--ease-out);
}

/* CRT scanline overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: none;
  transition: opacity 0.5s;
}

/* ---- Entrance Animations ---- */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blurReveal {
  0% {
    filter: blur(12px) brightness(0.7);
    opacity: 0;
    transform: scale(1.02);
  }
  50% {
    filter: blur(3px) brightness(0.9);
    opacity: 0.8;
  }
  100% {
    filter: blur(0) brightness(1);
    opacity: 1;
    transform: scale(1);
  }
}

/* @keyframes pulseGlow {
  0%, 100% {
    box-shadow: 0 0 0 0 var(--accent-glow);
  }
  50% {
    box-shadow: 0 0 24px 4px var(--accent-glow);
  }
} */

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes dotBreathe {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

@keyframes selGlow {
  0%, 100% { box-shadow: 0 0 0 1.5px var(--accent), 0 4px 20px var(--accent-glow); }
  50%      { box-shadow: 0 0 0 1.5px var(--accent), 0 8px 40px var(--accent-glow), 0 0 50px var(--accent-glow); }
}

@keyframes cardEntrance {
  0%   { opacity: 0; transform: translateY(20px) scale(.96); filter: blur(8px); }
  60%  { filter: blur(1px); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

@keyframes labelFadeIn {
  0%   { opacity: 0; transform: translateY(5px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ---- Title ---- */
h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 4px;
  text-shadow: none;
  animation: fadeUp 0.8s var(--ease-out) both;
}

/* ---- Lobby ---- */
#lobby {
  text-align: center;
  padding: 2rem;
  animation: blurReveal 1s var(--ease-out) both;
}

#lobby p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  animation: fadeUp 0.7s var(--ease-out) 0.15s both;
}

.lobby-buttons {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  animation: fadeUp 0.7s var(--ease-out) 0.4s both;
}

.lobby-buttons .btn {
  width: min(300px, 85vw);
  text-align: center;
}

/* ---- Buttons ---- */
.btn {
  padding: 0.75rem 2rem;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 1rem;
  font-weight: bold;
  border: 2px solid;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 2px;
  transition: all 0.25s var(--ease-out);
  position: relative;
  overflow: hidden;
}

/* Shimmer hover effect on all buttons */
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 33%, rgba(255,255,255,0.06) 50%, transparent 67%);
  background-size: 200% 100%;
  opacity: 0;
  transition: opacity 0.3s;
}

.btn:hover::after {
  opacity: 1;
  animation: shimmer 1.5s linear infinite;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--btn-text);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 18px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn-secondary {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-secondary:hover {
  background: var(--accent);
  color: var(--btn-text);
  transform: translateY(-1px);
}

.btn-small {
  padding: 0.5rem 1.5rem;
  font-size: 0.8rem;
  letter-spacing: 1px;
  opacity: 0.7;
  transition: opacity 0.25s var(--ease-out), box-shadow 0.25s, transform 0.25s;
}

.btn-small:hover {
  opacity: 1;
  transform: translateY(-1px);
}

/* ---- Connection UI ---- */
#connectionUI {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 45; /* below footer (50) so footer remains visible */
  background: var(--bg-deep);
}

/* Host/join panels: absolutely fill the overlay and center their card */
#hostUI,
#joinUI {
  position: absolute;
  inset: 0;
  bottom: 60px; /* clear the footer */
  align-items: center;
  justify-content: center;
}

/* Connection panel — centered card */
.conn-panel {
  text-align: center;
  padding: 2.5rem 3rem;
  max-width: 520px;
  width: 90%;
  animation: blurReveal 0.65s var(--ease-out) both;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Stagger children entrance */
.stagger > * {
  opacity: 0;
  transform: translateY(10px);
  animation: stgIn 0.55s ease forwards;
}
.stagger > *:nth-child(1) { animation-delay: 0.08s; }
.stagger > *:nth-child(2) { animation-delay: 0.14s; }
.stagger > *:nth-child(3) { animation-delay: 0.20s; }
.stagger > *:nth-child(4) { animation-delay: 0.26s; }
.stagger > *:nth-child(5) { animation-delay: 0.32s; }
.stagger > *:nth-child(6) { animation-delay: 0.38s; }

@keyframes stgIn {
  to { opacity: 1; transform: translateY(0); }
}

/* Small uppercase tracking label — matches lobby section headers */
.panel-label {
  font-size: 0.75rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: none;
  margin-bottom: 1.5rem;
  font-weight: 500;
}

/* Room code — large accent display matching game's neon theme */
#connectionUI .room-code {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 4.12rem;
  font-weight: 700;
  letter-spacing: 12px;
  color: var(--accent);
  margin-bottom: 0.4rem;
  user-select: all;
  text-shadow: none;
}

/* Decorative line under room code */
.room-code-line {
  width: 55%;
  height: 1px;
  margin: 0 auto 0.7rem;
  background: linear-gradient(90deg, transparent, var(--accent-dim), transparent);
}

/* Status row with animated dot */
.host-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--status-ok);
  animation: dotPulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes dotPulse {
  0%, 100% { opacity: 0.3; box-shadow: none; }
  50% { opacity: 1; box-shadow: 0 0 8px 2px rgba(46, 204, 113, 0.2); }
}

#connectionStatus {
  font-size: 0.8rem;
  color: var(--text-muted);
}

#connectionStatus.status-connected {
  color: var(--status-ok);
}

/* Button row — side by side, width fits content */
.panel-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
  width: 100%;
}

/* Override lobby min-width so buttons size to their text */
.panel-actions .btn,
.join-actions .btn {
  min-width: 0;
  width: auto;
  white-space: nowrap;
}

/* Join screen — code input */
.room-input {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 3.2rem;
  font-weight: 700;
  letter-spacing: 10px;
  text-align: center;
  text-transform: uppercase;
  background: none;
  border: none;
  border-bottom: 1.5px solid var(--border-dark);
  color: var(--text-primary);
  padding: 0.65rem 1rem;
  width: min(460px, 90%);
  outline: none;
  caret-color: var(--accent);
  transition: border-color 0.3s, box-shadow 0.3s;
  display: block;
  margin: 0 auto;
}

.room-input::placeholder {
  color: var(--border-dark);
  letter-spacing: 6px;
  font-weight: 400;
}

.room-input:focus {
  border-color: var(--accent);
  box-shadow: 0 2px 0 var(--accent-dim);
}

/* Join status / error */
#joinStatus {
  margin-top: 0.85rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1em;
}

.join-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 2rem;
  width: 100%;
}

.status-connected {
  color: var(--status-ok) !important;
}

.status-error {
  color: var(--status-error) !important;
}

/* ---- Canvas Wrapper ---- */
#gameContainer {
  display: none;
  position: relative;
  width: 100%;
  justify-content: center;
  align-items: center;
  padding: 1rem 0;
}

canvas {
  border: 3px solid var(--border-dark);
  display: block;
  background: var(--bg-dark);
  transition: border-color 0.4s var(--ease-out);
}

/* ---- Overlay (countdown, game over) ---- */
#overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  pointer-events: none;
}

#overlay.active {
  display: flex;
  pointer-events: auto;
}

#overlay h2 {
  font-size: 4rem;
  color: var(--overlay-text);
}

#overlay p {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

#overlay .btn {
  margin-top: 1.5rem;
  pointer-events: auto;
}

/* ---- Maze Selector ---- */
#maze-selector {
  margin: 1.5rem 0;
  animation: fadeUp 0.7s var(--ease-out) 0.25s both;
}

#maze-selector h3 {
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 3px;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  text-shadow: none;
}

#maze-grid {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 920px;
}

/* ---- Maze Card (new design) ---- */
.maze-card {
  position: relative;
  width: 180px;
  padding: 10px;
  cursor: pointer;
  text-align: center;
  border: 1.5px solid var(--card-border);
  background: var(--card-bg);
  border-radius: 14px;
  overflow: hidden;
  transition:
    border-color .35s var(--ease-out),
    background .35s var(--ease-out),
    transform .4s var(--ease-out),
    box-shadow .5s var(--ease-out);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Entrance animation lives on the inner body so .maze-card transform is
   always transition-driven — prevents animation vs transition conflicts
   when the selection class is added or removed. */
.maze-card-body {
  animation: cardEntrance .7s var(--ease-out) both;
}

/* Shimmer sweep layer */
.maze-card::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 33%, var(--card-shimmer-color) 50%, transparent 67%);
  background-size: 200% 100%;
  opacity: 0;
  transition: opacity .3s;
  z-index: 2;
  pointer-events: none;
}

.maze-card:hover {
  border-color: var(--card-hover-border);
  background: var(--card-hover-bg);
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
}

.maze-card:hover::before {
  opacity: 1;
  animation: shimmer 2s linear infinite;
}

.maze-card.sel {
  border-color: var(--accent);
  background: var(--card-hover-bg);
  transform: translateY(-4px);
  animation: selGlow 3s ease infinite;
}

.maze-card canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  margin-bottom: 8px;
  image-rendering: pixelated;
  position: relative;
  z-index: 1;
}

.maze-card-name {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: .6rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  transition: color .35s var(--ease-out);
  animation: labelFadeIn .6s var(--ease-out) .3s both;
}

.maze-card.sel .maze-card-name {
  color: var(--text-primary);
}

.maze-card:hover .maze-card-name {
  color: var(--text-muted);
}

.maze-card-desc {
  font-family: 'Outfit', 'Courier New', monospace;
  font-size: .55rem;
  color: var(--text-dark);
  line-height: 1.5;
  margin-top: 2px;
  transition: color .35s var(--ease-out);
  animation: labelFadeIn .6s var(--ease-out) .45s both;
}

.maze-card:hover .maze-card-desc {
  color: var(--text-dim);
}

.maze-card.sel .maze-card-desc {
  color: var(--text-dim);
}

.maze-rotation-note {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 1rem;
  animation: fadeUp 0.7s var(--ease-out) 0.35s both;
}

.lobby-mark {
  font-family: 'Space Mono', monospace;
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--text-20);
  margin-bottom: 2.2rem;
}

.lobby-title {
  font-family: 'Space Mono', monospace;
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text-100);
  letter-spacing: -.02em;
  line-height: 1.55;
  margin-bottom: .5rem;
}

.lobby-sub {
  font-size: .68rem;
  color: var(--text-50);
  font-weight: 300;
  letter-spacing: .02em;
  line-height: 1.65;
  margin-bottom: 2rem;
}

/* ---- Settings Button ---- */
#settingsBtn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
  background: var(--bg-panel);
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.25s var(--ease-out), background 0.25s, transform 0.35s var(--ease-spring);
  user-select: none;
  padding: 0;
}

#settingsBtn:hover {
  border-color: var(--accent);
  background: var(--bg-elevated);
  transform: rotate(35deg) scale(1.05);
}

/* ---- Settings Drawer ---- */
@keyframes drawerSlideLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

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

#settingsModal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(0, 0, 0, 0.38);
}

#settingsModal.open {
  display: block;
  animation: scrimIn 0.22s ease both;
}

#settingsBox {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 300px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-dark);
  box-shadow: 8px 0 48px rgba(0, 0, 0, 0.45);
  padding: 1.25rem 1.5rem 2rem;
  overflow-y: auto;
  animation: drawerSlideLeft 0.28s var(--ease-out) both;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.4rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-title {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: none;
}

#settingsClose {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  transition: color 0.2s, background 0.2s;
  line-height: 1;
}

#settingsClose:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.settings-section-label {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.6rem;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.7rem;
}

#settings-theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.theme-card {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  cursor: pointer;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.62rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  text-align: left;
  width: 100%;
}

.theme-card:hover {
  border-color: var(--t-accent, var(--accent));
  color: var(--text-primary);
}

.theme-card.active {
  border-color: var(--t-accent, var(--accent));
  color: var(--text-primary);
  box-shadow: 0 0 0 1px var(--t-accent, var(--accent));
}

.theme-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--t-accent, var(--accent));
  flex-shrink: 0;
  box-shadow: 0 0 6px var(--t-accent, var(--accent));
}

/* .author-credit is only used by #gameplay-author (portrait mobile gameplay) */
.author-credit {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* ---- Suppress entrance animations on lobby return visits ---- */
/* Added when returnToLobby()/cancelOnline() is called — skips the blur/fade-in */
body.lobby-seen h1,
body.lobby-seen #lobby,
body.lobby-seen #lobby p,
body.lobby-seen .lobby-buttons,
body.lobby-seen #maze-selector,
body.lobby-seen .maze-card-body,
body.lobby-seen .maze-card-name,
body.lobby-seen .maze-card-desc,
body.lobby-seen .maze-rotation-note {
  animation: none;
}

.author-credit a {
  color: var(--author-link);
  text-decoration: none;
  transition: color 0.2s;
}

.author-credit a:hover {
  color: var(--overlay-text);
  text-decoration: underline;
}

/* Hidden on desktop; shown inside portrait mobile media query */
#gameplay-author {
  display: none;
}

/* ---- Global Site Footer ---- */
#site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-deep);
  padding: 0.45rem 1.5rem 0.55rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.footer-meta {
  font-size: 0.52rem;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  opacity: 0.6;
}

.footer-links {
  font-size: 0.58rem;
  color: var(--text-dim);
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-links a,
.footer-meta a {
  color: var(--author-link);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover,
.footer-meta a:hover {
  color: var(--overlay-text);
  text-decoration: underline;
}

.footer-sep {
  color: var(--text-dim);
  opacity: 0.35;
  margin: 0 0.45rem;
  user-select: none;
}

/* ---- Controls Help ---- */
#controls-help {
  margin-top: 1rem;
  padding-bottom: 0.95rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
}

#controls-help span {
  margin: 0 1rem;
}

.key {
  display: inline-block;
  background: var(--bg-panel);
  border: 1px solid var(--key-border);
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 0.7rem;
  color: var(--key-text);
  transition: border-color 0.2s, color 0.2s;
}

/* ---- Back Button (top-left, mirrors mute button) ---- */
#backBtn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1000;
  background: var(--bg-panel);
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1.4rem;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.25s var(--ease-out), background 0.25s, transform 0.25s;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
  line-height: 1;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

#backBtn:hover {
  border-color: var(--status-error);
  background: var(--bg-elevated);
  transform: scale(1.05);
}

/* ---- Leave Confirmation Modal ---- */
#leaveModal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#leaveModalBox {
  background: var(--bg-panel);
  border: 1px solid var(--border-dark);
  border-radius: 8px;
  padding: 1.6rem 2rem 1.4rem;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 0 32px rgba(0, 0, 0, 0.6);
  animation: fadeUp 0.3s var(--ease-spring) both;
}

#leaveModalMsg {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 1.2rem;
  line-height: 1.5;
}

#leaveModalMsg span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

#leaveModalBtns {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

#leaveCancel {
  padding: 0.5rem 1.4rem;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: bold;
  border: 1px solid var(--border-dark);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.2s var(--ease-out), background 0.2s;
}

#leaveCancel:hover {
  border-color: var(--text-muted);
  background: var(--leave-cancel-hover);
}

#leaveConfirm {
  padding: 0.5rem 1.4rem;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: bold;
  border: 1px solid var(--status-error);
  border-radius: 4px;
  background: transparent;
  color: var(--status-error);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s var(--ease-out), color 0.2s, transform 0.2s;
}

#leaveConfirm:hover {
  background: var(--status-error);
  color: var(--overlay-text);
  transform: translateY(-1px);
}

/* ---- Mute Toggle Button ---- */
#muteBtn {
  position: fixed;
  top: 12px;
  right: 60px;
  z-index: 1000;
  background: var(--bg-panel);
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1.4rem;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.25s var(--ease-out), background 0.25s, transform 0.25s;
  user-select: none;
  padding: 0;
  line-height: 1;
}

#muteBtn:hover {
  border-color: var(--accent);
  background: var(--bg-elevated);
  transform: scale(1.05);
}

/* ---- Voice Chat Settings Row ---- */
.settings-voice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 0.9rem;
}

.settings-voice-label {
  margin-bottom: 0 !important;
}

#micBtn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.65rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  user-select: none;
  white-space: nowrap;
}

#micBtn:hover {
  border-color: var(--accent);
  background: var(--bg-panel);
}

#micBtn.voice-active {
  border-color: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.35);
}

.mic-btn-label {
  font-size: 0.62rem;
  letter-spacing: 1.5px;
}

/* ---- Voice Toast Notification ---- */
.voice-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border-dark);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.7rem;
  padding: 0.6rem 1.2rem;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.95;
  white-space: nowrap;
}

/* ================ Mobile Touch Controls ================ */
#touch-controls {
  display: none; /* hidden by default; shown by portrait media query */
}

@media (orientation: portrait) and (max-width: 1024px) {
  /* Keyboard hints not relevant on touch devices */
  #controls-help {
    display: none !important;
  }

  /* Lobby: vertically centers content between the fixed top buttons and footer */
  #lobby {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100svh;
    /* top: clear the fixed mute/settings buttons (40px + 12px top + gap) */
    padding: 68px 1rem 5rem;
    width: 100%;
    gap: 0;
  }

  h1 {
    font-size: clamp(1.25rem, 7.5vw, 1.8rem);
    letter-spacing: 3px;
    margin-bottom: 0.2rem;
    white-space: nowrap;
  }

  #lobby > header > p {
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
  }

  #maze-selector {
    margin: 0.4rem 0 0.3rem;
  }

  #maze-selector h3 {
    margin-bottom: 0.5rem;
    font-size: 0.65rem;
  }

  .lobby-buttons {
    gap: 0.5rem;
    margin-bottom: 0.4rem;
  }

  .lobby-buttons .btn {
    padding: 0.65rem 1.5rem;
    font-size: 0.85rem;
  }

  .maze-rotation-note {
    font-size: 0.6rem;
    margin-top: 0.4rem;
  }

  /* Always show footer on mobile (desktop JS hides it only on non-mobile) */
  #gameContainer:not([style*="none"]) ~ #site-footer {
    display: flex !important;
  }

  /* Compact unified footer on mobile — mirrors desktop but smaller */
  #site-footer {
    padding: 0.3rem 0.75rem 0.4rem;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
  }

  .footer-meta {
    display: flex;
    font-size: 0.42rem;
    letter-spacing: 1px;
    opacity: 0.55;
  }

  .footer-links {
    font-size: 0.52rem;
    letter-spacing: 0.5px;
  }

  .footer-sep {
    margin: 0 0.28rem;
  }

  /* Settings drawer slides from the top on mobile */
  @keyframes drawerSlideTop {
    from { transform: translateY(-100%); }
    to   { transform: translateY(0); }
  }

  #settingsBox {
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    height: auto;
    max-height: 80dvh;
    border-right: none;
    border-bottom: 1px solid var(--border-dark);
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.45);
    animation: drawerSlideTop 0.28s var(--ease-out) both;
  }

  #settings-theme-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  /* Maze carousel */
  #maze-selector {
    margin: 0.6rem 0;
    width: 100%;
    overflow: visible;
  }

  #maze-grid {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    justify-content: flex-start;
    max-width: 100vw;
    padding: 0.6rem 28vw 0.6rem 28vw;
    gap: 0.5rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  #maze-grid::-webkit-scrollbar {
    display: none;
  }

  .maze-card {
    flex-shrink: 0;
    width: 44vw;
    max-width: 220px;
    scroll-snap-align: center;
    transform: scale(0.95);
    opacity: 0.9;
    transition:
      border-color .35s var(--ease-out),
      background .35s var(--ease-out),
      transform .35s var(--ease-out),
      opacity .35s var(--ease-out),
      box-shadow .5s var(--ease-out);
  }

  .maze-card.sel {
    transform: scale(1);
    opacity: 1;
  }

  .maze-card canvas {
    width: 100%;
    height: auto;
  }

  /* Game container stacks canvas + touch bar vertically.
     display is controlled by JS (show/hide); only override layout here.
     flex: 1 makes it fill the full viewport so --touch-area-bg covers
     the entire area below the canvas with no gap before the footer. */
  #gameContainer {
    flex-direction: column;
    align-items: center;
    padding: 0.25rem 0 0;
    flex: 1;
    min-height: 0;
    background: var(--touch-area-bg);
  }

  /* Author credit shown at the bottom during gameplay */
  #gameplay-author {
    display: block;
    width: 100%;
    text-align: center;
    padding: 3px 0 4px;
    margin-top: 0;
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.28);
    pointer-events: none;
    user-select: none;
    flex-shrink: 0;
  }

  #gameplay-author a {
    color: rgba(0, 212, 255, 0.45);
    text-decoration: none;
    pointer-events: auto;
  }

  /* Touch controls bar fills full width below canvas */
  #touch-controls {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 42vh;
    min-height: 160px;
    max-height: 300px;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
  }

  /* ---- Left half: shoot button ---- */
  #shoot-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #shoot-btn {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: var(--shoot-btn-bg);
    border: 3px solid var(--shoot-btn-border);
    color: var(--shoot-btn-text);
    font-size: 2.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 0 18px rgba(192, 57, 43, 0.7);
    transition: background 0.08s, transform 0.08s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
  }

  #shoot-btn:active {
    background: var(--shoot-btn-border);
    transform: scale(0.92);
  }

  /* ---- Right half: joystick ---- */
  #joystick-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
  }

  #joystick-base {
    position: relative;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: var(--joystick-base-bg);
    border: 2px solid var(--joystick-base-border);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #joystick-knob {
    position: absolute;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--joystick-knob-bg);
    border: 2px solid var(--joystick-knob-border);
    pointer-events: none;
    transform: translate(0px, 0px);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
  }

  /* ---- Connection UI mobile overrides ---- */
  .conn-panel {
    padding: 1.5rem 1.2rem;
    max-width: 100%;
    width: 95%;
  }

  #connectionUI .room-code {
    font-size: clamp(2rem, 9vw, 4.12rem);
    letter-spacing: clamp(4px, 2vw, 12px);
  }

  .room-input {
    font-size: clamp(1.6rem, 7vw, 3.2rem);
    letter-spacing: clamp(4px, 2vw, 10px);
    width: min(460px, 95%);
  }

  .panel-actions,
  .join-actions {
    flex-wrap: wrap;
  }

  .panel-actions .btn,
  .join-actions .btn {
    flex: 1 1 auto;
    min-width: 120px;
    text-align: center;
  }
}
