/* ————————————————————————————————————————————————
   STOOR — a title page in the dark
   ink night · pale gold · one lamp
   ———————————————————————————————————————————————— */

:root {
  --ink: #031a1a;            /* deep teal night */
  --ink-2: #052424;
  --bone: #d0e8e0;           /* pale mint paper */
  --bone-dim: #7c938b;
  --gold: #f8c898;           /* the lamp, candle-apricot */
  --gold-hot: #ffdfb8;
  --hairline: rgba(208, 232, 224, 0.14);

  --serif: "Cormorant Garamond", "Times New Roman", serif;
  --mono: "IBM Plex Mono", "Courier New", monospace;
}

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

html, body {
  height: 100%;
  background: var(--ink);
}

body {
  font-family: var(--serif);
  color: var(--bone);
  background:
    radial-gradient(1100px 700px at 70% -10%, rgba(16, 96, 96, 0.2), transparent 60%),
    radial-gradient(900px 900px at 10% 110%, rgba(8, 48, 48, 0.38), transparent 55%),
    var(--ink);
  overflow: hidden;
  line-height: 1.6;
}

::selection {
  background: rgba(248, 200, 152, 0.28);
  color: var(--bone);
}

.mono { font-family: var(--mono); font-weight: 300; }
.dim  { color: var(--bone-dim); }

/* the hidden attribute must win over our display rules */
[hidden] { display: none !important; }

/* ————— atmosphere ————— */

#sky {
  position: fixed;
  inset: 0;
  z-index: 0;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 42%, transparent 52%, rgba(2, 18, 18, 0.8) 100%);
}

.grain {
  position: fixed;
  inset: -100px;
  z-index: 2;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.7'/%3E%3C/svg%3E");
  animation: grain-drift 1.1s steps(4) infinite;
}

/* falls when the lamp is put out */
.dark {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: rgba(1, 10, 10, 0.62);
  opacity: 0;
  transition: opacity 2.5s ease;
}

body.unlit .dark { opacity: 1; }

@keyframes grain-drift {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-34px, 18px); }
  50%  { transform: translate(20px, -30px); }
  75%  { transform: translate(-12px, -14px); }
  100% { transform: translate(0, 0); }
}

/* ————— the seal ————— */

.seal {
  position: fixed;
  top: 26px;
  left: 30px;
  z-index: 10;
  cursor: pointer;
  user-select: none;
  opacity: 0.6;
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.6s;
}

.seal:hover { opacity: 1; }
.seal:active { transform: scale(0.92); }

.seal .ring {
  fill: none;
  stroke: var(--gold);
  stroke-width: 0.75;
  opacity: 0.55;
  transform-origin: 60px 60px;
}

.seal .r1 { animation: ring-spin 90s linear infinite; stroke-dasharray: 3 5; }
.seal .r2 { animation: ring-spin 60s linear infinite reverse; }
.seal .r3 { animation: ring-spin 40s linear infinite; }

@keyframes ring-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.seal .star { fill: var(--bone); }

.seal .trace {
  stroke: var(--gold);
  stroke-width: 0.6;
  opacity: 0.7;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: trace-draw 14s ease-in-out infinite alternate;
}

@keyframes trace-draw {
  to { stroke-dashoffset: 0; }
}

/* after the seventh touch, the seal stays lit */
.seal.open .ring { stroke: var(--gold-hot); opacity: 0.9; }
.seal.open {
  opacity: 1;
  filter: drop-shadow(0 0 12px rgba(255, 223, 184, 0.45));
}

/* ————— the title page ————— */

.plate {
  position: relative;
  z-index: 5;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 34px;
  padding: 24px;
}

