:root {
  color-scheme: dark;
  --ivory: #fff6e6;
  --muted: #c4c8bd;
  --lime: #d4ff58;
  --dirt: #c96b3e;
  --glass: rgb(19 28 29 / 78%);
  --line: rgb(255 246 230 / 18%);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: "Arial Narrow", "Roboto Condensed", "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
  background: #263b40;
  color: var(--ivory);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: relative;
  height: 100vh;
  height: 100dvh;
  isolation: isolate;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

main,
#app,
#game {
  width: 100%;
  height: 100%;
}

#scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(#7196ae, #e7d4ad 65%, #886148);
  touch-action: none;
}

#scene canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.hidden,
[hidden] {
  display: none !important;
}

/* Keep the live basin visible, but reserve the intro for instructions. */
#intro:not(.hidden):not([hidden]) ~ :is(#hud, #minimap, #controls) {
  display: none !important;
}

button {
  min-width: 58px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 22px;
  background: var(--glass);
  color: var(--ivory);
  font: 800 14px/1.1 "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: none;
  -webkit-touch-callout: none;
  box-shadow: 0 5px 18px rgb(0 0 0 / 16%);
  transition: background 130ms ease, border-color 130ms ease, transform 130ms ease,
    box-shadow 130ms ease;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 4px;
}

button:active,
button.pressed,
.pressed {
  transform: translateY(2px);
  background: var(--lime);
  border-color: var(--lime);
  color: #19231c;
  box-shadow: 0 0 22px rgb(212 255 88 / 22%);
}

button:disabled {
  cursor: wait;
  opacity: 0.48;
  transform: none;
  box-shadow: none;
}

button svg {
  width: 26px;
  height: 26px;
  vertical-align: middle;
  fill: currentColor;
}

#intro,
#results {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
  padding: calc(32px + var(--safe-top))
    calc(clamp(24px, 7vw, 108px) + var(--safe-right))
    calc(32px + var(--safe-bottom))
    calc(clamp(24px, 7vw, 108px) + var(--safe-left));
  background: linear-gradient(
    90deg,
    rgb(13 24 27 / 93%) 0%,
    rgb(16 27 28 / 77%) 39%,
    rgb(16 27 28 / 20%) 78%,
    rgb(16 27 28 / 8%)
  );
}

#intro > *,
#results > * {
  max-width: 570px;
  margin-top: 0;
  margin-bottom: 0;
}

#intro > div,
#intro > section,
#results > div,
#results > section {
  width: 100%;
}

#intro h1,
#result-title {
  font-family: Impact, "Arial Narrow", "Helvetica Neue", sans-serif;
  font-size: clamp(54px, 8vw, 112px);
  line-height: 0.91;
  font-weight: 900;
  letter-spacing: -0.035em;
  text-transform: uppercase;
  text-wrap: balance;
  text-shadow: 0 4px 28px rgb(0 0 0 / 18%);
}

#intro h2,
#intro h3,
#results h2,
#results h3 {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#intro p,
#intro li,
#result-detail {
  color: #dfdfd2;
  font-size: clamp(14px, 1.5vw, 17px);
  line-height: 1.6;
  text-wrap: pretty;
}

#intro p,
#intro ul,
#intro ol {
  max-width: 460px;
}

#intro ul,
#intro ol {
  padding-left: 20px;
}

#intro li + li {
  margin-top: 5px;
}

#intro small,
#results small {
  color: var(--muted);
  line-height: 1.5;
}

kbd {
  display: inline-block;
  min-width: 24px;
  margin: 1px 2px;
  padding: 2px 6px;
  border: 1px solid rgb(255 255 255 / 23%);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgb(255 255 255 / 7%);
  color: var(--ivory);
  font: 700 12px/1.5 inherit;
}

#start,
#restart {
  align-self: flex-start;
  min-width: 206px;
  margin-top: 10px;
  padding: 19px 30px;
  border-color: var(--lime);
  background: var(--lime);
  color: #1e2a1c;
  font-size: 16px;
  box-shadow: 0 7px 30px rgb(135 172 47 / 18%);
}

