/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d1f;
  --surface:   #161628;
  --surface2:  #1e1e3a;
  --surface3:  #12122a;
  --border:    rgba(255,255,255,0.09);
  --accent:    #3b82f6;
  --accent2:   #facc15;
  --green:     #22c55e;
  --red:       #ef4444;
  --orange:    #f97316;
  --purple:    #7c3aed;
  --text:      #f0f0f5;
  --muted:     #6b7280;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ---- Map ---- */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* ============================================================
   SPLASH SCREEN
   ============================================================ */
#splashScreen {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
  overflow-y: auto;
}

.splash-inner {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.splash-logo {
  text-align: center;
}
.splash-icon {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 10px;
}
.splash-logo h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
}
.splash-logo p {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.splash-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
}

.splash-hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
  margin-top: 4px;
}

.splash-tagline {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.form-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.form-divider::before,
.form-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---- Shared Input Style ---- */
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px; /* must be 16px+ to prevent iOS zoom */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--accent);
}
input::placeholder { color: var(--muted); }

/* ---- Buttons ---- */
.btn {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s, transform 0.1s;
  min-height: 52px;
  -webkit-appearance: none;
}
.btn:active { transform: scale(0.97); opacity: 0.9; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface3); color: var(--text); border: 1px solid var(--border); }
.btn-outline  { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.btn-start    { background: var(--green); color: #fff; margin-top: 12px; }
.btn-danger   { background: #7f1d1d; color: #fca5a5; margin-top: 8px; border: 1px solid #ef4444; }

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ============================================================
   SCREEN OVERLAYS (waiting / host / hider / seeker)
   ============================================================ */
#waitingScreen,
#hostScreen,
#hiderScreen,
#seekerScreen {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: rgba(8,8,20,0.9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 20px;
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(20px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Center vertically only when content is short enough to fit */
#waitingScreen,
#hiderScreen,
#seekerScreen {
  align-items: center;
}

.screen-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
}
.screen-card.scrollable {
  /* The outer screen container is now the scroll root, so the card
     just needs to be full-width with no artificial height cap. */
  width: 100%;
}
.screen-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}
.screen-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
}
.waiting-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}
.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: left;
  margin: 16px 0 8px;
}
.panel-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ---- Host player list ---- */
#hostPlayerList {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#hostPlayerList button {
  width: 100%;
  padding: 14px;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  min-height: 52px;
  transition: background 0.15s;
  -webkit-appearance: none;
}
#hostPlayerList button:active { background: #2a2a50; }

