:root {
  --bg: #0f1320;
  --panel: #1b2035;
  --accent: #4f62ff;
  --text: #e7e9ee;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, Arial, sans-serif; background: var(--bg); color: var(--text); }
header { padding: 10px 16px; background: var(--panel); display: flex; align-items: center; justify-content: space-between; }
h1 { margin: 0; font-size: 18px; }
.room-info span { margin-right: 12px; }
.controls { display: flex; gap: 10px; align-items: center; }
/* Center controls on controller page */
.controller .controls { justify-content: center; }
button { background: var(--accent); color: white; border: none; padding: 10px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; }
button.big { padding: 16px 22px; font-size: 18px; }
/* Shade out disabled buttons for clearer affordance */
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(35%);
}

main { display: grid; grid-template-columns: 280px 1fr; gap: 14px; padding: 14px; }
/* On controller page, stack sections vertically so controls sit below image */
.controller main { grid-template-columns: 1fr; }
/* When race starts on host, expand canvas to full width */
main.full { grid-template-columns: 1fr; }
.qr { background: var(--panel); padding: 12px; border-radius: 12px; text-align: center; }
.qr img { width: 100%; height: auto; background: white; padding: 8px; border-radius: 8px; }
.canvas-wrap { background: #0a0a0a; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; position: relative; }
canvas { width: 100%; height: auto; background: #6b8e23; }
/* On controller pages, avoid stretching the game image on desktop; keep natural size */
.controller canvas { width: auto; max-width: 100%; height: auto; }
/* Center mini-map canvas on controller */
.controller .mini-map { display: flex; justify-content: center; }

/* Hide QR elements but keep Players list visible when toggled */
.qr.hidden h2,
.qr.hidden #qrImg,
.qr.hidden #joinUrl,
.qr.hidden #copyJoinBtn,
.qr.hidden .credit { display: none; }

/* Center URL under QR and make it smaller */
#joinUrl { text-align: center; font-size: 12px; opacity: 0.95; word-break: break-word; }
/* Style copy link button */
#copyJoinBtn { display: block; margin: 8px auto; padding: 8px 12px; font-size: 14px; }

/* Centered credit text below QR heading on host */
.qr .credit { text-align: center; margin: 6px 0 10px; opacity: 0.9; }

.join { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; }
.join input { padding: 10px; border-radius: 8px; border: 1px solid #333; background: #10142a; color: var(--text); }

.pad { display: flex; gap: 12px; justify-content: center; margin: 10px 0; }
.control { min-width: 90px; min-height: 60px; font-size: 20px; }
.hint { text-align: center; opacity: 0.8; }

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
}
.overlay-controls { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; justify-content: center; gap: 12px; padding: 10px 12px; background: linear-gradient(to top, rgba(27,32,53,0.95), rgba(27,32,53,0)); }
.overlay-controls .control { min-width: 100px; min-height: 64px; font-size: 22px; }

/* Prevent accidental text selection/copy callouts on mobile controls */
.overlay-controls,
.overlay-controls .control {
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* Reduce double-tap zoom/gesture issues on supported browsers */
.overlay-controls .control { touch-action: manipulation; }

/* Host audio overlay panel */
.audio-overlay {
  position: fixed;
  right: 12px;
  top: 60px;
  width: 280px;
  background: var(--panel);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  z-index: 5;
}
.audio-overlay h3 { margin: 0 0 8px; font-size: 16px; }
.audio-overlay .row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px; margin: 8px 0; }
.audio-overlay input[type="range"] { width: 100%; }

/* Generic modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: none; /* shown by inline style initially */
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal-content {
  width: min(640px, calc(100% - 32px));
  background: var(--panel);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.45);
}
.modal-content h3 { margin: 0 0 8px; font-size: 18px; }
.modal-content p { margin: 8px 0 12px; line-height: 1.4; opacity: 0.92; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }