:root {
  color-scheme: dark;
  font-family: Georgia, "Times New Roman", serif;
  background: #11181e;
  color: #f8e6bc;
}

* { box-sizing: border-box; }

body { margin: 0; }

.library-stage {
  position: fixed;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #11181e;
}

.library-stage[inert] { pointer-events: none; }

.gate[data-opening] .field,
.gate[data-opening] .controls { display: none; }

.gate[data-opening] .message {
  margin-block: 12px 0;
  text-align: center;
}

.page {
  --center-x: 50%;
  --center-y: 46%;
  --mechanism-size: max(147vw, 157svh);
  --aperture: calc(var(--mechanism-size) * .235);
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100svh;
  isolation: isolate;
  overflow: hidden;
  padding: 0 16px;
}

@supports (width: hypot(100px, 100px)) {
  .page { --mechanism-size: calc(hypot(100vw, 109svh) * 1.025); }
}

.page::before,
.page::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.page::before {
  z-index: 1;
  inset: 0;
  background:
    linear-gradient(180deg, #130f0caa, transparent 20% 63%, #131016e0),
    radial-gradient(ellipse at var(--center-x) var(--center-y), transparent 15%, #100d0c20 53%, #12131ba8 100%);
}

.page::after {
  z-index: 2;
  inset: 12px;
  border: 1px solid #ebc88a66;
  background:
    linear-gradient(90deg, #e6be7d 0 20px, transparent 20px calc(100% - 20px), #e6be7d 0) top / 100% 1px no-repeat,
    linear-gradient(90deg, #e6be7d 0 20px, transparent 20px calc(100% - 20px), #e6be7d 0) bottom / 100% 1px no-repeat,
    linear-gradient(#e6be7d 0 20px, transparent 20px calc(100% - 20px), #e6be7d 0) left / 1px 100% no-repeat,
    linear-gradient(#e6be7d 0 20px, transparent 20px calc(100% - 20px), #e6be7d 0) right / 1px 100% no-repeat;
  box-shadow: 0 0 0 12px #11131c33;
}

.mechanism {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background: radial-gradient(circle at var(--center-x) var(--center-y), #3e2e1f 16%, #1a1415 45%, #1a2731);
}

.ring,
.seal {
  position: absolute;
  top: var(--center-y);
  left: var(--center-x);
  translate: -50% -50%;
  aspect-ratio: 1;
}

.ring {
  width: calc(var(--mechanism-size) * var(--size));
  height: auto;
  display: block;
  transform: rotate(var(--offset, 0deg));
  animation: turn var(--period) linear infinite var(--direction, normal);
}

.ring--stone {
  --size: 1;
  --period: 196s;
  --offset: -6deg;
}

.ring--oak {
  --size: .729;
  --period: 138s;
  --offset: 11deg;
  --direction: reverse;
}

.ring--brass {
  --size: .549;
  --period: 103s;
  --offset: -21deg;
}

.ring--walnut {
  --size: .414;
  --period: 82s;
  --offset: 19deg;
  --direction: reverse;
}

.ring--glass {
  --size: .312;
  --period: 64s;
  --offset: -9deg;
}

@keyframes turn {
  to { transform: rotate(calc(var(--offset, 0deg) + 360deg)); }
}

.seal {
  --current-panel: 0%;
  width: var(--aperture);
  border-radius: 50%;
  overflow: hidden;
  border: clamp(2px, .23vw, 5px) solid #d1a570;
  background: #201913;
  box-shadow: 0 0 0 1px #563821, 0 0 9px 4px #120c06b8;
}

.seal::after {
  content: "";
  position: absolute;
  z-index: 4;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  background: linear-gradient(137deg, #ffe6a61f, transparent 33% 70%, #d2a5642e);
  box-shadow: inset 0 0 18px 5px #180f11b0;
}

.portrait,
.moon-sweep {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.portrait--current {
  background: url("visions.webp") var(--current-panel) center / 300% 100% no-repeat;
}

.masthead,
.signature,
.motion {
  position: absolute;
  z-index: 3;
  margin: 0;
  color: #f2deb8;
  text-align: center;
  text-shadow: 0 1px 3px #110b08, 0 0 14px #0e0b0b;
}

.masthead {
  top: clamp(17px, 3.15svh, 33px);
  left: 50%;
  translate: -50% 0;
  padding: 6px 27px 10px;
  isolation: isolate;
  background: radial-gradient(ellipse at center, #17130fe8 23%, #17130f8a 61%, transparent 76%);
}

.masthead::before,
.masthead::after {
  position: absolute;
  inset-inline: 12%;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, #936637 16%, #efce8d 50%, #936637 84%, transparent);
}

.masthead::before { top: 0; }
.masthead::after { bottom: 1px; }

.wordmark {
  position: relative;
  margin: 0;
  color: #f6dba1;
  font-family: Baskerville, "Palatino Linotype", Georgia, serif;
  font-size: clamp(30px, 3.3vw, 60px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: .105em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 2px 1px #120a06, 0 0 20px #150b04;
}

.wordmark::before,
.wordmark::after {
  position: absolute;
  top: 49%;
  width: 6px;
  height: 6px;
  content: "";
  rotate: 45deg;
  border: 1px solid #f1d99d;
  background: #7c512b;
  box-shadow: 0 0 0 2px #191410a8;
}

.wordmark::before { left: -18px; }
.wordmark::after { right: -18px; }

.signature {
  left: 50%;
  bottom: 25px;
  translate: -50% 0;
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: .23em;
  text-transform: uppercase;
  white-space: nowrap;
}

.motion {
  top: 18px;
  right: 19px;
  min-height: 36px;
  border: 1px solid #d8b78175;
  border-radius: 2px;
  background: #171512d9;
  padding: 4px 10px;
  font: 12px Georgia, "Times New Roman", serif;
  cursor: pointer;
}

.motion:hover { background: #2d2219; }

.gate {
  position: relative;
  z-index: 3;
  isolation: isolate;
  width: min(100%, 448px);
  margin-top: min(calc(46svh + var(--aperture) * .41), calc(100svh - 200px));
  margin-bottom: 45px;
  padding: 30px clamp(25px, 4.8vw, 42px) 30px;
}

.gate::before,
.gate::after {
  position: absolute;
  pointer-events: none;
  content: "";
}

.gate::before {
  z-index: -1;
  inset: 18px 8px;
  border: 1px solid #ab8051;
  border-radius: 12px 12px 9px 9px;
  background: linear-gradient(142deg, #282620, #0e1918 54%, #211712);
  box-shadow: inset 0 0 0 3px #5e4028, inset 0 0 0 4px #bc945c, 0 10px 23px #0f0a07b8;
}

.gate::after {
  z-index: -1;
  inset: -19px -4px -24px;
  background: url("form-plaque.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 9px 9px #0f0a08a0);
}

.gate h1 {
  margin: 0;
  color: #ffedc7;
  font-family: Baskerville, "Palatino Linotype", Georgia, serif;
  font-size: clamp(26px, 5.7vw, 37px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.035em;
  text-align: center;
  text-shadow: 0 2px 3px #0c0907;
}

.gate h1::after {
  display: block;
  width: 75%;
  height: 1px;
  margin: 10px auto 9px;
  content: "";
  background: linear-gradient(90deg, transparent, #92683c 22%, #dfb876 50%, #92683c 78%, transparent);
}

.field {
  display: block;
  margin-bottom: 6px;
  color: #f2d4a1;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .075em;
}

.controls {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.input-well {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
}

.input-well::before {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 12px;
  width: 10px;
  height: 16px;
  translate: 0 -50%;
  background: #bc9362;
  clip-path: polygon(0 25%, 15% 6%, 50% 0, 85% 6%, 100% 25%, 86% 47%, 64% 56%, 76% 100%, 24% 100%, 36% 56%, 14% 47%);
  pointer-events: none;
  content: "";
}

.controls input,
.controls button {
  min-height: 46px;
  border: 1px solid #a77d4b;
  font: inherit;
}

.controls input {
  width: 100%;
  min-width: 0;
  border-radius: 7px 3px 3px 7px;
  padding: 8px 11px 8px 29px;
  background: #080f11;
  color: #fff1cc;
  font-size: 16px;
  box-shadow: inset 0 2px 7px #050708, inset 0 0 0 2px #2e251e;
}

.controls button {
  position: relative;
  flex: 0 0 auto;
  padding: 0 clamp(12px, 2.4vw, 23px);
  border-radius: 3px 7px 7px 3px;
  background: linear-gradient(164deg, #ffe4ad 0%, #d6aa6b 53%, #ab7341 100%);
  color: #271712;
  font: 700 15px Baskerville, Georgia, serif;
  text-shadow: 0 1px #ffe1a28a;
  box-shadow: inset 0 0 0 2px #ffe1a479, 0 2px 5px #050807a3;
  cursor: pointer;
}

.controls button:hover { background: linear-gradient(164deg, #fff0c5, #ddb37a 53%, #be8752); }
.controls button:active { box-shadow: inset 0 2px 4px #794717; }

input:focus-visible,
button:focus-visible {
  outline: 2px solid #fff0ae;
  outline-offset: 3px;
}

.message { margin: 9px 0 0; color: #ffd3bd; font-size: 13px; line-height: 1.4; }
.message:empty { display: none; }

.motion-paused .ring { animation-play-state: paused; }

@media (max-width: 530px) {
  .masthead { left: 15px; top: 24px; translate: 0; padding-inline: 15px; }
  .wordmark { font-size: clamp(17px, 4.9vw, 26px); letter-spacing: .065em; }
  .wordmark::before { left: -10px; }
  .wordmark::after { right: -10px; }
  .wordmark::before,
  .wordmark::after { width: 4px; height: 4px; }
  .motion { right: 18px; top: 19px; }
  .signature { bottom: 21px; }
  .page::after { inset: 9px; }
}

@media (max-width: 345px) {
  .masthead { left: 10px; }
  .wordmark { letter-spacing: .045em; }
  .motion { right: 15px; padding-inline: 7px; }
  .gate { padding-inline: 21px; }
}

@media (max-height: 540px) and (min-aspect-ratio: 4/3) {
  .page {
    --center-x: 37%;
    --mechanism-size: max(155vw, 157svh);
    align-items: flex-end;
    justify-content: center;
    padding-right: 5vw;
  }

  @supports (width: hypot(100px, 100px)) {
    .page { --mechanism-size: calc(hypot(126vw, 109svh) * 1.025); }
  }

  .wordmark { font-size: clamp(23px, 4.5svh, 31px); }

  .gate { width: min(43vw, 448px); margin: 43px 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ring { animation: none; }

  .motion { display: none; }
}
