:root {
  --ink: #eef1f4;
  --dim: #aab2bb;
  --panel: rgba(12, 14, 17, 0.72);
  --accent: #ffd43b;
  --good: #4dff88;
  --bad: #ff6b5e;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #a9b0ad;
  color: var(--ink);
  font: 15px/1.45 system-ui, "Segoe UI", sans-serif;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden {
  display: none !important;
}

.panel {
  background: var(--panel);
  border-radius: 10px;
  backdrop-filter: blur(3px);
}

#fade {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}

#fade.visible {
  opacity: 1;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#clock {
  position: absolute;
  top: 16px;
  left: 16px;
  padding: 10px 16px;
  min-width: 190px;
}

#timer {
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

#penalty {
  color: var(--bad);
  font-weight: 600;
  min-height: 1.3em;
}

#speed {
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

#speed-value {
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
}

#trip {
  margin-top: 2px;
  color: var(--dim);
  font-size: 13px;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

#trip-value {
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
}

#banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1a12;
  font-weight: 700;
  letter-spacing: 0.04em;
}

#banner:empty {
  display: none;
}

#paper-map {
  position: absolute;
  top: 16px;
  right: 16px;
  border-radius: 3px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  cursor: zoom-in;
}

#notebook {
  position: absolute;
  top: 150px;
  left: 16px;
  width: 330px;
  max-height: calc(100vh - 380px);
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  background: rgba(239, 230, 207, 0.94);
  color: #2a241b;
  pointer-events: auto;
}

.notebook-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.6;
}

#notebook-lines {
  flex: 1;
  min-height: 60px;
  margin: 6px 0;
  overflow-y: auto;
  font-size: 17px;
  line-height: 1.5;
}

.notebook-line {
  padding: 1px 6px;
  border-radius: 4px;
}

.notebook-line.current {
  background: rgba(255, 196, 0, 0.45);
  font-weight: 700;
}

.notebook-distance {
  display: inline-block;
  min-width: 46px;
  margin-right: 8px;
  color: #8a5a12;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#notebook .keys {
  color: #6b5f4a;
}

#notebook-text {
  min-height: 260px;
  font-size: 15px;
  line-height: 1.5;
}

#maps {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#countdown {
  position: absolute;
  top: 26%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 96px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
}

#driver-bubble {
  position: absolute;
  --bubble: #f4f4f0;
  left: 30px;
  top: 46%;
  max-width: min(340px, 42vw);
  padding: 10px 18px;
  border-radius: 18px;
  background: var(--bubble);
  color: #15171a;
  font-size: 20px;
  font-weight: 600;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateX(-14px) scale(0.94);
  transform-origin: left center;
  transition: opacity 0.2s, transform 0.2s;
}

#driver-bubble::before {
  content: attr(data-speaker);
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.55;
}

/* The tail points off the left edge: the driver sits to the co-driver's left. */
#driver-bubble::after {
  content: "";
  position: absolute;
  left: -11px;
  top: 50%;
  margin-top: -9px;
  border: 9px solid transparent;
  border-left: 0;
  border-right: 12px solid var(--bubble);
}

#driver-bubble.visible {
  opacity: 1;
  transform: none;
}

@media (min-width: 601px) and (min-height: 501px) {
  #notebook:not(.hidden) ~ #driver-bubble {
    left: 372px;
  }
}

#driver-bubble[data-mood="angry"],
#driver-bubble[data-mood="annoyed"] {
  --bubble: #ffd9d4;
}

#driver-bubble[data-mood="happy"] {
  --bubble: #d6ffe1;
}

#voice {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(720px, 92vw);
  padding: 10px 14px;
  pointer-events: auto;
}

#mic-state {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

#mic-state::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 50%;
  background: #777;
}

#mic-state[data-state="listening"]::before {
  background: var(--good);
}

#mic-state[data-state="blocked"]::before,
#mic-state[data-state="failed"]::before,
#mic-state[data-state="unsupported"]::before {
  background: var(--bad);
}

