:root {
  --bg: #070608;
  --ink: #d9cfbf;
  --dim: #6f665a;
  --faint: #2a2520;
  --ember: #e0a35a;
  --blood: #b3412f;
  --serif: 'Instrument Serif', 'Times New Roman', serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --mx: 50vw;
  --my: 50vh;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  overflow: hidden;
  cursor: crosshair;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--ember); color: var(--bg); }

.mono { font-family: var(--mono); font-weight: 300; letter-spacing: 0.08em; }
.serif { font-family: var(--serif); }
.dim { color: var(--dim); }
.soft { color: color-mix(in srgb, var(--ink) 70%, transparent); }
.tiny { font-size: 10px; line-height: 1.7; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

#field { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ── lantern layer ── */
.whispers {
  position: fixed; inset: 0; pointer-events: none;
  -webkit-mask-image: radial-gradient(circle 150px at var(--mx) var(--my), #000 0%, rgba(0,0,0,.6) 45%, transparent 100%);
          mask-image: radial-gradient(circle 150px at var(--mx) var(--my), #000 0%, rgba(0,0,0,.6) 45%, transparent 100%);
}
.whispers span {
  position: absolute;
  left: var(--x); top: var(--y);
  font-family: var(--serif); font-style: italic;
  font-size: clamp(15px, 1.6vw, 22px);
  color: var(--ember);
  white-space: nowrap;
  transform: translate(-10%, -50%);
  opacity: .85;
}

.vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 35%, rgba(0,0,0,.75) 100%);
}

.grain {
  position: fixed; inset: -50%; pointer-events: none; opacity: .09;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -4%); }
  60% { transform: translate(-4%, -1%); }
  80% { transform: translate(3%, 3%); }
  100% { transform: translate(0, 0); }
}

/* ── corners ── */
.corner { position: fixed; z-index: 3; font-size: 11px; padding: 22px 26px; pointer-events: none; }
.corner.tl { top: 0; left: 0; font-family: var(--mono); }
.corner.tr { top: 0; right: 0; text-align: right; }
.corner.bl { bottom: 0; left: 0; letter-spacing: .25em; }
.corner.br { bottom: 0; right: 0; }

/* ── stage ── */
#stage {
  position: relative; z-index: 2;
  height: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 16px max(9vh, 64px);
  text-align: center;
  overflow-y: auto; overscroll-behavior: contain;
}
/* Pushes content to the bottom when it fits, scrolls when it does not. */
#stage > .title { margin-top: auto; padding-top: 24px; }

.title {
  font-family: var(--mono); font-weight: 300;
  font-size: clamp(13px, 1.4vw, 16px);
  letter-spacing: 1.2em; margin-right: -1.2em;
  color: var(--ink);
  margin-bottom: 14px;
}

.line {
  font-style: italic;
  font-size: clamp(26px, 4.2vw, 46px);
  line-height: 1.1;
  margin-bottom: 34px;
  min-height: 1.1em;
  max-width: 18ch;
}
.line .c { opacity: 0; transition: opacity .9s ease; }
.line .c.on { opacity: 1; }

/* ── gate ── */
.gate {
  position: relative;
  width: 84px; height: 84px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--ink);
  cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.gate svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.gate .track { fill: none; stroke: var(--faint); stroke-width: 1; }
.gate .fill {
  fill: none; stroke: var(--ember); stroke-width: 1.5;
  stroke-dasharray: 289.03; stroke-dashoffset: 289.03;
  transition: stroke-dashoffset .35s ease-out;
}
.gate.holding .fill { transition: none; }
.gate span { position: relative; font-size: 11px; text-transform: lowercase; }
.gate:focus-visible { outline: 1px dashed var(--ember); outline-offset: 6px; }
.gate::after {
  content: ''; position: absolute; inset: -10px; border-radius: 50%;
  border: 1px solid var(--faint);
  animation: breathe 4.5s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: scale(.92); opacity: .2; }
  50% { transform: scale(1.12); opacity: .7; }
}

.hint { font-size: 10px; margin-top: 22px; text-transform: lowercase; }

body.open .gate, body.open .hint { display: none; }
body.open .line { margin-bottom: 26px; }

