/* ─────────────────────────────────────
   THE RACE — race.css
───────────────────────────────────── */

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

:root {
  --bg:       #0d0d0d;
  --bg-right: #111111;
  --fg:       #e8e4df;
  --fg-muted: #999;
  --fg-dim:   #666;
  --accent:   #9fd3b0;
  --gold:     #c8a53a;
  --border:   rgba(255,255,255,0.10);
  --radius:   4px;
  --danger:   #e8735a;
  --font:     'Inter', system-ui, -apple-system, sans-serif;
  --ease:     cubic-bezier(0.16, 1, 0.3, 1);
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ── Game screen ── */
.game-screen {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  cursor: crosshair;
  background: var(--bg-right);
}

canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-touch-callout: none;
}

/* ── HUD (soccer scoreboard) ── */
.hud {
  position: absolute;
  top: max(1.5rem, env(safe-area-inset-top) + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: 0;
  background: rgba(10,10,10,0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
  pointer-events: none;
  white-space: nowrap;
}

.hud-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.875rem 0;
  gap: 0.2rem;
  width: 200px;
  flex-shrink: 0;
  overflow: hidden;
}
.hud-left  { border-right: 1px solid rgba(255,255,255,0.06); }
.hud-right { border-left:  1px solid rgba(255,255,255,0.06); }

.hud-team-label {
  font-size: 0.5rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.hud-cause-icon {
  font-size: 1.1rem;
  line-height: 1;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}
.hud-cause-icon.accent { color: var(--accent); }
.hud-cause-icon.gold   { color: var(--gold); }

.hud-score {
  font-size: 1.625rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-score.accent { color: var(--accent); }
.hud-score.gold   { color: var(--gold); }

.hud-team-unit {
  font-size: 0.5625rem;
  color: var(--fg-dim);
  letter-spacing: 0.06em;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.875rem 2rem;
  gap: 0.15rem;
  width: 120px;
  flex-shrink: 0;
}

.pie-timer {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pie-svg {
  width: 52px;
  height: 52px;
  transform: rotate(-90deg);
  overflow: visible;
}
.pie-bg {
  fill: none;
  stroke: rgba(255,255,255,0.08);
  stroke-width: 3;
}
.pie-arc {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-dasharray: 113.097;
  stroke-dashoffset: 0;
  stroke-linecap: round;
  transition: stroke 0.3s;
}
.pie-num {
  position: absolute;
  font-size: 0.9375rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1;
  transition: color 0.3s;
}

/* ── Floating controls ── */
.mute-btn {
  position: absolute;
  top: max(1.5rem, env(safe-area-inset-top) + 0.5rem);
  right: max(1.5rem, env(safe-area-inset-right) + 0.5rem);
  z-index: 11;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,10,10,0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg-dim);
  font-family: var(--font);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: color 0.15s, border-color 0.15s;
}
.mute-btn .material-symbols-rounded {
  font-size: 1.1rem;
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20;
  line-height: 1;
}
.mute-btn:hover { color: var(--fg-muted); border-color: rgba(255,255,255,0.18); }
.mute-btn.muted { color: var(--fg-dim); opacity: 0.5; }

/* ── Fill label ── */
.fill-label {
  position: absolute;
  bottom: 1.25rem;
  right: 1.5rem;
  font-size: 0.4375rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(200,165,58,0.18);
  pointer-events: none;
  z-index: 2;
}

/* ── Countdown ── */
.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: rgba(10,10,10,0.75);
  z-index: 20;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}


.countdown-num {
  font-size: clamp(6rem, 20vw, 16rem);
  font-weight: 300;
  letter-spacing: -0.04em;
  color: var(--accent);
  line-height: 1;
  animation: countIn 1s var(--ease) forwards;
}
.countdown-num.go { color: var(--fg); animation: countIn 0.5s var(--ease) forwards; }
.countdown-hint {
  font-size: clamp(0.875rem, 2.5vw, 1.125rem);
  font-weight: 300;
  color: var(--fg-dim);
  text-align: center;
  padding: 0 2rem;
  margin: 0;
  animation: countIn 1s var(--ease) forwards;
}
@keyframes countIn {
  from { opacity: 0; transform: scale(1.3); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── End overlay ── */
.end-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8,8,8,0.95);
  z-index: 30;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(2rem, env(safe-area-inset-top) + 1rem)
           max(2rem, env(safe-area-inset-right) + 1rem)
           max(2rem, env(safe-area-inset-bottom) + 1rem)
           max(2rem, env(safe-area-inset-left) + 1rem);
}

.end-inner {
  max-width: 680px;
  width: 100%;
  text-align: center;
  animation: endIn 0.65s var(--ease) forwards;
}
@keyframes endIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.end-label {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 300;
  letter-spacing: -0.02em;
  color: var(--fg);
  margin-bottom: 1.75rem;
}

.end-actions.blocked,
.play-again-btn.blocked {
  pointer-events: none;
  opacity: 0.35;
  transition: opacity 0.4s;
}

/* ── Two-column comparison ── */
.end-compare {
  display: flex;
  align-items: flex-start;
  gap: 0;
  margin-bottom: 1.5rem;
  text-align: left;
}

.end-col {
  flex: 1;
  padding: 0 1.5rem;
}
.end-col:first-child { padding-left: 0; }
.end-col:last-child  { padding-right: 0; }

.end-col-divider {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  flex-shrink: 0;
}

.end-col-label {
  display: block;
  font-size: 0.5rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 0.5rem;
}

.end-cause-icon {
  display: block;
  font-size: 1.5rem;
  line-height: 1;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
  margin-bottom: 0.5rem;
}
.end-cause-icon.accent { color: var(--accent); }
.end-cause-icon.gold   { color: var(--gold); }

.end-units {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 0.25rem;
}
.end-units.accent { color: var(--accent); }
.end-units.gold   { color: var(--gold); }

.end-unit-label {
  font-size: 0.6875rem;
  color: var(--fg-muted);
  margin-bottom: 0.35rem;
}

.end-dollars-small {
  font-size: 0.8125rem;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.75rem;
}

.end-detail {
  font-size: 0.5625rem;
  color: var(--fg-dim);
  line-height: 1.65;
  border-left: 2px solid rgba(255,255,255,0.12);
  padding-left: 0.625rem;
}

.end-detail a {
  color: var(--fg-dim);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.end-detail a:hover { color: var(--fg-muted); }

.end-col-note {
  font-size: 0.625rem;
  color: var(--fg-dim);
  margin-top: 0.5rem;
}

/* ── Wealth insight ── */
.wealth-insight {
  background: rgba(200,165,58,0.06);
  border: 1px solid rgba(200,165,58,0.15);
  border-top: 2px solid var(--gold);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  text-align: left;
  font-size: 0.8125rem;
  color: rgba(200,165,58,0.75);
  line-height: 1.7;
}

.wealth-insight strong {
  color: var(--gold);
  font-weight: 600;
}

/* ── Action panel ── */
.end-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.action-share,
.action-donate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  min-height: 48px;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  transition: opacity 0.15s, transform 0.1s;
}
.action-share:hover,
.action-donate:hover { opacity: 0.88; transform: translateY(-1px); }
.action-share:active,
.action-donate:active { transform: translateY(0); }

.action-share {
  background: var(--accent);
  color: #0d1f15;
}

.action-donate {
  background: var(--gold);
  color: #1a1200;
}

.action-share .material-symbols-rounded,
.action-donate .material-symbols-rounded {
  font-size: 1rem;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

.action-secondary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  min-height: 44px;
  font-family: var(--font);
  font-size: 0.6875rem;
  touch-action: manipulation;
  color: var(--fg-dim);
  background: transparent;
  border: 1px solid var(--border);
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  justify-content: center;
}
.action-secondary:hover { border-color: rgba(255,255,255,0.15); color: var(--fg-muted); }
.action-secondary .material-symbols-rounded {
  font-size: 0.875rem;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

/* ── End footer ── */
.end-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.play-again-btn {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  font-family: var(--font);
  font-size: 0.75rem;
  padding: 0;
  cursor: pointer;
  transition: color 0.15s;
}
.play-again-btn:hover { color: var(--fg-muted); }

.end-ponder {
  font-size: 0.5625rem;
  color: var(--fg-dim);
  letter-spacing: 0.06em;
}
.end-ponder a {
  color: var(--fg-dim);
  text-decoration: none;
  transition: color 0.15s;
}
.end-ponder a:hover { color: var(--fg-muted); }

/* ── Cause modal ── */
.cause-modal {
  position: fixed;
  inset: 0;
  background: rgba(8,8,8,0.97);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(2rem, env(safe-area-inset-top) + 1rem)
           max(2rem, env(safe-area-inset-right) + 1rem)
           max(2rem, env(safe-area-inset-bottom) + 1rem)
           max(2rem, env(safe-area-inset-left) + 1rem);
}

.cause-modal-inner {
  max-width: 820px;
  width: 100%;
  text-align: center;
}

.modal-eyebrow {
  font-size: 0.5625rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 1rem;
}

.modal-title {
  font-size: clamp(1.75rem, 4vw, 3rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  color: var(--fg);
  line-height: 1.15;
  margin-bottom: 1rem;
}

.modal-sub {
  font-size: 0.9375rem;
  color: var(--fg-muted);
  line-height: 1.65;
  max-width: 540px;
  margin: 0 auto 2rem;
}

.modal-choose {
  font-size: 0.5625rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 1rem;
}

.modal-footnote {
  font-size: 0.75rem;
  color: var(--fg-muted);
  opacity: 0.6;
  margin-top: 1.5rem;
  line-height: 1.5;
}
.modal-footnote a { color: inherit; text-decoration: underline; }

.cause-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.cause-card {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-family: var(--font);
  cursor: pointer;
  padding: 0.875rem 1rem;
  touch-action: manipulation;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
}
.cause-card:hover {
  border-color: rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.03);
  color: var(--fg);
  transform: translateY(-1px);
}
.cause-card:active { transform: translateY(0); }

.cc-icon {
  font-size: 1.25rem;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 0.125rem;
}

.cc-name {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: block;
}
.cc-unit {
  font-size: 0.5625rem;
  color: var(--fg-dim);
  letter-spacing: 0.06em;
  display: block;
}
.cause-card:hover .cc-unit { color: var(--fg-muted); }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Mobile ── */
@media (max-width: 680px) {
  .hud { top: 0.75rem; }
  .hud-team { padding: 0.5rem 0; width: 110px; }
  .hud-center { padding: 0.5rem 0.75rem; width: 64px; }
  .hud-score { font-size: 1rem; }
  .hud-team-unit { font-size: 0.45rem; }
  .pie-svg { width: 44px; height: 44px; }
  .pie-num { font-size: 0.8125rem; }
  .mute-btn {
    top: auto;
    right: auto;
    bottom: max(1.5rem, env(safe-area-inset-bottom) + 0.5rem);
    left: max(1.5rem, env(safe-area-inset-left) + 0.5rem);
  }
  .end-overlay {
    align-items: flex-start;
    padding-top: max(3.5rem, env(safe-area-inset-top) + 2rem);
  }
  .cause-grid { grid-template-columns: repeat(2, 1fr); }
  .end-compare { flex-direction: column; gap: 1.5rem; }
  .end-col-divider { display: none; }
  .end-col { padding: 0; }
  .modal-title { font-size: 1.5rem; }
  .end-actions { grid-template-columns: 1fr; }
  .end-footer { flex-direction: column; gap: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .end-inner, .countdown-num, .countdown-icon { animation: none; }
}
