/* Manhunt — orienteering-map look: cool paper, ink, magenta overprint, team colours. */

:root {
  --paper: #f3f4ef;
  --surface: #ffffff;
  --sunk: #e8eae2;
  --ink: #1a1e1a;
  --ink-2: #596159;
  --line: #d6dacf;
  --runner: #e2560b;
  --runner-ink: #ffffff;
  --chaser: #2450b2;
  --chaser-ink: #ffffff;
  --overprint: #b3127a;
  --good: #2b7a36;
  --bad: #c42b2b;
  --warn: #9a5c00;
  --team: var(--ink);
  --team-ink: var(--paper);
  --shadow: 0 1px 2px rgba(26, 30, 26, .08), 0 8px 24px rgba(26, 30, 26, .10);
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151915;
    --surface: #1d221d;
    --sunk: #262c26;
    --ink: #eceee7;
    --ink-2: #9ba49b;
    --line: #313831;
    --runner: #ff7a33;
    --runner-ink: #1a0d05;
    --chaser: #6b93f0;
    --chaser-ink: #0b1430;
    --overprint: #e655b4;
    --good: #5fbf6c;
    --bad: #ff6b6b;
    --warn: #e0a040;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font: 400 16px/1.45 var(--body);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
.app { min-height: 100dvh; }
.app[data-team="RUNNER"] { --team: var(--runner); --team-ink: var(--runner-ink); }
.app[data-team="CHASER"] { --team: var(--chaser); --team-ink: var(--chaser-ink); }

h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.05; margin: 0; letter-spacing: .005em; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.25rem; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--overprint); outline-offset: 2px; }

.mark { width: 56px; height: 56px; fill: none; stroke: var(--overprint); stroke-width: 4; stroke-linejoin: round; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 52px; padding: 0 1.25rem; border-radius: 10px;
  border: 2px solid var(--ink); background: transparent; color: var(--ink);
  font-weight: 600; font-size: 1.0625rem; cursor: pointer; text-decoration: none;
  transition: transform .08s ease, background .15s ease;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--paper); }
.app[data-team] .btn-primary { background: var(--team); border-color: var(--team); color: var(--team-ink); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-small { min-height: 40px; padding: 0 .9rem; font-size: .9375rem; border-radius: 8px; border-width: 1.5px; }
.btn-quiet { border-color: var(--line); color: var(--ink-2); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line);
  background: var(--surface); display: grid; place-items: center; font-size: 1.1rem; cursor: pointer;
}
.icon-sm { width: 32px; height: 32px; font-size: .8rem; }
.link-back { background: none; border: 0; padding: .5rem 0; color: var(--ink-2); font-weight: 600; cursor: pointer; }
.link-back::before { content: '‹ '; }

.field { display: grid; gap: .4rem; }
.field > span { font-weight: 600; font-size: .9375rem; }
.field input, .field select, .code-input, select {
  min-height: 52px; padding: 0 1rem; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface); font-size: 1.0625rem;
}
.field input:focus, .code-input:focus, select:focus { border-color: var(--ink); outline: none; }
.field-row { grid-template-columns: 1fr auto; align-items: center; gap: .75rem; padding: .35rem 0; }
.field-row select { min-height: 44px; min-width: 8.5rem; }
.code-input {
  width: 100%; text-align: center; font-family: var(--display); font-weight: 700;
  font-size: 2.5rem; letter-spacing: .35em; text-transform: uppercase; padding-left: .35em;
}
.stack { display: grid; gap: .75rem; }
.error { color: var(--bad); min-height: 1.4em; font-weight: 500; }

