/*
  Cave Escape — the public site.

  The palette is docs/index.html's, unchanged, and the display face is the game's own Grenze, so
  the site, the store capsules and the game all read as one thing. Committed to a single dark
  theme for the reason every page in docs/ gives: everything pictured here is a pitch-black cave
  lit by one torch, and a light ground would misrepresent all of it.

  External rather than an inline <style>, which is the one place this diverges from the docs/
  house style. Those pages inline theirs because they must open from file:// with no server. This
  one is served, so keeping 'unsafe-inline' out of style-src in public/_headers costs nothing.
*/

@font-face {
  font-family: "Grenze";
  /* Copied out of assets/ by tools/make_web_images.py rather than committed twice. `swap` because
     136 KB of display face must never hold up the words it is setting. */
  src: url("gen/font/grenze-variable.ttf") format("truetype-variations");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: #100d0b;
  --card: #1a1613;
  --edge: #332b24;
  --bone: #ece2d4;
  --ash: #9d8d7c;
  --torch: #e8a33d;
  /* The torch's own colour, from CaveMood.TORCH_COLOUR — used for the glows so that every warm
     light on the page is the same light that lights the game. */
  --flame: rgb(255 202 102);

  --display: "Grenze", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Cascadia Mono", Consolas, monospace;

  --wrap: 62rem;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

body {
  background: var(--ink);
  color: var(--bone);
  font-family: var(--sans);
  line-height: 1.65;
  margin: 0;
  /* The cave never fully lights. A single faint warm pool behind everything, fixed so it reads as
     the page's own light source rather than as a decal that scrolls away. */
  background-image: radial-gradient(60rem 40rem at 50% -10rem, rgb(232 163 61 / 0.07), transparent 70%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 1.25rem; }
.prose { max-width: 42rem; }

/* ---------------------------------------------------------------- type */

h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: clamp(2.4rem, 7vw, 4.4rem); line-height: 1.02; margin: 0 0 1rem; }
h2 { font-size: clamp(1.7rem, 4vw, 2.5rem); line-height: 1.1; margin: 0 0 0.8rem; }
h3 { font-size: 1.25rem; line-height: 1.25; margin: 0 0 0.4rem; }

p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--torch); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--flame); }
:focus-visible { outline: 2px solid var(--torch); outline-offset: 3px; border-radius: 2px; }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--torch);
  margin: 0 0 0.75rem;
}
.lede { font-size: clamp(1.05rem, 2vw, 1.2rem); color: var(--ash); }
.quiet { color: var(--ash); }
.small { font-size: 0.88rem; }
code { font-family: var(--mono); font-size: 0.86em; color: var(--torch); }

/* A line of the game's own narration. Used on the story page, where the words are the content. */
.said {
  font-family: var(--display);
  font-size: clamp(1.15rem, 2.6vw, 1.6rem);
  line-height: 1.45;
  color: var(--bone);
  border-left: 2px solid var(--edge);
  padding: 0.15rem 0 0.15rem 1.25rem;
  margin: 0 0 1.6rem;
}
.said:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ skip link */

.skip {
  position: absolute; left: -9999px;
  background: var(--card); color: var(--bone);
  padding: 0.6rem 1rem; border: 1px solid var(--torch); border-radius: 3px;
}
.skip:focus { left: 1rem; top: 1rem; z-index: 10; }

/* ---------------------------------------------------------------- chrome */

