:root {
  --bg: #f4f2ec;              /* warm off-white, like a program page */
  --surface: #ffffff;
  --ink: #142019;
  --muted: #66706a;
  --line: #e2e0d8;
  --chip: #e9e7df;
  --accent: #e8590c;          /* CampusTap orange: the pin (a basketball's colour) */
  --accent-soft: #fde6d6;
  --answer: #1660c9;          /* the campus */
  --primary: #14382b;         /* deep field green */
  --primary-ink: #ffffff;
  --good: #1d7a4c;
  --bad: #c4321f;
  --q-bg: #14382b;
  --q-ink: #ffffff;
  --map-bg: #dfe3e0;
  --map-water: #cdd9e1;
  --map-land: #f7f6f2;
  --map-border: #9fa49c;
  --map-coast: #93a6b3;
  --map-line: #14382b;
  --shadow: 0 10px 40px rgba(16, 24, 20, 0.14);
  --radius: 14px;
  --rounded: ui-rounded, "SF Pro Rounded", "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512;
    --surface: #18211c;
    --ink: #edf2ee;
    --muted: #97a39b;
    --line: #2a352f;
    --chip: #222c26;
    --accent: #ff7a2e;
    --accent-soft: #4a2412;
    --answer: #5b9bff;
    --primary: #edf2ee;
    --primary-ink: #0f1512;
    --good: #3cbf7f;
    --q-bg: #1d4a39;
    --q-ink: #ffffff;
    --map-bg: #1b2320;
    --map-water: #13202a;
    --map-land: #27302c;
    --map-border: #5b6a62;
    --map-coast: #3c5464;
    --map-line: #f2f6f3;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  }
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* No rubber-band bounce or pull-to-refresh while playing */
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  /* No double-tap zoom anywhere, no text-selection loupe on long-press */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.modal-card p, .modal-card li, .reveal-fact, .credit, .question-text { -webkit-user-select: text; user-select: text; }

button { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- Buttons ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  min-height: 48px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  min-width: 180px;
  transition: transform 0.1s ease, opacity 0.2s, background 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: transparent; border: 1.5px solid var(--ink); }
.btn-wide { width: 100%; }
.icon-btn {
  width: 44px; height: 44px; /* Apple's minimum touch target */
  border: 0; background: transparent; border-radius: 10px;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }
@media (hover: hover) { .icon-btn:hover { background: var(--line); } }

/* ---------- Splash ---------- */
.splash {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  text-align: center;
}
.splash-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 360px; }
.splash-logo { width: 88px; height: 88px; }
.splash-title { font-family: var(--rounded); font-weight: 800; font-size: 46px; margin: 0; letter-spacing: -0.5px; }
.splash-tag { font-size: 20px; margin: 0 0 10px; line-height: 1.35; }
.btn-play { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 100%; max-width: 300px; padding: 13px 22px; font-size: 18px; }
.btn-play:disabled { opacity: 0.6; }
.play-meta { font-size: 13px; font-weight: 500; opacity: 0.75; }
.play-meta:empty { display: none; }
#splash-help { width: 100%; max-width: 300px; }
.splash-meta { color: var(--muted); font-size: 14px; line-height: 1.6; margin-top: 8px; }
.splash-meta span:first-child { font-weight: 700; color: var(--ink); }
.splash-foot { margin: 0; font-size: 13px; color: var(--muted); }
.splash-foot a { color: var(--muted); display: inline-block; padding: 10px 4px; }