/* ---------- landing */
.landing, .join, .results, .loading {
  min-height: 100dvh; max-width: 440px; margin: 0 auto;
  padding: calc(2rem + var(--safe-t)) 1.25rem calc(1.5rem + var(--safe-b));
  display: flex; flex-direction: column; gap: 2rem;
}
.landing-top { display: grid; gap: .75rem; margin-top: 6vh; }
.wordmark {
  font-size: clamp(4rem, 21vw, 7.5rem); font-weight: 800; line-height: .82;
  letter-spacing: -.02em; text-transform: none;
}
.lede { font-size: 1.125rem; color: var(--ink-2); max-width: 30ch; }
.choice { display: grid; gap: .75rem; }
.how { border-top: 1.5px solid var(--line); padding-top: 1rem; margin-top: auto; }
.how summary { cursor: pointer; font-weight: 600; }
.how ol { padding-left: 1.25rem; margin: .75rem 0 0; color: var(--ink-2); display: grid; gap: .5rem; }
.join h2 { font-size: 2.5rem; }
.loading { align-items: center; justify-content: center; }

/* ---------- lobby */
.lobby {
  max-width: 980px; margin: 0 auto; min-height: 100dvh;
  padding: calc(.75rem + var(--safe-t)) 1rem calc(7.5rem + var(--safe-b));
  display: grid; gap: 1.25rem; align-content: start;
}
.lobby-head { display: flex; align-items: center; gap: .75rem; }
.room { flex: 1; display: grid; justify-items: center; }
.room .muted { font-size: .8125rem; }
.room-code { font-family: var(--display); font-size: 2.75rem; font-weight: 800; letter-spacing: .12em; line-height: 1; padding-left: .12em; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.team { border-top: 4px solid; padding-top: .75rem; display: grid; gap: .6rem; align-content: start; }
.team-runner { border-color: var(--runner); }
.team-chaser { border-color: var(--chaser); }
.team h3 { display: flex; align-items: baseline; gap: .4rem; }
.team-runner h3 { color: var(--runner); }
.team-chaser h3 { color: var(--chaser); }
.count { font-size: 1rem; color: var(--ink-2); font-weight: 600; }
.roster { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.roster li {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .1rem .5rem;
  padding: .5rem .6rem; background: var(--surface); border-radius: 8px; border: 1px solid var(--line);
}
.roster li:has(.icon-btn) { grid-template-columns: 1fr auto; }
.roster li .icon-btn { grid-row: span 2; grid-column: 2; }
.roster li.is-me { border-color: var(--ink); }
.roster li.empty { color: var(--ink-2); background: none; border-style: dashed; }
.who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who em { font-style: normal; font-weight: 500; font-size: .8125rem; color: var(--ink-2); margin-left: .25rem; }
.gps { font-size: .8125rem; grid-column: 1; }
.gps::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: .35rem; vertical-align: 1px; }
.gps-on { color: var(--good); } .gps-on::before { background: var(--good); }
.gps-off { color: var(--ink-2); } .gps-off::before { background: var(--line); }
.btn-team { min-height: 44px; font-size: .9375rem; border-width: 1.5px; }
.team-runner .btn-team { border-color: var(--runner); color: var(--runner); }
.team-chaser .btn-team { border-color: var(--chaser); color: var(--chaser); }

.settings { display: grid; gap: .9rem; }
.settings-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.settings-head .muted { font-size: .875rem; }
.zone-map-wrap { display: grid; gap: .4rem; }
.zone-map { height: 220px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--sunk); }
.zone-note { font-size: .875rem; color: var(--ink-2); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button {
  border: 0; background: var(--surface); padding: .7rem .5rem; cursor: pointer; text-align: left;
  font-weight: 600; display: grid; gap: .1rem;
}
.segmented button + button { border-left: 1.5px solid var(--line); }
.segmented button small { font-weight: 400; color: var(--ink-2); font-size: .8125rem; line-height: 1.25; }
.segmented button.on { background: var(--ink); color: var(--paper); }
.segmented button.on small { color: inherit; opacity: .75; }
.fields { display: grid; border-top: 1px solid var(--line); }
.fields .field-row-wrap { border-bottom: 1px solid var(--line); }
.custom-input { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; padding: 0 0 .5rem; }
.custom-input input { width: 8.5rem; min-height: 44px; padding: 0 .75rem; border-radius: 10px; border: 1.5px solid var(--ink); background: var(--surface); font-size: 1.0625rem; text-align: right; }
.custom-input span { color: var(--ink-2); font-size: .875rem; min-width: 4.5rem; }
.more summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
.summary { margin: 0; display: grid; gap: 0 1.25rem; }
@media (min-width: 520px) { .summary { grid-template-columns: 1fr 1fr; } }
.summary div { display: flex; justify-content: space-between; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.summary dt { color: var(--ink-2); }
.summary dd { margin: 0; font-weight: 600; text-align: right; }
.gps-note:empty { display: none; }
.warn-box { padding: .75rem 1rem; border-radius: 10px; background: var(--sunk); border-left: 4px solid var(--warn); }
.lobby-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: .75rem 1rem calc(.75rem + var(--safe-b));
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: grid; gap: .5rem; justify-items: center;
}
.lobby-foot p { font-size: .875rem; text-align: center; max-width: 46ch; }
.btn-start { width: min(100%, 440px); }

@media (min-width: 760px) {
  .lobby { grid-template-columns: 1fr 1fr; column-gap: 2rem; }
  .lobby-head, .gps-note { grid-column: 1 / -1; }
  .teams { align-content: start; }
  .zone-map { height: 260px; }
}

/* ---------- countdown */
.countdown {
  min-height: 100dvh; display: grid; place-items: center; align-content: center; gap: 1rem;
  padding: 2rem 1.5rem calc(2rem + var(--safe-b)); text-align: center;
  background: var(--team); color: var(--team-ink);
}
.countdown .mark { stroke: currentColor; width: 72px; height: 72px; }
.countdown .muted { color: inherit; opacity: .75; }
.cd-num {
  font-family: var(--display); font-weight: 800; font-size: min(52vh, 72vw); line-height: .8;
  font-variant-numeric: tabular-nums; letter-spacing: -.04em;
}
.cd-num.tick { animation: tick .6s cubic-bezier(.2, .9, .3, 1); }
@keyframes tick { from { transform: scale(1.18); opacity: .2; } to { transform: scale(1); opacity: 1; } }
.cd-role { font-size: 1.25rem; font-weight: 600; max-width: 26ch; }

/* ---------- game */
.game { position: fixed; inset: 0; overflow: hidden; }
.map { position: absolute; inset: 0; background: var(--sunk); }
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 500;
  padding: calc(.5rem + var(--safe-t)) .75rem .5rem;
  display: flex; align-items: center; gap: .75rem;
  background: color-mix(in srgb, var(--paper) 90%, transparent); backdrop-filter: blur(10px);
  border-bottom: 3px solid var(--team);
}
.hud-phase, .hud-coins { display: grid; line-height: 1; }
.hud-phase span, .hud-coins span { font-size: .8125rem; color: var(--ink-2); font-weight: 600; }
.hud-phase strong, .hud-coins strong { font-family: var(--display); font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-phase { flex: 1; }
.hud-coins { text-align: right; }
.alerts {
  position: absolute; z-index: 499; left: .75rem; right: .75rem;
  top: calc(4.4rem + var(--safe-t)); display: grid; gap: .4rem; pointer-events: none;
}
.alert { padding: .6rem .85rem; border-radius: 8px; font-weight: 600; font-size: .9375rem; box-shadow: var(--shadow); background: var(--surface); border-left: 5px solid; }
.alert-bad { border-color: var(--bad); }
.alert-warn { border-color: var(--warn); }
.alert-good { border-color: var(--good); }
.map-btns {
  position: absolute; right: .75rem; z-index: 498; display: grid; gap: .5rem;
  bottom: calc(8.5rem + var(--safe-b));
}
.map-btns .icon-btn { box-shadow: var(--shadow); }
.statusbar {
  position: absolute; left: 0; right: 0; z-index: 498; bottom: calc(3.75rem + var(--safe-b));
  display: flex; gap: .5rem; overflow-x: auto; padding: .5rem .75rem; scrollbar-width: none;
}
.statusbar::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: grid; gap: .05rem; padding: .45rem .75rem; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); line-height: 1.15; text-align: left;
}
.chip span { font-size: .75rem; color: var(--ink-2); font-weight: 600; }
.chip strong { font-family: var(--display); font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.chip-radar { align-content: center; font-weight: 700; border-left: 5px solid var(--line); }
.chip-radar.is-warm { border-left-color: var(--warn); }
.chip-radar.is-hot { border-left-color: var(--bad); color: var(--bad); }
.chip-radar.is-calm { border-left-color: var(--good); }
.chip-code { cursor: pointer; font: inherit; }
.chip-code .code { letter-spacing: .18em; color: var(--runner); }
.chip-out { align-content: center; font-weight: 600; }
.chip-hound.is-warmer strong { color: var(--bad); }
.chip-hound.is-colder strong { color: var(--chaser); }

.tabs {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 600;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1; min-height: 3.75rem; border: 0; background: none; cursor: pointer; position: relative;
  font-weight: 600; font-size: .9375rem; color: var(--ink-2);
}
.tabs button.on { color: var(--ink); }
.tabs button.on::before { content: ''; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--team); }
.badge { position: absolute; top: .9rem; margin-left: .2rem; width: 7px; height: 7px; border-radius: 50%; background: var(--overprint); }

