/*
 * Стили экспозиции «Строительство Эйфелевой башни, 1887–1889».
 *
 * Образ — лист гравированного альбома XIX века: тёплая бумага, тёмно-коричневые чернила,
 * акцент цвета сурика (minium — оранжево-красный свинцовый грунт по железу).
 * Шрифты только системные: заголовки — антиква, служебный текст — гротеск. Из сети ничего не грузится.
 *
 * Раскладка страницы — три строки: шапка, сцена, полоса таймлайна. Панели интерфейса лежат поверх
 * сцены в сетке `.overlay`: у каждой своя ячейка, поэтому они не перекрывают друг друга
 * ни на широком экране, ни на телефоне (от 380 px). Средняя ячейка сетки (`#stage-safe`) пуста —
 * по ней сцена узнаёт, куда вписать башню, чтобы панели её не закрывали.
 *
 * Порядок разделов: основа, шапка, сцена, подписи сторон, метки узлов, сетка панелей, подпись фазы,
 * карточка справки, фото, окно крупного просмотра, кнопки, таймлайн, сообщения, средний и узкий экран.
 */

/* ───────────── Палитра и размеры ───────────── */

:root {
  --paper: #efe6d2; /* бумага листа */
  --paper-light: #f7f1e3; /* подложка панелей */
  --paper-shade: #e2d6bc; /* тень бумаги, полоса таймлайна */
  --ink: #2f2118; /* чернила: текст и линии */
  --ink-soft: #6b5a4a; /* второстепенный текст */
  --rule: rgb(47 33 24 / 35%); /* тонкие линии рамок */
  --minium: #b4452b; /* сурик: акцент, фокус, фронт работ */
  --minium-dark: #8f3520;

  --font-serif: Georgia, 'Times New Roman', serif;
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;

  --gap: 12px; /* отступ между панелями и от рамки сцены */
  --frame: 6px; /* отступ гравировальной рамки от края сцены */
}

/* ───────────── Основа ───────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Атрибут hidden должен побеждать любое display из правил ниже. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh; /* на телефоне — видимая высота без адресной строки */
  overflow: hidden; /* страница не прокручивается: жесты достаются сцене */
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.45 var(--font-sans);
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
p,
pre {
  margin: 0;
}

/* Заголовки везде — антиква, как подписи на гравированных листах. */
h1,
h2,
h3 {
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.2;
}

:focus-visible {
  outline: 2px solid var(--minium);
  outline-offset: 2px;
}

/* ───────────── Шапка ───────────── */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 14px;
  padding: 10px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  border-bottom: 3px double var(--ink);
}

.masthead__title {
  font: 400 clamp(1.05rem, 2.6vw, 1.5rem) / 1.15 var(--font-serif);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.masthead__subtitle {
  font: italic 400 clamp(0.9rem, 2vw, 1.05rem) / 1.2 var(--font-serif);
  color: var(--ink-soft);
}

/* ───────────── Сцена ───────────── */

.viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--paper-light);
}

/* Тонкая рамка, как у гравированного листа. Сквозь неё проходят клики и жесты. */
.viewport::after {
  content: '';
  position: absolute;
  inset: var(--frame);
  border: 1px solid var(--rule);
  pointer-events: none;
}

#stage {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* жесты пальцами обрабатывает OrbitControls, а не прокрутка страницы */
  outline-offset: -4px;
}

/* Слой меток узлов: занимает всю сцену, но клики ловят только сами метки. */
#hotspot-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

#hotspot-layer > * {
  pointer-events: auto;
}

/* Подписи сторон площадки: стоят на земле сцены, мышь их не замечает. */
#site-labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.site-label {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font: italic 400 13px/1 var(--font-serif);
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--ink);
  text-shadow: 0 0 4px var(--paper-light), 0 0 2px var(--paper-light), 0 0 1px var(--paper-light);
  will-change: transform;
}

.site-label__arrow {
  display: inline-block;
  font-style: normal;
  color: var(--minium-dark);
}

