/*
  THE HOUSE'S SHARED STYLES: on every page, the reading pages included.
  The base and focus rules, the smoke, vignette and curtain, the eyes' drawing and
  their motions, the mini eyes, the way back, the subscribe seal.
  css/site.css adds the House, its pop-ups, About and the 404; css/read.css the reading pages.
*/
/* ───────── The House of Fiends ───────── */

:root {
  --accent: var(--bronze);      /* the current eye's colour; set per eye below */
  --accent-text: var(--accent); /* words in that colour (a lighter shade where the colour is dark) */
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-weight: var(--body-weight);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

body { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }
body.locked { overflow: hidden; }

a { color: inherit; }

/* no rectangular highlight boxes anywhere: tap, text selection and focus are all custom */
* { -webkit-tap-highlight-color: transparent; }
::selection { background: transparent; color: var(--bronze-hi); text-shadow: 0 0 10px color-mix(in srgb, var(--bronze-hi) 55%, transparent); }
:focus { outline: none; }
:focus-visible { outline: none; }
/* keyboard focus: a soft bronze ring on links and buttons that don't draw their own
   (the eyes, story cards, Return control and email seal light up in their own way) */
:where(a, button, summary):focus-visible:not(.eye-link, .card, .return, .presiding) {
  outline: 2px solid color-mix(in srgb, var(--bronze-hi) 80%, transparent);
  outline-offset: 4px;
  border-radius: 6px;
}

/* the body text weight: lighter than regular, still Grenze */

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ───────── Atmosphere: smoke + vignette ───────── */

/* drawn by js/smoke.js into one low-resolution canvas */
.smoke-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s ease;
}
.smoke-canvas.is-ready { opacity: 1; }

/* ───────── Page transitions: the curtain ───────── */

/* A transparent circle with an enormous dark shadow: the circle is what you can see.
   Closed (no circle) the page is dark; open, the circle is wider than the screen. */
/* The curtain: a dark layer exactly the size of the screen, with a round hole that opens from
   (--cx, --cy). It never reaches past the screen's edges (a curtain larger than the screen made
   phones open the page slightly zoomed out). */