.name {
  font-weight: 300;
  font-size: clamp(1.6rem, 4.2vw, 2.9rem);
  letter-spacing: 0.85em;
  text-indent: 0.85em; /* re-center against the tracking */
  color: var(--bone);
  animation: arrive 3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes arrive {
  from { opacity: 0; letter-spacing: 1.4em; }
  to   { opacity: 1; letter-spacing: 0.85em; }
}

.rule {
  width: 34px;
  height: 1px;
  background: var(--gold);
  opacity: 0;
  animation: rise 2.4s ease 1.2s both;
}

@keyframes rise {
  from { opacity: 0; transform: scaleX(0); }
  to   { opacity: 0.8; transform: scaleX(1); }
}

/* ————— the relic ————— */

.relic {
  position: relative;
  width: 150px;
  height: 150px;
  perspective: 700px;
  cursor: pointer;
  opacity: 0;
}

.relic-levitate {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

/* three engraved rings, orbiting on their own axes */
.relic-rings {
  position: absolute;
  inset: 14px;
  transform-style: preserve-3d;
}

.ring3d {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(248, 200, 152, 0.5);
}

.ring3d.a { animation: orbit-a 26s linear infinite; }
.ring3d.b {
  animation: orbit-b 38s linear infinite reverse;
  border-style: dashed;
  border-color: rgba(248, 200, 152, 0.35);
}
.ring3d.c { animation: orbit-c 19s linear infinite; }

@keyframes orbit-a {
  from { transform: rotateY(66deg) rotateZ(0deg); }
  to   { transform: rotateY(66deg) rotateZ(360deg); }
}
@keyframes orbit-b {
  from { transform: rotateX(72deg) rotateZ(0deg); }
  to   { transform: rotateX(72deg) rotateZ(360deg); }
}
@keyframes orbit-c {
  from { transform: rotateX(18deg) rotateY(34deg) rotateZ(0deg); }
  to   { transform: rotateX(18deg) rotateY(34deg) rotateZ(360deg); }
}

/* the core: an old power, kept warm */
.relic-core {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 42% 36%, rgba(255, 240, 214, 0.95), var(--gold) 38%, rgba(140, 92, 51, 0.85) 72%, rgba(24, 22, 16, 0.9));
  box-shadow:
    0 0 18px rgba(248, 200, 152, 0.55),
    0 0 52px rgba(248, 200, 152, 0.28),
    0 0 120px rgba(248, 200, 152, 0.14),
    inset 0 0 10px rgba(60, 38, 20, 0.55);
  animation: core-breathe 5.5s ease-in-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes core-breathe {
  0%, 100% {
    box-shadow:
      0 0 16px rgba(248, 200, 152, 0.45),
      0 0 44px rgba(248, 200, 152, 0.22),
      0 0 100px rgba(248, 200, 152, 0.1),
      inset 0 0 10px rgba(60, 38, 20, 0.55);
  }
  50% {
    box-shadow:
      0 0 24px rgba(248, 200, 152, 0.7),
      0 0 66px rgba(248, 200, 152, 0.36),
      0 0 140px rgba(248, 200, 152, 0.18),
      inset 0 0 10px rgba(60, 38, 20, 0.55);
  }
}

/* the engraving */
.relic-sigil {
  width: 78%;
  height: 78%;
}

.relic-sigil * {
  fill: none;
  stroke: rgba(66, 40, 18, 0.6);
  stroke-width: 1.4;
}

.relic-sigil path { fill: rgba(66, 40, 18, 0.28); }

.relic-glow {
  position: absolute;
  inset: -55px;
  background: radial-gradient(circle, rgba(248, 200, 152, 0.13), transparent 62%);
  animation: glow-pulse 5.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes glow-pulse {
  0%, 100% { opacity: 0.55; transform: scale(0.96); }
  50%      { opacity: 1;    transform: scale(1.05); }
}

.relic:hover .ring3d { border-color: rgba(255, 223, 184, 0.7); }

/* sparks, when the power returns */
.spark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #ffdfb8;
  box-shadow: 0 0 7px rgba(255, 223, 184, 0.9);
  pointer-events: none;
  z-index: 6;
}

/* the relic, dimmed */
body.unlit #sky { opacity: 0.4; }
#sky { transition: opacity 2.5s ease; }

body.unlit .relic-core {
  animation: none;
  background: radial-gradient(circle at 42% 36%, rgba(124, 147, 139, 0.25), rgba(30, 42, 40, 0.9) 70%);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.6);
}

body.unlit .relic-sigil * { stroke: rgba(124, 147, 139, 0.35); }
body.unlit .ring3d {
  animation-play-state: paused;
  border-color: rgba(124, 147, 139, 0.3);
}
body.unlit .relic-glow { opacity: 0; animation: none; }
body.unlit .name { color: var(--bone-dim); }
.name { transition: color 2.5s ease; }

/* ————— the word ————— */

.word {
  font-family: var(--mono);
  font-weight: 300;
  font-size: 0.62rem;
  letter-spacing: 0.34em;
  text-transform: lowercase;
  color: var(--bone-dim);
  min-height: 1.4em;
  transition: opacity 0.9s ease;
  opacity: 0;
  animation: rise 2.4s ease 2.6s both;
}

.word.fading { opacity: 0 !important; }

/* ————— footer ————— */

.site-foot {
  position: fixed;
  bottom: 26px;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  gap: 28px;
  font-size: 0.6rem;
  letter-spacing: 0.24em;
}

#foot-clock { color: var(--gold); }

/* ————— the keeper, elsewhere ————— */

.traces {
  position: fixed;
  right: 30px;
  bottom: 26px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 9px;
}

.traces a {
  font-family: var(--mono);
  font-weight: 300;
  font-size: 0.56rem;
  letter-spacing: 0.26em;
  color: var(--bone-dim);
  text-decoration: none;
  text-transform: lowercase;
  opacity: 0;
  animation: rise 2s ease both;
  transition: color 0.5s, text-shadow 0.5s;
}

.traces a:nth-child(1) { animation-delay: 3.2s; }
.traces a:nth-child(2) { animation-delay: 3.4s; }
.traces a:nth-child(3) { animation-delay: 3.6s; }
.traces a:nth-child(4) { animation-delay: 3.8s; }
.traces a:nth-child(5) { animation-delay: 4.0s; }

.traces a:hover {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(248, 200, 152, 0.4);
}

/* ————— the counter ————— */

.door-veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(2, 18, 18, 0.84);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.6s ease;
}