.site-label__arrow::before {
  content: '→';
}

/* ───────────── Метки узлов ───────────── */

/* Кнопка — прозрачная область нажатия 34 px; видимый кружок с номером — внутри неё. Место задаёт transform из JS. */
.hotspot {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: none; /* жест, начатый на метке, достаётся сцене */
  will-change: transform;
}

.hotspot__number {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--minium-dark);
  border-radius: 50%;
  background: var(--paper-light);
  box-shadow: 0 1px 4px rgb(47 33 24 / 45%);
  color: var(--ink);
  font: 700 12px/1 var(--font-serif);
  transition: transform 0.15s ease, background-color 0.15s ease, opacity 0.2s ease;
}

.hotspot:hover .hotspot__number,
.hotspot:focus-visible .hotspot__number {
  transform: scale(1.2);
}

.hotspot--open .hotspot__number {
  background: var(--minium);
  border-color: var(--paper-light);
  color: var(--paper-light);
  transform: scale(1.2);
}

/* Узел на дальней стороне башни: метка есть, но не спорит с ближними. */
.hotspot--far .hotspot__number {
  opacity: 0.5;
  transform: scale(0.82);
}

.hotspot--far:hover .hotspot__number,
.hotspot--far:focus-visible .hotspot__number,
.hotspot--far.hotspot--open .hotspot__number {
  opacity: 1;
}

/* Узел позади камеры: метки нет ни на экране, ни в обходе клавишей Tab. */
.hotspot--offscreen {
  visibility: hidden;
}

/* ───────────── Сетка панелей поверх сцены ───────────── */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 21rem) minmax(0, 1fr) minmax(0, 19rem);
  /* Строки с minmax(0, …) умеют сжиматься: если места мало, панель прокручивается внутри, а не налезает на соседку. */
  grid-template-rows: minmax(0, auto) minmax(0, 1fr) auto;
  grid-template-areas:
    'caption free photo'
    'card    free photo'
    'card    free tools';
  gap: var(--gap);
  padding: calc(var(--frame) + var(--gap));
  pointer-events: none; /* пустые ячейки не мешают вращать сцену */
}

.overlay > * {
  min-width: 0;
  min-height: 0;
  pointer-events: auto;
}

/* Свободная часть сцены: в ней нет панелей, туда вписывается башня. Сама ячейка невидима и прозрачна для мыши. */
#stage-safe {
  grid-area: free;
  pointer-events: none;
}

/* Общий вид панели: светлая бумага, чернильная линия и вторая линия внутри — «плашка» гравюры. */
#hotspot-card,
#phase-caption:not(:empty),
#photo-panel:not(:empty),
#perf-panel {
  background: rgb(247 241 227 / 94%);
  border: 1px solid var(--ink);
  box-shadow:
    inset 0 0 0 3px var(--paper-light),
    inset 0 0 0 4px var(--rule),
    0 6px 18px rgb(47 33 24 / 18%);
  padding: 14px;
}

/* ───────────── Подпись: что сейчас строится ───────────── */

#phase-caption {
  grid-area: caption;
  align-self: start;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.caption__eyebrow {
  display: flex;
  flex-wrap: wrap;
  gap: 0 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

.caption__phase-number {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--minium-dark);
}

.caption__phase-fr {
  font-style: italic;
  font-family: var(--font-serif);
}

.caption__title {
  font-size: clamp(1.2rem, 2vw, 1.45rem);
}

.caption__height {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: baseline;
  gap: 2px 6px;
  font-size: 14px;
}

.caption__height-value {
  font: 400 1.25rem/1 var(--font-serif);
  font-variant-numeric: tabular-nums;
  color: var(--minium-dark);
}

/* Столбик высоты: доля от трёхсот метров. */
.caption__height-bar {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--paper-shade);
  box-shadow: inset 0 0 0 1px var(--rule);
}

.caption__height-fill {
  display: block;
  height: 100%;
  background: var(--minium);
}

.caption__summary {
  font-size: 13.5px;
}

.caption__milestone {
  padding-top: 7px;
  border-top: 1px solid var(--rule);
}

.caption__milestone-title {
  font: 400 15px/1.3 var(--font-serif);
}

.caption__milestone-date {
  color: var(--minium-dark);
}

.caption__milestone-date::after {
  content: ' — ';
  color: var(--ink-soft);
}

.caption__milestone-text {
  margin-top: 3px;
  font-size: 13px;
  color: var(--ink-soft);
}

/* Пока открыта справка об узле, подпись сжимается до главного — справке нужно место. */
.overlay:has(#hotspot-card:not([hidden])) :is(.caption__summary, .caption__milestone-text) {
  display: none;
}

/* ───────────── Карточка справки об узле ───────────── */

#hotspot-card {
  grid-area: card;
  align-self: start;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#hotspot-card:focus {
  outline: none; /* фокус сюда ставит сама страница при открытии с клавиатуры — рамка не нужна */
}

.card__head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.card__number {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--minium);
  color: var(--paper-light);
  font: 700 13px/1 var(--font-serif);
}

.card__title {
  font-size: 1.15rem;
}

.card__title-fr {
  margin-top: 2px;
  font: italic 400 13.5px/1.3 var(--font-serif);
  color: var(--ink-soft);
}

.card__close,
.lightbox__close {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper-light);
  font: 400 20px/1 var(--font-serif);
  cursor: pointer;
}

.card__close:hover,
.lightbox__close:hover {
  background: var(--minium);
  border-color: var(--minium-dark);
  color: var(--paper-light);
}

.card__text {
  font-size: 13.5px;
}

