:root {
  --ink: #1D1133;
  --ink-deep: #120A22;
  --violet: #3A1F6B;
  --purple: #9059FF;
  --fox: #FF7139;
  --ember: #FFBD4F;
  --pink: #FF4F5E;
  --lilac: #C9B8FF;
  --snow: #FFF8F1;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--ink-deep);
  color: var(--snow);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

:focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 4px;
}

/* Sticker lettering: an ink outline plus a hard orange offset, like a die-cut
   laptop sticker. Set --o to change the outline weight. */
.sticker-text {
  --o: 3px;
  --d: calc(var(--o) * 0.7);
  color: var(--snow);
  text-shadow:
    var(--o) 0 var(--ink),
    calc(var(--o) * -1) 0 var(--ink),
    0 var(--o) var(--ink),
    0 calc(var(--o) * -1) var(--ink),
    var(--d) var(--d) var(--ink),
    calc(var(--d) * -1) var(--d) var(--ink),
    var(--d) calc(var(--d) * -1) var(--ink),
    calc(var(--d) * -1) calc(var(--d) * -1) var(--ink),
    calc(var(--o) + 2px) calc(var(--o) + 4px) 0 var(--fox);
}

.title {
  --o: 4px;
  margin: 0;
  font-size: clamp(3rem, 15vw, 4.5rem);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.03em;
  transform: rotate(-3deg);
}

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  min-width: 12rem;
  min-height: 3.5rem;
  padding: 0 2rem;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--fox);
  color: var(--ink);
  font: 900 1.25rem/1 var(--font);
  box-shadow: 0 0 0 3px var(--snow), 0 8px 0 3px var(--ink-deep);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.btn:active {
  transform: translateY(5px);
  box-shadow: 0 0 0 3px var(--snow), 0 3px 0 3px var(--ink-deep);
}

.link-btn {
  padding: 0.75rem 1rem;
  border: 0;
  background: none;
  color: var(--lilac);
  font: 700 1rem var(--font);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid rgba(255, 248, 241, 0.25);
  border-radius: 12px;
  background: rgba(18, 10, 34, 0.45);
  color: var(--snow);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.mute-btn .icon-off,
.mute-btn[aria-pressed="true"] .icon-on {
  display: none;
}

.mute-btn[aria-pressed="true"] .icon-off {
  display: inline;
}

/* ------------------------------------------------------------- game pages */

body.game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Capped width keeps the playfield the same shape on tablets and laptops. */
.stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--ink);
}

.stage > canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  pointer-events: none;
}

.hud-left,
.hud-side {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-score {
  font-size: 2.75rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.hud-best {
  margin-right: 4px;
  color: var(--lilac);
  font-size: 0.9375rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-time {
  --o: 2px;
  min-width: 3ch;
  margin-right: 4px;
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hud-time.is-hurry {
  color: var(--pink);
  animation: hurry 0.5s ease-in-out infinite alternate;
}

@keyframes hurry {
  to { transform: scale(1.15); }
}

.combo {
  padding: 0.125rem 0.5rem;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--ember);
  color: var(--ink);
  font-size: 1.125rem;
  font-weight: 900;
  box-shadow: 0 0 0 2px var(--snow);
  transform: rotate(-6deg);
}

.combo[hidden] {
  display: none;
}

.safe-probe {
  position: absolute;
  bottom: 0;
  height: env(safe-area-inset-bottom, 0px);
  visibility: hidden;
}

/* --------------------------------------------------------------- overlays */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 2rem 1.5rem calc(2rem + env(safe-area-inset-bottom));
  background: rgba(18, 10, 34, 0.82);
  text-align: center;
  touch-action: pan-y;
}

.overlay[hidden] {
  display: none;
}

/* margin: auto centres the panel but still lets it scroll on short screens. */
.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  margin: auto;
}

.panel .title {
  margin-bottom: 0.5rem;
}

.legend {
  display: grid;
  gap: 0.75rem;
  max-width: 20rem;
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.legend li {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
}

.legend canvas {
  width: 48px;
  height: 48px;
}

.howto {
  max-width: 21rem;
  margin: 0;
  color: var(--lilac);
}

.over-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
}

.final-score {
  --o: 5px;
  margin: 0;
  font-size: clamp(4.5rem, 24vw, 6.5rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.over-best {
  margin: 0;
  color: var(--lilac);
  font-size: 1.125rem;
  font-weight: 800;
}

.over-best.is-new {
  padding: 0.25rem 0.875rem;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--ember);
  color: var(--ink);
  box-shadow: 0 0 0 3px var(--snow);
  transform: rotate(-4deg);
}

.over-stats {
  max-width: 21rem;
  margin: 0 0 0.5rem;
}

/* ------------------------------------------------------------------- menu */

body.menu {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--ink);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(201, 184, 255, 0.7) 1.2px, transparent 1.7px),
    radial-gradient(circle at 70% 80%, rgba(255, 248, 241, 0.55) 1px, transparent 1.5px),
    radial-gradient(circle at 85% 15%, rgba(255, 189, 79, 0.7) 1.4px, transparent 1.9px);
  background-size: 180px 180px, 240px 240px, 310px 310px;
}

.home {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 30rem;
  margin: 0 auto;
  padding: max(2.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) calc(2.5rem + env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}

.dash[hidden],
.step[hidden],
.btn-link[hidden],
.link-btn[hidden] {
  display: none;
}

/* Hero: the title, then the fox running along its lane. */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.hero-title {
  --o: 5px;
  font-size: clamp(4rem, 21vw, 6.5rem);
  white-space: nowrap;
}

.hero-by {
  margin: 0.75rem 0 0;
  color: var(--lilac);
  font-size: 1rem;
  font-weight: 800;
  transform: rotate(-3deg);
}

.runway {
  align-self: stretch;
  height: 136px;
  margin: 0.25rem -1.25rem 0;
}

.runway canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hero-pitch {
  max-width: 24ch;
  margin: 0.5rem 0 0;
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 1.35;
}

/* Gate and name form. */
.step {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.25rem;
}

.step-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1.15;
}

.step-text {
  max-width: 30ch;
  margin: 0;
  color: var(--lilac);
  font-size: 1.125rem;
}

.step-actions {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 0.5rem;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 22rem;
}

.field-label {
  font-weight: 800;
}

.field-input {
  min-height: 3.5rem;
  padding: 0 1rem;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--snow);
  color: var(--ink);
  font: 800 1.25rem var(--font);
  box-shadow: 0 0 0 3px var(--lilac);
}

.field-input:focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 3px;
}

/* Inline error under the name field, e.g. when the name is taken. */
.field-error {
  max-width: 22rem;
  margin: -0.25rem 0 0;
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem;
  background: rgba(226, 40, 80, 0.15);
  border: 2px solid #e22850;
  color: #ffb3c4;
  font-weight: 700;
}
.field-error[hidden] { display: none; }
.field-input[aria-invalid="true"] { outline: 3px solid #e22850; }

/* Official App Store / Google Play badges on the install gate. */
.store-badge { display: inline-block; }
.store-badge[hidden] { display: none; }
.store-badge img { display: block; height: 3.5rem; width: auto; }

/* Main screen. */
.dash {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.run-card {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.player-line {
  margin: 0;
  color: var(--lilac);
  font-size: 1.125rem;
  text-align: center;
}

.player-line strong {
  color: var(--snow);
  overflow-wrap: anywhere;
}

.player-line .link-btn:not([hidden])::before {
  content: "·";
  display: inline-block;
  margin: 0 0.5rem 0 0.25rem;
  color: var(--lilac);
  text-decoration: none;
}

.link-btn.inline {
  padding: 0;
  font-size: inherit;
}

/* Tries: one arcade token per try, spent tokens leave a dashed outline. */
.tries {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.875rem;
}

.tries[hidden] {
  display: none;
}

.tokens {
  display: flex;
  gap: 0.375rem;
}

.token {
  width: 2rem;
  height: 2rem;
  border: 2px dashed rgba(201, 184, 255, 0.6);
  border-radius: 50%;
}

.token.is-full {
  border: 3px solid var(--ink);
  background: radial-gradient(circle at 50% 50%, var(--ember) 0 38%, #F2A93A 40% 52%, var(--ember) 54%);
  box-shadow: 0 0 0 2px var(--snow), 0 3px 0 2px var(--fox);
}

.tries-text {
  margin: 0;
  color: var(--lilac);
  font-size: 0.9375rem;
  line-height: 1.3;
}

.tries-text strong {
  color: var(--snow);
  font-size: 1.125rem;
}

.best {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 0;
  line-height: 1.1;
}

.best[hidden] {
  display: none;
}

.best-label {
  color: var(--lilac);
  font-size: 0.875rem;
  font-weight: 700;
}

.best-score {
  font-size: 1.75rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.btn-play {
  width: 100%;
  min-height: 4.5rem;
  font-size: 1.625rem;
  letter-spacing: -0.01em;
}

.btn-play:hover {
  background: #FF8452;
}

/* Out of tries: a plain message instead of a button that can't be used. */
.done {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.25rem 1.25rem 1.375rem;
  border: 2px dashed rgba(201, 184, 255, 0.55);
  border-radius: 20px;
  text-align: center;
}

.done[hidden] {
  display: none;
}

.done p,
.done-title {
  margin: 0;
}

.done-title {
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1.2;
}

.done-score {
  color: var(--ember);
  font-size: 1.25rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.done-rank {
  font-weight: 800;
}

.done-help {
  margin-top: 0.25rem !important;
  color: var(--lilac);
}

.side {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* Prize: an arcade redemption ticket, notched at both ends. */
.ticket {
  position: relative;
  padding: 1.125rem 2rem 1.25rem;
  border-radius: 6px;
  background: var(--ember);
  color: var(--ink);
  text-align: center;
  transform: rotate(-1.5deg);
  -webkit-mask:
    radial-gradient(circle at 0 50%, transparent 13px, #000 13.5px) left / 51% 100% no-repeat,
    radial-gradient(circle at 100% 50%, transparent 13px, #000 13.5px) right / 51% 100% no-repeat;
  mask:
    radial-gradient(circle at 0 50%, transparent 13px, #000 13.5px) left / 51% 100% no-repeat,
    radial-gradient(circle at 100% 50%, transparent 13px, #000 13.5px) right / 51% 100% no-repeat;
}

.ticket[hidden] {
  display: none;
}

.ticket::before {
  content: "";
  position: absolute;
  inset: 7px 22px;
  border: 2px dashed rgba(29, 17, 51, 0.35);
  border-radius: 4px;
  pointer-events: none;
}

.ticket p {
  margin: 0;
}

.ticket-prize {
  font-size: 1.125rem;
  font-weight: 800;
  line-height: 1.2;
}

.ticket-prize strong {
  display: block;
  margin-top: 0.125rem;
  font-size: 1.625rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.ticket-clock {
  margin-top: 0.5rem !important;
  text-wrap: balance;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.ticket.is-over {
  background: var(--fox);
}

/* Mini leaderboard. */
.board {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.board-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 900;
}

.board-rows {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.board-row {
  display: grid;
  grid-template-columns: 1.75rem 1fr auto;
  align-items: center;
  gap: 0.625rem;
  min-height: 2.75rem;
  padding: 0 1rem 0 0.75rem;
  border-radius: 12px;
  background: rgba(58, 31, 107, 0.6);
  font-size: 1.0625rem;
  font-weight: 800;
}

.board-rank {
  color: var(--lilac);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.board-row:first-child .board-rank {
  color: var(--ember);
}

.board-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-score {
  color: var(--ember);
  font-variant-numeric: tabular-nums;
}

.board-row.is-me {
  background: var(--fox);
  color: var(--ink);
  box-shadow: inset 0 0 0 3px var(--ink), 0 0 0 2px var(--snow);
}

.board-row.is-me .board-rank,
.board-row.is-me .board-score {
  color: var(--ink);
}

.board-gap {
  height: 0.75rem;
  background: radial-gradient(circle, rgba(201, 184, 255, 0.6) 1.5px, transparent 2px) center / 10px 100% repeat-x;
  background-size: 10px 6px;
  background-repeat: repeat-x;
  background-position: center;
  margin: 0 40%;
}

.board-note {
  margin: 0;
  color: var(--lilac);
}

.board-note[hidden] {
  display: none;
}

/* Tablets and laptops: hero across the top, play and scores side by side. */
@media (min-width: 52rem) {
  .home {
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: 60rem;
    gap: 2.5rem;
  }

  .hero-by {
    font-size: 1.25rem;
  }

  .step-text {
    max-width: 40ch;
  }

  .hero-title {
    font-size: 7.5rem;
  }

  .runway {
    height: 180px;
    margin-inline: 0;
  }

  .hero-pitch {
    max-width: none;
    font-size: 1.375rem;
  }

  .dash {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: 3.5rem;
  }

  .step {
    align-items: center;
    text-align: center;
  }

  .player-line {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hud-time.is-hurry {
    animation: none;
  }

  .btn {
    transition: none;
  }
}