.sheet {
  position: absolute; left: 0; right: 0; z-index: 550; bottom: calc(3.75rem + var(--safe-b));
  max-height: min(68dvh, calc(100dvh - 9rem - var(--safe-t))); overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper); border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
  padding: 1.25rem 1rem 1.5rem; display: grid; gap: .85rem; align-content: start;
}
.sheet[hidden] { display: none; }
@media (min-width: 760px) {
  .sheet { right: auto; width: 420px; left: .75rem; bottom: calc(4.5rem + var(--safe-b)); border-radius: 16px; }
}
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list li { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.li-main { flex: 1; font-weight: 600; }
.shop-item { flex-wrap: wrap; }
.li-text { flex: 1 1 14rem; display: grid; gap: .15rem; }
.li-text .muted { font-size: .875rem; }
.li-act { display: flex; gap: .5rem; align-items: center; margin-left: auto; }
.li-act select { min-height: 40px; max-width: 10rem; font-size: .9375rem; }
.riding { padding: .75rem 1rem; border-radius: 10px; background: var(--sunk); font-weight: 600; }
.contract { display: grid; gap: .75rem; }
.contract header { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.contract h3 { font-size: 1.75rem; }
.reward { font-family: var(--display); font-size: 1.5rem; font-weight: 700; color: var(--good); }
.progress { height: 10px; border-radius: 5px; background: var(--sunk); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--team); transition: width .4s ease; }
.detail { font-family: var(--display); font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.empty-state { display: grid; gap: .85rem; }
.catch-form { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.catch-form .code-input { font-size: 2rem; letter-spacing: .3em; }
.catch-form .btn { min-height: 60px; }
.feed { list-style: none; margin: 0; padding: 0; display: grid; }
.feed li { display: grid; grid-template-columns: 3.25rem 1fr; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.feed time { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: .875rem; padding-top: .1rem; }
.feed .tone-bad span { color: var(--bad); }

/* ---------- toasts & modals */
.toasts {
  position: fixed; z-index: 2000; left: 50%; transform: translateX(-50%);
  top: calc(.75rem + var(--safe-t)); width: min(94vw, 460px); display: grid; gap: .4rem; pointer-events: none;
}
.is-game ~ .toasts, .app.is-game + .toasts { top: calc(5rem + var(--safe-t)); }
.toast {
  padding: .7rem .9rem; border-radius: 10px; background: var(--ink); color: var(--paper);
  box-shadow: var(--shadow); font-weight: 500; animation: toast .25s ease-out;
}
.toast.tone-bad { background: var(--bad); color: #fff; }
.toast.tone-good { background: var(--good); color: #fff; }
.toast.tone-warn { background: var(--overprint); color: #fff; }
@keyframes toast { from { transform: translateY(-8px); opacity: 0; } }
.modal-wrap { position: fixed; inset: 0; z-index: 3000; background: rgba(10, 12, 10, .45); display: grid; place-items: end center; padding: 1rem 1rem calc(1rem + var(--safe-b)); }
.modal { width: min(100%, 420px); background: var(--paper); border-radius: 16px; padding: 1.25rem; display: grid; gap: .9rem; box-shadow: var(--shadow); }
@media (min-width: 760px) { .modal-wrap { place-items: center; } }

/* ---------- results */
.results { gap: 1.25rem; }
.results .mark { stroke: var(--team); }
.winner { font-size: clamp(3.5rem, 18vw, 5.5rem); font-weight: 800; line-height: .85; color: var(--team); }
.app.is-results:not([data-team="RUNNER"]):not([data-team="CHASER"]) .winner { color: var(--ink); }
.board { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.board li { counter-increment: rank; display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: .5rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.board li::before { content: counter(rank); font-family: var(--display); font-weight: 700; font-size: 1.25rem; color: var(--ink-2); }
.board li.is-me { font-weight: 700; }
.board .who { display: grid; }
.board small { font-weight: 400; color: var(--ink-2); font-size: .8125rem; }
.board strong { font-family: var(--display); font-size: 1.5rem; font-variant-numeric: tabular-nums; }

/* ---------- map */
.maplibregl-map { font-family: var(--body); }
.maplibregl-ctrl-attrib { font-size: 10px; }
.game .maplibregl-ctrl-bottom-right, .game .maplibregl-ctrl-bottom-left { bottom: calc(3.75rem + var(--safe-b)); }
.game .maplibregl-ctrl-bottom-right { right: 3.75rem; }
.area-label {
  background: var(--paper); color: var(--overprint); border: 1.5px solid var(--overprint); border-radius: 6px;
  font-weight: 700; font-size: .8125rem; padding: 2px 6px; margin-top: 6px; white-space: nowrap; pointer-events: none;
}
.pin { width: 18px; height: 18px; pointer-events: none; }
.flag { width: 26px; height: 26px; pointer-events: none; }
.pin-dot {
  position: absolute; inset: 1px; border-radius: 50%; border: 2.5px solid var(--surface);
  background: var(--ink-2); box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.pin.is-runner .pin-dot { background: var(--runner); }
.pin.is-chaser .pin-dot { background: var(--chaser); }
.pin.is-me .pin-dot { inset: -3px; border-width: 3px; }
.pin.is-me::after {
  content: ''; position: absolute; inset: -10px; border-radius: 50%;
  border: 2px solid var(--team, var(--ink)); opacity: .5; animation: pulse 2.4s ease-out infinite;
}
.pin.is-exposed .pin-dot { box-shadow: 0 0 0 4px var(--bad); }
.pin.is-stale { opacity: .5; }
.pin.is-stale .pin-dot { background: var(--ink-2); }
.pin-label {
  position: absolute; left: 50%; top: 21px; transform: translateX(-50%); white-space: nowrap;
  font-weight: 700; font-size: .75rem; padding: 0 5px; border-radius: 4px;
  background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
@keyframes pulse { from { transform: scale(.6); opacity: .7; } to { transform: scale(1.6); opacity: 0; } }
.flag span {
  position: absolute; inset: 0; border: 2px solid var(--ink);
  background: linear-gradient(135deg, #fff 50%, var(--runner) 50%);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
