/* ============================================================
   VARIATION 5 — "The Gate"
   The page only opens when the visitor turns the volume knob
   all the way up. At 100, the page plays loud: bass-shake,
   chromatic aberration, beat-synced distortion.
   ============================================================ */

/* ------------------------------------------------------------
   The gate overlay
   ------------------------------------------------------------ */

body.gated { overflow: hidden; }

#gate {
  position: fixed;
  inset: 0;
  background: var(--black);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease), visibility 0.9s;
}

#gate.open {
  opacity: 0;
  transform: scale(1.08);
  visibility: hidden;
  pointer-events: none;
}

#gate .gate-hint {
  font-family: var(--font-head);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.18em;
  font-size: clamp(1rem, 2.4vw, 1.6rem);
  text-align: center;
  max-width: 26ch;
  line-height: 1.3;
  /* fixed two-line box so the knob never shifts as the hint changes;
     column so the two sentences stack vertically, not side by side */
  height: 7em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15em;
}

#gate .gate-hint .g { color: var(--green); }

#gate .knob-stage { touch-action: none; }

#gate .knob-body {
  cursor: grab;
  transition: box-shadow 0.3s;
}

#gate .knob-body:active { cursor: grabbing; }

/* when the custom cursor is active, don't fight it with the native one */
@media (hover: hover) and (pointer: fine) {
  body.custom-cursor #gate .knob-body,
  body.custom-cursor #gate .knob-body:active { cursor: none; }
}

#gate.armed .knob-body {
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.08),
    0 18px 50px rgba(0, 0, 0, 0.65),
    0 0 60px rgba(145, 199, 61, 0.25);
}

#gate .gate-counter {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 3.4rem;
  color: var(--white);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

#gate .gate-sub {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--grey);
  text-align: center;
}

#gate .gate-skip {
  margin-top: 1.4rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--grey-dark);
  color: var(--grey);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  padding: 0.3rem 0.1rem;
  transition: color 0.3s, border-color 0.3s;
}

#gate .gate-skip:hover { color: var(--white); border-color: var(--green); }

/* shake the whole gate slightly as the volume climbs */
#gate.rumble .knob-stage { animation: gate-rumble 0.12s infinite; }

@keyframes gate-rumble {
  0% { transform: translate(0, 0); }
  25% { transform: translate(0.6px, -0.4px); }
  50% { transform: translate(-0.5px, 0.5px); }
  75% { transform: translate(0.4px, 0.3px); }
  100% { transform: translate(0, 0); }
}

/* Fit the gate to small / touch screens. Centered layout + the tall
   hint box could push the knob and the "enter quietly" button off the
   viewport (and the gate's black bg makes that look like an empty page).
   Top-align, pad, allow internal scroll, and collapse the hint height. */
@media (max-width: 720px), (hover: none) and (pointer: coarse) {
  #gate {
    justify-content: flex-start;
    gap: 1.1rem;
    padding: max(7vh, 1.5rem) 1.2rem 2.5rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #gate .gate-hint {
    height: auto;
    min-height: 0;
    font-size: 1.1rem;
    gap: 0.2em;
  }
  #gate .gate-counter { font-size: 2.8rem; }
}

/* ------------------------------------------------------------
   Sound-wave band — replaces the quotes ticker. A reactive
   signal line that idles at rest and swells under the cursor.
   ------------------------------------------------------------ */

.wave-band {
  height: 132px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  position: relative;
}

/* .book-cover--photo lives in css/style.css so every page can use it */

/* ------------------------------------------------------------
   LOUD MODE — the page after the gate.
   Visual distortion as if music is playing loudly.
   ------------------------------------------------------------ */

/* the whole page trembles with the bass */
body.loud main, body.loud footer {
  animation: bass-shake 0.484s infinite linear;
}

@keyframes bass-shake {
  0%   { transform: translate(0, 0); }
  8%   { transform: translate(0, -1.6px); }   /* the kick */
  16%  { transform: translate(0.8px, 0.6px); }
  30%  { transform: translate(-0.6px, 0.2px); }
  50%  { transform: translate(0.4px, -0.3px); }
  70%  { transform: translate(-0.3px, 0.2px); }
  100% { transform: translate(0, 0); }
}

