:root {
  --ink: #0c131a;
  --cream: #f5f2ea;
  --accent: #f2b24d;
  --teal: #2bb3a7;
  --panel: rgba(14, 19, 24, 0.92);
  --panel-border: rgba(255, 255, 255, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Space Grotesk", sans-serif;
  background: #87c9ff;
  color: var(--cream);
}

canvas {
  display: block;
}

#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(
    circle at top,
    rgba(13, 19, 25, 0.15),
    rgba(10, 12, 15, 0.7)
  );
  backdrop-filter: blur(8px);
  z-index: 10;
  transition: opacity 0.4s ease;
}

#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(520px, 90vw);
  padding: 32px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.panel h1 {
  margin: 12px 0 10px;
  font-size: 2.2rem;
  letter-spacing: 0.02em;
}

.panel p {
  margin: 0 0 24px;
  line-height: 1.5;
  color: rgba(245, 242, 234, 0.86);
}

.badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  background: rgba(43, 179, 167, 0.2);
  color: var(--teal);
  border: 1px solid rgba(43, 179, 167, 0.5);
}

label {
  display: block;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin-bottom: 8px;
  color: rgba(245, 242, 234, 0.65);
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.row.secondary {
  margin-top: 12px;
  flex-wrap: wrap;
}

#roomInput,
#nameInput {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: var(--cream);
  font-size: 1rem;
  outline: none;
}

#nameInput {
  width: 100%;
  margin-bottom: 16px;
}

#shareLink {
  flex: 1 1 260px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(245, 242, 234, 0.9);
  font-size: 0.85rem;
  font-family: "DM Mono", monospace;
  outline: none;
}

#copyLinkBtn,
#copyCodeBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(18, 24, 30, 0.75);
  color: rgba(245, 242, 234, 0.9);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#copyLinkBtn svg,
#copyCodeBtn svg {
  width: 18px;
  height: 18px;
}

#copyLinkBtn:hover,
#copyCodeBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

#copyLinkBtn.copied,
#copyCodeBtn.copied {
  background: rgba(43, 179, 167, 0.9);
  color: #072022;
  border-color: rgba(43, 179, 167, 0.9);
}

#roomInput:focus,
#nameInput:focus {
  border-color: rgba(242, 178, 77, 0.7);
  box-shadow: 0 0 0 3px rgba(242, 178, 77, 0.18);
}

#joinBtn {
  padding: 12px 18px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #291b08;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#joinBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(242, 178, 77, 0.35);
}

#joinBtn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.tips {
  display: flex;
  gap: 16px;
  margin-top: 18px;
  font-size: 0.85rem;
  color: rgba(245, 242, 234, 0.7);
  flex-wrap: wrap;
}

.tips span {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  z-index: 5;
  font-family: "DM Mono", monospace;
}

#status {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(11, 15, 20, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#controlsHint {
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(11, 15, 20, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#toolbar {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-self: flex-end;
  pointer-events: auto;
}

#toolbar button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(18, 24, 30, 0.75);
  color: rgba(245, 242, 234, 0.9);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#toolbar button svg {
  width: 20px;
  height: 20px;
}

#toolbar button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

#muteBtn.muted {
  background: rgba(217, 93, 93, 0.9);
  color: #2b0d0d;
  border-color: rgba(217, 93, 93, 0.9);
}

#toolbar button.active {
  background: rgba(242, 178, 77, 0.9);
  color: #2a1c08;
  border-color: rgba(242, 178, 77, 0.9);
}

#toolbar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

#toolbar .slider {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(18, 24, 30, 0.6);
  color: rgba(245, 242, 234, 0.8);
  font-family: "DM Mono", monospace;
  pointer-events: auto;
}

#toolbar .slider label {
  margin: 0;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(245, 242, 234, 0.6);
}

#masterVolume {
  width: 120px;
}

#volumePopup {
  position: fixed;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  background: rgba(10, 14, 18, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
  z-index: 20;
  min-width: 160px;
}

#volumePopup.hidden {
  opacity: 0;
  pointer-events: none;
}

#mobileControls {
  position: fixed;
  inset: 0;
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  --stick-size: 150px;
  --stick-offset: 16px;
  --button-size: 50px;
  --button-gap: 10px;
}

#mobileControls.active {
  opacity: 1;
}

#mobileControls .joystick-zone {
  position: absolute;
  width: var(--stick-size);
  height: var(--stick-size);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(10, 14, 18, 0.45);
  backdrop-filter: blur(6px);
  pointer-events: auto;
  touch-action: none;
}

