:root {
  --ink: #f3e6cf;
  --ink-dim: rgba(243, 230, 207, 0.62);
  --ink-faint: rgba(243, 230, 207, 0.28);
  --ochre: #d69a4a;
  --clay: #9c3b25;
  --night: #1d120b;
  --card: rgba(34, 21, 12, 0.82);

  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --serif: "Fraunces", Georgia, serif;

  --gutter: clamp(16px, 3vw, 36px);
}

* { box-sizing: border-box; }

html { background: var(--night); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--night);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  z-index: 0;
}

.track { position: relative; z-index: -1; width: 1px; }

/* ---------- Atmosphere overlays ---------- */
.vignette, .grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.vignette {
  background: radial-gradient(ellipse 120% 90% at 50% 45%, transparent 45%, rgba(29, 14, 6, 0.55) 100%);
}
.grain {
  opacity: 0.12;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 0.9s steps(3) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-3%, 2%); }
  66% { transform: translate(2%, -3%); }
}

/* ---------- Intro ---------- */
.intro {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  background: var(--night);
  transition: opacity 2.4s ease 0.3s, visibility 0s linear 2.7s;
}
.intro.is-done { opacity: 0; visibility: hidden; }
.intro__line {
  margin: 0;
  font-family: var(--serif);
  font-weight: 300;
  font-style: italic;
  font-size: clamp(22px, 3.2vw, 38px);
  letter-spacing: 0.01em;
}
.intro__sub {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(40, 20, 8, 0.6);
}
.hud--top { top: var(--gutter); align-items: center; }
.hud--bottom { bottom: var(--gutter); }

.hud__log { display: flex; align-items: center; gap: 14px; }
.hud__mark {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink);
}

.readout { display: flex; gap: 28px; margin: 0; }
.readout div { display: grid; gap: 4px; }
.readout dt { color: var(--ink-faint); }
.readout dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Trail (scroll navigation) ---------- */
.trail {
  position: fixed;
  right: var(--gutter);
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
}
.trail ol {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 34px;
}
.trail ol::before {
  content: "";
  position: absolute;
  right: 5px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--ink-faint);
}
.trail button {
  all: unset;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  transition: color 0.4s ease;
  text-shadow: 0 1px 12px rgba(40, 20, 8, 0.6);
}
.trail button::after {
  content: "";
  width: 11px;
  height: 11px;
  border: 1px solid currentColor;
  transform: rotate(45deg) scale(0.7);
  background: transparent;
  transition: background 0.4s ease, transform 0.4s ease;
}
.trail button:hover,
.trail button:focus-visible { color: var(--ink); }
.trail button:focus-visible { outline: 1px solid var(--ochre); outline-offset: 6px; }
.trail li.is-active button { color: var(--ink); }
.trail li.is-active button::after { background: var(--ochre); border-color: var(--ochre); transform: rotate(45deg) scale(1); }
.trail li.is-passed button::after { background: currentColor; }