.card__facts {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.card__facts-caption {
  padding-bottom: 4px;
  text-align: left;
  font: 400 12px/1.2 var(--font-sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--minium-dark);
}

.card__facts th,
.card__facts td {
  padding: 4px 0;
  border-top: 1px solid var(--rule);
  vertical-align: top;
}

.card__facts th {
  padding-right: 10px;
  font-weight: 400;
  text-align: left;
  color: var(--ink-soft);
}

.card__facts td {
  width: 42%;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.card__figure,
.photo {
  margin: 0;
}

.card__zoom,
.photo__zoom {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: #fbf8ef;
  cursor: zoom-in;
}

.card__image {
  display: block;
  width: 100%;
  max-height: 15rem;
  object-fit: cover; /* высокий лист в карточке показан частью; целиком — в крупном просмотре */
  object-position: top;
}

.card__image-error,
.photo__error {
  display: block;
  padding: 18px 10px;
  font: italic 400 13px/1.3 var(--font-serif);
  color: var(--ink-soft);
}

.card__source {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 5px;
  font-size: 12px;
}

.card__sheet {
  font-family: var(--font-serif);
  font-style: italic;
}

.card__origin,
.card__note {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

/* ───────────── Фото на выбранную дату ───────────── */

#photo-panel {
  grid-area: photo;
  align-self: start;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
}

/* Снимки архива — узкие и высокие (вся башня в кадре): фото слева целиком, подпись справа. */
.photo {
  display: grid;
  grid-template-columns: minmax(0, 46%) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.photo__image {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(48vh, 22rem);
  object-fit: cover;
  object-position: bottom; /* если фото приходится подрезать по высоте — режем небо, а не стройку */
}

.photo__caption {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.photo__heading {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--minium-dark);
}

.photo__date {
  font: 400 1.05rem/1.2 var(--font-serif);
}

.photo__offset {
  font: italic 400 12.5px/1.3 var(--font-serif);
  color: var(--ink-soft);
}

.photo__text {
  font-size: 13px;
}

.photo__credit,
.photo__source {
  font-size: 11px;
  line-height: 1.35;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.photo__empty {
  font: italic 400 14px/1.4 var(--font-serif);
  color: var(--ink-soft);
}

.overlay__tools {
  grid-area: tools;
  align-self: end;
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none; /* сам столбик прозрачен для мыши, кликаются только его кнопки и панели */
}

.overlay__tools > * {
  pointer-events: auto;
}

.overlay__hint {
  max-width: 19rem;
  font-size: 12px;
  line-height: 1.35;
  padding: 5px 9px;
  text-align: right;
  color: var(--ink);
  background: rgb(247 241 227 / 72%);
  pointer-events: none;
}

#perf-panel {
  padding: 8px 10px;
  font: 12px/1.4 var(--font-mono);
  white-space: pre;
}

/* ───────────── Окно крупного просмотра ───────────── */

.lightbox {
  max-width: min(94vw, 70rem);
  max-height: 94vh;
  max-height: 94dvh;
  padding: 14px;
  border: 1px solid var(--ink);
  background: var(--paper-light);
  color: var(--ink);
  box-shadow: 0 18px 60px rgb(20 12 6 / 55%);
}

.lightbox[open] {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
}

.lightbox::backdrop {
  background: rgb(30 20 12 / 72%);
}

.lightbox__close {
  justify-self: end;
}

.lightbox__frame {
  min-height: 0;
  overflow: auto;
  text-align: center;
  background: #fbf8ef;
  border: 1px solid var(--rule);
}

.lightbox__image {
  display: block;
  max-width: 100%;
  max-height: 74vh;
  max-height: 74dvh;
  margin: 0 auto;
  cursor: zoom-in;
}

/* Второй щелчок по картинке — во всю ширину окна, с прокруткой: так читаются надписи на высоких листах. */
.lightbox--full .lightbox__image {
  width: 100%;
  max-height: none;
  cursor: zoom-out;
}

.lightbox__caption {
  max-width: 60rem;
  font-size: 13px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

/* ───────────── Кнопки ───────────── */

button {
  font: inherit;
  color: inherit;
}

#reset-view {
  padding: 7px 14px;
  background: var(--paper-light);
  border: 1px solid var(--ink);
  border-radius: 0;
  box-shadow: 2px 2px 0 var(--rule);
  font: 400 13px/1.2 var(--font-serif);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

#reset-view:hover {
  background: var(--minium);
  border-color: var(--minium-dark);
  color: var(--paper-light);
}

#reset-view:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--rule);
}

/* ───────────── Полоса таймлайна ───────────── */

#timeline {
  --thumb: 18px; /* ширина бегунка: на её половину шкала отступает от краёв ползунка, чтобы засечки совпадали с ним */
  min-width: 0;
  min-height: 4.5rem; /* место зарезервировано, чтобы сцена не прыгала, когда появится ползунок */
  padding: 8px max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: var(--paper-shade);
  border-top: 3px double var(--ink);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    'head   track'
    'legend track';
  align-items: center;
  gap: 2px 20px;
}

.timeline__head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 12px;
}

.timeline__play {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-light);
  box-shadow: 2px 2px 0 var(--rule);
  cursor: pointer;
}

.timeline__play:hover {
  background: var(--minium);
  border-color: var(--minium-dark);
}

/* Значок рисуется фигурой, а не символом шрифта: ▶ в покое, ⏸ при проигрывании. */
.timeline__play-icon {
  width: 14px;
  height: 16px;
  background: var(--ink);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  transform: translateX(2px);
}

#timeline[data-playing='true'] .timeline__play-icon {
  clip-path: polygon(0 0, 36% 0, 36% 100%, 0 100%, 0 0, 64% 0, 100% 0, 100% 100%, 64% 100%, 64% 0);
  transform: none;
}

.timeline__play:hover .timeline__play-icon {
  background: var(--paper-light);
}

.timeline__now {
  display: flex;
  flex-direction: column;
  min-width: 11.5rem; /* самая длинная дата — «30 сентября 1888»: ширина не прыгает при проигрывании */
}

.timeline__date {
  font: 400 1.5rem/1.15 var(--font-serif);
  font-variant-numeric: lining-nums tabular-nums;
  white-space: nowrap;
}

