:root {
  --bg: #eef6fd;
  --surface: #ffffff;
  --text: #10233a;
  --muted: #5b6b80;
  --line: #d3e2f0;
  --accent: #2f8fe8;
  --accent-strong: #1768b8;
  --good: #1f9d55;
  --warn: #c98a00;
  --bad: #d1343b;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1622;
    --surface: #152435;
    --text: #e5f0fb;
    --muted: #93a7bd;
    --line: #25384d;
    --accent: #4aa3f5;
    --accent-strong: #7dbcf8;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; margin-bottom: .5rem; }
p { margin: 0 0 .75rem; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hero { text-align: center; padding: 24px 0 8px; }
.hero-icon { width: 96px; height: 96px; }
.hero h1 { font-size: 1.8rem; margin: 8px 0 4px; }
.hero p { color: var(--muted); }
.hero .hero-sub { margin: -6px 0 6px; color: var(--accent); font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card.muted { opacity: .7; }

.topbar { display: flex; align-items: center; gap: 10px; }
.topbar h1 { flex: 1; }
.back { font-size: 2rem; line-height: 1; text-decoration: none; color: var(--accent); padding: 0 6px; }

.pill { font-size: .75rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; color: #fff; }
.pill-good { background: var(--good); }
.pill-warn { background: var(--warn); }
.pill-bad { background: var(--bad); }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: var(--radius);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-block { width: 100%; }
.btn-throw {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: #fff;
  font-size: 1.2rem;
  padding: 18px;
  box-shadow: 0 4px 0 var(--accent-strong);
}
.btn-throw:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-strong); }
.btn-throw img { width: 36px; height: 36px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat-value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-detail { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.quality-good { color: var(--good); }
.quality-warn { color: var(--warn); }
.quality-bad { color: var(--bad); }

.banner { border-radius: var(--radius); padding: 10px 14px; font-weight: 600; }
.banner-bad { background: color-mix(in srgb, var(--bad) 15%, var(--surface)); color: var(--bad); }
.banner-warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.banner-good { background: color-mix(in srgb, var(--good) 15%, var(--surface)); color: var(--good); }

.aim {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.aim-dial {
  width: 76px;
  height: 76px;
  flex: none;
  border-radius: 50%;
  border: 3px solid var(--line);
  position: relative;
}
.aim-dial::before {
  /* Marks "straight ahead" (top edge of the phone). */
  content: "";
  position: absolute;
  top: -3px;
  left: 50%;
  width: 3px;
  height: 12px;
  margin-left: -1.5px;
  background: var(--muted);
}
.aim-arrow {
  position: absolute;
  inset: 8px;
  transition: transform .15s linear;
}
.aim-arrow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  margin-left: -11px;
  border: 11px solid transparent;
  border-bottom: 26px solid var(--muted);
  border-top: 0;
}
.aim-arrow.on-target::before { border-bottom-color: var(--good); }
.aim-arrow.off-target::before { border-bottom-color: var(--bad); }
.aim-text { display: flex; flex-direction: column; min-width: 0; }
.aim-hint { font-weight: 700; font-size: 1.05rem; }

.map {
  height: 45vh;
  min-height: 260px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  z-index: 0;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .btn { flex: 1; }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: .9rem; color: var(--muted); }
.sim { display: flex; flex-direction: column; gap: 10px; }
.slider { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.slider input { width: 100%; }

.log { margin: 0; padding-left: 1.3rem; display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }
.log .hit { color: var(--good); font-weight: 700; }
.log .miss { color: var(--bad); font-weight: 700; }

.leaflet-marker-icon.flying { transition: none; }
.icon-pulse { animation: pulse .6s ease-out; }
@keyframes pulse {
  from { transform: scale(.3); opacity: .3; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------------------------------------------------------------- forms */

.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span:first-child, .field legend { font-weight: 600; }
.input {
  font: inherit;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field input[type=range] { width: 100%; }
.form-error { color: var(--bad); font-size: .9rem; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.segmented { flex-direction: row; flex-wrap: wrap; }
.segmented legend { width: 100%; margin-bottom: 6px; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  text-align: center;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.segmented label:first-of-type span { border-radius: 10px 0 0 10px; }
.segmented label:last-of-type span { border-radius: 0 10px 10px 0; }
.segmented input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent-strong); }

.join-form { display: flex; gap: 8px; margin-bottom: 8px; }
.input-code { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; flex: 1; min-width: 0; }

.btn-small { padding: 6px 10px; font-size: .8rem; border-radius: 10px; }
.btn-danger { color: var(--bad); }

.center { text-align: center; }
.link-muted { color: var(--muted); font-size: .9rem; }

/* ---------------------------------------------------------------- lobby */

.map-small { height: 220px; min-height: 0; }

.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .15em; }
.code-big { font-size: 2rem; font-weight: 800; }

.invite { display: flex; gap: 14px; align-items: center; }
.qr { width: 140px; height: 140px; flex: none; border-radius: 8px; background: #fff; }
.invite-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.invite-text .btn { margin-top: 6px; }
@media (max-width: 380px) {
  .invite { flex-direction: column; text-align: center; }
  .qr { width: 200px; height: 200px; }
}

.team-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; }
.team-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.team-list li:last-child { border-bottom: 0; }
.team-list-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.team-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--team-color, var(--muted));
  flex: none;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--team-color, var(--muted));
}
.online { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.online.is-online { background: var(--good); }

.team-badge { display: flex; align-items: center; gap: 14px; border-left: 6px solid var(--team-color); }
.team-badge .team-dot { width: 22px; height: 22px; }
.team-badge div { display: flex; flex-direction: column; }
.team-name { font-size: 1.3rem; }

/* ---------------------------------------------------------------- play */

.play {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.play-map { flex: 1; min-height: 0; z-index: 0; }

.hud {
  padding: max(10px, env(safe-area-inset-top)) 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 2;
}
.hud-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.hud-title { font-size: 1.05rem; }
.zone-info { font-weight: 700; font-variant-numeric: tabular-nums; }

.wet { display: flex; align-items: center; gap: 8px; }
.wet-icon { width: 26px; height: 26px; }
.wet-bar {
  flex: 1;
  height: 16px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  box-shadow: inset 0 0 0 2px var(--team-color);
}
.wet-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #6cc0ff, #1768b8);
  transition: width .6s ease;
}
.wet-value { font-weight: 800; min-width: 4.5em; text-align: right; font-variant-numeric: tabular-nums; }

.banner-stack {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 72px);
  left: 12px;
  right: 12px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.banner-stack > * { pointer-events: auto; }
.banner-stack > .toasts { pointer-events: none; }

.rain-banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #324a66;
  color: #fff;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 4px 14px rgb(0 0 0 / .25);
  animation: rain-pulse 1.2s ease-in-out infinite alternate;
}
@keyframes rain-pulse { from { opacity: .85; } to { opacity: 1; } }

.toasts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.toast {
  align-self: center;
  max-width: 100%;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 3px 12px rgb(0 0 0 / .2);
  transition: opacity .5s, transform .5s;
}
.toast.good { background: var(--good); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast-out { opacity: 0; transform: translateY(-8px); }

.controls {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 2;
  position: relative;
}
.ctrl {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  cursor: pointer;
}
.ctrl img { width: 34px; height: 34px; }
.ctrl:disabled { opacity: .4; cursor: not-allowed; }
.ctrl-umbrella { flex: none; min-width: 92px; }
.ctrl-umbrella.active { background: #ff5a5f; border-color: #d1343b; color: #fff; opacity: 1; }
.ctrl-throw {
  flex: 1;
  background: var(--accent);
  border-color: var(--accent-strong);
  color: #fff;
  font-size: 1.15rem;
  box-shadow: 0 4px 0 var(--accent-strong);
}
.ctrl-throw:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-strong); }
.heading-info {
  position: absolute;
  top: -30px;
  left: 16px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface);
  font-size: .8rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgb(0 0 0 / .15);
}

.map-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgb(0 0 0 / .2);
}
.item-icon { filter: drop-shadow(0 2px 2px rgb(0 0 0 / .35)); }
.team-tip { font-weight: 700; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgb(12 22 34 / .6);
  color: #fff;
  text-align: center;
}
.overlay-soft { background: rgb(12 22 34 / .35); pointer-events: none; }
.overlay-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
.countdown-number { font-size: 6rem; font-weight: 900; line-height: 1; text-shadow: 0 4px 20px rgb(0 0 0 / .4); }

.ranking { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.ranking li { display: flex; align-items: center; gap: 10px; }

.sim-float {
  position: absolute;
  bottom: 110px;
  left: 16px;
  right: 16px;
  z-index: 3;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 10px rgb(0 0 0 / .2);
}

.watch-panel {
  max-height: 38vh;
  overflow-y: auto;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 2;
}
.mini-bar { width: 70px; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; flex: none; }
.mini-bar span { display: block; height: 100%; background: var(--accent); }

.conn-banner {
  padding: 10px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--warn);
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 4px 14px rgb(0 0 0 / .25);
}
.resume-bar { background: var(--accent); cursor: pointer; width: auto; }
.compass-banner { background: var(--bad); }

.resume { border: 2px solid var(--accent); }
.resume-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.resume-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  color: var(--text);
  text-decoration: none;
}
.resume-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.resume-go { font-size: 1.6rem; color: var(--accent); }
#finished-bar .btn { flex: 1; }
.menu-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  font-size: 1.2rem;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
}
.hud-row .zone-info { flex: 1; }

.site-footer { text-align: center; padding: 8px 16px 24px; font-size: .85rem; color: var(--muted); }
.site-footer a { color: var(--muted); }
.legal h2 { margin-top: 1.2rem; }
.legal p, .legal li { color: var(--text); }

/* ---------------------------------------------------------------- calibration & safety */

.calib { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.calib-svg { width: 180px; height: 90px; }
.calib-path { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 6; opacity: .6; }
.calib-phone rect { fill: var(--surface); stroke: var(--text); stroke-width: 2.5; }
.calib-phone circle { fill: var(--text); }
.calib p { margin: 0; }

.safety { padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.safety ul { margin: 6px 0 0; padding-left: 20px; }
.safety li { margin: 4px 0; }
