:root {
  --paper: #f3efe6;
  --ink: #1d1b18;
  --ink-soft: rgba(29, 27, 24, 0.62);
  --hair: rgba(29, 27, 24, 0.22);
  --bronze: #8c6b3f;
  --glass: rgba(243, 239, 230, 0.72);
  --serif: "Cormorant Garamond", "Times New Roman", serif;
  --sans: "IBM Plex Sans Condensed", "Arial Narrow", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --gutter: clamp(16px, 3vw, 40px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); overscroll-behavior: none; }
@media (pointer: coarse) { html, body { touch-action: none; } }
body { font-family: var(--sans); -webkit-font-smoothing: antialiased; overflow-x: hidden; }

#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; z-index: 0; }
#scroll { position: relative; height: 900vh; pointer-events: none; }

/* ---------------------------------------------------------------- sheet frame + title block */
.sheet { position: fixed; inset: 0; pointer-events: none; z-index: 1; }
.sheet__frame {
  position: absolute; inset: calc(var(--gutter) * 0.75);
  border: 1px solid var(--ink);
  box-shadow: inset 0 0 0 5px var(--paper), inset 0 0 0 5.6px var(--hair);
}
.cartiglio {
  position: absolute; right: calc(var(--gutter) * 0.75); bottom: calc(var(--gutter) * 0.75);
  width: min(360px, 52vw); background: var(--paper);
  border-left: 1px solid var(--ink); border-top: 1px solid var(--ink);
  font-size: 11px; letter-spacing: 0.04em;
}
.cartiglio__row { display: flex; gap: 12px; padding: 7px 12px; border-bottom: 1px solid var(--hair); }
.cartiglio__row:last-child { border-bottom: 0; }
.cartiglio__brand { flex-direction: column; gap: 2px; padding: 12px 12px 10px; border-bottom: 1px solid var(--ink); }
.cartiglio__name { font-family: var(--serif); font-size: 22px; font-weight: 500; letter-spacing: 0.02em; }
.cartiglio__place { text-transform: uppercase; letter-spacing: 0.18em; font-size: 10px; color: var(--ink-soft); }
.cartiglio__k { width: 44px; flex: none; text-transform: uppercase; letter-spacing: 0.14em; font-size: 9.5px; color: var(--ink-soft); padding-top: 1px; }
.cartiglio__v { font-family: var(--mono); font-size: 11px; letter-spacing: 0; }

/* ---------------------------------------------------------------- brand */
.brand {
  position: fixed; z-index: 3; top: calc(var(--gutter) * 0.75 + 18px); left: calc(var(--gutter) * 0.75 + 22px);
  display: flex; flex-direction: column; gap: 4px; pointer-events: none;
  transition: color 0.6s ease;
}
.brand__mark { font-family: var(--serif); font-size: 26px; font-weight: 500; letter-spacing: 0.01em; line-height: 1; }
.brand__sub { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.26em; color: var(--ink-soft); }

/* ---------------------------------------------------------------- back to the property page */
.back {
  position: fixed; z-index: 3; top: calc(var(--gutter) * 0.75 + 18px); right: calc(var(--gutter) * 0.75 + 16px);
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border: 1px solid var(--hair); background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--ink); text-decoration: none; font-size: 11px; text-transform: uppercase; letter-spacing: 0.2em;
  transition: background 0.25s ease, color 0.25s ease;
}
.back svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.4; }
.back:hover { background: var(--ink); color: var(--paper); }
.back:focus-visible { outline: 1px solid var(--ink); outline-offset: 3px; }
.is-recording .back { display: none; }
@media (max-width: 760px) { .back { top: 26px; right: 14px; padding: 0 10px; } .back span { display: none; } }

/* ---------------------------------------------------------------- rail */
/* A quiet column of dots in a glass capsule: the stop number and name live in the caption;
   the name of any stop appears beside its dot on hover or keyboard focus. */
.rail {
  position: fixed; z-index: 3; right: calc(var(--gutter) * 0.75 + 16px); top: 50%; transform: translateY(-50%);
  padding: 10px 6px; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--hair); border-radius: 999px;
}
.rail__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rail__btn {
  all: unset; cursor: pointer; position: relative; display: grid; place-items: center;
  width: 22px; height: 22px; color: var(--ink-soft);
}
.rail__btn:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; border-radius: 50%; }
.rail__dot {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: 0.45;
  transition: transform 0.3s ease, opacity 0.3s ease, background 0.3s ease;
}
.rail__btn:hover .rail__dot { opacity: 0.9; transform: scale(1.3); }
.rail__btn[aria-current="step"] { color: var(--ink); }
.rail__btn[aria-current="step"] .rail__dot { opacity: 1; transform: scale(1.7); }
.rail__btn.is-pressed .rail__dot { background: var(--bronze); }
.rail__name {
  position: absolute; right: 30px; top: 50%; transform: translate(6px, -50%); pointer-events: none;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.2em; white-space: nowrap; color: var(--ink);
  background: var(--glass); padding: 4px 8px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 0.3s ease, transform 0.3s ease;
}
.rail__name em { font-style: normal; font-family: var(--mono); color: var(--bronze); margin-right: 8px; letter-spacing: 0; }
.rail__btn:hover .rail__name, .rail__btn:focus-visible .rail__name { opacity: 1; transform: translate(0, -50%); }