@property --d { syntax: '<length>'; inherits: false; initial-value: 0px; }
.curtain {
  --cx: 50vw;
  --cy: 50vh;
  --d: 0px;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  -webkit-mask: radial-gradient(circle at var(--cx) var(--cy), transparent max(0px, calc(var(--d) / 2 - 60px)), #000 calc(var(--d) / 2));
          mask: radial-gradient(circle at var(--cx) var(--cy), transparent max(0px, calc(var(--d) / 2 - 60px)), #000 calc(var(--d) / 2));
  pointer-events: none;
  transition: --d .65s cubic-bezier(.7,0,.3,1);
  /* if scripts never run, don't leave the page dark */
  animation: curtain-failsafe 0s 3s forwards;
}
.curtain.js-ready { animation: none; }
.curtain.is-open { --d: 300vmax; transition-duration: 1s; transition-timing-function: cubic-bezier(.3,0,.2,1); }
@keyframes curtain-failsafe { to { visibility: hidden; } }

.vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(ellipse at center, transparent 45%, color-mix(in srgb, var(--shadow) 75%, transparent) 100%);
}

/* ───────── Home: the hexagon ───────── */

.stage {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;           /* phones: the screen height without the address bar's jumps */
  display: grid;
  place-items: center;
  padding: 16px;
}

/* The hexagon is several stacked SVG layers (js/home/hexagon.js). The still backdrop
   gets its own compositor layer, so only the eyes layer repaints as they move. */
.house-wrap {
  position: relative;
  width: min(96vw, calc((100dvh - 32px) * 1200 / 1060));
  aspect-ratio: 1200 / 1060;
  transition: filter .6s ease, transform .6s ease, opacity .6s ease;
}
.house-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.house-back { will-change: transform; pointer-events: none; }
.house-glow, .house-twinkle { pointer-events: none; }
.house-twinkle { will-change: opacity; animation: twinkle var(--d, 4s) ease-in-out infinite; animation-delay: var(--o, 0s); }
@keyframes twinkle { 0%,100% { opacity: .7; } 50% { opacity: .1; } }
body.modal-open .house-wrap {
  filter: blur(1.5px) brightness(.6) saturate(.85);
  transform: scale(.985);
}
/* behind an open pop-up the hexagon is blurred: freeze its animations, or the blur is redrawn every frame */
body.modal-open .house-wrap *, body.modal-open .house-wrap *::before, body.modal-open .house-wrap *::after { animation-play-state: paused; }

/* the hidden <svg> that holds the gradients every eye shares (js/shared/eye.js) */
.eye-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* the opening sequence: the lattice draws itself in, ornaments and frames fade up */
.house-wrap.intro .bar {
  stroke-dasharray: 1 1;
  stroke-dashoffset: 1;
  animation: bar-draw calc(1.3s * var(--intro-speed, 1)) cubic-bezier(.55,0,.2,1) calc(.1s * var(--intro-speed, 1)) forwards;
}
@keyframes bar-draw { to { stroke-dashoffset: 0; } }
.house-wrap.intro { animation: house-in calc(.9s * var(--intro-speed, 1)) ease both; }
@keyframes house-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

/* eyes as links; the court's small eyes ignore the pointer */
.court { pointer-events: none; }
.eye-link { cursor: pointer; outline: none; }
.glow-ring { opacity: 0; transition: opacity .35s ease; }
.eye-link:hover .glow-ring,
.eye-link:focus-visible .glow-ring,
.eye-link.chosen .glow-ring,
.eye-link.previewed .glow-ring { opacity: .95; }
.eye-link:focus-visible .focus-ring { opacity: 1; }
.focus-ring { opacity: 0; transition: opacity .2s; }

/* the Moon (Essays): its orbiting moon, its drifting lunar shadow, its voice rippling out while awake */
.orbit { transform-box: view-box; animation: spin 46s linear infinite; }
.moon-phase { transform-box: fill-box; animation: lunar-phase 28s ease-in-out infinite alternate; }
@keyframes lunar-phase { from { transform: translateX(-118%); } to { transform: translateX(118%); } }
.vox-ripple { transform-box: fill-box; transform-origin: center; opacity: 0; }
.eye.awake .vox-ripple { animation: vox 3.9s ease-out infinite; }
@keyframes vox { 0% { opacity: .5; transform: scale(1); } 100% { opacity: 0; transform: scale(1.5); } }

/* the Blind Eye: a breathing aura and a slowly swaying corona */
.aura { transform-box: fill-box; transform-origin: center; animation: breathe 7s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { opacity: .55; transform: scale(.96); } 50% { opacity: 1; transform: scale(1.04); } }
.corona { transform-box: view-box; animation: sway 16s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }

/* the Golden Fool (Fantasy): its gold iris strands swirl the opposite way to its rays */
.swirl { transform-box: view-box; animation: spin 70s linear infinite reverse; }

/* hover or click: Other Fiction's rings thrum, the Honor Guard's filigree shimmers,
   the Blue Moon's lens sweeps a scanning arc. Low-key by design. */
.thrum, .filigree, .crest { transform-box: fill-box; transform-origin: center; }
.scan { opacity: 0; transition: opacity .3s ease; transform-box: fill-box; transform-origin: center; }
.eye-link:hover .thrum, .eye-link:focus-visible .thrum, .eye-link.pulse .thrum { animation: thrum .22s ease-in-out infinite alternate; }
.eye-link:hover .thrum-late, .eye-link.pulse .thrum-late { animation-delay: .11s; }
@keyframes thrum { from { transform: scale(1); } to { transform: scale(1.025); } }
.eye-link:hover .filigree, .eye-link:focus-visible .filigree, .eye-link.pulse .filigree { animation: shimmer 1.6s ease-in-out infinite; }
.eye-link:hover .crest, .eye-link:focus-visible .crest, .eye-link.pulse .crest { animation: crest-breathe 1.6s ease-in-out infinite; }
@keyframes shimmer { 0%, 100% { stroke-opacity: .6; transform: scale(1); } 50% { stroke-opacity: 1; transform: scale(1.015); } }
@keyframes crest-breathe { 0%, 100% { fill-opacity: .75; } 50% { fill-opacity: 1; } }
.eye-link:hover .scan, .eye-link:focus-visible .scan, .eye-link.pulse .scan { opacity: 1; animation: spin 1.8s linear infinite; }
.eye-link:hover .ticks circle, .eye-link.pulse .ticks circle { animation: tick-blink .9s steps(2) infinite; }
@keyframes tick-blink { 50% { fill-opacity: .2; } }

.spin-slow { transform-box: fill-box; transform-origin: center; animation: spin 90s linear infinite; }
.spin-rev  { transform-box: fill-box; transform-origin: center; animation: spin 140s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }
/* the Blind Eye's constellation turning (transform-origin is set on the element) */
.drift { animation: spin 120s linear infinite reverse; }
@media (prefers-reduced-motion: reduce) { .drift { animation: none; } }

/* hover label (desktop) */
.label {
  position: fixed;
  z-index: 4;
  pointer-events: none;
  max-width: 280px;
  padding: 10px 14px 12px;
  border-radius: 12px;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--bg) 82%, transparent), color-mix(in srgb, var(--bg) 55%, transparent) 70%, transparent);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .25s ease, transform .25s ease;
}
.label.show { opacity: 1; transform: none; }
.label .name {
  display: block;
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.05;
  color: var(--ink);
  text-shadow: 0 2px 14px var(--shadow);
}
.label .epithet {
  display: block;
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--accent-text);
  margin-bottom: 3px;
}
.label .count {
  display: block;
  margin-top: 6px;
  font: 11px var(--font-body);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
/* a category with a newly entered story: a small dot in its colour, breathing */
.new-dot {
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: 8px;
  vertical-align: 1px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: new-dot 2.4s ease-in-out infinite;
}
@keyframes new-dot { 50% { opacity: .35; box-shadow: 0 0 2px var(--accent); } }
@media (prefers-reduced-motion: reduce) { .new-dot { animation: none; } }
.label.right { text-align: right; }
.label.center { text-align: center; }

/* ───────── Mini eyes (Bench, phone menu, neighbour links) ───────── */

.mini-eye { display: block; overflow: visible; }
.mini-ball {
  transform-box: fill-box;
  transform-origin: center;
  animation: mini-blink 7s ease-in-out infinite;
  animation-delay: var(--blink-delay, 0s);
}
.mini-iris { transition: transform .35s ease; }
@keyframes mini-blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.08); } }
@keyframes mini-blink-once { 50% { transform: scaleY(.08); } }
/* still eyes for reduced motion (this must come after the rule above to win) */
@media (prefers-reduced-motion: reduce) { .mini-ball { animation: none !important; } }