#hud {
  position: fixed;
  z-index: 10;
  top: calc(16px + var(--safe-top));
  left: calc(16px + var(--safe-left));
  right: calc(16px + var(--safe-right));
  display: flex;
  align-items: stretch;
  gap: 8px;
  max-width: 820px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

#hud > :not(#message) {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--glass);
  box-shadow: 0 5px 20px rgb(0 0 0 / 12%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#hud label,
#hud small,
#hud .label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.1em;
  font-weight: 700;
}

#time,
#rank,
#checkpoint,
#speed,
#stunts {
  font-size: clamp(22px, 3vw, 31px);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  color: var(--ivory);
}

#hud :is(span, strong, b)#time,
#hud :is(span, strong, b)#rank,
#hud :is(span, strong, b)#checkpoint,
#hud :is(span, strong, b)#speed,
#hud :is(span, strong, b)#stunts {
  display: block;
}

#checkpoint,
#stunts {
  color: var(--lime);
}

#message {
  position: absolute;
  top: calc(100% + 16px);
  left: 0;
  width: max-content;
  max-width: min(65vw, 450px);
  padding: 10px 15px;
  border-left: 3px solid var(--lime);
  border-radius: 0 8px 8px 0;
  background: rgb(18 29 29 / 83%);
  color: var(--ivory);
  font-size: clamp(13px, 1.8vw, 19px);
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 3px rgb(0 0 0 / 25%);
}

#message:empty {
  display: none;
}

#minimap {
  position: fixed;
  z-index: 9;
  top: calc(108px + var(--safe-top));
  right: calc(16px + var(--safe-right));
  display: block;
  width: 142px;
  height: 142px;
  border: 1px solid rgb(255 246 230 / 27%);
  border-radius: 16px;
  background: rgb(20 34 34 / 77%);
  box-shadow: 0 7px 24px rgb(0 0 0 / 20%);
  pointer-events: none;
}

#controls {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}

#controls button {
  position: absolute;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 8px;
  border: 1px solid rgb(255 246 230 / 34%);
  background: rgb(20 31 32 / 74%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
  font-size: 14px;
}

#left {
  left: calc(20px + var(--safe-left));
  bottom: calc(22px + var(--safe-bottom));
}

#right {
  left: calc(102px + var(--safe-left));
  bottom: calc(22px + var(--safe-bottom));
}

#controls #gas {
  right: calc(20px + var(--safe-right));
  bottom: calc(104px + var(--safe-bottom));
  height: 88px;
  border-color: rgb(212 255 88 / 65%);
  background: rgb(118 146 44 / 68%);
  color: #f0ffca;
}

#brake {
  right: calc(20px + var(--safe-right));
  bottom: calc(22px + var(--safe-bottom));
}

#controls #recover {
  left: 50%;
  bottom: calc(110px + var(--safe-bottom));
  width: 118px;
  height: 58px;
  margin-left: -59px;
  font-size: 12px;
  letter-spacing: 0.08em;
}

#controls #mute {
  top: calc(264px + var(--safe-top));
  right: calc(16px + var(--safe-right));
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 12px;
  letter-spacing: 0.02em;
}

#controls button.pressed,
#controls button:active {
  background: var(--lime);
  border-color: var(--lime);
  color: #1c281c;
}

#mute[aria-pressed="true"] {
  color: var(--muted);
  border-style: dashed;
}

#results {
  z-index: 40;
  align-items: center;
  text-align: center;
  gap: 20px;
  background: radial-gradient(ellipse at 50% 45%, rgb(21 34 33 / 90%), rgb(11 20 24 / 96%));
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}

#result-title {
  font-size: clamp(40px, 7vw, 76px);
  color: var(--lime);
}

#result-detail {
  width: min(100%, 460px);
  padding: 20px 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgb(255 255 255 / 4%);
  font-variant-numeric: tabular-nums;
  white-space: pre-line;
}

#result-detail p + p {
  margin-top: 8px;
}

#result-detail strong,
#result-detail b {
  color: var(--ivory);
}

#results #restart {
  align-self: center;
}

@media (hover: hover) {
  button:not(:disabled):hover {
    border-color: var(--lime);
    background: #35453b;
  }

  #start:not(:disabled):hover,
  #restart:not(:disabled):hover {
    background: #e2ff90;
    color: #1e2a1c;
    transform: translateY(-2px);
  }
}

