:root {
  --bone: #e8e4d8;
  --ink: #070707;
  --ash: #a9a598;
  --fw: min(18.6vw, 45vh);
  --serif: 'IM Fell English', 'Iowan Old Style', Georgia, serif;
  --caps: 'IM Fell English SC', 'IM Fell English', Georgia, serif;
  --mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --out: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--ink);
  color: var(--bone);
  font-family: var(--serif);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
body.fine-pointer, body.fine-pointer button { cursor: none; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* ---------- backdrop ---------- */
#sky, #fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#sky { z-index: 0; }
#fx { z-index: 3; }

.orrery {
  position: fixed; left: 50%; top: 46%; z-index: 0;
  width: min(150vh, 120vw); aspect-ratio: 1;
  transform: translate(-50%, -50%);
  opacity: 0; transition: opacity 3s 0.6s;
  pointer-events: none;
}
.live .orrery { opacity: .13; }
.orrery svg { width: 100%; height: 100%; animation: turn 260s linear infinite; }
.orrery svg g { transform-origin: 0 0; animation: turn 180s linear infinite reverse; }
@keyframes turn { to { transform: rotate(360deg); } }

/* ---------- layout ---------- */
#rite {
  position: relative; z-index: 1;
  height: 100dvh;
  display: grid; grid-template-rows: auto 1fr auto;
  padding: clamp(18px, 3vh, 34px) clamp(20px, 3.4vw, 54px);
}

.top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start;
  opacity: 0; transform: translateY(-10px);
  transition: opacity 1.2s .3s, transform 1.2s .3s var(--out);
}
.live .top { opacity: 1; transform: none; }
.corner {
  display: flex; flex-direction: column; gap: 4px;
  font: 400 11px/1.3 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ash);
}
.corner.r { align-items: flex-end; }
.corner .mark { font: 400 20px/1 var(--caps); letter-spacing: 0; color: var(--bone); text-transform: none; }
#snd { font: inherit; letter-spacing: inherit; text-transform: uppercase; color: var(--bone); padding: 4px 0; border-bottom: 1px solid transparent; }
#snd:hover, #snd:focus-visible { border-bottom-color: var(--bone); outline: none; }
#bound { color: var(--ash); transition: color .4s; }
#bound.is { color: var(--bone); }

.title { text-align: center; }
.kicker { font: 400 11px/1.3 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ash); }
h1 {
  font: 400 clamp(26px, 3.6vw, 52px)/1.05 var(--caps);
  margin-top: 6px;
}

/* ---------- the five ---------- */
#stage {
  display: flex; justify-content: center; align-items: center;
  min-height: 0;
}
.char {
  --dy: 0px;
  position: relative;
  width: var(--fw); flex: none;
  display: flex; flex-direction: column; align-items: center;
  transform: translateY(var(--dy));
  -webkit-tap-highlight-color: transparent;
  outline: none;
  z-index: 1;
}
.char:nth-child(odd) { --dy: -3.2vh; }
.char:nth-child(even) { --dy: 3.2vh; }
.char.chosen { z-index: 3; }
.char:hover, .char:focus-visible { z-index: 4; }

.fig {
  display: block; width: 100%; aspect-ratio: 320 / 400;
  opacity: 0; transform: translateY(40px) scale(.9);
  transition: transform .7s var(--out), opacity .6s ease;
  will-change: transform;
}
.live .fig { opacity: 1; transform: none; }
.entering .fig { transition: transform 1.4s var(--out), opacity 1.2s ease; transition-delay: calc(var(--i) * 140ms + 200ms); }
.fig svg { display: block; width: 100%; height: 100%; overflow: visible; }

.live .char:hover .fig, .live .char:focus-visible .fig { transform: translateY(-1.4vh) scale(1.05); }
.live .char.chosen .fig { transform: translateY(-1vh) scale(1.12); }
.live .char.summoned .fig { transform: translateY(-.6vh) scale(1.03); }
.has-chosen .char:not(.chosen):not(:hover):not(:focus-visible):not(.summoned) .fig { opacity: .38; }
.char.released .fig { animation: gutter .5s steps(5); }
@keyframes gutter { 0%, 40% { opacity: 1; } 20%, 60% { opacity: .2; } 100% { opacity: .38; } }

/* revelation layers inside each drawing */
.halo, .reveal { opacity: 0; transition: opacity .9s ease; }
.char:hover .halo, .char:focus-visible .halo { opacity: .22; }
.char.chosen .halo, .char.chosen .reveal { opacity: 1; }
.halo-text { font: 500 10px var(--mono); }
.tear { animation: tear 3.1s cubic-bezier(.6, 0, .9, .5) infinite; }
.chosen .tear { animation-duration: 1.1s; }
@keyframes tear {
  0% { transform: translateY(-9px) scale(0); opacity: 1; }
  30%, 55% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(27px) scale(.8); opacity: 0; }
}