/* ── form ── */
.rite {
  width: min(420px, 100%);
  text-align: left;
  animation: rise 1.4s cubic-bezier(.2,.7,.1,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

.q { font-size: 11px; margin: 0 0 8px; color: var(--ink); }
.field {
  display: flex; align-items: baseline; gap: 6px;
  border-bottom: 1px solid var(--faint);
  margin-bottom: 24px;
  transition: border-color .4s;
}
.field:focus-within { border-color: var(--ember); }
.field input {
  flex: 1; min-width: 0;
  background: transparent; border: 0; outline: 0;
  color: var(--ink); caret-color: var(--ember);
  font-size: 16px; padding: 8px 0 10px;
}
.field input::placeholder { color: #3c362f; }
.at { color: var(--dim); }

.trap { position: absolute; left: -9999px; }

.mark, .acts button, .acts a {
  display: inline-block;
  background: transparent; color: var(--ember);
  border: 1px solid color-mix(in srgb, var(--ember) 45%, transparent);
  padding: 13px 22px; font-size: 11px;
  text-transform: lowercase; text-decoration: none;
  cursor: pointer;
  transition: background .3s, color .3s;
}
.mark { width: 100%; }
.mark:hover, .acts button:hover, .acts a:hover, .mark:focus-visible, .acts :focus-visible {
  background: var(--ember); color: var(--bg); outline: 0;
}
.mark[disabled] { opacity: .5; pointer-events: none; }

.err { min-height: 1.6em; margin-top: 12px; font-size: 11px; color: var(--blood); }

/* ── door ── */
body.eye-hover, body.eye-hover * { cursor: pointer; }
.door {
  position: fixed; inset: 0; z-index: 8;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(7,6,8,.55), rgba(7,6,8,.94) 60%);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: rise .9s ease both;
  padding: 16px;
}
.door[hidden] { display: none; }
.door-in { position: relative; width: min(380px, 100%); text-align: center; }
.door-in > p:first-child { font-size: 11px; margin-bottom: 18px; text-transform: lowercase; }
.door input {
  width: 100%; background: transparent; border: 0; border-bottom: 1px solid var(--ember);
  color: var(--ember); caret-color: var(--ink); outline: 0;
  font-size: 22px; letter-spacing: .4em; text-align: center; text-transform: uppercase;
  padding: 8px 0 12px;
}
.door-say { min-height: 3.4em; margin-top: 18px; font-size: 11px; line-height: 1.7; color: var(--ink); }
.door-say.bad { color: var(--blood); }
.door-say.good { color: var(--ember); }
.door-close {
  position: absolute; top: -48px; right: 0;
  background: none; border: 0; color: var(--dim); font-size: 20px; cursor: pointer; padding: 6px 10px;
}
.door-close:hover, .door-close:focus-visible { color: var(--ink); outline: 0; }
.door.shake .door-in { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.passed { color: var(--ember); font-size: 11px !important; margin-bottom: 18px !important; letter-spacing: .2em; }

/* ── missions ── */
.note { margin-top: 12px; text-align: center; }
.rite .mark { display: block; text-align: center; }
.who { font-size: 11px; margin-bottom: 14px; text-align: center; }
.link { background: none; border: 0; color: var(--ember); cursor: pointer; font-size: inherit; text-decoration: underline; text-underline-offset: 3px; padding: 0; }
.tasks { list-style: none; display: grid; gap: 0; text-align: left; }
.task { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 4px 10px; padding: 11px 0; border-bottom: 1px solid var(--faint); }
.task .n { font-size: 10px; color: var(--dim); }
.task .label { font-family: var(--serif); font-style: italic; font-size: 19px; line-height: 1.2; }
.task .label small { display: block; font-family: var(--mono); font-style: normal; font-size: 10px; color: var(--dim); letter-spacing: .08em; margin-top: 2px; }
.task .go, .task .ok {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: lowercase; white-space: nowrap;
  background: transparent; color: var(--ember); border: 1px solid color-mix(in srgb, var(--ember) 45%, transparent);
  padding: 7px 12px; cursor: pointer; text-decoration: none;
}
.task .go:hover, .task .ok:hover, .task .go:focus-visible, .task .ok:focus-visible { background: var(--ember); color: var(--bg); outline: 0; }
.task .ok[disabled] { opacity: .45; pointer-events: none; }
.task .state { font-family: var(--mono); font-size: 10.5px; color: var(--dim); white-space: nowrap; }
.task.done .label { color: var(--dim); }
.task.done .state { color: var(--ember); }
.task .proof { grid-column: 2 / 4; display: flex; gap: 8px; border-bottom: 1px solid var(--faint); }
.task .proof input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; color: var(--ink); caret-color: var(--ember); font-size: 13px; padding: 8px 0; }
.task .proof input::placeholder { color: #3c362f; }
.marks { color: var(--ember); font-size: 12px !important; letter-spacing: .3em; margin-bottom: 8px !important; }

#ritual { width: min(440px, 100%); }
.final { margin-top: 26px; text-align: left; }
.final .field { margin-bottom: 16px; }
.final .mark[disabled] { opacity: .4; pointer-events: none; }
.hint-line { margin-top: 10px; text-align: center; min-height: 1.4em; }
body.marked #sealed { margin-bottom: 28px; }

/* ── seal ── */
.sealed { animation: rise 1.6s cubic-bezier(.2,.7,.1,1) both; max-width: 440px; }
.sealed > p { margin-bottom: 6px; font-size: 11px; }
.ordinal { font-style: italic; font-size: clamp(56px, 9vw, 104px) !important; line-height: 1; color: var(--ink); margin: 4px 0 10px !important; }
.sign { font-size: 22px !important; letter-spacing: .5em; margin-right: -.5em; color: var(--ember); margin: 8px 0 14px !important; }
#invites { font-style: italic; font-size: 18px !important; margin-bottom: 22px !important; }
.acts { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-style: italic; font-size: 28px; z-index: 9; }

@media (max-width: 640px) {
  .corner { padding: 16px; font-size: 10px; }
  .corner.bl { display: none; }
  #stage { padding-bottom: max(7vh, 44px); }
  .title { letter-spacing: .9em; margin-right: -.9em; }
  .whispers span { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .grain, .gate::after { animation: none; }
  .rite, .sealed, .door { animation: none; }
}