/* ---------------------------------------------------------------- caption */
.caption {
  position: fixed; z-index: 3; left: calc(var(--gutter) * 0.75 + 22px); bottom: calc(var(--gutter) * 0.75 + 22px);
  max-width: min(440px, 70vw); pointer-events: none;
  padding: 18px 20px 16px; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-left: 1px solid var(--ink);
}
.caption__n { font-family: var(--mono); font-size: 11px; color: var(--bronze); letter-spacing: 0.06em; }
.caption__title { margin: 4px 0 8px; font-family: var(--serif); font-weight: 500; font-size: clamp(28px, 3.2vw, 40px); line-height: 1.02; letter-spacing: 0.005em; }
.caption__text { margin: 0; font-size: 14px; line-height: 1.5; color: rgba(29, 27, 24, 0.82); max-width: 40ch; }

/* ---------------------------------------------------------------- controls */
.controls {
  position: fixed; z-index: 3; left: 50%; bottom: calc(var(--gutter) * 0.75 + 22px); transform: translateX(-50%);
  display: flex; gap: 8px;
}
.ctl {
  all: unset; cursor: pointer; height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid var(--ink); background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--ink); transition: background 0.25s ease, color 0.25s ease, opacity 0.3s ease;
}
.ctl svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; }
.ctl--next { padding: 0 18px 0 22px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.24em; }
.ctl:hover, .ctl.is-pressed { background: var(--ink); color: var(--paper); }
.ctl:focus-visible { outline: 1px solid var(--ink); outline-offset: 3px; }
.ctl[disabled] { opacity: 0.3; pointer-events: none; }
.hint {
  position: fixed; z-index: 3; left: 50%; transform: translateX(-50%); bottom: calc(var(--gutter) * 0.75 + 2px); margin: 0;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.22em; color: var(--ink-soft); transition: opacity 0.6s ease;
}

/* ---------------------------------------------------------------- background loading */
.preload { position: fixed; z-index: 4; top: 0; left: 0; right: 0; height: 2px; pointer-events: none; transition: opacity 0.6s ease; }
.preload span { display: block; height: 100%; width: 0; background: var(--bronze); transition: width 0.3s ease; }
.is-loaded .preload { opacity: 0; }
.ctl--next.is-waiting .ctl__label::after { content: "…"; }
.ctl--next.is-waiting { opacity: 0.7; }
.hint--touch { display: none; }
@media (pointer: coarse) { .hint--pointer { display: none; } .hint--touch { display: inline; } }

/* ---------------------------------------------------------------- loader */
.loader {
  position: fixed; inset: 0; z-index: 10; background: var(--paper); display: grid; place-content: center; gap: 14px;
  transition: opacity 0.9s ease, visibility 0.9s;
}
.loader.is-done { opacity: 0; visibility: hidden; }
.loader__line { width: 180px; height: 1px; background: var(--hair); overflow: hidden; }
.loader__line span { display: block; height: 100%; width: 0; background: var(--ink); transition: width 0.3s ease; }
.loader__text { margin: 0; text-align: center; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.26em; color: var(--ink-soft); }

/* recording: no pointer, no hint */
.is-recording, .is-recording * { cursor: none !important; }

@media (max-width: 760px) {
  .cartiglio { display: none; }
  .rail { top: 96px; transform: none; right: 14px; padding: 8px 4px; }
  .rail__name { display: none; }
  .caption { left: 16px; right: 16px; max-width: none; bottom: calc(var(--gutter) * 0.75 + 76px); padding: 12px 14px; }
  .caption__title { font-size: 25px; margin: 2px 0 6px; }
  .caption__text { font-size: 12.5px; line-height: 1.45; }
  .brand { left: 28px; top: 28px; }
  .controls { left: auto; right: 16px; transform: none; bottom: 24px; }
  .hint { display: none; }
}
/* touch devices: no backdrop blur over the canvas (Safari re-composites it on every frame) */
@media (pointer: coarse) {
  .caption, .rail, .ctl, .back, .rail__name { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .caption, .rail, .back { background: rgba(243, 239, 230, 0.9); }
  .ctl { background: rgba(243, 239, 230, 0.92); }
}
.hud {
  position: fixed; z-index: 30; left: 8px; top: 8px; margin: 0; padding: 6px 8px; pointer-events: none;
  background: rgba(29, 27, 24, 0.82); color: #f3efe6; font: 11px/1.35 ui-monospace, monospace;
}

@media (prefers-reduced-motion: reduce) {
  .caption, .rail__name, .loader { transition: none; }
}
