:root {
  --navy: #1D2B53;
  --ink: #1B2236;
  --muted: #5B6478;
  --line: #E1E5EE;
  --bg: #F4F6FB;
  --card: #FFFFFF;
  --accent: #FF6B35;
  --accent-dark: #D9531F;
  --good: #0E8A5F;
  --good-bg: #E3F6EE;
  --warn: #9A5B00;
  --warn-bg: #FFF1D6;
  --bad: #C0283B;
  --star: #F5B301;
  --star-off: #D5DAE4;
  --radius: 14px;
  --tabs-h: 64px;
}

* { box-sizing: border-box; }
/* No pinch or double-tap zoom: it feels like an app, and quick taps on stars kept zooming. */
html { -webkit-text-size-adjust: 100%; touch-action: pan-x pan-y; overscroll-behavior-y: none; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--navy); }
h2 { font-size: 1.35rem; margin: 0 0 8px; }
h3 { font-size: 1.05rem; margin: 0 0 8px; }
h4 { font-size: .95rem; margin: 16px 0 6px; }
[hidden] { display: none !important; }

/* ---- top bar and tabs ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--navy); color: #fff;
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; }
.back {
  background: none; border: 0; color: #fff; font-size: 2rem; line-height: 1; padding: 0 8px 4px 0; cursor: pointer;
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .72rem; color: var(--muted); text-decoration: none;
}
.tabs a span { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.tabs a.active { color: var(--navy); font-weight: 600; }
.tabs a.active span { filter: none; opacity: 1; }

.ptr {
  height: 0; overflow: hidden; display: flex; align-items: flex-end; justify-content: center;
  color: var(--muted); font-size: .85rem; font-weight: 600; transition: height .15s;
}
.ptr span { padding-bottom: 12px; }
.ptr span::before { content: "↓ "; display: inline-block; transition: transform .15s; }
.ptr.ready span::before { transform: rotate(180deg); }
.ptr.loading span::before { content: "↻ "; animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

main { max-width: 640px; margin: 0 auto; padding: 14px; outline: none; }
/* Every screen is at least as tall as the phone. On iPhone home-screen apps the fixed tab bar sits too
   high on pages shorter than the screen (Runs, or any tab while loading) and snaps down once the page
   is taller, so make every page taller. */
#view { min-height: calc(100vh - 100px); }
section { margin-bottom: 14px; }

