/* SPIRE — site styles, pixel theme
   Pixel-art dawn: a dithered pixel sky, sliding pixel fog, RPG dialog-box
   panels with notched pixel borders, pixel fonts. Colors from the gold logo. */

:root {
  --night:   #120a22;   /* top of the sky, menu bar */
  --stone:   #211222;   /* buttons, menu */
  --panel:   rgba(28, 13, 26, 0.92);
  --hover:   #36192f;
  --gold:    #ffc453;   /* borders, accents */
  --gold-hi: #ffe9a8;   /* headings, highlights */
  --ember:   #6b2a14;   /* hard text shadows, second bar line */
  --parch:   #fbecd2;   /* main text */
  --sand:    #e6cfae;   /* secondary text */
  --dim:     #a08b98;   /* locked items */
  --rim-top: #3c2344;   /* inner top edge of frames */
  --rim-bot: #0e0610;   /* inner bottom edge of frames */

  --font-body: "Pixelify Sans", "Trebuchet MS", system-ui, sans-serif;
  --font-pixel: "Silkscreen", "Courier New", monospace;
  --bar-h: 64px;

  /* One art pixel of the sky image: the sky is 720 x 450 art pixels, scaled
     to cover the screen (about 2 CSS px per art pixel on a desktop, the same
     as the logo). Fog and embers use the same size, so all pixels line up. */
  --px: max(100vw / 720, 100vh / 450);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--night); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--parch);
  font-family: var(--font-body);
  font-size: 1.25rem;
  line-height: 1.6;
}

/* Every image scales with hard pixel edges. */
img { image-rendering: pixelated; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

svg { fill: currentColor; shape-rendering: crispEdges; }

:focus-visible {
  outline: 4px solid var(--gold-hi);
  outline-offset: 4px;
}

/* ---------- Pixel frames ----------
   The RPG dialog box: a 4 px border made of four offset shadows (this leaves
   the corners notched), a lighter inner top edge, a darker inner bottom edge,
   and a hard drop shadow. */

.index-toggle,
.index-panel,
.plaque,
.button {
  box-shadow:
    0 -4px 0 0 var(--gold),
    0 4px 0 0 var(--gold),
    -4px 0 0 0 var(--gold),
    4px 0 0 0 var(--gold),
    inset 0 4px 0 0 var(--rim-top),
    inset 0 -4px 0 0 var(--rim-bot);
  filter: drop-shadow(4px 4px 0 rgba(26, 8, 18, 0.55));
}

.lock-tag,
.footer p {
  box-shadow:
    0 -4px 0 0 #5b3a3e,
    0 4px 0 0 #5b3a3e,
    -4px 0 0 0 #5b3a3e,
    4px 0 0 0 #5b3a3e,
    inset 0 4px 0 0 var(--rim-top),
    inset 0 -4px 0 0 var(--rim-bot);
}

/* ---------- Sky (pixel-art image) ---------- */

.sky-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--night) url("/assets/sky.png?v=2") center 60% / cover no-repeat;
  image-rendering: pixelated;
}

/* ---------- Fog bands ----------
   Five strips of pixel mist. Each image is one tile of 720 art pixels and
   repeats seamlessly; the strip slides one tile, one art pixel per step. */

.fog {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Bands sit on the sky's pixel grid: the sky image is centered horizontally
   and anchored at 60% of the screen height (background-position above). */
.fog-band {
  position: absolute;
  left: calc(50vw - var(--px) * 1080);
  width: calc(var(--px) * 2160);
  height: calc(var(--px) * var(--h));
  top: calc(60vh + (var(--y) - 0.6) * var(--px) * 450 - var(--px) * var(--h) / 2);
}

.fog-strip {
  width: calc(var(--px) * 2880);
  height: 100%;
  background-image: var(--img);
  background-size: calc(var(--px) * 720) 100%;
  background-repeat: repeat-x;
  image-rendering: pixelated;
  will-change: transform;
  animation: fog-left var(--speed) steps(720) infinite;
}

.b1 { --y: 0.30; --h: 42; }
.b2 { --y: 0.44; --h: 48; }
.b3 { --y: 0.57; --h: 48; }
.b4 { --y: 0.71; --h: 54; }
.b5 { --y: 0.86; --h: 60; }

.b1 .fog-strip { --img: url("/assets/fog-1.png?v=2"); --speed: 170s; }
.b2 .fog-strip { --img: url("/assets/fog-2.png?v=2"); --speed: 130s; animation-name: fog-right; }
.b3 .fog-strip { --img: url("/assets/fog-3.png?v=2"); --speed: 100s; }
.b4 .fog-strip { --img: url("/assets/fog-4.png?v=2"); --speed: 80s; animation-name: fog-right; }
.b5 .fog-strip { --img: url("/assets/fog-5.png?v=2"); --speed: 64s; }

@keyframes fog-left {
  from { transform: translateX(0); }
  to   { transform: translateX(calc(var(--px) * -720)); }
}

@keyframes fog-right {
  from { transform: translateX(calc(var(--px) * -720)); }
  to   { transform: translateX(0); }
}

/* ---------- Embers (canvas) ---------- */

#sky {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s steps(4);
}

#sky.ready { opacity: 1; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--bar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) clamp(16px, 4vw, 40px) 0;
  background: var(--night);
  border-bottom: 4px solid var(--gold);
  box-shadow: 0 4px 0 0 var(--ember);
}