#heard,
.heard {
  min-height: 1.5em;
  color: var(--dim);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mic-level {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.mic-level-meter {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mic-level.hidden {
  display: none;
}

.mic-level-track {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

#mic-level-bar {
  width: 0;
  height: 100%;
  background: var(--dim);
}

#mic-level-bar.loud {
  background: var(--good);
}

#mic-level-db {
  min-width: 4.5em;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#chips,
#test-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 30px;
  margin: 4px 0 8px;
}

.chip {
  padding: 2px 10px;
  border-radius: 999px;
  background: #2f6f47;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chip-distance,
.chip-modifier {
  background: #33506e;
}

.chip-hazard,
.chip-surface {
  background: #7a5a1e;
}

.chip-pace,
.chip-correction,
.chip-incomplete {
  background: #6e3a3a;
}

#typed {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font: inherit;
}

.keys {
  margin-top: 6px;
  font-size: 12px;
  color: var(--dim);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 10, 12, 0.55);
  overflow: auto;
}

.sheet {
  width: min(1040px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 24px 28px;
  border-radius: 14px;
  background: rgba(16, 18, 22, 0.94);
}

.sheet.narrow {
  width: min(560px, 100%);
}

h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

h1 small {
  font-size: 13px;
  font-weight: 500;
  color: var(--dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2 {
  margin: 14px 0 8px;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.lead {
  margin: 0 0 6px;
  max-width: 75ch;
  color: var(--dim);
}

.lead strong,
.lead em {
  color: var(--ink);
}

.columns {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.25fr);
  gap: 28px;
}

@media (max-width: 800px) {
  .columns {
    grid-template-columns: 1fr;
  }
}

label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--dim);
}

label.check {
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--ink);
}

select,
textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: #0d0f12;
  color: var(--ink);
  font: inherit;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, Consolas, monospace;
}

button {
  padding: 9px 16px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: #23272e;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #2e333c;
}

button:disabled {
  opacity: 0.7;
  cursor: default;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #1a1a12;
}

button.primary:hover {
  background: #ffe066;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.cheats table,
#result-table {
  width: 100%;
  border-collapse: collapse;
}

.cheats th,
.cheats td,
#result-table td {
  padding: 6px 8px 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  vertical-align: top;
}

.cheats th {
  width: 84px;
  color: var(--dim);
  font-weight: 600;
}

#result-table td:first-child {
  color: var(--dim);
  width: 40%;
}

code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.09);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  white-space: nowrap;
}

.example {
  margin: 12px 0 8px;
}

.example em {
  color: var(--good);
}

.hint {
  font-size: 13px;
  color: var(--dim);
}

.verdict {
  margin: 6px 0 16px;
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
}

/* Keyboard and mouse hints mean nothing on a touch screen. */
@media (hover: none) {
  .keys {
    display: none;
  }
}

@media (max-width: 600px), (max-height: 500px) {
  #clock {
    top: 8px;
    left: 8px;
    min-width: 0;
    padding: 6px 10px;
    font-size: 12px;
  }

  #timer {
    font-size: 24px;
  }

  #speed-value {
    font-size: 16px;
  }

  #trip {
    font-size: 11px;
  }

  #trip-value {
    font-size: 14px;
  }

  #maps {
    top: 8px;
    right: 8px;
    gap: 6px;
  }

  #map {
    width: 34vw;
    height: auto;
  }

  #overview {
    width: 20vw;
    height: auto;
  }

  #paper-map {
    top: 8px;
    right: 8px;
  }

  #notebook {
    top: 112px;
    left: 8px;
    width: calc(62vw - 16px);
    max-height: 38vh;
    padding: 6px 8px;
  }

  #notebook-lines {
    font-size: 14px;
  }

  #banner {
    top: 34%;
    max-width: calc(100vw - 32px);
    text-align: center;
  }

  #countdown {
    font-size: 72px;
  }

  #driver-bubble {
    left: 20px;
    top: auto;
    bottom: 150px;
    max-width: calc(100vw - 40px);
    font-size: 16px;
  }

  #voice {
    bottom: 8px;
    width: calc(100vw - 16px);
    padding: 8px 10px;
  }

  #chips {
    min-height: 0;
  }

  .chip {
    font-size: 13px;
  }

  #typed {
    font-size: 16px;
  }

  .overlay {
    padding: 8px;
  }

  .sheet {
    padding: 18px 16px;
  }

  h1 {
    font-size: 24px;
  }
}

/* Landscape phone: the tall map must be sized by height, not width. */
@media (max-height: 500px) and (min-width: 601px) {
  #map {
    width: auto;
    height: 58vh;
  }

  #overview {
    width: auto;
    height: 30vh;
  }

  #maps {
    flex-direction: row-reverse;
    align-items: flex-start;
  }

  #voice {
    width: min(560px, 60vw);
  }

  #driver-bubble {
    bottom: 120px;
  }
}