/* ---------- Sound toggle ---------- */
.sound {
  all: unset;
  position: fixed;
  right: var(--gutter);
  bottom: var(--gutter);
  z-index: 9;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 8px 2px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-shadow: 0 1px 12px rgba(40, 20, 8, 0.6);
  transition: color 0.3s ease;
}
.sound:hover { color: var(--ink); }
.sound:focus-visible { outline: 1px solid var(--ochre); outline-offset: 6px; }
.sound b { font-weight: 500; color: var(--ink); }
.sound__bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 14px;
}
.sound__bars i {
  width: 2px;
  height: 2px;
  background: currentColor;
  transition: height 0.4s ease;
}
.sound[aria-pressed="true"] { color: var(--ink); }
.sound[aria-pressed="true"] b { color: var(--ochre); }
.sound[aria-pressed="true"] .sound__bars i { animation: breathe 2.6s ease-in-out infinite; }
.sound[aria-pressed="true"] .sound__bars i:nth-child(2) { animation-delay: -0.7s; animation-duration: 3.1s; }
.sound[aria-pressed="true"] .sound__bars i:nth-child(3) { animation-delay: -1.4s; animation-duration: 2.2s; }
.sound[aria-pressed="true"] .sound__bars i:nth-child(4) { animation-delay: -2s; animation-duration: 3.4s; }
.sound.is-waiting .sound__bars i { animation: waiting 1.8s ease-in-out infinite; height: 6px; }
@keyframes waiting {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
@keyframes breathe {
  0%, 100% { height: 3px; }
  50% { height: 14px; }
}

/* ---------- Scroll hint ---------- */
.scroll-hint {
  position: fixed;
  left: 50%;
  bottom: calc(var(--gutter) + 6px);
  transform: translateX(-50%);
  z-index: 5;
  display: grid;
  justify-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0;
  transition: opacity 1s ease;
  pointer-events: none;
}
.scroll-hint.is-visible { opacity: 1; }
.scroll-hint i {
  width: 1px;
  height: 42px;
  background: linear-gradient(var(--ink), transparent);
  transform-origin: top;
  animation: drip 2.2s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes drip {
  0% { transform: scaleY(0); opacity: 1; }
  60% { transform: scaleY(1); opacity: 1; }
  100% { transform: scaleY(1); opacity: 0; }
}

/* ---------- Buscalibre link pinned to Wall II ---------- */
.buy {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 7;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px 14px 24px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none;
  color: #fff4e2;
  background: var(--clay);
  border: 1px solid rgba(255, 220, 170, 0.35);
  box-shadow: 0 10px 30px rgba(40, 14, 4, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, background 0.25s ease, visibility 0s linear 0.5s;
  will-change: transform;
}
.buy.is-visible { opacity: 1; visibility: visible; transition: opacity 0.5s ease, background 0.25s ease; }
.buy:hover { background: #b4462b; }
.buy:focus-visible { outline: 2px solid var(--ochre); outline-offset: 4px; opacity: 1; visibility: visible; }
.buy__arrow { font-size: 15px; transition: transform 0.25s ease; }
.buy:hover .buy__arrow { transform: translate(2px, -2px); }

/* ---------- Content cards ---------- */
/* Default: visually hidden, readable by assistive tech. */
.cards .card {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Portrait / narrow: the wall text is too small, so show the card. */
@media (max-aspect-ratio: 9/10), (max-width: 640px) {
  .cards .card {
    position: fixed;
    left: var(--gutter);
    right: var(--gutter);
    bottom: calc(var(--gutter) + 52px);
    width: auto;
    height: auto;
    max-height: 52vh;
    overflow: auto;
    clip: auto;
    clip-path: none;
    white-space: normal;
    z-index: 8;
    padding: 20px 20px 22px;
    background: var(--card);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-top: 2px solid var(--ochre);
    opacity: 0;
    transform: translateY(16px);
    visibility: hidden;
    transition: opacity 0.5s ease, transform 0.5s ease, visibility 0s linear 0.5s;
  }
  .cards .card.is-visible {
    opacity: 1;
    transform: none;
    visibility: visible;
    transition: opacity 0.5s ease, transform 0.5s ease;
  }
  .card p { margin: 0 0 10px; font-size: 15px; line-height: 1.5; color: var(--ink-dim); }
  .card__tag {
    font-family: var(--mono);
    font-size: 10px !important;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ochre) !important;
  }
  .card__title { margin: 0 0 4px; font-weight: 600; font-size: 28px; line-height: 1.1; color: var(--ink); }
  .card__lead { font-style: italic; color: var(--ink) !important; }
  .card__buy {
    display: inline-block;
    margin-top: 6px;
    padding: 12px 18px;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-decoration: none;
    color: #fff4e2;
    background: var(--clay);
  }

  .buy { display: none; }
  .hud__coords { display: none; }
  .readout { gap: 18px; }
  .trail ol { gap: 26px; }
  .trail button span { display: none; }
}

@media (max-width: 420px) {
  .readout div:nth-child(2) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .grain { animation: none; }
  .scroll-hint i { animation: none; }
  .sound[aria-pressed="true"] .sound__bars i { animation: none; height: 10px; }
  .sound.is-waiting .sound__bars i { animation: none; opacity: 0.6; }
  .intro { transition-duration: 0.6s; }
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  font-family: var(--mono);
}
