:root {
  --bg: #0f1224;
  --surface: #1b2040;
  --accent: #8ef9f3;
  --accent-2: #f9a8d4;
  --text: #f4f7ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #23295a, var(--bg));
  color: var(--text);
  font-family: ui-rounded, system-ui, -apple-system, Segoe UI, sans-serif;
}

.landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  width: min(520px, 100%);
  background: color-mix(in hsl, var(--surface), #000 12%);
  border: 1px solid #ffffff2b;
  border-radius: 16px;
  padding: 18px;
}

.subtitle {
  opacity: 0.9;
  margin-top: 4px;
}

.form-block {
  margin-top: 16px;
}

button,
input {
  border-radius: 12px;
  border: 1px solid #ffffff4f;
  padding: 10px 12px;
  font-size: 16px;
}

button {
  cursor: pointer;
  background: #293062;
  color: var(--text);
}

.primary {
  background: linear-gradient(90deg, var(--accent), #86efac);
  color: #032726;
  font-weight: 700;
  width: 100%;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
}

.status,
.hint,
.status-line {
  margin-top: 12px;
  opacity: 0.85;
  font-size: 14px;
}

.instructions {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #ffffff20;
}

.instructions-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
  opacity: 0.95;
}

.instructions-list {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.5;
  opacity: 0.9;
}

.instructions-list li {
  margin-bottom: 6px;
}

.instructions-list li:last-child {
  margin-bottom: 0;
}

.created-room {
  background: #0f1634;
  border: 1px solid #ffffff2b;
  border-radius: 12px;
  padding: 12px;
}

.room-code {
  margin: 8px 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #222c5a;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-align: center;
  font-size: 20px;
}

.secondary-cta {
  margin-top: 10px;
}

.game {
  overflow: hidden;
}

.hud {
  position: fixed;
  inset: 10px 10px auto 10px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  z-index: 30;
}

.hud > * {
  background: #10162ed4;
  border: 1px solid #ffffff2d;
  padding: 8px 10px;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}

#progressInfo {
  font-size: 12px;
}

.exit-game-btn {
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  top: 66px;
  z-index: 31;
  background: #0f1734d9;
  border: 1px solid #ffffff3f;
  color: #e8ebff;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.audio-toggle {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  top: 66px;
  z-index: 31;
  background: #0f1734d9;
  border: 1px solid #ffffff3f;
  color: #e8ebff;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
}

.pill.runner {
  color: #04211f;
  background: #7ef9e0;
}

.pill.chaser {
  color: #2f0520;
  background: #ffb3d8;
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

.swap-cue {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 12px 16px;
  border-radius: 12px;
  background: #fff2;
  border: 1px solid #fff5;
  font-size: 18px;
  font-weight: 800;
}

.role-flash {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 45;
  padding: 14px 20px;
  border-radius: 14px;
  font-size: clamp(28px, 6vw, 52px);
  font-weight: 900;
  letter-spacing: 0.08em;
  background: #0f152fcc;
  border: 1px solid #ffffff40;
  text-shadow: 0 2px 16px #0008;
  pointer-events: none;
}

.role-flash.run {
  color: #7ef9e0;
}

.role-flash.chase {
  color: #ffb3d8;
}

.hidden {
  display: none;
}

.mobile-controls {
  position: fixed;
  /* Thumb-friendly zone: respect safe area on iPhone (notch, home indicator) */
  left: max(12px, env(safe-area-inset-left));
  right: 12px;
  bottom: max(16px, env(safe-area-inset-bottom));
  top: auto;
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
  z-index: 50;
  pointer-events: none;
}

/* Invisible hit area for dynamic joystick: left half, below HUD/buttons so Exit and HUD stay tappable */
.mobile-controls-touch-zone {
  position: fixed;
  left: 0;
  top: 110px; /* below HUD (~66px) + padding so Exit/Audio and HUD receive taps */
  width: 50%;
  height: calc(100% - 110px);
  z-index: 51;
  pointer-events: none;
}

.mobile-controls-touch-zone.active {
  pointer-events: auto;
}

.joystick-base {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  /* Prevent tap highlight and callout on iOS */
  -webkit-tap-highlight-color: transparent;
}

/* Dynamic mode (touch): joystick is positioned where user first touches */
.joystick-base.dynamic {
  position: fixed;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  top: auto;
  right: auto;
}

.joystick-base {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.35);
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.joystick-base:active {
  transform: scale(1.02);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

.joystick-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.6);
  position: absolute;
  left: 29px;
  top: 29px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  transition: box-shadow 0.1s ease;
  pointer-events: none;
}

.joystick-base.active .joystick-knob {
  box-shadow: 0 4px 16px rgba(142, 249, 243, 0.4);
}

/* Larger, higher-contrast joystick on touch devices for easier thumb control */
@media (max-width: 900px), (pointer: coarse) {
  .joystick-base {
    width: 130px;
    height: 130px;
    background: rgba(255, 255, 255, 0.18);
    border: 2px solid rgba(255, 255, 255, 0.5);
  }

  .joystick-knob {
    width: 60px;
    height: 60px;
    left: 35px;
    top: 35px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.7);
  }
}

.status-line {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  background: #091020d1;
  border: 1px solid #ffffff2c;
  border-radius: 8px;
  padding: 6px 10px;
  z-index: 60;
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: #050a1fcc;
  backdrop-filter: blur(3px);
}

.result-overlay.hidden {
  display: none;
}

.result-card {
  width: min(420px, calc(100vw - 28px));
  border-radius: 18px;
  border: 1px solid #ffffff33;
  background: #101735f2;
  padding: 18px;
  text-align: center;
}

.result-card h2 {
  margin: 0;
  font-size: 30px;
}

.result-card p {
  margin: 8px 0 10px;
  font-size: 18px;
  opacity: 0.92;
}

.result-score {
  border-radius: 12px;
  border: 1px solid #ffffff24;
  background: #0a122bd6;
  padding: 10px 12px;
  font-size: 18px;
  font-weight: 700;
}

.result-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

@media (min-width: 900px) {
  .mobile-controls {
    max-width: 600px;
    margin: 0 auto;
    left: 0;
    right: 0;
  }
}