/* chromatic aberration on display type — speaker pushed too hard */
body.loud h1, body.loud h2, body.loud .mega, body.loud .quote-band blockquote {
  animation: chroma 0.484s infinite linear;
}

@keyframes chroma {
  0%, 100% { text-shadow: none; }
  6%  { text-shadow: 3px 0 rgba(145, 199, 61, 0.55), -3px 0 rgba(39, 70, 216, 0.45); }
  12% { text-shadow: 1.5px 0 rgba(145, 199, 61, 0.35), -1.5px 0 rgba(39, 70, 216, 0.3); }
  24% { text-shadow: 0.5px 0 rgba(145, 199, 61, 0.2), -0.5px 0 rgba(39, 70, 216, 0.15); }
  40% { text-shadow: none; }
}

/* the cover art rattles in its frame */
body.loud .book-cover { animation: cover-rattle 0.484s infinite linear; }

@keyframes cover-rattle {
  0%, 100% { transform: rotate(0deg); }
  8%  { transform: rotate(-0.5deg) translateY(-2px); }
  20% { transform: rotate(0.35deg); }
  40% { transform: rotate(-0.15deg); }
}

/* beat pulse — JS toggles .beat on the body every bar */
body.loud main { transition: filter 0.1s; }
body.loud.beat main { filter: brightness(1.12) saturate(1.15); }

/* full-width equalizer pinned to the bottom of the viewport */
.loud-eq {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 110px;
  display: none;
  align-items: flex-end;
  gap: 3px;
  z-index: 1;
  pointer-events: none;
  opacity: 0.22;
}

body.loud .loud-eq { display: flex; }

.loud-eq i {
  flex: 1;
  background: linear-gradient(to top, var(--green), transparent);
  height: 20%;
  animation: loud-eq-bar 0.6s ease-in-out infinite;
}

@keyframes loud-eq-bar {
  0%, 100% { height: 12%; }
  50% { height: var(--peak, 70%); }
}

/* "turn it down" control, top-right under the header */
.loudness-toggle {
  position: fixed;
  top: 5.2rem;
  right: 1.4rem;
  z-index: 210;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 0;
  background: rgba(15, 14, 13, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--green);
  color: var(--green);
  cursor: pointer;
  transition: color 0.3s, border-color 0.3s, background 0.3s, box-shadow 0.3s;
}

.loudness-toggle svg { width: 23px; height: 23px; display: block; overflow: visible; }

.loudness-toggle .spk-body { fill: currentColor; }

.loudness-toggle .spk-waves,
.loudness-toggle .spk-mute {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* OFF state: muted speaker (the X is shown, waves hidden) */
.loudness-toggle .spk-waves { opacity: 0; transition: opacity 0.25s, transform 0.09s ease-out; transform-origin: 11px 12px; }
.loudness-toggle .spk-mute { opacity: 1; transition: opacity 0.25s; }

.loudness-toggle:hover { color: var(--white); box-shadow: 0 0 22px rgba(145, 199, 61, 0.3); }

/* ON state: active green, speaker plays, waves pulse with the beat */
.loudness-toggle.is-on {
  background: var(--green);
  border-color: var(--green);
  color: var(--black);
  box-shadow: 0 0 26px rgba(145, 199, 61, 0.55);
}

.loudness-toggle.is-on:hover { color: var(--black); }
.loudness-toggle.is-on .spk-waves { opacity: 1; }
.loudness-toggle.is-on .spk-mute { opacity: 0; }

body.beat .loudness-toggle.is-on .spk-waves { transform: scale(1.18); }

/* respect reduced motion completely */
@media (prefers-reduced-motion: reduce) {
  body.loud main, body.loud footer,
  body.loud h1, body.loud h2, body.loud .mega, body.loud .quote-band blockquote,
  body.loud .book-cover,
  .loud-eq i,
  #gate.rumble .knob-stage { animation: none; }
  body.loud.beat main { filter: none; }
}