.brand {
  display: flex;
  align-items: center;
  height: 100%;
  text-decoration: none;
}

/* Wordmark fits inside the bar: 40 px tall, never cropped. */
.brand img {
  display: block;
  width: auto;
  height: 40px;
  image-rendering: auto;
}

/* ---------- Index menu (details/summary disclosure) ---------- */

.index { position: relative; }

.index-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 16px;
  list-style: none;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-pixel);
  font-size: 14px;
  line-height: 1;
  color: var(--parch);
  background: var(--stone);
}

.index-toggle::-webkit-details-marker { display: none; }

.index-toggle:hover,
.index[open] > .index-toggle { background: var(--hover); }

.chev {
  width: 12px;
  height: 8px;
  color: var(--gold);
}

.index[open] .chev { transform: rotate(180deg); }

.index-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 16px);
  min-width: 240px;
  margin: 0;
  padding: 8px;
  list-style: none;
  background: var(--stone);
}

.index[open] .index-panel { animation: drop 0.16s steps(2) both; }

.index-panel a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  font-family: var(--font-pixel);
  font-size: 14px;
  line-height: 1.2;
  color: var(--parch);
  text-decoration: none;
}

.index-panel a[href]:hover,
.index-panel a[href]:focus-visible {
  background: var(--hover);
  outline-offset: -4px;
}

.index-panel a[aria-current="page"] {
  color: var(--gold-hi);
  background: var(--hover);
}

.mark {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--sand);
}

.index-panel a[aria-current="page"] .mark { color: var(--gold); }

.index-panel .is-locked {
  color: var(--dim);
  cursor: not-allowed;
}

.is-locked .mark {
  width: 15px;
  color: var(--dim);
}

.lock-tag {
  margin-left: auto;
  padding: 3px 8px;
  font-size: 10px;
  color: var(--dim);
  background: #1a0b14;
}

/* ---------- Lock screen ---------- */

main {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px 16px 40px;
  text-align: center;
}

.logo {
  margin: 0;
  line-height: 0;
  /* 906 px = the logo at exactly 2x its art pixels. Smaller on short or
     narrow screens so the panel stays on screen. 2.088 = width / height. */
  width: min(906px, 92vw, max(300px, calc((100vh - 470px) * 2.088)));
  width: min(906px, 92vw, max(300px, calc((100svh - 470px) * 2.088)));
}

.logo img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 8px 0 rgba(60, 14, 34, 0.35));
  animation: appear 0.8s steps(4) both;
}

.plaque {
  width: min(560px, 92vw);
  padding: 24px clamp(20px, 4vw, 36px) 28px;
  background: var(--panel);
  animation: appear 0.4s 0.6s steps(3) both;
}

.seal {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 auto 16px;
}

.seal-line {
  flex: 1;
  height: 4px;
  animation: draw 0.6s 0.8s steps(8) both;
}

.seal-line--left {
  background: repeating-linear-gradient(90deg, transparent 0 4px, var(--gold) 4px 12px);
  transform-origin: right center;
}

.seal-line--right {
  background: repeating-linear-gradient(90deg, var(--gold) 0 8px, transparent 8px 12px);
  transform-origin: left center;
}

.seal-star {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--gold);
  animation: appear 0.3s 1.3s steps(2) both;
}

.seal-lock {
  flex: none;
  width: 40px;
  height: 48px;
  color: var(--gold-hi);
  filter: drop-shadow(0 4px 0 var(--ember));
  animation: appear 0.3s 0.7s steps(2) both;
}

.status {
  margin: 0 0 12px;
  font-family: var(--font-pixel);
  font-size: clamp(24px, 3.4vw, 34px);
  font-weight: 700;
  line-height: 1.1;
  color: var(--gold-hi);
  text-shadow: 0 4px 0 var(--ember);
}

.lede {
  max-width: 48ch;
  margin: 0 auto;
  color: var(--sand);
}

/* ---------- Footer ---------- */

.footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom, 0px));
}

.footer p {
  margin: 0;
  padding: 6px 14px;
  font-family: var(--font-pixel);
  font-size: 12px;
  line-height: 1.4;
  color: var(--sand);
  background: #1c0d1a;
}

/* ---------- 404 page ---------- */

.notfound .plaque { animation-delay: 0s; }

.notfound-code {
  margin: 0 0 8px;
  font-family: var(--font-pixel);
  font-size: clamp(48px, 12vw, 88px);
  font-weight: 700;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 6px 0 var(--ember);
}

.button {
  display: inline-block;
  margin-top: 24px;
  padding: 12px 20px;
  font-family: var(--font-pixel);
  font-size: 14px;
  line-height: 1.2;
  color: var(--parch);
  text-decoration: none;
  background: var(--stone);
}

.button:hover { background: var(--hover); }

/* ---------- Motion ---------- */

@keyframes draw {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

@keyframes appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes drop {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 520px) {
  body { font-size: 1.0625rem; }
  main { gap: 20px; padding-top: 24px; }
  .plaque { padding: 20px 20px 24px; }
  .seal { gap: 10px; margin-bottom: 14px; }
  .seal-lock { width: 30px; height: 36px; }
  .status { font-size: 24px; }
  .lede br { display: none; }
}