/* ───────── Return to the House ───────── */

/* The eye always stays; the words fade while you scroll down and return when you scroll up. */
.return {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font: italic var(--body-weight) 15px var(--font-serif);
  text-decoration: none;
  cursor: pointer;
}
/* a slightly larger tap area than the 40px eye (48px), without changing the layout */
.return::before { content: ''; position: absolute; inset: -4px; }
.return-eye { display: inline-flex; flex: none; }
.return svg { width: 40px; height: 40px; flex: none; transition: transform .45s cubic-bezier(.3,1.4,.5,1); }
.return-text {
  display: inline-block;
  max-width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-shadow: 0 2px 10px var(--shadow);
  transition: opacity .35s ease, max-width .45s ease, transform .45s ease;
}
.return.is-quiet .return-text { opacity: 0; max-width: 0; transform: translateX(-8px); }
.return--modal.is-quiet .return-text { transform: translateX(8px); }
.return:focus-visible .return-text { opacity: 1; max-width: 200px; transform: none; }
.return:hover, .return:focus-visible { color: var(--bronze-hi); }
.return:hover svg, .return:focus-visible svg { transform: scale(1.1); }
.return:hover .mini-ball { animation: mini-blink-once .3s ease; }
.return:focus-visible svg { filter: drop-shadow(0 0 8px color-mix(in srgb, var(--bronze-hi) 60%, transparent)); }

