@font-face{font-family:RoadText;src:url('./assets/fonts/LiberationSans-Bold.ttf') format('truetype');font-weight:700;font-display:block}
/* Надпись «ФИНИШ» над местом парковки: Oswald (OFL), вариативный, жирное начертание 700. */
@font-face{font-family:FinishText;src:url('./assets/fonts/Oswald-VariableFont_wght.ttf') format('truetype');font-weight:200 700;font-display:block}
/* Интерфейс: системный Andale Mono (Apple/Monotype, не вкладывается), без него вложенный Liberation Mono (OFL). */
@font-face {
  font-family: 'Liberation Mono';
  src: url('./assets/fonts/LiberationMono-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* У Andale Mono одно начертание, поэтому везде обычный вес: иерархия размером и цветом. */
:root {
  --ink: #eef1ef;
  --muted: #9ba6a2;
  --chrome: #101413;
  --panel: #111615eb;
  --panel-solid: #141a19;
  --line: #ffffff21;
  --line-strong: #ffffff3d;
  --hover: #ffffff12;
  --danger: #b4412d;
  --radius: 6px;
  font-family: 'Andale Mono', 'Liberation Mono', monospace;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink);
  background: var(--chrome);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, strong, th, dt, summary { font-weight: 400; }
h1, h2 { text-wrap: balance; }
p, dd { text-wrap: pretty; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, select:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
a { color: var(--ink); text-underline-offset: 3px; }

/* Верхняя полоса. Высоты 76 + 46 сохранены: размер сцены и масштаб указателей те же, что в 0.8.0. */
.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--ink); text-decoration: none; font-size: 17px; }
nav { display: flex; gap: 28px; align-self: stretch; }
.nav-button {
  position: relative;
  border: 0;
  background: none;
  padding: 0;
  color: var(--muted);
  transition: color 150ms ease-out;
}
.nav-button:hover, .nav-button.active { color: var(--ink); }
.nav-button.active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--ink);
}
#result-count {
  display: inline-block;
  min-width: 2ch;
  margin-left: 6px;
  padding: 0 5px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.text-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: none;
  font-size: 12px;
  transition: background-color 150ms ease-out;
}
.text-button:hover, .icon-button:hover, .secondary:hover { background: var(--hover); }
.icon-button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: none;
  font-size: 20px;
  line-height: 1;
  transition: background-color 150ms ease-out;
}

/* Сцена */
.simulator {
  position: relative;
  height: calc(100dvh - 122px);
  min-height: 480px;
  overflow: hidden;
  background: #92b6c5;
}
canvas { display: block; width: 100%; height: 100%; }
#scene.monochrome { filter: grayscale(1); }
.simulator::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 78% 78% at 50% 45%, transparent 74%, rgb(0 0 0 / 12%) 100%);
}

/* Цель: маленькая плашка в углу, меньше, чем карточка 0.8.0. */
.route-card {
  position: absolute;
  top: 24px;
  left: 30px;
  padding: 8px 14px 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.route-label { display: block; font-size: 11px; color: var(--muted); }
h1 { margin: 0; font-size: 17px; line-height: 1.3; }

/* Переключатель разметки: подписи вместо флагов. */
.variant-control {
  position: absolute;
  top: 24px;
  right: 30px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
}
.variant-control > span { padding: 0 8px 0 6px; font-size: 11px; color: var(--muted); }
.variant-control button {
  height: 36px;
  min-width: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  font-size: 12px;
  color: #c9d1ce;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}
.variant-control button:hover { background: var(--hover); color: var(--ink); }
.variant-control button.selected { background: var(--ink); color: var(--chrome); }

/* Рамка зеркала: место и размер совпадают с окном зеркала в world.js (ширина min(290, 24%), отступ сверху 105). */
.mirror-border {
  position: absolute;
  top: 104px;
  left: 50%;
  transform: translateX(-50%);
  width: min(290px, 24%);
  aspect-ratio: 3.4;
  border: 5px solid #161b1d;
  border-radius: 9px;
  pointer-events: none;
}

/* Подсказка клавиш во время проезда */
.controls-hint {
  position: absolute;
  left: 30px;
  bottom: 16px;
  max-width: 65%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #d3dad7;
}
.controls-hint > span { margin-right: 6px; }
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  background: #0f1413b3;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font: inherit;
  font-size: 11px;
  line-height: 1;
  color: var(--ink);
}

/* Передача и сообщения об управлении */
.speed-hud { position: absolute; left: 74%; bottom: 52px; display: flex; align-items: center; gap: 12px; }
.gear {
  min-width: 52px;
  height: 52px;
  padding: 0 12px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}
.gear:disabled { opacity: 1; color: var(--ink); }
.driving-notice {
  position: absolute;
  left: 50%;
  bottom: 160px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 10px 15px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 15px;
  text-align: center;
  pointer-events: none;
}

.warning:not([hidden]) + .driving-notice { bottom: 195px; }

.warning {
  position: absolute;
  left: 50%;
  bottom: 140px;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--danger);
  border-radius: var(--radius);
  font-size: 14px;
  white-space: nowrap;
}

/* Окна поверх сцены: сплошной фон без размытия и теней (размытие над WebGL дорого на слабой графике). */
.intro-panel, .pause-panel, .finish-panel {
  position: absolute;
  padding: 22px 24px 24px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.intro-panel, .pause-panel {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 380px;
  max-width: calc(100% - 30px);
}
.intro-panel { max-height: calc(100% - 24px); overflow: auto; scrollbar-width: thin; scrollbar-color: #5d6a66 transparent; }
.finish-panel { z-index: 4; right: 24px; bottom: 22px; width: 340px; max-width: calc(100% - 24px); }
h2 { margin: 0 0 16px; font-size: 20px; line-height: 1.25; }

.goal-select { display: block; margin: 0 0 14px; font-size: 12px; color: var(--muted); }
.goal-select select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  background: #ffffff08;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--ink);
}
.goal-select option { background: var(--panel-solid); }

.primary, .secondary {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius);
  font-size: 13px;
  text-align: center;
  transition-property: background-color, transform;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}
