/* ==========================================================================
   UI: entry gate, top bar and its controls, chapter dots, pitch player, lightbox.
   Everything here is chrome around the story, so it stays quiet and readable.
   ========================================================================== */

#main:focus { outline: none; }

kbd {
  padding: 1px 8px 2px; border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 7px;
  background: rgb(255 255 255 / 0.1); font: inherit; font-size: 0.85em; font-weight: 700;
}

/* ---------- Entry gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, #0b1a3d, var(--ink) 72%);
  clip-path: circle(150% at var(--ix, 50%) var(--iy, 50%));
}
/* Slow coloured glows behind the card (the `drift` keyframes live in hero.css). */
.gate::before {
  content: ""; position: absolute; inset: -20%;
  background:
    radial-gradient(38% 38% at 24% 30%, rgb(139 92 255 / 0.5), transparent 70%),
    radial-gradient(36% 36% at 78% 68%, rgb(25 240 200 / 0.4), transparent 70%),
    radial-gradient(28% 28% at 72% 18%, rgb(255 61 165 / 0.3), transparent 70%);
}
html.fx .gate::before { animation: drift 18s ease-in-out infinite alternate; }

/* Three rings spread out from the middle like ripples on still water. Without motion they rest as a still picture. */
.gate__bg { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.gate__bg i { grid-area: 1 / 1; width: 40vmin; height: 40vmin; border: 2px solid rgb(25 240 200 / 0.5); border-radius: 50%; opacity: 0.4; }
.gate__bg i:nth-child(1) { scale: 1.3; }
.gate__bg i:nth-child(2) { scale: 2.3; border-color: rgb(200 255 61 / 0.45); }
.gate__bg i:nth-child(3) { scale: 3.3; border-color: rgb(139 92 255 / 0.55); }
html.fx .gate__bg i { animation: ripple 7.5s ease-out infinite; }
html.fx .gate__bg i:nth-child(2) { animation-delay: -2.5s; }
html.fx .gate__bg i:nth-child(3) { animation-delay: -5s; }
@keyframes ripple {
  0% { scale: 0.3; opacity: 0; }
  12% { opacity: 0.9; }
  100% { scale: 4.4; opacity: 0; }
}

.gate__card {
  position: relative; display: grid; justify-items: center; gap: 14px; width: min(640px, 100%); max-height: 100%; overflow: auto;
  padding: clamp(26px, 5vw, 52px) clamp(20px, 5vw, 56px); text-align: center;
  border: 1px solid rgb(255 255 255 / 0.22); border-radius: 36px;
  background: linear-gradient(155deg, rgb(255 255 255 / 0.12), rgb(255 255 255 / 0.03)), rgb(8 12 30 / 0.7);
  backdrop-filter: blur(22px) saturate(1.4);
  box-shadow: 0 50px 140px -30px rgb(0 0 0 / 0.9), 0 0 90px -30px var(--teal);
}
.gate__eyebrow { color: var(--lime); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.22em; text-transform: uppercase; }
.gate__title {
  padding: 0 0.05em 0.06em; font-size: clamp(5.4rem, 22vw, 9.5rem); font-weight: 800; line-height: 0.88; letter-spacing: -0.06em;
  background: linear-gradient(105deg, var(--lime), var(--teal) 38%, var(--sky) 68%, var(--violet)) 0 50% / 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 40px rgb(25 240 200 / 0.35));
}
html.fx .gate__title { animation: sheen 7s ease-in-out infinite alternate; }
.gate__tag { font-size: clamp(1.25rem, 3vw, 1.8rem); font-weight: 800; line-height: 1.2; letter-spacing: -0.03em; }
.gate__desc { max-width: 44ch; color: var(--muted); }
.gate__actions { display: grid; gap: 12px; width: 100%; max-width: 420px; margin-top: 8px; }
.gate__hint { color: var(--muted); font-size: 0.85rem; }
/* The Esc shortcut means nothing on a phone or tablet. */
@media (pointer: coarse) { .gate__hint { display: none; } }