.glow {
  position: absolute; left: 50%; top: 32%; width: 230%; aspect-ratio: 1;
  transform: translate(-50%, -50%) scale(.5);
  background: radial-gradient(circle, rgba(232, 228, 216, .30) 0%, rgba(232, 228, 216, .11) 30%, rgba(232, 228, 216, 0) 60%);
  opacity: 0; pointer-events: none;
  transition: opacity .8s ease, transform 1.2s var(--out);
}
.char:hover .glow, .char:focus-visible .glow { opacity: .35; transform: translate(-50%, -50%) scale(.7); }
.char.chosen .glow { opacity: 1; transform: translate(-50%, -50%) scale(1); animation: throb 3.6s ease-in-out infinite; }
@keyframes throb { 50% { opacity: .72; } }

.tag {
  position: relative; margin-top: 1.6vh;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  opacity: 0; transition: opacity 1s 1.3s;
}
.live .tag { opacity: 1; }
.tag i { font: 400 10px/1 var(--mono); color: var(--ash); letter-spacing: .1em; }
.tag b {
  font: 400 clamp(13px, 1.25vw, 19px)/1.15 var(--caps); white-space: nowrap;
  padding: 2px 8px; transition: background .3s, color .3s;
}
.tag em {
  font: 400 9.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .12em;
  opacity: 0; transform: translateY(-4px); transition: opacity .4s, transform .4s var(--out);
}
.char:hover .tag b, .char:focus-visible .tag b { box-shadow: 0 0 0 1px var(--bone); }
.char.chosen .tag b { background: var(--bone); color: var(--ink); }
.char.chosen .tag em { opacity: 1; transform: none; }
.has-chosen .char:not(.chosen):not(:hover):not(:focus-visible) .tag { opacity: .45; transition-delay: 0s; }

#stage.quake { animation: quake .55s linear; }
@keyframes quake {
  0% { transform: translate(0, 0) scale(1.018); }
  12% { transform: translate(-7px, 4px) scale(1.018); }
  24% { transform: translate(6px, -5px) scale(1.014); }
  38% { transform: translate(-4px, -3px) scale(1.01); }
  54% { transform: translate(3px, 3px) scale(1.006); }
  72% { transform: translate(-2px, 1px); }
  100% { transform: none; }
}

/* ---------- the reading ---------- */
#panel {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 1fr);
  gap: clamp(20px, 4vw, 70px); align-items: start;
  min-height: 118px;
  padding-top: 16px; border-top: 1px solid rgba(232, 228, 216, .22);
  opacity: 0; transition: opacity 1.2s 1.2s;
}
.live #panel { opacity: 1; }
#panel.swap > * { animation: swap .5s var(--out) both; }
#panel.swap > :nth-child(2) { animation-delay: 50ms; }
#panel.swap > :nth-child(3) { animation-delay: 100ms; }
@keyframes swap { from { opacity: 0; transform: translateY(8px); } }

.p-state { font: 400 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ash); display: flex; gap: 10px; }
.p-status.is { color: var(--ink); background: var(--bone); padding: 0 5px; margin: -1px 0; line-height: 13px; }
.p-name { font: 400 clamp(24px, 2.7vw, 40px)/1.05 var(--caps); margin-top: 8px; white-space: nowrap; }
.p-epi { font: italic 400 clamp(14px, 1.2vw, 17px)/1.3 var(--serif); color: var(--ash); margin-top: 4px; }
.p-lore { font: 400 clamp(14px, 1.22vw, 18px)/1.5 var(--serif); max-width: 54ch; text-wrap: pretty; }
.p-stats { justify-self: end; width: min(100%, 300px); }
.p-stats dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; align-items: center; }
.p-stats dt { font: 400 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ash); }
.p-stats dd { display: flex; gap: 5px; justify-content: flex-end; }
.p-stats dd span { width: 9px; height: 9px; border: 1px solid var(--ash); transform: rotate(45deg) scale(.8); transition: background .3s, border-color .3s; }
.p-stats dd span.on { background: var(--bone); border-color: var(--bone); }
.p-rite { margin-top: 12px; font: 400 11px/1.4 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ash); text-align: right; }
.p-rite b { font-weight: 500; color: var(--bone); margin-right: 6px; }