.return--modal { position: absolute; top: 14px; right: 16px; z-index: 3; }
.return--inline { position: relative; margin-top: 6px; color: var(--ink); font-size: 17px; }
@media (max-width: 520px) {
  .return--modal { top: 10px; right: 10px; }
  .return--modal .return-text { display: none; }
}

/* ───────── ?perf overlay (js/shared/perf.js) ───────── */

.perf-overlay {
  position: fixed;
  left: 10px; bottom: 10px;
  z-index: 200;
  padding: 6px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--shadow) 80%, transparent);
  color: var(--bronze-hi);
  font: 12px ui-monospace, Menlo, monospace;
  pointer-events: none;
}

/* ───────── The subscribe seal ("Join the Court"): pop-ups and the end of each story ───────── */
.modal-subscribe { margin: 48px 0 0; text-align: center; }
/* a small seal button, like the ones at the end of About */
.modal-subscribe a {
  display: inline-flex; align-items: center; gap: 12px; min-height: 44px;
  padding: 7px 18px 7px 7px; border-radius: 999px; text-decoration: none; text-align: left;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 6%, color-mix(in srgb, var(--panel) 60%, transparent));
  transition: border-color .35s ease, box-shadow .35s ease;
}
.modal-subscribe-text { display: flex; flex-direction: column; line-height: 1.15; }
.modal-subscribe-name { font-family: var(--font-display); font-size: 17px; color: var(--accent-text); }
.modal-subscribe-sub { margin-top: 2px; font: italic var(--body-weight) 12.5px/1.25 var(--font-serif); color: var(--muted); }
.modal-subscribe a:hover, .modal-subscribe a:focus-visible { border-color: var(--accent); box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 28%, transparent); }
/* the seal is smaller here, and takes the eye's colour */
.modal-subscribe .seal-disc {
  width: 40px; height: 40px; margin: 0; flex: none;
  background: radial-gradient(circle at 38% 32%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 60%), radial-gradient(circle, color-mix(in srgb, var(--accent) 22%, var(--bg)) 0 58%, color-mix(in srgb, var(--accent) 45%, var(--bg)) 59% 64%, color-mix(in srgb, var(--accent) 16%, var(--bg)) 65%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent);
}
.modal-subscribe .seal-disc svg { width: 18px; height: 18px; stroke: var(--accent-text); }
.modal-subscribe a:hover .seal-disc, .modal-subscribe a:focus-visible .seal-disc { transform: scale(.94); }
.modal-subscribe a:hover .seal-disc svg, .modal-subscribe a:focus-visible .seal-disc svg { opacity: 1; }
.modal-subscribe a:hover .modal-subscribe-sub, .modal-subscribe a:focus-visible .modal-subscribe-sub { color: var(--ink-soft); }
.modal-subscribe + .modal-neighbours { margin-top: 28px; }
.seal-disc {
  display: grid; place-items: center;
  width: 74px; height: 74px; margin-bottom: 12px; border-radius: 50%;
  /* a bronze seal pressed into wax: a raised rim and a sunken face */
  background:
    radial-gradient(circle at 38% 32%, color-mix(in srgb, var(--bronze-hi) 32%, transparent), transparent 60%),
    radial-gradient(circle, color-mix(in srgb, var(--bronze) 30%, var(--bg)) 0 58%, color-mix(in srgb, var(--bronze) 55%, var(--bg)) 59% 64%, color-mix(in srgb, var(--bronze) 22%, var(--bg)) 65%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--bronze) 55%, transparent), 0 6px 18px color-mix(in srgb, var(--shadow) 70%, transparent);
  transition: transform .4s cubic-bezier(.3, 1.4, .5, 1), box-shadow .4s ease;
}
.seal-disc svg { width: 30px; height: 30px; fill: none; stroke: var(--bronze-hi); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: .85; transition: opacity .3s ease; }
@media (prefers-reduced-motion: reduce) { .seal-disc { transition: none; } .seal:hover .seal-disc { transform: none; } }
