:root {
  --ink: #0d1013;
  --panel: rgba(13, 16, 19, 0.86);
  --line: rgba(244, 240, 232, 0.13);
  --paper: #f4f0e8;
  --muted: #c2bbae;
  --signal: #ffb21a;
  --signal-ink: #1f1500;
  --good: #63dc95;
  --route: #3fd47f;
  --danger: #ff7a66;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-body: 'Barlow', 'Helvetica Neue', sans-serif;
  --gutter: max(14px, env(safe-area-inset-left));
  --top: max(14px, env(safe-area-inset-top));
  --bottom: max(14px, env(safe-area-inset-bottom));
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#map {
  position: fixed;
  inset: 0;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Run list */

#menu {
  position: fixed;
  left: var(--gutter);
  top: var(--top);
  /* leave the bottom strip clear for the map data attribution */
  bottom: calc(var(--bottom) + 22px);
  width: min(430px, calc(100vw - 2 * var(--gutter)));
  box-sizing: border-box;
  padding: 28px 26px 20px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#menu h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.7rem, 7vw, 3.8rem);
  line-height: 0.92;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  margin: 0 0 14px;
}

.intro {
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.45;
  margin: 0 0 22px;
  max-width: 36ch;
}

.runs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.run {
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 16px;
  row-gap: 2px;
  padding: 11px 15px 12px;
  background: rgba(244, 240, 232, 0.04);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 120ms ease-out, background-color 120ms ease-out;
}

.run:hover,
.run:focus-visible {
  border-color: var(--signal);
  background: rgba(255, 178, 26, 0.09);
  outline: none;
}

.run.is-mission {
  border-color: rgba(63, 212, 127, 0.5);
  background: rgba(63, 212, 127, 0.08);
}

.run.is-mission:hover,
.run.is-mission:focus-visible {
  border-color: var(--route);
  background: rgba(63, 212, 127, 0.15);
}

.run-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.45rem;
  line-height: 1.05;
}

.run-meta {
  grid-column: 1;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.35;
}

.run-best {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  text-align: right;
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.run-best strong {
  display: block;
  color: var(--paper);
  font-weight: 600;
  font-size: 1.35rem;
}

.controls-hint {
  margin: auto 0 0;
  padding-top: 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  color: var(--muted);
  font-size: 0.86rem;
}

.controls-hint div {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.controls-hint dt {
  flex: none;
  min-width: 4.6em;
}

.controls-hint dd {
  margin: 0;
}

.controls-hint .wide {
  grid-column: 1 / -1;
}

.small-print {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.controls-short {
  display: none;
  margin: auto 0 0;
  padding-top: 14px;
  color: var(--muted);
  font-size: 0.86rem;
}

.controls-short kbd {
  margin-right: 2px;
}

@media (max-height: 820px) and (min-width: 561px) {
  #menu {
    padding-top: 22px;
    padding-bottom: 14px;
  }

  .intro {
    margin-bottom: 16px;
  }

  .runs {
    gap: 6px;
  }

  .run {
    padding: 9px 15px 10px;
  }

  .controls-hint {
    display: none;
  }

  .controls-short {
    display: block;
  }

  .small-print {
    margin-top: 6px;
  }
}

kbd {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--paper);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
}

/* Loading, result and pause sheets */

.sheet {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, calc(100vw - 2 * var(--gutter)));
  box-sizing: border-box;
  padding: 26px 26px 24px;
  text-align: center;
}

.sheet-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  line-height: 1;
  text-transform: uppercase;
  margin: 0 0 18px;
}

.sheet-note {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
  margin: 14px 0 0;
}

.bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(244, 240, 232, 0.12);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: 4%;
  background: var(--signal);
  transition: width 200ms ease-out;
}

.sheet.is-error .sheet-title {
  color: var(--signal);
}

.result-time {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 4rem;
  line-height: 1;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.result-time.is-best {
  color: var(--good);
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 22px;
}

.btn {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(244, 240, 232, 0.05);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 120ms ease-out, border-color 120ms ease-out;
}

.btn:hover,
.btn:focus-visible {
  border-color: var(--paper);
  outline: none;
}

.btn-primary {
  background: var(--signal);
  border-color: var(--signal);
  color: var(--signal-ink);
}

.btn-primary:hover,
.btn-primary:focus-visible {
  background: #ffc34d;
  border-color: #ffc34d;
}

.btn:disabled {
  opacity: 0.65;
  cursor: progress;
}

/* Mission brief */

.sheet-wide {
  width: min(460px, calc(100vw - 2 * var(--gutter)));
  text-align: left;
}

.brief-text {
  font-size: 1.02rem;
  line-height: 1.5;
  margin: 0 0 20px;
}

.brief-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  margin: 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--line);
}

