/* ==========================================================================
   Калькулятор трассы — стили поверх lk-theme.css.
   Все правила ограничены корнем .route-calculator: глобальная тема ЛК
   не меняется. Токены берутся из lk-theme.css.
   ========================================================================== */

.route-calculator {
  width: 100%;
  max-width: 1140px;
  margin-inline: auto;
  padding: 0 24px 48px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- Шапка страницы ------------------------------------------------------ */

.route-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 88px;
  padding-block: 16px;
  border-bottom: 2px solid var(--text);
}

.route-brand {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  text-decoration: none;
}

.route-brand img {
  height: 40px;
  width: auto;
}

.route-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* --- Основной контейнер -------------------------------------------------- */

.route-main {
  padding-top: 32px;
}

.route-workspace {
  display: grid;
  gap: 32px;
}

.route-intro h1 {
  margin-bottom: 8px;
}

.route-intro p {
  max-width: 72ch;
}

/* --- Загрузка ------------------------------------------------------------ */

.route-upload-form {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.2fr) auto;
  grid-template-rows: auto 44px auto auto;
  align-items: start;
  gap: 6px 16px;
}

/* Обычные поля (имя, файл) и кнопка занимают первую строку сетки.
   Явные колонки/строки — без subgrid, чтобы селектор линии не наследовал
   их размещение и не накладывался на поля. */
.route-upload-form > .route-upload-name {
  grid-column: 1;
  grid-row: 1 / 4;
}

.route-upload-form > .route-upload-file {
  grid-column: 2;
  grid-row: 1 / 4;
}

.route-upload-form > .route-upload-action {
  grid-column: 3;
  grid-row: 1 / 4;
}

.route-upload-form > .form-field {
  display: grid;
  grid-template-rows: subgrid;
  align-content: start;
  min-width: 0;
}

.route-upload-form > .form-field > label {
  grid-row: 1;
  align-self: end;
}

.route-upload-form > .form-field > input {
  grid-row: 2;
  align-self: center;
}

.route-upload-form > .form-field > .route-hint {
  grid-row: 3;
  margin-top: 0;
}

.route-upload-action {
  display: grid;
  grid-template-rows: subgrid;
  align-items: center;
}

.route-upload-action .btn {
  grid-row: 2;
  align-self: center;
  min-height: 44px;
}

/* Селектор линии — отдельная полноширинная строка под основными полями. */
.route-upload-line {
  grid-column: 1 / -1;
  grid-row: 4;
  /* Собственные строки: не наследует subgrid родителя. */
  display: grid;
  grid-template-rows: auto 44px auto;
}

.route-upload-line[hidden] {
  display: none;
}

.route-upload-line select {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
}

.route-status {
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

.route-status:not(:empty) {
  padding: 8px 12px;
  border-left: 3px solid var(--control-line);
  background: var(--soft);
}

.route-error {
  margin-top: 8px;
  padding: 8px 12px;
  border-left: 3px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

.route-hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* Общие контролы: единая высота и оформление в пределах страницы */
.route-calculator input[type="text"],
.route-calculator input[type="datetime-local"],
.route-calculator input[type="file"],
.route-calculator textarea {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
}

.route-calculator input[type="text"],
.route-calculator input[type="datetime-local"],
.route-calculator input[type="file"] {
  min-height: 44px;
  padding: 9px 10px;
}

.route-calculator input[type="file"] {
  padding: 0;
  line-height: 1.4;
}

.route-calculator input[type="file"]::file-selector-button {
  min-height: 42px;
  margin: 0 10px 0 0;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--control-line);
  border-radius: calc(var(--radius) - 1px) 0 0 calc(var(--radius) - 1px);
  background: var(--soft);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.route-calculator input[type="file"]::file-selector-button:hover {
  background: var(--accent-soft);
}

.route-calculator input[type="file"]::-webkit-file-upload-button {
  min-height: 42px;
  margin: 0 10px 0 0;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--control-line);
  border-radius: calc(var(--radius) - 1px) 0 0 calc(var(--radius) - 1px);
  background: var(--soft);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.route-calculator textarea {
  min-height: 120px;
  padding: 9px 10px;
  resize: vertical;
}

.route-calculator .form-field > label,
.route-calculator .race-form > label {
  font-size: 13px;
  font-weight: 600;
  line-height: 20px;
  color: var(--text);
}

/* --- Заголовок и метрики ------------------------------------------------- */

.route-summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
}

.route-title {
  font-size: clamp(24px, 2.7vw, 32px);
  letter-spacing: -.035em;
}

.route-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-top: 12px;
  font-variant-numeric: tabular-nums;
}