/* ---------- App layout ----------
 * The app fills exactly one screen: header, the five rounds, the question, the map (which takes
 * whatever height is left) and the Confirm button pinned at the bottom.
 */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding:
    env(safe-area-inset-top)
    max(10px, env(safe-area-inset-right))
    0
    max(10px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overflow: clip; /* not even scrollable from script */
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 0;
  flex: none;
}
.brand { display: flex; flex-direction: column; align-items: center; }
.brand-name { font-family: var(--rounded); font-weight: 800; font-size: 23px; letter-spacing: -0.3px; }
.brand-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* The five rounds: a chip each, showing points once played. */
.rounds { display: grid; grid-template-columns: repeat(5, 1fr) auto; gap: 5px; align-items: center; padding: 2px 0 8px; flex: none; }
.round {
  height: 28px; border-radius: 8px; background: var(--chip); color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 4px;
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  border: 0; padding: 0;
}
.round.current { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 2px var(--accent); }
.round.done { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.round .sq { font-size: 10px; }
.total { font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; padding-left: 4px; min-width: 52px; text-align: right; }
.total small { display: block; font-size: 10px; font-weight: 600; color: var(--muted); line-height: 1; }

/* ---------- The question ---------- */
.question {
  flex: none; margin: 0; padding: 12px 14px 14px;
  border-radius: 12px; background: var(--q-bg); color: var(--q-ink);
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  animation: rise-in 0.25s ease;
}
.hint-chip {
  background: rgba(255, 255, 255, 0.16); color: #fff;
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; letter-spacing: 0.01em;
}
.hint-chip:empty { display: none; }
.question-text { margin: 0; font-family: var(--rounded); font-weight: 700; font-size: 18px; line-height: 1.3; }
@media (max-height: 700px) { .question-text { font-size: 16.5px; } .question { padding: 10px 12px 12px; gap: 6px; } }

/* ---------- Map ---------- */
.map-wrap {
  position: relative; flex: 1 1 auto; min-height: 150px;
  margin-top: 8px; border-radius: 12px; overflow: hidden; background: var(--map-bg);
  isolation: isolate;
}
.map-canvas { position: absolute; inset: 0; outline: none; }
.map-canvas .maplibregl-canvas { outline: none; }
.map-canvas.editable .maplibregl-canvas-container.maplibregl-interactive { cursor: crosshair; }
.map-canvas:focus-within { box-shadow: inset 0 0 0 3px var(--accent); }
.map-loading {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center;
  color: var(--muted); font-size: 14px; font-weight: 600; z-index: 1;
}
/* Bottom-left; MapLibre's attribution sits bottom-right. */
.map-tools { position: absolute; left: 6px; bottom: 6px; display: grid; grid-template-columns: 44px 44px; gap: 6px; z-index: 3; }
.map-tool {
  width: 44px; height: 44px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  font-size: 24px; font-weight: 500; line-height: 1; display: grid; place-items: center;
}
.map-tool-text { font-size: 14px; font-weight: 800; letter-spacing: 0.04em; }
.map-tool svg { width: 20px; height: 20px; }
.map-tool:active { transform: scale(0.94); }
.map-tip {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); z-index: 3;
  margin: 0; padding: 7px 12px; border-radius: 999px; white-space: nowrap;
  background: rgba(10, 16, 13, 0.75); color: #fff; font-size: 13px; font-weight: 600;
  pointer-events: none; transition: opacity 0.25s;
}
.map-tip.gone { opacity: 0; }
.map-tip.gone ~ .map-note { top: 8px; }
.map-note {
  position: absolute; left: 50%; transform: translateX(-50%); top: 46px; z-index: 3; margin: 0; white-space: nowrap;
  padding: 4px 9px; border-radius: 8px; font-size: 11.5px; font-weight: 600;
  background: var(--surface); color: var(--muted); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); pointer-events: none;
}
.map-wrap:not(.ready) .map-tools, .map-wrap:not(.ready) .map-tip { visibility: hidden; }
/* After confirming, the buttons would cover the pin or campus; pinch, drag and the wheel still work. */
.app.revealing .map-tools, .app.finished .map-tools { display: none; }
/* MapLibre's attribution, compact, in the game's colours. */
.map-wrap .maplibregl-ctrl-attrib { font-size: 10.5px; }
.map-wrap .maplibregl-ctrl-bottom-right { z-index: 3; }
@media (prefers-color-scheme: dark) {
  .map-wrap .maplibregl-ctrl-attrib { background: rgba(24, 33, 28, 0.8); color: #c9d3cc; }
  .map-wrap .maplibregl-ctrl-attrib a { color: #dfe7e1; }
  .map-wrap .maplibregl-ctrl-attrib-button { filter: invert(1); }
  .map-wrap .maplibregl-ctrl-attrib.maplibregl-compact-show { background: #18211c; }
}

/* Pins and campus markers. */
.ct-pin { width: 30px; height: 42px; cursor: grab; --pin: var(--accent); }
.ct-pin svg { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 1px 1px rgba(0,0,0,.2)); }
.ct-pin.small { width: 24px; height: 34px; }
.ct-guess { cursor: default; }
.ct-answer { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: color-mix(in srgb, var(--answer) 22%, transparent); }
.ct-answer-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--answer); border: 2.2px solid #fff; color: #fff; font: 800 11px/1 -apple-system, system-ui, sans-serif; display: grid; place-items: center; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.ct-answer-dot svg { width: 14px; height: 14px; }
.ct-answer.small { width: 24px; height: 24px; }
.ct-answer.small .ct-answer-dot { width: 18px; height: 18px; font-size: 10px; }

/* ---------- Confirm ---------- */
.actionbar { flex: none; padding: 10px 0 max(10px, env(safe-area-inset-bottom)); }
.btn-confirm { width: 100%; font-size: 17px; min-height: 52px; }
.btn-confirm:disabled { background: var(--chip); color: var(--muted); }
.btn-confirm.ready { background: var(--accent); color: #fff; }

/* ---------- Reveal ---------- */
.app.revealing .actionbar { display: none; }
.app.revealing .question { padding-top: 8px; padding-bottom: 10px; }
.app.revealing .question-text { font-size: 15px; font-weight: 600; opacity: 0.92; }
.reveal {
  flex: 0 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  animation: rise-in 0.3s ease;
}
.reveal-score { display: flex; align-items: center; gap: 12px; }
.reveal-badge { font-size: 46px; line-height: 1; flex: none; animation: pop 0.45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }
.reveal-verdict { flex: 1; }
.reveal-points { display: flex; flex-direction: column; align-items: flex-end; min-width: 64px; }
.reveal-points .big { font-size: 32px; line-height: 1; }
.reveal-verdict { display: flex; flex-direction: column; gap: 2px; font-size: 14px; color: var(--muted); }
.reveal-verdict strong { font-size: 22px; font-family: var(--rounded); color: var(--ink); }
.reveal-bar { height: 6px; border-radius: 3px; background: var(--chip); margin: 10px 0 12px; overflow: hidden; }
.reveal-bar span { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width 0.8s ease-out 0.2s; }
.reveal-title { font-family: var(--rounded); font-size: 20px; line-height: 1.2; margin: 0 0 2px; }
.reveal-place { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.35; }
.reveal-fact { font-size: 14.5px; line-height: 1.45; margin: 10px 0 6px; }
.credit { font-size: 11.5px; line-height: 1.4; color: var(--muted); margin: 0 0 12px; }
.credit a { color: var(--muted); }
.reveal .btn { position: sticky; bottom: 0; box-shadow: 0 -8px 12px var(--bg); }

/* ---------- The finished day ---------- */
.app.finished .actionbar, .app.finished .reveal { display: none; }
.app.finished .map-wrap { flex: none; height: 32vh; height: clamp(170px, 34dvh, 360px); }
.summary {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 12px 0 max(16px, env(safe-area-inset-bottom));
}
.summary-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.summary-score { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.summary-of { color: var(--muted); font-weight: 600; margin-left: 4px; }
.summary-squares { font-size: 22px; letter-spacing: 2px; }
.summary-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.summary-list li { background: var(--surface); border-radius: 12px; }
.summary-list summary {
  list-style: none; cursor: pointer; min-height: 52px; padding: 6px 10px 6px 8px;
  display: grid; grid-template-columns: 22px 1fr auto 14px; gap: 10px; align-items: center;
}
.summary-list summary::-webkit-details-marker { display: none; }
.summary-list .n { font-size: 12px; font-weight: 800; color: #fff; background: var(--accent); width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; }
.summary-list .t { font-size: 14px; font-weight: 700; line-height: 1.25; }
.summary-list .pts { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.summary-list .pts small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.summary-list .chev { width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-top: -4px; transition: transform 0.2s; }
.summary-list details[open] .chev { transform: rotate(-135deg); margin-top: 4px; }
.summary-list .more { padding: 0 14px 12px 40px; animation: rise-in 0.2s ease; -webkit-user-select: text; user-select: text; }
.summary-list .more p { margin: 0 0 6px; line-height: 1.45; }
.summary-list .more .q { font-size: 13px; color: var(--muted); font-style: italic; }
.summary-list .more .a { font-size: 14.5px; }
.summary-list .more .src { font-size: 12px; color: var(--muted); }
.summary-list .more a { color: var(--muted); }
.site-footer { font-size: 12px; color: var(--muted); text-align: center; margin-top: 14px; line-height: 2; }
.site-footer a { color: inherit; padding: 8px 2px; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  z-index: 50;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 440px;
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 28px 24px 24px;
  animation: rise-in 0.25s ease;
}
@keyframes rise-in { from { transform: translateY(16px); opacity: 0; } }
.modal-close {
  position: absolute; top: 6px; right: 6px;
  width: 44px; height: 44px; border: 0; background: transparent;
  font-size: 28px; line-height: 1; cursor: pointer; color: var(--muted);
}
.modal h2 { font-family: var(--rounded); margin: 0 0 8px; font-size: 26px; }
.modal h3 { font-size: 15px; margin: 18px 0 6px; }
.modal p { line-height: 1.5; margin: 0 0 8px; }
.lead { font-size: 16.5px; }
.steps { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; line-height: 1.45; font-size: 15px; }
.step-n { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 800; font-size: 14px; display: grid; place-items: center; margin-top: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; }
.units { display: flex; align-items: center; gap: 8px; margin: 14px 0 10px; font-size: 14px; color: var(--muted); }
.unit-btn { border: 0; border-radius: 999px; padding: 0 16px; min-height: 36px; background: var(--chip); font-weight: 700; cursor: pointer; }
.unit-btn[aria-checked="true"] { background: var(--primary); color: var(--primary-ink); }
.small-print { font-size: 13px; color: var(--muted); }

.result-kicker { text-transform: uppercase; letter-spacing: 0.1em; font-size: 12px; font-weight: 700; color: var(--accent); margin: 0; }
.result-title { margin-top: 2px; }
.result-score { display: flex; flex-direction: column; align-items: center; background: var(--bg); border-radius: 12px; padding: 12px; margin: 12px 0 8px; }
.big { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.small { font-size: 12px; color: var(--muted); }
.squares { font-size: 30px; text-align: center; letter-spacing: 4px; margin: 6px 0 12px; }
.btn-share { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; background: var(--good); color: #fff; }
.btn-share svg { width: 20px; height: 20px; }
.next { text-align: center; color: var(--muted); font-size: 14px; margin-top: 12px !important; }
.next strong { color: var(--ink); font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.stats-heading { font-size: 18px !important; font-family: var(--sans) !important; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; text-align: center; }
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat-num { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 11px; color: var(--muted); line-height: 1.2; }
@media (max-width: 360px) { .stat-num { font-size: 20px; } }
.dist-heading { text-transform: uppercase; letter-spacing: 0.06em; font-size: 13px !important; }
.dist { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; align-items: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.dist-bar { background: var(--muted); color: #fff; font-weight: 700; padding: 2px 8px; text-align: right; border-radius: 4px; min-width: 24px; font-size: 12px; }
.dist-bar.today { background: var(--accent); }
.stat-note { font-size: 12px; color: var(--muted); text-align: center; margin: 10px 0 0 !important; }

.a2hs {
  position: relative;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--bg); border-radius: 12px;
  padding: 12px 44px 12px 14px; margin-top: 14px;
  font-size: 14px; line-height: 1.4;
}
.a2hs svg { width: 16px; height: 16px; vertical-align: -3px; color: var(--accent); }
.a2hs-close {
  position: absolute; top: 0; right: 0; width: 44px; height: 44px;
  border: 0; background: transparent; font-size: 22px; color: var(--muted); cursor: pointer;
}

.ad-slot { width: 100%; min-height: 100px; margin-top: 14px; display: flex; justify-content: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(18px + env(safe-area-inset-top));
  transform: translate(-50%, -20px);
  background: var(--primary); color: var(--primary-ink);
  padding: 10px 16px; border-radius: 8px; font-weight: 600; font-size: 14px;
  max-width: calc(100vw - 32px); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Bigger screens: question beside the map ---------- */
@media (min-width: 900px) and (min-height: 560px) {
  .app { max-width: 1180px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); grid-template-rows: auto auto auto 1fr; column-gap: 16px; }
  .topbar, .rounds { grid-column: 1 / -1; }
  .question { grid-column: 1; grid-row: 3; align-self: start; padding: 18px 20px 20px; }
  .question-text { font-size: 22px; }
  .map-wrap { grid-column: 2; grid-row: 3 / 5; margin: 0 0 16px; }
  .actionbar, .reveal { grid-column: 1; grid-row: 4; align-self: start; max-height: 100%; }
  .app.finished .map-wrap { grid-column: 2; grid-row: 3 / 5; height: auto; }
  .summary { grid-column: 1; grid-row: 3 / 5; padding-top: 0; }
}

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