/* The card rises in piece by piece. */
html.fx .gate__card > * { animation: rise 0.9s var(--ease) backwards; }
html.fx .gate__card > :nth-child(2) { animation-delay: 0.1s; }
html.fx .gate__card > :nth-child(3) { animation-delay: 0.2s; }
html.fx .gate__card > :nth-child(4) { animation-delay: 0.3s; }
html.fx .gate__card > :nth-child(5) { animation-delay: 0.4s; }
html.fx .gate__card > :nth-child(6) { animation-delay: 0.5s; }

/* Leaving: the gate closes like an iris onto the spot that was clicked, then ui.js hides it. */
.gate.is-leaving { clip-path: circle(0% at var(--ix, 50%) var(--iy, 50%)); transition: clip-path 1.15s cubic-bezier(0.7, 0, 0.2, 1); }
.gate.is-leaving .gate__card { opacity: 0; scale: 0.9; transition: opacity 0.45s ease, scale 1s var(--ease); }

@media (max-height: 560px) {
  .gate__title { font-size: 4.4rem; }
  .gate__card { gap: 8px; padding-block: 18px; }
  .gate__actions { grid-template-columns: 1fr 1fr; max-width: none; }
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 120; height: var(--topbar);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 var(--gutter);
  border-bottom: 1px solid transparent;
  transition: background-color 0.4s, border-color 0.4s, backdrop-filter 0.4s;
}
.topbar.is-solid { background: rgb(5 8 22 / 0.72); border-color: var(--line); backdrop-filter: blur(16px) saturate(1.4); }
/* Without JavaScript nothing toggles .is-solid, so let the bar scroll away rather than float over headlines. */
html.no-js .topbar { position: absolute; }

.brand { display: inline-flex; align-items: center; gap: 0.45em; min-height: 44px; font-size: 1.55rem; font-weight: 800; letter-spacing: -0.045em; text-decoration: none; }
.brand__mark { width: 1.15em; height: 1.15em; color: var(--lime); filter: drop-shadow(0 0 8px var(--lime)); }
html.fx .brand__mark { animation: bob 5s ease-in-out infinite; }

/* The chapter indicator changes as you scroll. It fills the free space after the brand and truncates with an
   ellipsis rather than run under the controls, which a centred label would do on mid-sized desktops. */