/* ---- building blocks ---- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 2px 8px rgba(20, 33, 61, .04);
}
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.block { display: block; }
.lead { font-size: 1.1rem; font-weight: 600; }
.notice { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 10px; }
.error { color: var(--bad); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; flex-wrap: nowrap; }
.row-between { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
ul.plain, ol.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li, ol.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child, ol.plain li:last-child { border-bottom: 0; }
ol.numbered { counter-reset: n; }
ol.numbered li::before { counter-increment: n; content: counter(n) ". "; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #F1C3CA; }
.btn.danger:not(.ghost) { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.big { width: 100%; min-height: 52px; font-size: 1.05rem; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.link-btn { background: none; border: 0; padding: 6px 0; color: var(--navy); font: inherit; font-weight: 600; cursor: pointer; }
.link-btn.danger { color: var(--bad); }
.link-btn.small { font-size: .85rem; }

input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid #C9CFDB; border-radius: 10px; background: #fff;
  font: inherit; color: var(--ink);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .stars.input:focus-visible {
  outline: 3px solid rgba(255, 107, 53, .35); outline-offset: 1px; border-color: var(--accent);
}
.row input, .row select { flex: 1; min-width: 0; width: auto; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }
.field input, .field select, .field textarea { font-weight: 400; font-size: 1rem; }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--accent); flex: none; margin: 2px 0 0; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: #EEF1F7; color: var(--navy); white-space: nowrap;
}
.tag.good { background: var(--good-bg); color: var(--good); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.muted { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: #fff; font-weight: 600; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }

.install-tip {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  max-width: 640px; margin: 10px auto 0; padding: 10px 14px; border-radius: 12px;
  background: #E8EEFF; color: var(--navy); font-size: .9rem;
}
.install-tip span { flex: 1; min-width: 200px; }

/* ---- sign in / sign up ---- */
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 12px; }
.brand-icon { width: 96px; height: 96px; border-radius: 22px; box-shadow: 0 4px 14px rgba(20, 33, 61, .25); }
.brand h2 { margin: 4px 0 0; }
.choices { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.choice {
  min-height: 48px; padding: 10px 14px; text-align: left; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer;
}
.choice:active { background: #FFF2EC; border-color: var(--accent); }
.choice.new { color: var(--accent-dark); border-style: dashed; }

/* ---- runs ---- */
.run-card {
  display: block; margin-bottom: 10px; padding: 14px; border-radius: var(--radius);
  background: var(--card); color: inherit; text-decoration: none;
  box-shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 2px 8px rgba(20, 33, 61, .04);
}
.run-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.run-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.score-pill { font-weight: 700; color: var(--ink); white-space: nowrap; }
.meta { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 4px; }
.notes { white-space: pre-wrap; background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.avg { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 10px; font-weight: 600; }

.route-card {
  display: flex; align-items: center; gap: 12px; margin: 10px 0; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: inherit; background: #FBFCFE;
}
.route-icon { font-size: 1.6rem; }
.route-text { flex: 1; display: flex; flex-direction: column; }
.route-open { color: var(--accent-dark); font-weight: 700; white-space: nowrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; min-height: 34px;
  border-radius: 999px; background: #EEF1F7; font-weight: 600; font-size: .9rem;
}
.chip:not(:has(.chip-x)) { padding-right: 12px; }
.chip.ghost { background: #fff; border: 1px dashed #B8C0D0; color: var(--muted); }
.chip-note { font-weight: 400; font-size: .75rem; color: var(--muted); }
.chip-x {
  width: 28px; height: 28px; border-radius: 50%; border: 0; background: transparent; color: var(--muted);
  font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.adder { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.adder .choices { margin: 0; }

.vote { padding: 10px 0; border-bottom: 1px solid var(--line); }
.vote:last-of-type { border-bottom: 0; }
.comment { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.score-num { font-weight: 700; min-width: 2ch; text-align: right; }

/* ---- stars ---- */
.stars { display: inline-flex; gap: 1px; line-height: 1; white-space: nowrap; }
.star { position: relative; display: inline-block; font-size: 1.05rem; color: var(--star-off); }
.star::before { content: "★"; }
.star.full::after, .star.half::after {
  content: "★"; position: absolute; left: 0; top: 0; color: var(--star); overflow: hidden; white-space: nowrap;
}
.star.full::after { width: 100%; }
.star.half::after { width: 50%; }
.stars.small .star { font-size: .8rem; }
.star-input { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 10px; }
.stars.input { gap: 0; touch-action: none; cursor: pointer; padding: 4px 0; border-radius: 8px; user-select: none; -webkit-user-select: none; }
.stars.input .star { font-size: clamp(1.6rem, 8.2vw, 2.2rem); padding: 0 1px; }
.star-value { font-weight: 700; color: var(--muted); }

/* ---- wheel ---- */
.wheel-card { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wheel { width: 100%; max-width: 360px; height: auto; }
.wheel-spinner { transform-box: fill-box; transform-origin: center; }
.wheel-name { fill: #fff; font-weight: 700; paint-order: stroke; stroke: rgba(20, 33, 61, .35); stroke-width: 2px; }
.wheel-hub { font-size: 24px; }
.wheel-empty { fill: var(--muted); font-size: 14px; }
.wheel-result { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.winner { font-size: 1.3rem; font-weight: 800; margin: 4px 0; }
.wheel-people { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.undone .spin-winner { text-decoration: line-through; color: var(--muted); }
.person-toggle { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }

/* ---- stats ---- */
.segmented { display: flex; gap: 4px; padding: 4px; margin-bottom: 14px; background: #E4E8F1; border-radius: 12px; }
.segmented a {
  flex: 1; text-align: center; padding: 8px 4px; border-radius: 9px; text-decoration: none;
  color: var(--muted); font-weight: 600; font-size: .85rem;
}
.segmented a.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(20, 33, 61, .15); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--card); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; }
.tile-value { font-size: 1.15rem; font-weight: 800; }
.tile-label { font-size: .75rem; color: var(--muted); }
.leaderboard { list-style: none; padding: 0; margin: 0; }
.leaderboard li {
  display: grid; grid-template-columns: 34px 1fr auto; grid-template-areas: "rank name score" "rank sub sub";
  align-items: center; gap: 0 8px; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.leaderboard li:last-child { border-bottom: 0; }
.rank { grid-area: rank; font-size: 1.2rem; text-align: center; font-weight: 700; }
.lb-name { grid-area: name; font-weight: 700; text-decoration: none; }
.lb-score { grid-area: score; display: flex; align-items: center; gap: 6px; }
.lb-sub { grid-area: sub; }
.stat-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.stat-row:last-child { border-bottom: 0; }
.stat-name { font-weight: 700; text-decoration: none; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px; margin: 6px 0 0; }
.stat-grid dt { font-size: .75rem; color: var(--muted); }
.stat-grid dd { margin: 0; font-weight: 600; }

.charts { display: grid; gap: 14px; }
.chart-card { margin: 0; background: var(--card); border-radius: var(--radius); padding: 14px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; }
.chart-head figcaption { font-weight: 700; }
.chart-readout { margin: 2px 0 6px; font-size: .85rem; color: var(--muted); min-height: 1.3em; }
.chart { width: 100%; height: auto; display: block; }
.chart.hidden { display: none; }
.chart .grid { stroke: #EEF0F5; stroke-width: 1; }
.chart .axis { stroke: #C9CFDB; stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 9px; }
.chart .bar { fill: #3A6FD8; }
.chart .bar.on { fill: #1D2B53; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.chart-table th, .chart-table td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }

/* ---- people, me ---- */
.people-list { display: flex; flex-direction: column; margin-top: 10px; }
.person {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; font-weight: 600;
}
.person:last-child { border-bottom: 0; }
.link-card { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit; margin-bottom: 14px; }
.link-box { display: flex; gap: 8px; }
.link-box .link-text { flex: 1; min-width: 0; font-size: 16px; color: var(--muted); } /* 16px stops iOS zooming on focus */
.version { margin-top: 20px; }

@media (max-width: 360px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .wheel-people { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