#moveStick {
  left: max(var(--stick-offset), env(safe-area-inset-left));
  right: auto;
  bottom: max(var(--stick-offset), env(safe-area-inset-bottom));
}

#lookStick {
  left: auto;
  right: max(var(--stick-offset), env(safe-area-inset-right));
  bottom: max(var(--stick-offset), env(safe-area-inset-bottom));
}

#mobileControls .mobile-buttons {
  position: absolute;
  right: max(var(--stick-offset), env(safe-area-inset-right));
  bottom: calc(
    var(--stick-size) + var(--stick-offset) + var(--button-gap) + env(safe-area-inset-bottom)
  );
  display: flex;
  flex-direction: column;
  gap: var(--button-gap);
  pointer-events: auto;
}

#mobileControls .mobile-buttons button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--button-size);
  height: var(--button-size);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(18, 24, 30, 0.78);
  color: rgba(245, 242, 234, 0.9);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#mobileControls .mobile-buttons button svg {
  width: 24px;
  height: 24px;
}

#mobileControls .mobile-buttons button:active {
  transform: translateY(1px);
}

#popupPeerName {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(245, 242, 234, 0.8);
}

#peerVolume {
  width: 160px;
}

#mutePeerBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(18, 24, 30, 0.75);
  color: rgba(245, 242, 234, 0.9);
  cursor: pointer;
}

#mutePeerBtn svg {
  width: 18px;
  height: 18px;
}

#localIdentity {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

#localVideo {
  width: 160px;
  height: 120px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  object-fit: cover;
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

#nameHudInput {
  width: 160px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(11, 15, 20, 0.6);
  color: rgba(245, 242, 234, 0.9);
  font-family: "DM Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  text-align: center;
  outline: none;
}

#nameHudInput::placeholder {
  color: rgba(245, 242, 234, 0.55);
}

#nameHudInput:focus {
  border-color: rgba(242, 178, 77, 0.6);
  box-shadow: 0 0 0 2px rgba(242, 178, 77, 0.2);
}

@media (max-width: 700px) {
  .panel {
    padding: 20px;
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    width: min(520px, calc(100vw - 32px));
  }

  .panel h1 {
    font-size: 1.5rem;
    margin: 8px 0 6px;
  }

  .panel p {
    font-size: 0.9rem;
    margin-bottom: 16px;
    line-height: 1.4;
  }

  .badge {
    padding: 4px 10px;
    font-size: 0.7rem;
  }

  label {
    font-size: 0.8rem;
    margin-bottom: 6px;
  }

  #nameInput {
    margin-bottom: 12px;
  }

  .row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .row.secondary {
    margin-top: 8px;
    flex-direction: row;
    gap: 6px;
  }

  #shareLink {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px;
    font-size: 0.75rem;
  }

  #copyLinkBtn,
  #copyCodeBtn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
  }

  #copyLinkBtn svg,
  #copyCodeBtn svg {
    width: 16px;
    height: 16px;
  }

  #joinBtn {
    width: 100%;
    padding: 14px 18px;
  }

  .tips {
    margin-top: 12px;
    gap: 8px;
    font-size: 0.75rem;
  }

  .tips span {
    padding: 4px 8px;
  }

  #localVideo {
    width: 120px;
    height: 90px;
  }

  #nameHudInput {
    width: 120px;
  }

  #mobileControls {
    --stick-size: 120px;
    --stick-offset: 12px;
    --button-size: 44px;
  }

  body.mobile-active #status {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
  }

  body.mobile-active #controlsHint {
    position: fixed;
    top: calc(44px + env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
  }

  body.mobile-active #toolbar {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    margin-top: 0;
  }

  body.mobile-active #localIdentity {
    position: fixed;
    top: calc(76px + env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    margin-top: 0;
  }
}

/* Very short screens (landscape phones) */
@media (max-height: 500px) {
  .panel {
    padding: 16px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }

  .panel h1 {
    font-size: 1.3rem;
    margin: 4px 0;
  }

  .panel p {
    display: none;
  }

  .badge {
    display: none;
  }

  label {
    font-size: 0.75rem;
    margin-bottom: 4px;
  }

  #nameInput {
    margin-bottom: 8px;
    padding: 10px 12px;
  }

  #roomInput {
    padding: 10px 12px;
  }

  .row {
    gap: 6px;
  }

  .row.secondary {
    display: none;
  }

  #joinBtn {
    padding: 12px 16px;
  }

  .tips {
    display: none;
  }
}
