/* ─── That way! ─────────────────────────────────────────────── */

:root {
  --bg-0: #0b1020;
  --bg-1: #121a33;
  --ink: #eef2ff;
  --ink-dim: #98a2c3;
  --accent: #3dd6f5;
  --accent-2: #ff5d73;
  --gold: #ffd166;
  --card: rgba(255, 255, 255, 0.06);
  --card-line: rgba(255, 255, 255, 0.1);
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 800px at 80% -10%, #1c2a55 0%, transparent 60%),
    radial-gradient(900px 700px at -10% 110%, #241a44 0%, transparent 55%),
    var(--bg-0);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app { height: 100dvh; overflow: hidden; }

.screen {
  display: none;
  height: 100dvh;
  padding: calc(16px + var(--safe-top)) 20px calc(16px + var(--safe-bottom));
  flex-direction: column;
  overflow-y: auto; /* tall content (lobby/setup cards) must stay reachable */
}
.screen.active { display: flex; }
#screen-aim, #screen-reveal { overflow: hidden; } /* fixed layouts */

.hidden { display: none !important; }

/* ─── shared bits ─── */

.btn {
  font: inherit;
  font-weight: 700;
  color: #061018;
  background: linear-gradient(135deg, var(--accent), #6ef0c2);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.96); filter: brightness(1.1); }
.btn:disabled { opacity: 0.35; pointer-events: none; }

.btn-big {
  width: 100%;
  max-width: 420px;
  padding: 17px 24px;
  font-size: 18px;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 30px rgba(61, 214, 245, 0.35);
  margin: 0 auto;
}

.btn-small { padding: 12px 18px; font-size: 15px; flex-shrink: 0; }

.btn-lock {
  background: linear-gradient(135deg, var(--accent-2), #ff9f43);
  box-shadow: 0 8px 30px rgba(255, 93, 115, 0.4);
  color: #1c0509;
}

.hint { color: var(--ink-dim); font-size: 13px; text-align: center; margin-top: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  backdrop-filter: blur(10px);
}
.card h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  margin-bottom: 12px;
}

.round-pill {
  display: inline-block;
  align-self: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(61, 214, 245, 0.12);
  border: 1px solid rgba(61, 214, 245, 0.3);
  border-radius: 999px;
  padding: 6px 14px;
}

.center-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* `safe` falls back to top-aligned when content overflows, so nothing
     gets clipped above the scroll area on small screens */
  justify-content: safe center;
  gap: 14px;
  text-align: center;
  max-width: 460px;
  margin: 0 auto;
  width: 100%;
}

/* ─── setup ─── */

#screen-setup { overflow-y: auto; }
.setup-inner { max-width: 460px; margin: 0 auto; width: 100%; }

.brand { text-align: center; padding: 28px 0 24px; }
.brand-mark { font-size: 56px; line-height: 1; filter: drop-shadow(0 6px 18px rgba(61, 214, 245, 0.45)); }
.brand h1 {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-top: 10px;
  background: linear-gradient(135deg, #fff, #9fd8ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tagline { color: var(--ink-dim); margin-top: 6px; font-size: 15px; }

.add-row { display: flex; gap: 10px; }
.add-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
.add-row input:focus { border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chips:empty { margin-top: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 8px 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-line);
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip button {
  font: inherit;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  line-height: 1;
  cursor: pointer;
}

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-line);
  border-radius: 14px;
  padding: 12px 0;
  cursor: pointer;
}
.seg button.on {
  color: #061018;
  background: linear-gradient(135deg, var(--accent), #6ef0c2);
  border-color: transparent;
}

.rule-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.rule-label { font-size: 15px; font-weight: 600; }
.rule-sub { display: block; color: var(--ink-dim); font-size: 12px; font-weight: 400; margin-top: 2px; }

.switch {
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--card-line);
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform 0.2s ease, background 0.2s ease;
}
.switch[aria-checked="true"] { background: rgba(61, 214, 245, 0.45); border-color: transparent; }
.switch[aria-checked="true"]::after { transform: translateX(22px); background: #fff; }

/* ─── handoff ─── */

.pass-label { color: var(--ink-dim); font-size: 16px; margin-top: 12px; }
.handoff-name {
  font-size: 46px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--handoff-color, var(--accent));
  text-shadow: 0 0 40px color-mix(in srgb, var(--handoff-color, var(--accent)) 55%, transparent);
}
.pass-sub { color: var(--ink-dim); font-size: 14px; max-width: 300px; margin-bottom: 14px; }

/* ─── aim ─── */

#screen-aim { align-items: center; justify-content: space-between; }

.aim-header { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.aim-instruction { color: var(--ink-dim); font-size: 14px; text-transform: uppercase; letter-spacing: 0.12em; }

.target-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: var(--radius);
  padding: 12px 22px;
  backdrop-filter: blur(10px);
  animation: pop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.target-flag { font-size: 52px; line-height: 1; }
.target-name { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; }

.aim-player { font-size: 13px; color: var(--ink-dim); }

@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.dial-container {
  position: relative;
  width: min(78vw, 46dvh, 360px);
  aspect-ratio: 1;
  margin: 8px 0;
  touch-action: none;
}
.dial-container svg { width: 100%; height: 100%; display: block; }

.lubber {
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 18px solid var(--accent-2);
  filter: drop-shadow(0 2px 8px rgba(255, 93, 115, 0.8));
}

.heading-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.heading-deg {
  font-size: clamp(38px, 11vw, 56px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.heading-cardinal {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.aim-footer { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 4px; }
.aim-footer .hint { margin: 0 0 10px; }

.locked-flash { animation: locked 0.5s ease; }
@keyframes locked {
  0% { filter: brightness(1); }
  30% { filter: brightness(2.2); transform: scale(1.03); }
  100% { filter: brightness(1); }
}

/* ─── AR aim mode ─── */

#screen-aim { position: relative; }
#screen-aim .aim-header,
#screen-aim .aim-footer { position: relative; z-index: 2; }

.ar-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
  z-index: 1;
}
.ar-layer video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ar-horizon {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 200vmax;
  height: 0;
  margin-left: -100vmax;
  will-change: transform;
}
.ar-horizon-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent,
    rgba(61, 214, 245, 0.9) 20%, rgba(61, 214, 245, 0.9) 80%, transparent);
  box-shadow: 0 0 12px rgba(61, 214, 245, 0.7);
}
.ar-cardinals span {
  position: absolute;
  top: -36px;
  left: 50%;
  margin-left: -0.5em;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.9);
  will-change: transform, opacity;
  transition: opacity 0.2s ease;
}

.ar-crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  pointer-events: none;
}
.ar-crosshair::before,
.ar-crosshair::after {
  content: '';
  position: absolute;
  background: var(--accent-2);
  box-shadow: 0 0 8px rgba(255, 93, 115, 0.8);
}
.ar-crosshair::before { left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.ar-crosshair::after { top: 50%; left: 0; right: 0; height: 2px; margin-top: -1px; }

/* ─── reveal / globe ─── */

#screen-reveal { padding: 0; }

#globe {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: #0a0f1d;
}

.sheet {
  background: rgba(13, 18, 38, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--card-line);
  border-radius: 22px 22px 0 0;
  padding: 18px 20px calc(18px + var(--safe-bottom));
  max-height: 48dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet h2 { font-size: 19px; font-weight: 800; }
.reveal-sub { color: var(--ink-dim); font-size: 13px; margin-top: -8px; }

.results {
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.results li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 15px;
}
.results li.winner { border-color: var(--gold); background: rgba(255, 209, 102, 0.1); }
.results .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.results .r-name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .r-detail { color: var(--ink-dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.results .r-badge { font-weight: 800; color: var(--gold); font-size: 14px; }

.results.final li { font-size: 17px; padding: 14px 16px; }
.results.final { width: 100%; max-width: 420px; }

.final-title { font-size: 28px; font-weight: 800; margin-bottom: 8px; }

/* globe labels */
.player-label, .target-label {
  background: rgba(10, 15, 29, 0.85);
  border: 1px solid var(--card-line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 700;
  font-size: 12px;
  padding: 2px 7px;
  white-space: nowrap;
}
.target-label { font-size: 13px; border-color: var(--gold); }

/* ─── multiplayer ─── */

.btn-alt {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border: 1px solid var(--card-line);
  box-shadow: none;
}
.btn-ghost {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--card-line);
  box-shadow: none;
}

.join-card { width: 100%; text-align: left; }
.join-card input {
  width: 100%;
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  margin-bottom: 14px;
}
.join-card input:focus { border-color: var(--accent); }
#join-code { text-transform: uppercase; letter-spacing: 0.35em; font-weight: 800; }

.lobby-brand { padding: 18px 0 10px; }
.lobby-code {
  font-size: 54px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--accent);
  text-shadow: 0 0 34px rgba(61, 214, 245, 0.5);
}

.chip .presence { width: 8px; height: 8px; border-radius: 50%; background: #58d68d; flex-shrink: 0; }
.chip .presence.off { background: #66708f; }
.chip .you { color: var(--ink-dim); font-size: 12px; }

.wait-status { font-size: 24px; font-weight: 800; }
.wait-roster { justify-content: center; }
.chip.locked { border-color: var(--gold); }

.live-globe {
  width: min(72vw, 300px);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--card-line);
  box-shadow: 0 0 40px rgba(61, 214, 245, 0.15);
}
.live-globe:empty { display: none; }

.turn-timer {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: 16px;
  z-index: 1500;
  min-width: 52px;
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: rgba(13, 18, 38, 0.9);
  border: 1px solid var(--card-line);
  border-radius: 999px;
  padding: 8px 14px;
}
.turn-timer.urgent {
  color: #fff;
  background: rgba(255, 93, 115, 0.9);
  border-color: transparent;
  animation: timer-pulse 1s ease infinite;
}
@keyframes timer-pulse {
  50% { transform: scale(1.08); }
}

/* ─── toast ─── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(13, 18, 38, 0.95);
  border: 1px solid var(--card-line);
  color: var(--ink);
  font-size: 14px;
  padding: 12px 18px;
  border-radius: 14px;
  max-width: 86vw;
  text-align: center;
  z-index: 2000;
  transition: opacity 0.3s ease;
}