@media (max-width: 600px) {
  #hud {
    top: calc(10px + var(--safe-top));
    left: calc(10px + var(--safe-left));
    right: calc(10px + var(--safe-right));
    gap: 5px;
  }

  #hud > :not(#message) {
    padding: 9px 7px;
    border-radius: 8px;
    font-size: 12px;
    letter-spacing: 0.015em;
  }

  #hud label,
  #hud small,
  #hud .label {
    font-size: 12px;
    line-height: 1.3;
    min-height: 2.6em;
    letter-spacing: 0;
  }

  #time,
  #rank,
  #checkpoint,
  #speed,
  #stunts {
    font-size: 23px;
  }

  #minimap {
    top: calc(94px + var(--safe-top));
    right: calc(12px + var(--safe-right));
    width: 112px;
    height: 112px;
    border-radius: 12px;
  }

  #message {
    top: calc(100% + 12px);
    max-width: calc(100vw - 158px - var(--safe-left) - var(--safe-right));
    padding: 9px 10px;
    font-size: 13px;
  }

  #controls button {
    width: 64px;
    height: 64px;
    border-radius: 12px;
  }

  #left {
    left: calc(12px + var(--safe-left));
    bottom: calc(16px + var(--safe-bottom));
  }

  #right {
    left: calc(84px + var(--safe-left));
    bottom: calc(16px + var(--safe-bottom));
  }

  #controls #gas {
    right: calc(12px + var(--safe-right));
    bottom: calc(88px + var(--safe-bottom));
    height: 80px;
  }

  #brake {
    right: calc(12px + var(--safe-right));
    bottom: calc(16px + var(--safe-bottom));
  }

  #controls #recover {
    bottom: calc(104px + var(--safe-bottom));
    width: 106px;
    margin-left: -53px;
  }

  #controls #mute {
    top: calc(218px + var(--safe-top));
    right: calc(12px + var(--safe-right));
  }

  #intro {
    justify-content: center;
    gap: 16px;
    padding: calc(28px + var(--safe-top)) calc(26px + var(--safe-right))
      calc(28px + var(--safe-bottom)) calc(26px + var(--safe-left));
    background: linear-gradient(90deg, rgb(14 25 27 / 89%), rgb(14 25 27 / 40%)),
      linear-gradient(0deg, rgb(14 25 27 / 72%), transparent 80%);
  }

  #intro h1 {
    max-width: 350px;
    font-size: clamp(56px, 16vw, 84px);
  }

  #intro p,
  #intro li {
    font-size: 14px;
    line-height: 1.5;
  }

  #results {
    padding: calc(24px + var(--safe-top)) calc(22px + var(--safe-right))
      calc(24px + var(--safe-bottom)) calc(22px + var(--safe-left));
    gap: 16px;
  }

  #result-detail {
    padding: 16px 18px;
    font-size: 14px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  #intro {
    gap: 9px;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  #intro h1 {
    font-size: clamp(42px, 10vh, 62px);
  }

  #intro p,
  #intro li {
    font-size: 12px;
    line-height: 1.35;
  }

  #intro ul,
  #intro ol {
    margin-block: 0;
  }

  #start,
  #restart {
    margin-top: 3px;
    padding: 14px 24px;
  }

  #hud {
    right: calc(160px + var(--safe-right));
    top: calc(8px + var(--safe-top));
    gap: 5px;
  }

  #hud > :not(#message) {
    padding: 6px 9px;
  }

  #minimap {
    top: calc(10px + var(--safe-top));
    width: 108px;
    height: 108px;
  }

  #controls #mute {
    top: calc(128px + var(--safe-top));
  }

  #results {
    gap: 10px;
    padding-block: calc(16px + var(--safe-top)) calc(16px + var(--safe-bottom));
  }

  #result-title {
    font-size: 38px;
  }

  #result-detail {
    padding: 10px 18px;
    font-size: 13px;
    line-height: 1.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  button:active,
  button.pressed,
  #start:not(:disabled):hover,
  #restart:not(:disabled):hover {
    transform: none;
  }
}
