:root {
  --bw-orange: #ff6a1a;
  --bw-orange-light: #ff8f4d;
  --bw-orange-deep: #e0530a;
  --bw-black: #1a1a1a;
  --bw-charcoal: #232323;
  --bw-charcoal-light: #2d2d2d;
  --bw-green: #1f9d55;
  --bw-red: #ff4d4d;
  --bw-white: #ffffff;
  --bw-muted: #b8b8b8;
  --sky-top: #7ec8ff;
  --sky-bottom: #cdeeff;
  --track-brown: #b5793f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overscroll-behavior: none;
  background: var(--bw-black);
  color: var(--bw-white);
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.screen.active {
  display: flex;
}

.panel {
  background: var(--bw-charcoal);
  border: 1px solid rgba(255, 106, 26, 0.4);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.panel-wide {
  max-width: 520px;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 4px;
}

.brand-mark svg { width: 34px; height: 34px; flex-shrink: 0; }

.brand-wordmark {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--bw-white);
  text-transform: lowercase;
}

.brand-wordmark .hl { color: var(--bw-orange); }

h1 {
  margin: 0 0 4px;
  font-size: 2rem;
  letter-spacing: 2px;
  color: var(--bw-orange);
}

h2 {
  margin-top: 0;
  color: var(--bw-orange);
}

.subtitle {
  margin: 0 0 16px;
  color: var(--bw-orange-light);
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.blurb {
  color: var(--bw-muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

#email-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

input[type="email"] {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: var(--bw-black);
  color: var(--bw-white);
  font-size: 1rem;
  outline: none;
}

input[type="email"]:focus {
  border-color: var(--bw-orange);
}

.btn {
  padding: 14px 20px;
  border-radius: 999px;
  border: none;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: var(--bw-orange);
  color: var(--bw-black);
}

.btn-primary:active { transform: scale(0.98); }

.btn-ghost {
  background: transparent;
  color: var(--bw-orange-light);
  border: 1.5px solid var(--bw-orange);
  margin-top: 14px;
  border-radius: 999px;
}

.error {
  color: var(--bw-red);
  min-height: 1.2em;
  font-size: 0.85rem;
  margin: 8px 0 0;
}

.instructions {
  text-align: left;
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.instr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: #e6e6e6;
}

.key-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  padding: 4px 8px;
  background: var(--bw-black);
  border: 1px solid var(--bw-orange);
  border-radius: 6px;
  color: var(--bw-orange-light);
  font-weight: 700;
  font-size: 0.75rem;
}

/* GAME SCREEN */
#screen-game {
  padding: 0;
  justify-content: flex-start;
  position: relative;
}

.hud {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 10px 16px;
  background: var(--bw-black);
  border-bottom: 2px solid var(--bw-orange);
  z-index: 2;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.hud-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--bw-orange);
  letter-spacing: 1px;
}

#hud-time, #hud-distance {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--bw-white);
}

.countdown {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 5rem;
  font-weight: 900;
  color: var(--bw-orange);
  text-shadow: 0 4px 12px rgba(0,0,0,0.6);
  z-index: 3;
  pointer-events: none;
}

#game-canvas {
  display: block;
  width: 100%;
  flex: 1 1 auto;
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
  touch-action: none;
}

.controls {
  display: flex;
  gap: 10px;
  padding: 14px;
  background: var(--bw-black);
  border-top: 2px solid var(--bw-orange);
  z-index: 2;
}

.ctrl-btn {
  flex: 1;
  padding: 22px 0;
  border-radius: 16px;
  border: none;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--bw-black);
  cursor: pointer;
}

.run-btn {
  background: linear-gradient(180deg, #ffffff, #d8d8d8);
  flex: 1.1;
}

.run-btn:active, .run-btn.pressed {
  background: linear-gradient(180deg, var(--bw-orange-light), var(--bw-orange));
  transform: scale(0.96);
}

.jump-btn {
  flex: 1.4;
  background: linear-gradient(180deg, var(--bw-orange-light), var(--bw-orange-deep));
  color: var(--bw-white);
}

.jump-btn:active, .jump-btn.pressed {
  background: linear-gradient(180deg, #ffffff, var(--bw-orange));
  color: var(--bw-black);
  transform: scale(0.96);
}

/* PODIUM */
.podium-stage {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 16px;
  min-height: 170px;
}

.podium-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100px;
}

.podium-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--bw-black);
  margin-bottom: 8px;
  border: 2px solid var(--bw-black);
}