/* ---------- print artefacts ---------- */
.flash { position: fixed; inset: 0; z-index: 4; background: #fff; mix-blend-mode: difference; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .7s ease-out; }
@keyframes flash { 0%, 10% { opacity: 1; } 22% { opacity: .15; } 30% { opacity: .7; } 100% { opacity: 0; } }

.vignette { position: fixed; inset: 0; z-index: 5; pointer-events: none; background: radial-gradient(ellipse at 50% 46%, transparent 60%, rgba(0, 0, 0, .6) 100%); }

.frame { position: fixed; inset: 10px; z-index: 6; pointer-events: none; border: 1px solid rgba(232, 228, 216, .2); }
.frame i { position: absolute; width: 9px; height: 9px; background: var(--bone); transform: rotate(45deg); }
.frame i:nth-child(1) { left: -5px; top: -5px; } .frame i:nth-child(2) { right: -5px; top: -5px; }
.frame i:nth-child(3) { left: -5px; bottom: -5px; } .frame i:nth-child(4) { right: -5px; bottom: -5px; }

.grain { position: fixed; inset: 0; z-index: 30; pointer-events: none; background-size: 240px 240px; image-rendering: pixelated; }
.grain.g1 { mix-blend-mode: multiply; opacity: .95; }
.grain.g2 { mix-blend-mode: screen; opacity: .55; }

.cursor {
  position: fixed; left: 0; top: 0; z-index: 40; width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border: 1px solid #fff; border-radius: 50%; pointer-events: none; mix-blend-mode: difference;
  opacity: 0; transition: width .3s var(--out), height .3s var(--out), margin .3s var(--out), background .3s, opacity .3s;
}
.cursor::after { content: ''; position: absolute; left: 50%; top: 50%; width: 3px; height: 3px; margin: -1.5px; background: #fff; border-radius: 50%; }
.fine-pointer .cursor { opacity: 1; }
.cursor.on { width: 58px; height: 58px; margin: -29px 0 0 -29px; background: rgba(255, 255, 255, .12); }
.cursor.down { width: 16px; height: 16px; margin: -8px 0 0 -8px; background: #fff; }

/* ---------- threshold ---------- */
#intro {
  position: fixed; inset: 0; z-index: 20; background: var(--ink);
  display: grid; place-items: center; text-align: center;
  transition: opacity 1s ease, visibility 0s 1s;
}
#intro.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-in { display: flex; flex-direction: column; align-items: center; }
.intro-eye { width: min(300px, 60vw); overflow: visible; transition: transform 1s cubic-bezier(.7, 0, .9, .4); }
.i-lid { transform-origin: 0 0; transform: scaleY(.035); transition: transform .55s var(--out); }
.i-rays { opacity: 0; transform-origin: 0 0; transform: scale(.7); transition: opacity .6s, transform .9s var(--out); }
#intro:not(.wake) .i-lid { animation: doze 4.5s ease-in-out infinite; }
@keyframes doze { 0%, 86%, 100% { transform: scaleY(.035); } 92% { transform: scaleY(.22); } }
.wake .i-lid { transform: scaleY(1); }
.wake .i-rays { opacity: 1; transform: none; }
.dive .intro-eye { transform: scale(46); }
#intro h2 { font: 400 clamp(64px, 12vw, 168px)/.95 var(--caps); margin: 10px 0 26px; }
#intro .kicker { margin-top: 22px; }
#enter {
  font: 400 12px/1 var(--mono); text-transform: uppercase; letter-spacing: .1em;
  padding: 14px 26px; border: 1px solid var(--bone);
  transition: background .25s, color .25s, transform .15s;
}
#enter:hover, #enter:focus-visible { background: var(--bone); color: var(--ink); outline: none; }
#enter:active { transform: scale(.97); }
.fine { margin-top: 16px; font: 400 10.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ash); }
.wake .kicker, .wake h2, .wake #enter, .wake .fine { opacity: 0; transition: opacity .5s; }

/* ---------- small screens: the quincunx from the source plate ---------- */
@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  :root { --fw: min(38vw, 16.2vh); }
  #stage { flex-wrap: wrap; align-content: center; row-gap: 0; }
  .char:nth-child(n) { --dy: 0px; margin-top: -1.2vh; }
  .char:nth-child(3) { margin-left: 28vw; margin-right: 28vw; }
  .char:nth-child(1), .char:nth-child(4) { margin-right: 6vw; }
  .tag { margin-top: .4vh; }
  .tag i { display: none; }
  .tag b { font-size: 12px; }
  .top { grid-template-columns: 1fr auto; }
  .corner.l { display: none; }
  .title { text-align: left; }
  .title .kicker { display: none; }
  h1 { font-size: 26px; margin-top: 0; }
  #panel { grid-template-columns: 1fr; gap: 6px; min-height: 132px; padding-top: 10px; }
  .p-stats { display: none; }
  .p-name { font-size: 24px; margin-top: 5px; }
  .p-epi { display: none; }
  .p-lore { font-size: 13.5px; line-height: 1.4; }
}

@media (prefers-reduced-motion: reduce) {
  #stage.quake, .flash.go { animation: none; }
  .orrery svg, .orrery svg g { animation: none; }
}