/* ---- Scores ---- */
.scores-panel { text-align: left; margin-bottom: 4px; }
.scores-panel h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.score-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface3);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 6px;
  font-size: 14px;
}
.score-rank  { color: var(--accent2); font-weight: 800; min-width: 24px; }
.score-name  { flex: 1; color: var(--text); font-weight: 600; }
.score-time  { color: var(--green); font-weight: 700; font-size: 13px; }
.score-bonus { color: #a78bfa; font-size: 11px; font-weight: 400; }

/* ---- Timer ---- */
.timer-display {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.timer-display span:first-child {
  font-size: 5rem;
  font-weight: 900;
  color: var(--accent2);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.timer-label { font-size: 14px; color: var(--muted); }

/* ============================================================
   HIDER SEEK SCREEN
   ============================================================ */
#hiderSeekScreen {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(8,8,20,0.96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  padding-top: calc(60px + var(--safe-top));
  padding-bottom: var(--safe-bottom);
  /* Prevent the outer container from growing beyond the viewport */
  overflow: hidden;
}

.hider-scroll-area {
  flex: 1;
  /* min-height: 0 is required for overflow-y: auto to work inside a flex child */
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Extra bottom padding so content clears the safe area */
  padding: 16px 16px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hider-panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}
.hider-panel h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.empty-msg { color: var(--muted); font-size: 13px; font-style: italic; }

/* ---- Hider question items ---- */
.hider-question-item {
  background: var(--surface3);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.hq-text { font-size: 15px; color: var(--text); margin-bottom: 12px; line-height: 1.4; }
.hq-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hq-btn {
  padding: 13px;
  border-radius: 10px;
  border: none;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  min-height: 52px;
  -webkit-appearance: none;
  transition: opacity 0.15s;
}
.hq-btn:active { opacity: 0.8; }
.hq-btn.yes { background: var(--green); color: #fff; }
.hq-btn.no  { background: var(--red);   color: #fff; }

/* ---- Hider cards ---- */
.hider-card {
  background: var(--surface3);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  border-left: 4px solid var(--muted);
}
.hider-card.challenge { border-left-color: var(--orange); }
.hider-card.buff      { border-left-color: var(--green); }

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.card-type-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: var(--muted);
  white-space: nowrap;
}
.card-name { font-size: 16px; font-weight: 700; color: var(--text); }
.card-desc { font-size: 14px; color: var(--muted); margin-bottom: 14px; line-height: 1.5; }
.card-play-btn {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  -webkit-appearance: none;
  transition: opacity 0.15s;
}
.card-play-btn:active { opacity: 0.85; }

/* ============================================================
   SEEK MAP SCREEN (seekers)
   ============================================================ */
#seekMapScreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}
#seekMapScreen > * { pointer-events: all; }

/* ---- Elapsed badge (shared) ---- */
.elapsed-badge {
  position: absolute;
  top: calc(14px + var(--safe-top));
  left: calc(14px + var(--safe-left));
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(13,13,31,0.92);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 700;
  color: #a5f3fc;
  z-index: 210;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}
.elapsed-icon { font-size: 15px; }
.elapsed-label { font-size: 11px; color: var(--muted); font-weight: 400; }
.bonus-badge {
  display: inline-flex;
  align-items: center;
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  padding: 2px 7px;
  margin-left: 2px;
}

/* ---- Ask button (top right) ---- */
.question-btn {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: calc(14px + var(--safe-right));
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  z-index: 210;
  min-height: 52px;
  box-shadow: 0 4px 16px rgba(59,130,246,0.4);
  -webkit-appearance: none;
  transition: opacity 0.15s;
}
.question-btn:active { opacity: 0.85; }

/* ---- Found hider button (bottom center) ---- */
.found-btn {
  position: absolute;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 18px 36px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  z-index: 210;
  min-height: 60px;
  white-space: nowrap;
  box-shadow: 0 6px 28px rgba(239,68,68,0.5);
  -webkit-appearance: none;
  transition: opacity 0.15s;
}
.found-btn:active { opacity: 0.85; transform: translateX(-50%) scale(0.97); }

/* ---- Question panel ---- */
.question-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface2);
  z-index: 250;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.question-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.question-panel-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.panel-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface3);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-appearance: none;
}

.question-panel > div:not(.question-panel-header) {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px;
  flex: 1;
}

/* Overriding for the scrollable inner area */
.question-panel .panel-divider { margin: 16px 0; }
.panel-section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.question-option {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 14px 16px;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  min-height: 52px;
  -webkit-appearance: none;
  transition: background 0.15s;
}
.question-option:active { background: #2a2a50; }

.question-entry {
  background: var(--surface3);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 14px;
}
.q-text    { display: block; color: #ccc; margin-bottom: 6px; line-height: 1.4; }
.q-answer  { display: block; color: var(--green); font-weight: 700; }
.q-pending { display: block; color: var(--accent2); font-style: italic; }
.q-auto-tag {
  display: inline-block;
  font-size: 10px;
  background: var(--purple);
  color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: middle;
  font-weight: 700;
}

/* ---- Challenge overlay ---- */
.challenge-overlay {
  position: absolute;
  inset: 0;
  z-index: 300;
  background: rgba(8,4,18,0.97);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
}

.challenge-card {
  background: var(--surface2);
  border: 2px solid var(--orange);
  border-radius: 24px;
  padding: 36px 28px;
  text-align: center;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 0 60px rgba(249,115,22,0.2), 0 8px 40px rgba(0,0,0,0.6);
  animation: challengePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes challengePop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.challenge-icon  { font-size: 3rem; margin-bottom: 14px; }
.challenge-title { font-size: 1.5rem; font-weight: 800; color: var(--orange); margin-bottom: 14px; }
.challenge-desc  { font-size: 15px; color: #ccc; line-height: 1.6; margin-bottom: 28px; }

.challenge-done-btn {
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  min-height: 56px;
  -webkit-appearance: none;
  margin-bottom: 12px;
  transition: opacity 0.15s;
}
.challenge-done-btn:active { opacity: 0.85; }
.challenge-timer {
  font-size: 15px;
  font-weight: 700;
  color: #facc15;
  margin: 0 0 16px;
  padding: 8px 12px;
  background: rgba(250, 204, 21, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(250, 204, 21, 0.25);
  text-align: center;
}
.challenge-note { font-size: 12px; color: var(--muted); font-style: italic; }

/* ---- Player markers ---- */
.player-marker { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.marker-dot {
  width: 16px; height: 16px;
  background: var(--accent);
  border: 2.5px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.marker-label {
  background: rgba(22,22,48,0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.marker-role {
  font-weight: 400;
  font-size: 10px;
  opacity: 0.7;
}

#serverStatus {
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(10px, env(safe-area-inset-left));
  font-size: 12px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border-radius: 6px;
  z-index: 999999; /* 🔥 increase this */
  pointer-events: none;
  font-family: sans-serif;
   margin: 0;
   overflow: hidden;
}

#versionInfo {
  position: fixed;
  bottom: max(40px, env(safe-area-inset-bottom));
  left: max(10px, env(safe-area-inset-left));
  font-size: 12px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border-radius: 6px;
  z-index: 999999;
  pointer-events: none;
  font-family: sans-serif;
   margin: 0;
   overflow: hidden;
}

#creditFooter {
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  right: max(10px, env(safe-area-inset-right));
  font-size: 12px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border-radius: 6px;
  z-index: 999999;
  pointer-events: none;
  font-family: sans-serif;
  margin: 0;
  overflow: hidden;
}

/* ---- Car Mode Toggle ---- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  margin: 12px 0;
}
.toggle-wrap {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}
.toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 28px;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle-input:checked + .toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: #fff;
}

/* ---- Car Mode Badge (seek map screen) ---- */
.car-mode-badge {
  position: absolute;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(13,13,31,0.92);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  z-index: 210;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  white-space: nowrap;
}
/* ---- Hider Map Panel ---- */
.hider-map-panel { padding-bottom: 0; overflow: hidden; }
#hiderMapDiv {
  width: 100%;
  height: 380px;
  border-radius: 10px;
  overflow: hidden;
}
.marker-dot-hider {
  background: var(--orange) !important;
  border-color: #fff;
}
/* ---- Leave / Exit Buttons ---- */
.btn-leave {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  margin-top: 16px;
  font-size: 14px;
}
.btn-leave:active { opacity: 0.7; }

/* Small exit button for map/hider screens — top right, below ask button */
.exit-btn {
  position: absolute;
  top: calc(76px + var(--safe-top)); /* below the elapsed badge, same left side */
  left: calc(14px + var(--safe-left));
  background: rgba(13,13,31,0.92);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  z-index: 210;
  min-height: 52px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  -webkit-appearance: none;
  white-space: nowrap;
}

/* Seeker dots on the hider's map — orange/red */
.marker-dot-seeker {
  background-color: #f97316; /* orange-500 */
  border-color: #ea580c;
}

/* "You" dot on the seeker map */
.marker-dot-me {
  background-color: #ffffff;
  border-color: #94a3b8;
}

.exit-btn:active { opacity: 0.7; }