.primary { margin-top: 18px; background: var(--ink); color: var(--chrome); border: 1px solid var(--ink); }
.primary:hover:not(:disabled) { background: #ffffff; }
.secondary { margin-top: 8px; background: none; border: 1px solid var(--line-strong); }
.primary:active:not(:disabled), .secondary:active { transform: scale(0.98); }
.city-notice { margin: 12px 0 0; font-size: 12px; color: #f0b597; }
.city-notice:empty { display: none; }

#finish-description { margin: 0 0 12px; font-size: 13px; color: #c5ceca; }
.finish-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 12px; margin: 4px 0 18px; }
.finish-metrics div { padding-top: 8px; border-top: 1px solid var(--line-strong); }
.finish-metrics span { display: block; font-size: 11px; color: var(--muted); }
.finish-metrics strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.finish-panel .primary { margin-top: 0; }

.touch-controls { display: none; }
.touch-controls button { touch-action: none; }

/* Нижняя полоса */
footer {
  height: 46px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 24px;
  padding: 0 32px;
  border-top: 1px solid var(--line);
}
footer button {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 11px;
  color: #c9d1ce;
  white-space: nowrap;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 4px;
}
footer button:hover { color: var(--ink); text-decoration-color: currentColor; }

/* История проездов */
.results-panel {
  position: fixed;
  top: 76px;
  right: 0;
  bottom: 0;
  z-index: 10;
  width: 660px;
  max-width: 100%;
  padding: 28px 32px;
  background: var(--panel-solid);
  border-left: 1px solid var(--line);
  overflow: auto;
}
.results-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.results-heading h2 { margin: 0; }
.table-wrap { overflow: auto; margin: 20px 0 24px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; text-align: left; font-variant-numeric: tabular-nums; }
th { padding: 8px 8px 8px 0; font-size: 11px; color: var(--muted); }
td { padding: 11px 8px 11px 0; border-top: 1px solid var(--line); white-space: nowrap; }
#empty-results { color: var(--muted); }
.history-notice { margin: 0 0 16px; color: #c5ceca; }
.results-panel .primary { width: auto; display: inline-block; }

/* Диалоги */
dialog {
  max-width: 520px;
  padding: 24px;
  background: var(--panel-solid);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
}
dialog::backdrop { background: #070b0acc; }
dialog h2 { margin-top: 0; }
dialog p { margin: 0 0 12px; }
.variant-dialog { width: min(520px, calc(100vw - 24px)); max-height: 88vh; overflow: auto; }
.variant-card-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.variant-card-heading h2 { margin: 0; }
.variant-card-heading .icon-button { margin-left: auto; }
#variant-card-icon {
  flex-shrink: 0;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 12px;
  color: var(--muted);
}
#variant-card-icon:empty { display: none; }
#variant-summary { font-size: 14px; line-height: 1.6; }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; align-items: baseline; margin: 0 0 16px; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; }
.monochrome-control { display: flex; align-items: center; gap: 9px; margin: 16px 0 0; }
.monochrome-control input { width: 16px; height: 16px; accent-color: var(--ink); }

@media (max-height: 750px) {
  .intro-panel { padding: 18px 22px 20px; }
  .goal-select { margin-bottom: 10px; }
  .intro-panel .primary { margin-top: 14px; }
}

@media (max-width: 700px) {
  .topbar { height: 62px; padding: 0 14px; }
  nav { gap: 18px; }
  .simulator { height: calc(100dvh - 108px); }
  .route-card { top: 12px; left: 12px; padding: 7px 11px 8px; }
  .route-card h1 { font-size: 15px; }
  .variant-control { top: 12px; right: 12px; max-width: calc(100vw - 24px); }
  .variant-control > span { display: none; }
  .variant-control button { padding: 0 7px; font-size: 11px; }
  .controls-hint { display: none; }
  .speed-hud { left: auto; right: 14px; bottom: 24px; }
  .driving-notice { bottom: 145px; }
  .finish-panel { right: 12px; bottom: 12px; width: calc(100% - 24px); max-height: 70vh; overflow: auto; padding: 18px; }
  .results-panel { top: 62px; padding: 20px; }
  footer { padding: 0 14px; }
  .variant-dialog { padding: 18px; }
  .touch-controls {
    display: flex;
    position: absolute;
    bottom: 85px;
    left: 15px;
    right: 15px;
    justify-content: space-between;
    pointer-events: none;
  }
  .touch-controls button {
    pointer-events: auto;
    min-width: 56px;
    min-height: 48px;
    background: #101413cc;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    font-size: 20px;
  }
}
/* В world.js окно зеркала опускается при ширине холста меньше 700 px; ширина остаётся min(290, 24%). */
@media (max-width: 699px) {
  .mirror-border { top: 168px; }
}
@media (max-width: 560px) {
  .text-button { padding: 0 8px; font-size: 11px; }
  .variant-control { top: 84px; left: 12px; right: auto; }
  .intro-panel { top: 144px; transform: translateX(-50%); max-height: calc(100% - 156px); }
}
@media (pointer: coarse) {
  .touch-controls {
    position: absolute;
    bottom: 8px;
    inset-inline: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 70%;
    z-index: 3;
  }
  .touch-controls button { min-width: 44px; min-height: 44px; background: var(--panel-solid); }
  .variant-control button { height: 44px; min-width: 44px; }
  .controls-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; transition: none !important; }
}