.door-veil.open { opacity: 1; }

.door {
  position: relative;
  width: min(400px, 100%);
  background: linear-gradient(170deg, var(--ink-2), var(--ink));
  border: 1px solid rgba(248, 200, 152, 0.35);
  padding: 46px 42px 30px;
  /* motion owns the drawer slide */
  box-shadow:
    0 0 0 1px rgba(2, 18, 18, 0.9),
    0 30px 80px rgba(0, 0, 0, 0.6),
    0 0 120px rgba(248, 200, 152, 0.08) inset;
}

.door::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 1px;
  background: var(--gold);
  opacity: 0.6;
}

.door-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--bone-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px;
  transition: color 0.3s;
}

.door-close:hover { color: var(--gold); }

.door-eyebrow {
  font-size: 0.6rem;
  letter-spacing: 0.3em;
  color: var(--gold);
  margin-bottom: 24px;
}

.door-title {
  font-weight: 400;
  font-style: italic;
  font-size: 1.8rem;
  margin-bottom: 28px;
}

.door-form { display: flex; flex-direction: column; }

.door-form label {
  font-size: 0.6rem;
  letter-spacing: 0.24em;
  text-transform: lowercase;
  color: var(--bone-dim);
  margin: 14px 0 6px;
}

.door-form input {
  font-family: var(--mono);
  font-weight: 300;
  font-size: 0.9rem;
  color: var(--bone);
  background: rgba(2, 18, 18, 0.6);
  border: 1px solid var(--hairline);
  border-bottom-color: rgba(248, 200, 152, 0.4);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.35s, box-shadow 0.35s;
}

.door-form input:focus {
  border-color: rgba(248, 200, 152, 0.7);
  box-shadow: 0 0 24px rgba(248, 200, 152, 0.12);
}

.door-form input::placeholder { color: rgba(143, 139, 128, 0.5); }

.door-submit {
  margin-top: 26px;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--gold);
  background: transparent;
  border: 1px solid rgba(248, 200, 152, 0.5);
  padding: 12px;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.4s, color 0.4s, box-shadow 0.4s, transform 0.1s;
}

.door-submit:hover {
  background: rgba(248, 200, 152, 0.1);
  box-shadow: 0 0 34px rgba(248, 200, 152, 0.15);
}

.door-submit:active { transform: translateY(1px); }

.door-msg {
  margin-top: 18px;
  min-height: 2.6em;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  color: var(--bone-dim);
  line-height: 1.8;
}

.door-msg.denied { color: var(--gold); }

.door.deny {
  animation: door-shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes door-shake {
  10%, 90%      { transform: translateX(-2px); }
  20%, 80%      { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60%      { transform: translateX(5px); }
}

/* a held breath before the denial is spoken */
.door.waiting .door-submit { opacity: 0.4; pointer-events: none; }

/* ————— toast ————— */

.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translate(-50%, 20px);
  z-index: 60;
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  color: var(--gold);
  background: rgba(7, 11, 20, 0.9);
  border: 1px solid rgba(248, 200, 152, 0.35);
  padding: 12px 22px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s, transform 0.5s;
  max-width: calc(100vw - 48px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ————— a11y ————— */

:focus-visible {
  outline: 1px solid var(--gold);
  outline-offset: 3px;
}

@media (max-width: 520px) {
  .seal { top: 20px; left: 20px; }
  .site-foot { gap: 18px; font-size: 0.54rem; }
  .name { letter-spacing: 0.6em; text-indent: 0.6em; }
  .door { padding: 38px 26px 26px; }
  .traces {
    right: 0;
    left: 0;
    bottom: 64px;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
    gap: 7px 18px;
  }
  .traces a { font-size: 0.52rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
  .grain { display: none; }
  .name, .rule, .relic, .word, .traces a { opacity: 1; }
}

/* the page refuses the printer */
@media print {
  body { background: #fff; overflow: visible; }
  body > * { display: none !important; }
  body::after {
    content: "this page does not print. the ledger is the only copy.";
    display: block;
    margin: 40vh auto 0;
    text-align: center;
    font-family: var(--serif);
    font-style: italic;
    font-size: 14pt;
    color: #000;
  }
}