.timeline__day,
.timeline__legend {
  font-size: 11.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.timeline__legend {
  grid-area: legend;
  display: flex;
  gap: 14px;
  padding-left: 54px;
}

.timeline__legend-item::before {
  content: '';
  display: inline-block;
  margin-right: 5px;
  background: var(--ink);
}

.timeline__legend-item--milestone::before {
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  background: var(--minium);
}

.timeline__legend-item--photo::before {
  width: 5px;
  height: 7px;
}

/* Шкала: все строки (месяцы, фазы, вехи, фото) отступают на полбегунка, как и ход самого бегунка. */
.timeline__track {
  grid-area: track;
  position: relative;
  min-width: 0;
  padding: 0 calc(var(--thumb) / 2);
}

.timeline__axis,
.timeline__phases,
.timeline__milestones,
.timeline__photos {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline__axis {
  height: 17px;
  font-size: 10.5px;
  line-height: 15px;
  color: var(--ink-soft);
}

.timeline__month {
  position: absolute;
  bottom: 0;
  height: 6px;
  border-left: 1px solid var(--rule);
}

.timeline__month--january {
  height: 100%;
  border-left-color: var(--ink);
}

.timeline__month-name {
  position: absolute;
  bottom: -1px;
  left: 3px;
  white-space: nowrap;
}

.timeline__month--january .timeline__month-name {
  display: none; /* на месте января стоит год */
}

.timeline__year {
  position: absolute;
  bottom: 0;
  padding-left: 4px;
  font: 700 12px/15px var(--font-serif);
  color: var(--ink);
}

.timeline__phases {
  height: 20px;
}

.timeline__phase {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 5px;
  overflow: hidden;
  border-right: 1px solid var(--paper-shade);
  background: var(--phase-color);
  color: var(--phase-ink, var(--paper-light));
  font-size: 11.5px;
  line-height: 1;
  white-space: nowrap;
}

.timeline__phase-number {
  font: 700 11.5px/1 var(--font-serif);
}

.timeline__phase-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Цвета фаз — от камня фундаментов через сурик и охру к тёмному железу вершины. */
[data-phase='foundation'] {
  --phase-color: #8a7f66;
}

[data-phase='tier1'] {
  --phase-color: #a5532f;
}

[data-phase='tier2'] {
  --phase-color: #c69a48;
  --phase-ink: #2f2118;
}

[data-phase='tier3'] {
  --phase-color: #5c7078;
}

[data-phase='summit'] {
  --phase-color: #3d3229;
}

.timeline__milestones {
  height: 15px;
}

/* Веха — ромб на шкале; кнопка шире ромба, чтобы в неё было легко попасть. */
.timeline__milestone {
  position: absolute;
  top: 0;
  width: 14px;
  height: 15px;
  margin-left: -7px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.timeline__milestone::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 4px;
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  border: 1px solid var(--minium-dark);
  background: var(--paper-light);
}

.timeline__milestone--past::before {
  background: var(--minium);
}

.timeline__milestone:hover,
.timeline__milestone:focus-visible {
  z-index: 3;
}

.timeline__milestone:hover::before,
.timeline__milestone:focus-visible::before {
  transform: rotate(45deg) scale(1.35);
}

/* Подсказка вехи: название и дата над шкалой. */
.timeline__tip {
  position: absolute;
  bottom: calc(100% + 26px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  gap: 2px;
  width: max-content;
  max-width: min(16rem, 70vw);
  padding: 6px 9px;
  border: 1px solid var(--ink);
  background: var(--paper-light);
  box-shadow: 0 4px 12px rgb(47 33 24 / 25%);
  color: var(--ink);
  font: 400 12.5px/1.3 var(--font-sans);
  text-align: left;
  white-space: normal;
  pointer-events: none;
}

.timeline__milestone[data-side='start'] .timeline__tip {
  left: 0;
  transform: none;
}

.timeline__milestone[data-side='end'] .timeline__tip {
  left: auto;
  right: 0;
  transform: none;
}

.timeline__milestone:hover .timeline__tip,
.timeline__milestone:focus-visible .timeline__tip {
  display: flex;
}

.timeline__tip-title {
  font: 400 14px/1.25 var(--font-serif);
}

.timeline__tip-date {
  color: var(--minium-dark);
}

/* Ползунок: тонкая линия и бегунок цвета сурика. Свой вид задаётся отдельно для движков WebKit/Blink и Gecko. */
.timeline__range {
  display: block;
  width: calc(100% + var(--thumb));
  height: 22px;
  margin: 0 calc(var(--thumb) / -2);
  background: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.timeline__range::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(var(--ink), var(--ink)) center / calc(100% - var(--thumb)) 2px no-repeat;
}

.timeline__range::-moz-range-track {
  height: 2px;
  background: var(--ink);
}

.timeline__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: -7px;
  border: 2px solid var(--paper-light);
  border-radius: 50%;
  background: var(--minium);
  box-shadow: 0 0 0 1px var(--minium-dark), 0 2px 5px rgb(47 33 24 / 40%);
}

.timeline__range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--paper-light);
  border-radius: 50%;
  background: var(--minium);
  box-shadow: 0 0 0 1px var(--minium-dark), 0 2px 5px rgb(47 33 24 / 40%);
}