.brief-facts dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.brief-facts dd {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  line-height: 1.15;
}

/* Cooler box meter */

.cooler {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  margin-top: 3px;
}

.cooler-label {
  color: var(--muted);
  font-size: 0.95rem;
}

.cooler-bar {
  height: 7px;
  border-radius: 4px;
  background: rgba(244, 240, 232, 0.15);
  overflow: hidden;
}

#cooler-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--route);
  transition: width 250ms ease-out, background-color 250ms ease-out;
}

.cooler-pct {
  font-weight: 600;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  min-width: 3.4ch;
  text-align: right;
}

.hud-run.is-hit {
  border-color: var(--danger);
}

.hud-timer.is-urgent {
  color: var(--signal);
}

/* Driving HUD */

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-family: var(--font-display);
}

.hud-top {
  position: absolute;
  top: var(--top);
  left: var(--gutter);
  right: var(--gutter);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 10px;
}

.hud-run {
  justify-self: start;
  padding: 7px 13px 8px;
  max-width: 100%;
  box-sizing: border-box;
}

.hud-run .name {
  font-weight: 600;
  font-size: 1.1rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-run .cp {
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.hud-run .cp:empty {
  display: none;
}

.hud-timer {
  justify-self: center;
  padding: 4px 16px;
  font-weight: 700;
  font-size: clamp(1.9rem, 6vw, 2.7rem);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.hud-btn {
  justify-self: end;
  pointer-events: auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.hud-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--paper);
  stroke-width: 2.6;
  stroke-linecap: round;
}

.guide {
  position: absolute;
  top: calc(var(--top) + 72px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 8px;
}

.guide svg {
  width: 34px;
  height: 34px;
  fill: var(--signal);
}

.guide .dist {
  font-weight: 600;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  min-width: 4.2ch;
}

.speedo {
  position: absolute;
  right: var(--gutter);
  bottom: calc(var(--bottom) + 8px);
  padding: 6px 14px 8px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.speedo .val {
  font-weight: 700;
  font-size: 2.6rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: right;
}

.speedo .unit {
  color: var(--muted);
  font-size: 1rem;
}

.toast {
  position: absolute;
  top: 36%;
  left: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-weight: 700;
  font-size: clamp(2.6rem, 11vw, 5.5rem);
  text-transform: uppercase;
  text-shadow: 0 4px 22px rgba(0, 0, 0, 0.6);
  opacity: 0;
}

.toast.is-small {
  font-size: clamp(1.6rem, 6vw, 2.6rem);
}

.toast.show {
  animation: toast 1100ms ease-out both;
}

@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -42%); }
  14% { opacity: 1; transform: translate(-50%, -50%); }
  78% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -50%); }
}

/* Touch controls */

#touch {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  /* sits above the map data attribution, which wraps to three lines on a phone */
  bottom: calc(var(--bottom) + 70px);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.pad {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.pad button {
  pointer-events: auto;
  touch-action: none;
  width: 76px;
  height: 76px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(13, 16, 19, 0.7);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  text-transform: uppercase;
}

.pad button svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: var(--paper);
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pad button.is-down {
  background: rgba(255, 178, 26, 0.3);
  border-color: var(--signal);
}

.pad .pedal-go {
  height: 104px;
  background: rgba(255, 178, 26, 0.18);
  border-color: rgba(255, 178, 26, 0.55);
}

body.is-touch .speedo {
  bottom: calc(var(--bottom) + 188px);
}

/* Keep Cesium's data attribution readable above the touch pads */

.cesium-widget-credits,
.cesium-widget-credits * {
  font-family: var(--font-body);
  font-size: 11px;
}

@media (max-width: 560px) {
  #menu {
    top: auto;
    max-height: calc(100% - var(--top) - var(--bottom));
    padding: 22px 18px 18px;
  }

  .controls-hint {
    display: none;
  }

  .hud-run .name {
    display: none;
  }

  .hud-run .cp {
    color: var(--paper);
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .cooler {
    grid-template-columns: 1fr auto;
    min-width: 0;
    width: 104px;
    margin-top: 0;
  }

  .cooler-label {
    display: none;
  }

  .brief-facts {
    gap: 12px 14px;
  }
}

@media (max-height: 760px) and (min-width: 561px) {
  #menu h1 {
    font-size: 2.9rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast.show {
    animation: none;
    opacity: 1;
  }
}