.route-metric {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.route-metric > span {
  color: var(--muted);
  font-size: 13px;
}

.route-metric b {
  font-size: 20px;
  font-weight: 800;
}

/* --- Карта --------------------------------------------------------------- */

.route-viewer {
  position: relative;
  width: 100%;
  height: clamp(400px, 52vh, 560px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
}

.route-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.route-map-logo {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 500;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  line-height: 0;
}

.route-map-logo img {
  height: 28px;
  width: auto;
}

.route-map-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.map-btn:hover:not(:disabled) {
  border-color: var(--text);
  background: var(--soft);
}

.map-btn:disabled {
  color: var(--muted);
  background: var(--soft);
  cursor: not-allowed;
}

.route-map-mode {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  margin: 0;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
}

.route-map-message {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  max-width: calc(100% - 120px);
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.route-map-message:empty {
  display: none;
}

.route-map-attribution {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 24px 0 0;
  padding: 12px 16px;
  background: #26352d;
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
}

.route-map-attribution a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.route-map-north {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 500;
  margin: 0;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  transform: translateX(-50%);
}

.route-map-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

/* --- Масштаб высот ------------------------------------------------------- */

.route-map-scale {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 500;
  display: flex;
  gap: 6px;
}

.map-scale-btn {
  width: 44px;
  height: 44px;
  font-size: 14px;
  font-weight: 750;
}

.map-scale-btn[aria-pressed="true"] {
  border-color: var(--text);
  background: var(--accent-soft);
}

/* --- Пустая карта -------------------------------------------------------- */

.route-map-empty {
  position: absolute;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}

/* display:flex перебивает браузерное [hidden]{display:none} — возвращаем. */
.route-map-empty[hidden] {
  display: none;
}

/* --- Загрузка карты ------------------------------------------------------ */

.route-map-loading {
  position: absolute;
  inset: 0;
  z-index: 450;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: var(--soft);
}

.route-map-loading[hidden] {
  display: none;
}

.route-map-loading img {
  max-width: min(240px, 60%);
  height: auto;
  opacity: 0.6;
}

.route-map-loading p {
  margin: 0;
  max-width: 32ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.route-public-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.route-map-empty img {
  max-width: min(240px, 60%);
  height: auto;
  opacity: 0.9;
}

.route-map-empty p {
  margin: 0;
  max-width: 32ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* --- Ползунок ------------------------------------------------------------ */

.route-slider {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--card);
}

.route-slider-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
}

.route-slider-head label {
  font-size: 14px;
  font-weight: 650;
}

.route-slider-head output {
  font-size: 15px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.route-distance {
  width: 100%;
  min-height: 44px;
  margin: 8px 0 0;
  accent-color: var(--orange);
}

.route-slider-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.route-slider-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.route-slider-totals .route-metric > span {
  color: var(--muted);
  font-size: 13px;
}

.route-slider-totals .route-metric b {
  font-size: 16px;
  font-weight: 800;
}

.route-position-summary {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* --- Профиль высот ------------------------------------------------------- */

.route-elevation {
  margin-top: 16px;
  padding: 12px 16px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.route-elevation-svg {
  display: block;
  width: 100%;
  height: 180px;
  /* viewBox задаётся из JS под фактический размер; preserveAspectRatio="none"
     растягивает SVG на CSS-бокс без искажения текста осей. */
}

.route-elevation-area {
  fill: rgba(252, 76, 2, 0.15);
}

.route-elevation-line {
  fill: none;
  stroke: var(--orange);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.route-elevation-grid-line {
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0.15;
  pointer-events: none;
}

.route-elevation-grid-label {
  fill: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.4;
  pointer-events: none;
}

.route-elevation-guide {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.route-elevation-dot {
  fill: var(--orange);
  stroke: var(--card);
  stroke-width: 2;
}

.route-elevation-axis {
  fill: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.route-elevation-readout {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.route-elevation-empty {
  margin: 0;
  padding: 24px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* --- График гонки -------------------------------------------------------- */

.race-form {
  display: grid;
  gap: 14px;
}

.race-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.race-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.race-form label.race-start {
  min-width: 0;
}

.race-form label.race-start input[type="datetime-local"] {
  max-width: 100%;
}

/* Сброс глобальных мобильных правил ЛК внутри страницы калькулятора */
.route-calculator .race-form label.race-check {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  align-self: end;
  min-height: 44px;
  padding: 0;
  cursor: pointer;
}

.route-calculator .race-check input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
}

.route-calculator .race-check .cold-text {
  text-align: left;
}

.route-calculator .race-actions {
  position: static;
  inset: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.route-calculator .race-actions .btn {
  min-height: 44px;
}

.race-status {
  color: var(--muted);
  font-size: 13px;
}

.race-result {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.race-result:empty {
  display: none;
  margin-top: 0;
}

.race-result .streak-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.race-result .streak-stat {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.race-result .streak-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.race-result .streak-stat b {
  display: block;
  margin-top: 5px;
  font-size: 21px;
  font-variant-numeric: tabular-nums;
}

.race-verdict {
  margin: 0;
  font-size: 14px;
}

.race-verdict.is-ok { color: var(--muted); }
.race-verdict.is-warn { color: var(--warning); }
.race-verdict.is-bad { color: var(--danger); }

.race-legs {
  display: grid;
  gap: 8px;
}

.race-leg {
  display: grid;
  grid-template-columns: minmax(120px, 1.4fr) repeat(3, minmax(90px, 1fr));
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}

.race-leg span {
  color: var(--muted);
}

.race-leg.is-tight {
  border-color: var(--warning);
}

.race-gear {
  display: grid;
  gap: 10px;
}

.race-gear h4 {
  margin: 0;
  font-size: 15px;
}

.race-gear .badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.race-gear .badge-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

.race-gear .badge-card.earned {
  border-top: 3px solid var(--orange);
}

.race-gear .badge-card.locked {
  border-style: dashed;
  color: var(--muted);
}

.race-gear .badge-card b {
  display: block;
  font-size: 13px;
}

.race-gear .badge-card small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.race-profile {
  display: block;
  width: 100%;
  height: auto;
}

/* --- Гостевые трассы ----------------------------------------------------- */

.route-guest-routes {
  display: grid;
  gap: 12px;
}

/* display:grid перебивает браузерное [hidden]{display:none} — возвращаем. */
.route-guest-routes[hidden] {
  display: none;
}

.route-guest-routes-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.route-guest-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.route-guest-check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 12px;
  cursor: pointer;
}

.route-guest-check input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
}

.route-guest-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.route-guest-length {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.route-guest-routes-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.route-guest-routes-actions[hidden] {
  display: none;
}

.route-guest-routes-actions .btn {
  min-height: 44px;
}

/* --- Поиск по каталогу --------------------------------------------------- */

.route-catalog-search {
  margin-bottom: 12px;
}

.route-catalog-search input[type="search"] {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
}

/* --- История ------------------------------------------------------------- */

.route-history table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.route-history caption {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding-bottom: 8px;
}

.route-history th,
.route-history td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.route-history th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.route-history th:last-child,
.route-history td:last-child {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Колонка набора высоты: числовая, не переносится. */
.route-history th:nth-child(3),
.route-history td:nth-child(3) {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.route-history tbody tr {
  min-height: 48px;
}

.route-history tbody tr[aria-current="true"] {
  background: var(--accent-soft);
}

.route-open {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-text);
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.route-open:hover {
  text-decoration-thickness: 2px;
}

.route-current {
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

/* --- Поделиться ---------------------------------------------------------- */

.route-share-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.route-share-name {
  font-weight: 700;
}

.route-share-panel {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.route-share-panel[hidden] {
  display: none;
}

.route-share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.route-guest-notice {
  display: grid;
  gap: 12px;
  padding: 12px 16px;
  border-left: 3px solid var(--orange);
  background: var(--soft);
  font-size: 14px;
}

.route-guest-notice[hidden] {
  display: none;
}

.route-guest-notice p {
  margin: 0;
}

.route-guest-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.route-guest-actions[hidden] {
  display: none;
}

.route-guest-actions .btn {
  min-height: 44px;
}

.route-public-note {
  padding: 12px 16px;
  border-left: 3px solid var(--orange);
  background: var(--soft);
  font-size: 14px;
}

.route-public-note p {
  margin: 0;
}

/* --- Недоступная ссылка / вход ------------------------------------------- */

.route-unavailable,
.route-signin {
  display: grid;
  gap: 12px;
  max-width: 560px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.route-unavailable[hidden],
.route-signin[hidden] {
  display: none;
}

.route-unavailable .btn,
.route-signin .btn {
  justify-self: start;
}

/* --- Адаптив ------------------------------------------------------------- */

@media (max-width: 959px) {
  .route-upload-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 44px auto auto auto;
  }

  .route-upload-form > .route-upload-name {
    grid-column: 1;
    grid-row: 1 / 4;
  }

  .route-upload-form > .route-upload-file {
    grid-column: 2;
    grid-row: 1 / 4;
  }

  .route-upload-form > .route-upload-action {
    grid-column: 1 / -1;
    grid-row: 4;
    grid-template-rows: auto;
  }

  .route-upload-action .btn {
    grid-row: 1;
    width: 100%;
  }

  .route-upload-line {
    grid-column: 1 / -1;
    grid-row: 5;
  }
}

@media (max-width: 760px) {
  .route-calculator {
    padding: 0 12px 32px;
  }

  .route-workspace {
    gap: 24px;
  }

  .route-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .route-viewer {
    height: clamp(280px, 44svh, 400px);
  }

  .route-elevation-svg {
    height: 140px;
  }

  .route-map-logo {
    top: 8px;
    left: 8px;
  }

  .route-map-message {
    max-width: calc(100% - 24px);
  }

  .route-upload-form {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 44px auto auto 44px auto auto;
    gap: 6px 0;
  }

  .route-upload-form > .route-upload-name {
    grid-column: 1;
    grid-row: 1 / 4;
  }

  .route-upload-form > .route-upload-file {
    grid-column: 1;
    grid-row: 4 / 7;
  }

  /* Селектор линии — между полем файла и кнопкой «Построить». */
  .route-upload-line {
    grid-column: 1;
    grid-row: 7;
    grid-template-rows: auto 44px auto;
  }

  .route-upload-form > .route-upload-action {
    grid-column: 1;
    grid-row: 8;
    grid-template-rows: auto;
  }

  .route-upload-action .btn {
    grid-row: 1;
    width: 100%;
  }

  .race-leg {
    grid-template-columns: 1fr 1fr;
  }

  /* Узкие экраны: имя переносится, числовые колонки не выталкивают страницу. */
  .route-history th,
  .route-history td {
    padding: 10px 6px;
  }

  .route-history th:nth-child(3),
  .route-history td:nth-child(3) {
    white-space: nowrap;
  }

  .route-share-actions .btn {
    width: 100%;
  }

  .route-calculator .race-actions .btn {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .route-calculator {
    padding: 0 12px 24px;
  }

  .route-intro h1 {
    font-size: 30px;
  }

  .route-metric b {
    font-size: 18px;
  }

  .route-title,
  .route-share-name {
    overflow-wrap: anywhere;
  }
}

@media (prefers-reduced-motion: reduce) {
  .route-calculator * {
    scroll-behavior: auto;
  }
}

/* ROUTE-STL: панель «Скачать 3D-модель (STL)» — в стиле панели «Поделиться». */
.route-summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#route-stl-panel {
  display: grid;
  flex-basis: 100%;
  gap: 10px;
  margin-top: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

#route-stl-panel[hidden] {
  display: none;
}

#route-stl-panel h3 {
  margin: 0;
  font-size: 1rem;
}

#route-stl-panel label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#route-stl-panel input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

#route-stl-panel label:has(input[type="checkbox"]) {
  justify-content: flex-start;
}

#route-stl-build {
  justify-self: start;
}

#route-stl-panel button:not(#route-stl-build) {
  justify-self: start;
}

#route-stl-status:empty,
#route-stl-warnings:empty {
  display: none;
}

#route-stl-warnings {
  margin: 0;
  padding-left: 18px;
  color: var(--muted, #6b6b6b);
}

/* ROUTE-3D: надпись, превью печатной модели, выгрузки и окно просмотра GLB/AR */
#route-stl-engrave-box {
  display: grid;
  gap: 4px;
  margin-left: 26px;
}

#route-stl-engrave-box[hidden],
#route-stl-modes[hidden],
#route-stl-plinth-view[hidden],
#route-stl-result[hidden] {
  display: none;
}

#route-stl-engrave-text {
  width: 100%;
  max-width: 420px;
}

#route-stl-result {
  display: grid;
  gap: 8px;
  min-width: 0;
}

#route-stl-result h4 {
  margin: 4px 0 0;
  font-size: 0.95rem;
}

#route-stl-preview {
  position: relative;
  width: 100%;
  height: min(62vw, 420px);
  min-height: 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: radial-gradient(circle at 50% 35%, #ffffff, #ece8df);
}

#route-stl-preview.failed {
  display: flex;
  align-items: center;
  justify-content: center;
  height: auto;
  min-height: 0;
  padding: 16px;
  color: var(--muted, #6b6b6b);
}

#route-stl-preview canvas {
  display: block;
  cursor: grab;
}

#route-stl-modes,
#route-stl-downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#route-stl-modes .btn {
  padding: 6px 12px;
  font-size: 0.875rem;
}

#route-stl-plinth-view {
  margin-left: auto;
}

#route-stl-modes .btn[aria-pressed="true"] {
  border-color: var(--orange, #e4572e);
  box-shadow: inset 0 0 0 1px var(--orange, #e4572e);
}

#route-stl-dims,
#route-stl-estimate {
  margin: 0;
}

#route-stl-dims {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#route-3d-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  background: #f4f1ea;
}

.route-3d-viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line, #ddd);
  background: var(--card, #fff);
}

.route-3d-viewer-head .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.route-3d-viewer-head strong {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#route-3d-viewer model-viewer {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: radial-gradient(circle at 50% 35%, #ffffff, #e6e1d6);
}

.route-3d-ar-start {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
}

.route-3d-viewer-note {
  margin: 0;
  padding: 10px 16px;
  color: var(--muted, #6b6b6b);
}

.route-3d-viewer-note:empty {
  display: none;
}