.timeline__range:focus-visible {
  outline-offset: 0;
}

.timeline__photos {
  height: 8px;
}

.timeline__photo {
  position: absolute;
  top: 0;
  width: 5px;
  height: 7px;
  margin-left: -2.5px;
  background: var(--ink);
  opacity: 0.75;
}

/* Линия текущей даты через всю шкалу: от месяцев до засечек фото. */
.timeline__playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--progress, 0));
  width: 1px;
  background: var(--minium-dark);
  opacity: 0.7;
  pointer-events: none;
}

/* ───────────── Сообщения вместо сцены ───────────── */

.notice {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  gap: 12px;
  padding: 24px max(20px, calc(50% - 19rem)); /* текст — колонкой не шире 38rem по центру */
  overflow: auto;
  background: var(--paper);
  font-size: 16px;
}

.notice h2 {
  font: 400 clamp(1.3rem, 4vw, 1.8rem) / 1.2 var(--font-serif);
  color: var(--minium-dark);
}

.notice__aside {
  font-size: 14px;
  color: var(--ink-soft);
}

.notice code {
  font: 0.92em var(--font-mono);
  overflow-wrap: anywhere;
}

.notice pre {
  padding: 10px 14px;
  background: var(--paper-light);
  border: 1px solid var(--ink);
  border-left: 4px solid var(--minium);
  overflow-x: auto;
  user-select: all; /* команда выделяется одним щелчком */
}

.notice pre code {
  font-size: 1.05em;
}