.podium-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--bw-white);
  text-align: center;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium-time {
  font-size: 0.75rem;
  color: var(--bw-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

.podium-block {
  width: 100%;
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6px;
  font-size: 1.6rem;
  font-weight: 900;
  color: rgba(0,0,0,0.55);
}

.podium-slot.place-1 .podium-block { height: 130px; background: linear-gradient(180deg, #ffe08a, #d4a017); }
.podium-slot.place-2 .podium-block { height: 92px; background: linear-gradient(180deg, #e7e7e7, #b3b3b3); }
.podium-slot.place-3 .podium-block { height: 66px; background: linear-gradient(180deg, #e0a878, #a9673a); }

.podium-slot.place-1 { order: 2; }
.podium-slot.place-2 { order: 1; }
.podium-slot.place-3 { order: 3; }

.podium-slot.is-you .podium-name { color: var(--bw-orange-light); }

/* RESULTS */
.result-time {
  font-size: 3rem;
  font-weight: 900;
  color: var(--bw-orange);
  margin: 8px 0;
}

.result-rank {
  color: var(--bw-muted);
  font-weight: 600;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

/* LEADERBOARD */
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 16px 0;
  max-height: 50vh;
  overflow-y: auto;
}

.lb-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bw-black);
  border-radius: 8px;
  font-size: 0.9rem;
}

/* No special treatment for first place - the only row that stands out is the
   player's own, otherwise two highlights compete for the same glance. */
.lb-place { font-weight: 800; color: var(--bw-orange); }
.lb-email { text-align: left; color: #e6e6e6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.loading, .empty { color: var(--bw-muted); font-size: 0.9rem; }

@media (min-width: 700px) {
  .controls { max-width: 600px; margin: 0 auto; width: 100%; }
  .hud { max-width: 600px; margin: 0 auto; width: 100%; }
}

/* Offered only when a time actually places on the board, so it should feel
   like the reward it is rather than another secondary action. */
.btn-publish {
  background: linear-gradient(180deg, #ffd23d, var(--bw-orange));
  color: var(--bw-black);
  box-shadow: 0 0 0 0 rgba(255, 210, 61, 0.6);
  animation: publish-invite 2s ease-in-out infinite;
}

@keyframes publish-invite {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 210, 61, 0.55); }
  50%      { box-shadow: 0 0 0 10px rgba(255, 210, 61, 0); }
}

.publish-status {
  margin: 6px 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--bw-orange-light);
  min-height: 1.2em;
}

.publish-status.done { color: var(--bw-green); }
.publish-status.missed { color: var(--bw-muted); font-weight: 600; }

/* The player's own row on the leaderboard. Pulses continuously while the board
   is open so they can pick themselves out of twenty near-identical masked
   addresses at a glance. */
.lb-row.is-you {
  border: 1px solid var(--bw-orange);
  animation: you-pulse 1.15s ease-in-out infinite;
}

.lb-row.is-you .lb-email,
.lb-row.is-you .lb-time { color: var(--bw-white); }

@keyframes you-pulse {
  0%, 100% { background: var(--bw-black); box-shadow: 0 0 0 0 rgba(255, 106, 26, 0.55); }
  50%      { background: #3a1e0c; box-shadow: 0 0 12px 2px rgba(255, 106, 26, 0.45); }
}

/* Respect a reduced-motion preference: keep the highlight, drop the flashing. */
/* Reduced motion asks for less movement, not less feedback. The row keeps
   pulsing but only as a slow colour fade - no expanding glow, half the speed,
   and far below any flash-rate threshold - so the player can still find
   themselves without anything darting around the screen. */
@media (prefers-reduced-motion: reduce) {
  .lb-row.is-you { animation: you-pulse-soft 3s ease-in-out infinite; }
  .btn-publish { animation: none; }
}

@keyframes you-pulse-soft {
  0%, 100% { background: #2a1710; }
  50%      { background: #4a2610; }
}

/* ---------- Record entry ---------- */

.field-label {
  display: block;
  text-align: left;
  margin: 16px 0 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--bw-orange);
  font-weight: 800;
}

.field-hint {
  margin: 6px 0 0;
  font-size: 0.75rem;
  color: var(--bw-muted);
  text-align: left;
  line-height: 1.35;
}

/* Arcade high-score entry: three big characters, wide tracking, monospace so
   the slots stay put as they type. */
.arcade-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 10px;
  border: 2px solid var(--bw-orange);
  background: var(--bw-black);
  color: var(--bw-orange);
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: 0.45em;
  text-indent: 0.45em; /* centres the glyphs despite the trailing letter-space */
  text-align: center;
  text-transform: uppercase;
  outline: none;
}

.arcade-input::placeholder { color: rgba(255, 106, 26, 0.28); }
.arcade-input:focus { box-shadow: 0 0 0 3px rgba(255, 106, 26, 0.25); }

#entry-form select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: var(--bw-black);
  color: var(--bw-white);
  font-size: 1rem;
  outline: none;
}

#entry-form select:focus { border-color: var(--bw-orange); }
#entry-form input[type="email"] { width: 100%; }
#entry-form button[type="submit"] { width: 100%; margin-top: 22px; }

/* ---------- New record celebration ---------- */

.record-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}

.record-overlay-text {
  font-size: clamp(1.8rem, 9vw, 4rem);
  font-weight: 900;
  letter-spacing: 4px;
  color: #ffd23d;
  text-shadow: 0 0 18px rgba(255, 210, 61, 0.7), 0 4px 0 var(--bw-orange-deep);
  animation: record-pop 1.6s ease-out both, record-flash 0.45s steps(2) 3;
}

@keyframes record-pop {
  0%   { transform: scale(0.4) rotate(-6deg); opacity: 0; }
  35%  { transform: scale(1.15) rotate(2deg); opacity: 1; }
  55%  { transform: scale(1) rotate(0deg); }
  100% { transform: scale(1) translateY(-6px); opacity: 0; }
}

@keyframes record-flash {
  0%, 100% { color: #ffd23d; }
  50%      { color: var(--bw-white); }
}

/* ---------- Submit prompt ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--bw-charcoal);
  border: 1px solid rgba(255, 106, 26, 0.45);
  border-radius: 18px;
  padding: 26px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,0.6);
}

.modal h3 { margin: 0 0 8px; color: var(--bw-orange); font-size: 1.35rem; }
.modal p { margin: 0 0 18px; color: #e6e6e6; font-size: 0.92rem; line-height: 1.45; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-actions .btn-ghost { margin-top: 0; }

/* ---------- Leaderboard rows now carry a name and firm ---------- */

.lb-row {
  grid-template-columns: 36px auto 1fr auto;
}

.lb-name {
  font-family: ui-monospace, "Courier New", monospace;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--bw-white);
}

.lb-firm {
  text-align: left;
  color: var(--bw-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .record-overlay-text { animation: record-pop 1.6s ease-out both; }
}