.masthead {
  border-bottom: 1px solid var(--edge);
  position: sticky; top: 0; z-index: 5;
  background: rgb(16 13 11 / 0.92);
  backdrop-filter: blur(8px);
}
.masthead > .wrap {
  display: flex; align-items: center; gap: 1.5rem;
  min-height: 3.75rem; flex-wrap: wrap;
}
.wordmark {
  font-family: var(--display); font-size: 1.15rem; font-weight: 600;
  letter-spacing: 0.02em; color: var(--bone); text-decoration: none; white-space: nowrap;
}
.wordmark:hover { color: var(--flame); }
.masthead nav { display: flex; gap: 1.1rem; flex-wrap: wrap; margin-left: auto; }
.masthead nav a {
  font-size: 0.9rem; color: var(--ash); text-decoration: none; padding: 0.2rem 0;
  border-bottom: 1px solid transparent;
}
.masthead nav a:hover { color: var(--bone); border-bottom-color: var(--edge); }
.masthead nav a[aria-current="page"] { color: var(--torch); border-bottom-color: var(--torch); }

footer.site {
  border-top: 1px solid var(--edge);
  margin-top: 5rem; padding: 2.5rem 0 4rem;
  color: var(--ash); font-size: 0.9rem;
}
footer.site .wrap { display: flex; gap: 2rem; flex-wrap: wrap; justify-content: space-between; }
footer.site nav { display: flex; gap: 1.1rem; flex-wrap: wrap; }
footer.site a { color: var(--ash); }
footer.site a:hover { color: var(--torch); }

/* ---------------------------------------------------------------- layout */

main { display: block; }
section { padding: 3.5rem 0; }
section + section { border-top: 1px solid var(--edge); }
.page-head { padding: 3.5rem 0 1rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--edge); border-radius: 3px;
  padding: 1.25rem; display: flex; flex-direction: column; gap: 0.4rem;
}
.card p { color: var(--ash); font-size: 0.94rem; margin: 0; }
a.card { text-decoration: none; color: inherit; transition: border-color 0.15s, transform 0.15s; }
a.card:hover, a.card:focus-visible { border-color: var(--torch); transform: translateY(-2px); }

/* ---------------------------------------------------------------- hero */

.hero { padding: 0 0 3.5rem; border-bottom: 1px solid var(--edge); }
.hero-art {
  position: relative;
  margin: 0 0 2.5rem;
  aspect-ratio: 3840 / 1240;
  overflow: hidden;
  background: #050403;
}
.hero-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* The art fades into the page rather than ending at an edge — a torch does not have a border. */
.hero-art::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, transparent 45%, var(--ink) 100%);
}
.tagline {
  font-family: var(--display);
  font-size: clamp(1.15rem, 3vw, 1.8rem);
  color: var(--torch);
  margin: 0 0 1.5rem;
}

.actions { display: flex; gap: 0.85rem; flex-wrap: wrap; margin-top: 1.75rem; }
.button {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--sans); font-size: 0.98rem; font-weight: 600;
  padding: 0.7rem 1.3rem; border-radius: 3px; text-decoration: none;
  border: 1px solid var(--torch); color: var(--ink); background: var(--torch);
  transition: filter 0.15s, transform 0.15s;
}
.button:hover { filter: brightness(1.12); transform: translateY(-1px); color: var(--ink); }
.button.ghost { background: transparent; color: var(--torch); }
.button.ghost:hover { background: rgb(232 163 61 / 0.1); color: var(--flame); border-color: var(--flame); }

/* ---------------------------------------------------------------- media */

figure { margin: 0; }
figure img, .shot img { width: 100%; height: auto; display: block; border-radius: 3px; }
figcaption { color: var(--ash); font-size: 0.88rem; margin-top: 0.6rem; }

.video {
  position: relative; aspect-ratio: 16 / 9;
  border: 1px solid var(--edge); border-radius: 3px; overflow: hidden; background: #050403;
}
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------------------------------------------------------------- bestiary */

.beasts { display: flex; flex-direction: column; gap: 1rem; }
.beast {
  background: var(--card); border: 1px solid var(--edge); border-radius: 3px;
  padding: 1.5rem; display: grid; gap: 1.25rem;
  grid-template-columns: minmax(11rem, 16rem) 1fr; align-items: start;
}
@media (max-width: 40rem) { .beast { grid-template-columns: 1fr; } }