/* Пока показано сообщение, сцены нет — панели и кнопки над ней не нужны. */
.viewport:has(> .notice:not([hidden])) > :is(#stage, #hotspot-layer, .overlay),
.viewport:has(> noscript > .notice) > :is(#stage, #hotspot-layer, .overlay) {
  display: none;
}

/* ───────────── Средний экран ───────────── */

@media (max-width: 1080px) {
  .overlay {
    grid-template-columns: minmax(0, 17rem) minmax(0, 1fr) minmax(0, 12.5rem);
  }

  /* В узкой колонке фото стоит над подписью, а не рядом. */
  .photo {
    grid-template-columns: minmax(0, 1fr);
  }

  .photo__image {
    max-height: min(34vh, 15rem);
  }

  .photo__credit,
  .photo__source {
    display: none; /* автор и файл архива остаются в крупном просмотре */
  }

  .timeline__month-name {
    display: none; /* месяцы — только засечками */
  }
}

/* Низкое окно: подсказка об управлении уступает место панелям. */
@media (max-height: 640px) {
  .overlay__hint {
    display: none;
  }
}

/* ───────────── Узкий экран (телефон) ───────────── */

@media (max-width: 700px) {
  :root {
    --gap: 8px;
    --frame: 4px;
  }

  body {
    font-size: 14px;
  }

  .masthead {
    padding-top: 6px;
    padding-bottom: 5px;
  }

  /*
   * Сверху — кнопка и миниатюра фото, внизу — подпись фиксированной высоты; справка выезжает над подписью.
   * Свободная часть сцены — всё, что выше подписи: башня вписывается туда и не прячется под текстом.
   */
  .overlay {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, auto) minmax(0, 1fr) minmax(0, auto) auto;
    grid-template-areas:
      'tools   photo'
      '.       .'
      'card    card'
      'caption caption';
  }

  #stage-safe {
    grid-area: 1 / 1 / 4 / -1;
  }

  .overlay__tools {
    align-self: start;
    justify-self: start;
    align-items: flex-start;
  }

  .overlay__hint {
    display: none;
  }

  /* Фото — миниатюра с датой; подпись и источник — в крупном просмотре по щелчку. */
  #photo-panel:not(:empty) {
    padding: 6px;
    max-width: 9.5rem;
  }

  .photo {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
    width: 52px;
  }

  .photo__image {
    max-height: 126px;
  }

  /* Пока открыта справка, от фото остаётся только дата: нижнему листу нужна высота. */
  .overlay:has(#hotspot-card:not([hidden])) .photo__zoom {
    display: none;
  }

  .photo__heading,
  .photo__offset,
  .photo__text,
  .photo__credit,
  .photo__source {
    display: none;
  }

  .photo__date {
    font-size: 10.5px;
    line-height: 1.15;
    text-align: center;
  }

  .photo__error {
    padding: 8px 2px;
    font-size: 10.5px;
  }

  .photo__empty {
    font-size: 11.5px;
    line-height: 1.3;
  }

  /* Подпись: высота постоянная, чтобы кадр сцены не прыгал при смене текста; длинное обрезается многоточием. */
  #phase-caption:not(:empty) {
    height: 7.9rem;
    padding: 9px 11px;
    gap: 3px;
    overflow: hidden;
  }

  .caption__eyebrow {
    flex-wrap: nowrap;
    font-size: 11px;
    white-space: nowrap;
  }

  .caption__phase-fr {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .caption__title {
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .caption__height {
    font-size: 12.5px;
  }

  .caption__height-value {
    font-size: 1rem;
  }

  .caption__height-bar {
    height: 3px;
  }

  .caption__summary {
    display: none; /* на телефоне место есть только для вехи; описание фазы — на широком экране */
  }

  .caption__milestone {
    padding-top: 4px;
  }

  .caption__milestone-title {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .caption__milestone-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    font-size: 11.5px;
    line-height: 1.3;
  }

  .overlay:has(#hotspot-card:not([hidden])) .caption__milestone-text {
    display: -webkit-box; /* высота подписи на телефоне не меняется и при открытой справке */
  }

  /* Справка — нижний лист на всю ширину: не выше 46 % экрана и не выше своей ячейки, длинная прокручивается внутри. */
  #hotspot-card {
    align-self: end;
    max-height: min(46vh, 100%);
    max-height: min(46dvh, 100%);
    padding: 11px;
  }

  .card__image {
    max-height: 9rem;
  }

  /* Таймлайн в столбик: дата с кнопкой, под ними шкала. */
  #timeline {
    min-height: 4rem;
    padding-top: 6px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      'head'
      'track';
    gap: 4px;
  }

  .timeline__legend {
    display: none;
  }

  .timeline__play {
    width: 36px;
    height: 36px;
  }

  .timeline__now {
    flex-direction: row;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
  }

  .timeline__date {
    font-size: 1.25rem;
  }

  .timeline__phase {
    padding: 0 3px;
    justify-content: center;
  }

  .timeline__phase-name {
    display: none; /* на узкой шкале — только номера фаз; названия — в подписи над таймлайном */
  }

  .site-label {
    font-size: 11.5px;
  }
}

/* Уважение к настройке «меньше движения»: без плавных переходов интерфейса. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