.topbar__now {
  flex: 1 1 0; min-width: 0; margin-left: 12px; overflow: hidden;
  display: flex; align-items: baseline; gap: 0.7em; white-space: nowrap; pointer-events: none;
}
.topbar__num {
  flex: none;
  font-size: 1.4rem; font-weight: 800; letter-spacing: -0.04em; font-variant-numeric: tabular-nums;
  background: linear-gradient(100deg, var(--a1), var(--a2)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbar__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: #dbe6f7; font-size: 0.82rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
/* Wide screens have room for the longest label, so it goes back to the true centre of the bar. */
@media (min-width: 1500px) {
  .topbar__now { position: absolute; left: 50%; translate: -50% 0; flex: none; margin: 0; overflow: visible; }
}

.controls { display: flex; align-items: center; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 0.55em; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px; background: rgb(8 12 30 / 0.72); backdrop-filter: blur(12px);
  font-size: 0.9rem; font-weight: 700; white-space: nowrap; cursor: pointer;
  transition: background-color 0.25s, border-color 0.25s, box-shadow 0.25s, transform 0.25s var(--ease);
}
.pill:hover { background: rgb(255 255 255 / 0.16); border-color: rgb(255 255 255 / 0.45); transform: translateY(-1px); }
.pill .icon { width: 1.15em; height: 1.15em; }

/* Music on: the pill glows lime and the equaliser bars move with the actual sound. */
#music-toggle[aria-pressed="true"] { border-color: color-mix(in srgb, var(--lime) 70%, transparent); box-shadow: 0 0 26px -6px var(--lime); }
/* Motion paused: the pill turns amber so it is clear why things are still. */
#motion-toggle[aria-pressed="true"] { border-color: color-mix(in srgb, var(--amber) 75%, transparent); background: rgb(255 176 32 / 0.16); }

.pill--hot {
  border-color: transparent; color: #04101c;
  background: linear-gradient(110deg, var(--lime), var(--teal) 55%, var(--sky)) 0 0 / 200% 100%;
  box-shadow: 0 8px 30px -8px rgb(25 240 200 / 0.8);
}
.pill--hot:hover { background: linear-gradient(110deg, var(--lime), var(--teal) 55%, var(--sky)) 100% 0 / 200% 100%; border-color: transparent; }
html.fx .pill--hot { animation: hot-pulse 2.8s ease-out infinite; }
@keyframes hot-pulse {
  0% { box-shadow: 0 0 0 0 rgb(200 255 61 / 0.5), 0 8px 30px -8px rgb(25 240 200 / 0.8); }
  70%, 100% { box-shadow: 0 0 0 14px rgb(200 255 61 / 0), 0 8px 30px -8px rgb(25 240 200 / 0.8); }
}

/* Equaliser: bar heights come from --b0 to --b3, which ui.js feeds from the live frequency bands. */
.eq { display: inline-flex; align-items: flex-end; gap: 2px; width: 18px; height: 16px; color: var(--lime); }
.eq i { width: 3px; border-radius: 2px; background: currentColor; opacity: 0.6; }
.eq i:nth-child(1) { height: calc(3px + var(--b0, 0.25) * 13px); }
.eq i:nth-child(2) { height: calc(3px + var(--b1, 0.55) * 13px); }
.eq i:nth-child(3) { height: calc(3px + var(--b2, 0.4) * 13px); }
.eq i:nth-child(4) { height: calc(3px + var(--b3, 0.15) * 13px); }
#music-toggle[aria-pressed="true"] .eq i { opacity: 1; }

/* ---------- Range sliders (volume and the chart scrubber) ---------- */
.vol { display: inline-flex; align-items: center; width: 104px; }
input[type="range"] {
  --fill: 50%;
  -webkit-appearance: none; appearance: none; width: 100%; height: 44px; margin: 0; border-radius: 22px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--lime), var(--teal)) 0 0 / var(--fill) 100% no-repeat, rgb(255 255 255 / 0.24);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; box-sizing: border-box; width: 22px; height: 22px; margin-top: -8px;
  border: 4px solid #04101c; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px var(--lime), 0 0 16px var(--lime);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: rgb(255 255 255 / 0.24); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--lime), var(--teal)); }
input[type="range"]::-moz-range-thumb {
  box-sizing: border-box; width: 22px; height: 22px; border: 4px solid #04101c; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 2px var(--lime), 0 0 16px var(--lime);
}

/* ---------- Chapter dots (wide screens only) ---------- */
.dots { position: fixed; right: clamp(6px, 1.4vw, 22px); top: 50%; z-index: 90; translate: 0 -50%; }
.dots ol { display: grid; gap: 0; }
.dots a { display: grid; place-items: center; width: 28px; height: 26px; }
.dots i {
  display: block; width: 8px; height: 8px; border-radius: 4px; background: rgb(255 255 255 / 0.38);
  transition: height 0.4s var(--ease), background-color 0.4s, box-shadow 0.4s;
}
.dots a:hover i { background: #fff; }
.dots a[aria-current="location"] i { height: 22px; background: var(--a1); box-shadow: 0 0 14px var(--a1); }
@media (max-width: 1099px), (max-height: 659px) { .dots { display: none; } }

/* ---------- Pitch player ---------- */
.tourbar {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 140; translate: -50% 0;
  display: flex; align-items: center; gap: 14px; width: min(660px, calc(100% - 24px)); padding: 9px 14px 9px 9px;
  border: 1px solid rgb(255 255 255 / 0.28); border-radius: 999px;
  background: rgb(8 12 30 / 0.84); backdrop-filter: blur(18px) saturate(1.5);
  box-shadow: 0 24px 70px -12px rgb(0 0 0 / 0.85), 0 0 60px -22px var(--a1);
}
html.fx .tourbar { animation: tour-in 0.6s var(--ease) backwards; }
@keyframes tour-in { from { opacity: 0; translate: -50% 40px; } }
.icon-btn--lg { width: 54px; height: 54px; border: 0; background: linear-gradient(120deg, var(--lime), var(--teal)); color: #04101c; }
.icon-btn--lg:hover { background: linear-gradient(120deg, var(--lime), var(--teal)); }
.icon-btn--lg .icon { width: 26px; height: 26px; }
.tour-ico { display: grid; place-items: center; }
.tour-ico--play { display: none; }
.tourbar.is-paused .tour-ico--pause { display: none; }
.tourbar.is-paused .tour-ico--play { display: grid; }
.tourbar__mid { flex: 1; display: grid; gap: 9px; min-width: 0; }
.tourbar__chapter { overflow: hidden; font-size: 0.95rem; font-weight: 700; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.tourbar__track { height: 6px; overflow: hidden; border-radius: 3px; background: rgb(255 255 255 / 0.2); }
.tourbar__track span {
  display: block; height: 100%; transform-origin: 0 50%; transform: scaleX(var(--tp, 0));
  background: linear-gradient(90deg, var(--lime), var(--teal), var(--sky)); box-shadow: 0 0 12px var(--teal);
}
.tourbar__time { color: var(--muted); font-size: 0.9rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* While the pitch plays, the top-bar shortcut is redundant. */
html.touring .topbar .pill--hot { display: none; }
/* Keyboard focus scrolls clear of the pitch bar while it is open. */
html.touring { scroll-padding-bottom: 110px; }

/* ---------- Lightbox ---------- */
.lightbox {
  width: min(1500px, 96vw); max-width: none; max-height: 96vh; margin: auto; padding: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: 24px; background: #070c1f; color: var(--text);
  box-shadow: 0 60px 160px rgb(0 0 0 / 0.8);
}
.lightbox::backdrop { background: rgb(2 4 12 / 0.86); backdrop-filter: blur(10px); }
html.fx .lightbox[open] { animation: pop 0.45s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(20px) scale(0.94); } }
.lightbox__bar { display: flex; align-items: center; gap: 18px; padding: 10px 12px 10px 22px; border-bottom: 1px solid var(--line); }
.lightbox__title { flex: 1; min-width: 0; font-weight: 800; }
.lightbox img { width: 100%; height: auto; max-height: calc(96vh - 72px); object-fit: contain; background: #000; }

/* ---------- Small screens ---------- */
@media (max-width: 1000px) {
  .topbar__now { display: none; }
}
@media (max-width: 760px) {
  .vol { display: none; }
  .topbar { padding: 0 14px; }
  .controls { gap: 6px; }
  /* Icon-only buttons: the text stays available to screen readers. */
  .pill { padding: 0 13px; }
  .pill:not(.pill--hot) .pill__text {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .tourbar { gap: 10px; padding-right: 10px; }
  .tourbar__time { font-size: 0.8rem; }
  .brand { font-size: 1.35rem; }
  /* The title gets the full width, the close button sits beside it, and the link to the original goes underneath. */
  .lightbox__bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 10px 10px 10px 18px; }
  .lightbox__title { grid-area: 1 / 1; }
  .lightbox__bar .link { grid-area: 2 / 1; justify-self: start; }
  .lightbox__bar .icon-btn { grid-area: 1 / 2 / 3 / 3; }
}
@media (max-width: 400px) {
  .pill--hot .pill__text { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