/*
  A fixed box, so a 3-frame bat and a 17-frame walk cycle sit on the same baseline and nothing
  reflows while the strips are still arriving.

  > [!IMPORTANT]
  > **The background is `--card` because the sprite strips already have `--card` baked into them,
  > and it must stay in step.** `regenerate.py` palette-reduces `docs/media/` through a
  > `convert("RGB")`, which composites the renderer's background in — measured at rgb(26, 22, 19),
  > which is this exact colour. So these images are opaque rectangles, and any other ground here
  > draws a visible box around every creature. `tools/make_web_images.py::SPRITE_GROUND` asserts
  > the other half and names this file when it fails.
*/
.stage {
  display: grid; place-items: center; min-height: 9rem;
  background: var(--card); border-radius: 3px; overflow: hidden;
}
/* Sprite strips are pixel art at their native size. Anything but nearest-neighbour turns the
   player's 17 frames to mush, and integer scaling is the only kind this may use. */
.sprite { image-rendering: pixelated; background-repeat: no-repeat; }
/* The two stills are lit scenes on black rather than sheets, so they read as pictures, take a
   picture's frame, and scale smoothly like one. */
.sprite.still {
  display: block; width: 100%; height: auto; image-rendering: auto;
  border: 1px solid var(--edge); border-radius: 3px;
}

.tags { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0 0.9rem; padding: 0; list-style: none; }
.tag {
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ash); border: 1px solid var(--edge); border-radius: 2px; padding: 0.15rem 0.45rem;
}
.tag.warn { color: var(--torch); border-color: currentColor; }

/* ---------------------------------------------------------------- board */

.board-frame { margin-top: 2rem; }
table.board { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.board caption { text-align: left; color: var(--ash); font-size: 0.9rem; padding-bottom: 0.75rem; }
table.board th {
  text-align: left; font-family: var(--mono); font-size: 0.66rem;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--ash); font-weight: 500;
  padding: 0 0.75rem 0.6rem 0; border-bottom: 1px solid var(--edge); white-space: nowrap;
}
table.board td { padding: 0.55rem 0.75rem 0.55rem 0; border-bottom: 1px solid var(--edge); }
table.board tr:last-child td { border-bottom: 0; }
table.board .rank { color: var(--ash); font-family: var(--mono); font-size: 0.9rem; width: 3rem; }
table.board .rank.top { color: var(--torch); }
table.board .num { text-align: right; white-space: nowrap; }
table.board .who { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
table.board .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.board .anon { color: var(--ash); font-style: italic; }

/* Reserved at build time, filled in later or not at all. A cell sized to its texture reflows the
   whole table every time one arrives — the same reason leaderboard.gd reserves its avatar box. */
.avatar {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 2px;
  background: var(--card); border: 1px solid var(--edge); display: block; object-fit: cover;
}

/* Ten rows of height, held from first paint, so the page does not jump when the fetch lands. */
tbody.rows { min-height: 22rem; }
.board-note { color: var(--ash); font-size: 0.85rem; margin-top: 1rem; }
.board-empty { padding: 2.5rem 0; color: var(--ash); }
.board-empty strong { display: block; color: var(--bone); font-family: var(--display); font-size: 1.3rem; margin-bottom: 0.4rem; }

.scroller { overflow-x: auto; }

/* ---------------------------------------------------------------- misc */

ul.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
ul.plain li { padding-left: 1.4rem; position: relative; }
ul.plain li::before { content: "▸"; position: absolute; left: 0; color: var(--torch); }

dl.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1.25rem; }
dl.facts dt { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ash); padding-top: 0.25rem; }
dl.facts dd { margin: 0; }

/* Spacing utilities. These exist because `style="margin-top:2rem"` is exactly what the CSP in
   public/_headers forbids — an inline style attribute needs 'unsafe-inline' in style-src, which
   would give away most of what the policy is for. */
.stack { margin-top: 2rem; }
.stack-sm { margin-top: 1rem; }
