/* ---------------------------------------------------------------------------
   Paganitzu (CoCo 3) — landing page

   Every color below is one of the port's RGB palette (paletteSetRgb in
   src/includes/paletteData.asm, the EGA sixteen), decoded from the 6-bit
   %R1G1B1R0G0B0 register format. No other colors are used.

   The art is the original's own (page/art/, cut by scripts/extract-page-art.py):
   16x16 slots drawn at 3x, a cell of 48 CSS px, square pixels, never smoothed.
   --------------------------------------------------------------------------- */

:root {
  --black:        #000000;  /* 0  — the floor */
  --blue:         #0000AA;  /* 1  — the panel's frames, water's deep */
  --green:        #00AA00;  /* 2  — moss */
  --red:          #AA0000;  /* 4  — the spider, the title's menu */
  --gray:         #AAAAAA;  /* 7  — stone */
  --dark-gray:    #555555;  /* 8  — stone's shade */
  --light-green:  #55FF55;  /* 10 */
  --light-cyan:   #55FFFF;  /* 11 — water, the gems, the panel's text */
  --light-red:    #FF5555;  /* 12 */
  --yellow:       #FFFF55;  /* 14 — the keys */
  --white:        #FFFFFF;  /* 15 */

  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas,
          "DejaVu Sans Mono", "Courier New", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;

  /* One cell of the game: a 16x16 slot at 3x. The page's unit of distance;
     every sprite is a cell, and a move is half of one (8 game pixels). */
  --cell: 48px;
  --wall: url("art/wall.png");
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--black);
  color: var(--white);
  font-family: var(--sans);
  font-size: clamp(1rem, 0.96rem + 0.25vw, 1.125rem);
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.wrap {
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* --- the game's art -------------------------------------------------------- */

/* A sprite is a cell showing one frame of its strip: the strip is the
   background, --frames cells wide, and frame n is background-position-x
   -n cells. Frame 0 without script. */
.sprite {
  display: inline-block;
  flex: none;
  width: var(--cell);
  height: var(--cell);
  background-repeat: no-repeat;
  background-size: calc(var(--frames, 1) * var(--cell)) var(--cell);
  background-position: 0 0;
  image-rendering: pixelated;
}

.sprite.al      { background-image: url("art/al-right.png"); }
.sprite.boulder { background-image: url("art/boulder.png"); }
.sprite.spider  { background-image: url("art/spider.png"); }
.sprite.snake   { background-image: url("art/snake-right.png"); }
.sprite.snake.left { background-image: url("art/snake-left.png"); }
.sprite.gem     { background-image: url("art/gem.png"); }
.sprite.key     { background-image: url("art/key.png"); }
.sprite.door    { background-image: url("art/door.png"); }
.sprite.al.left { background-image: url("art/al-left.png"); }
.sprite.boulder.appear { background-image: url("art/appear.png"); }
.sprite.splash  { background-image: url("art/splash.png"); }
/* Water by the game's id: 29 open water, 33 its bottom-left shore, 34 its bottom. */
.sprite.water   { background-image: url("art/water-29.png"); }
.sprite.water-33 { background-image: url("art/water-33.png"); }
.sprite.water-34 { background-image: url("art/water-34.png"); }

/* Walls: the mossy stone tile, repeated a cell at a time. */
.wall.band,
.wall.floor,
.corridor-wall {
  height: var(--cell);
  background-image: var(--wall);
  background-size: var(--cell) var(--cell);
  background-repeat: repeat-x;
  image-rendering: pixelated;
}

/* Section icons: a sprite on the heading's line. */
.hicon {
  margin-right: 0.8rem;
  vertical-align: middle;
}

/* --- the spider's frame round the hero screenshot --------------------------- */

/* A ring of wall outside a ring of floor, each one cell thick: the spider walks
   the floor beside the wall, as in the game. */
.spider-frame {
  position: relative;
  margin-top: 1.5rem;
  padding: var(--cell);
  background-image: var(--wall);
  background-size: var(--cell) var(--cell);
  background-repeat: repeat;
  image-rendering: pixelated;
}

.frame-floor {
  position: relative;
  padding: var(--cell);
  background: var(--black);
}

/* page.js sizes the frame to whole cells, the leftover split either side, and
   sets the spider's --x and --y, in half-steps from the ring's top-left cell. */
.frame-floor > .spider {
  position: absolute;
  top: calc(var(--y, 0) * var(--cell) / 2);
  left: calc(var(--x, 0) * var(--cell) / 2);
  z-index: 1;
}

/* Whole cells high once page.js has sized it, the screenshot centered in them. */
.hero-shot {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* --- Al's corridor ------------------------------------------------------- */

/* A band of floor a cell high between two rows of wall, a two-cell pool at its
   right end. Its cells are whole: page.js sets --margin, the leftover split
   either side, and each sprite's --x, in half-steps from the first cell. */
.corridor {
  --margin: 0px;
  margin-top: clamp(2.5rem, 6vw, 4.5rem);   /* as a section's top padding: just above Screenshots */
}

.corridor-wall { background-position-x: var(--margin); }

.corridor-floor {
  position: relative;
  height: var(--cell);
  background: var(--black);
}

.corridor-floor > .sprite {
  position: absolute;
  top: 0;
  left: calc(var(--margin) + var(--x, 0) * var(--cell) / 2);
}

/* The pool: the last two whole cells, counted from the left as the walls and
   the sprites are, so it lines up with or without page.js (--margin 0 then).
   round() takes the floor's width down to whole cells. A browser without it
   counts from the right instead, which lines up once page.js has set --margin. */
.corridor-floor > .pool-first { left: auto; right: calc(var(--margin) + var(--cell)); }
.corridor-floor > .pool-last  { left: auto; right: var(--margin); }

@supports (left: round(down, 100%, 1px)) {
  .corridor-floor > .pool-first,
  .corridor-floor > .pool-last {
    --cells-end: calc(var(--margin) + round(down, 100% - 2 * var(--margin), var(--cell)));
    right: auto;
  }
  .corridor-floor > .pool-first { left: calc(var(--cells-end) - 2 * var(--cell)); }
  .corridor-floor > .pool-last  { left: calc(var(--cells-end) - var(--cell)); }
}

/* The game draws the splash as a whole cell, over the water. */
.corridor-floor > .splash { background-color: var(--black); }

/* --- the cast and the items --------------------------------------------- */

.cast {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  align-items: stretch;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.cast-item {
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: end;
  justify-items: center;
  gap: 0.9rem;
}

.cast-name {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--yellow);
  text-align: center;
}

.wall.floor {
  margin-top: 0.5rem;
  background-repeat: repeat-x;
}

.glyphs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr));
  gap: 1.75rem 1rem;
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
}

.glyphs li {
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: end;
  justify-items: center;
  gap: 0.8rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gray);
  text-align: center;
}

/* Snakes out in the gutter beside the text column, hidden rather than
   reflowed once the gutter is gone. */
.margin-art {
  position: absolute;
  top: clamp(4rem, 9vw, 7rem);
}

.art-left { right: calc(50% + 33rem); }
.art-right { left: calc(50% + 33rem); }

.footer-snake {
  display: block;
  margin: 0 0 1rem;
}

/* --- headings ------------------------------------------------------------ */

h1, h2, h3, .eyebrow, .btn, kbd, .term, th {
  font-family: var(--mono);
}

h1 {
  margin: 0.6rem 0 0.5rem;
  font-size: clamp(2.1rem, 8vw, 4.25rem);
  line-height: 1.02;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--light-cyan);
  text-shadow: 4px 4px 0 var(--blue);
}

h2 {
  margin: 0 0 1.4rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--blue);
  font-size: clamp(1.35rem, 3.4vw, 1.9rem);
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--light-cyan);
}

h3 {
  margin: 2.2rem 0 0.6rem;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--yellow);
}

.eyebrow {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--light-green);
}

/* --- text --------------------------------------------------------------- */

p { max-width: 46rem; }

.tagline {
  margin: 0 0 1.25rem;
  font-size: clamp(1.1rem, 2.4vw, 1.4rem);
  color: var(--white);
}

.pitch { color: var(--gray); }

.caption,
.credits,
figcaption {
  font-size: 0.9rem;
  color: var(--gray);
}

.note {
  border-left: 4px solid var(--green);
  padding-left: 1rem;
  color: var(--gray);
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--light-cyan);
}

a {
  color: var(--light-cyan);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:hover { color: var(--yellow); }

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

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

.hero { padding-bottom: clamp(1rem, 3vw, 2rem); }

.hero .wrap { padding-top: clamp(2rem, 6vw, 4rem); }

main section {
  position: relative;            /* anchor for .margin-art */
  padding: clamp(2.5rem, 6vw, 4.5rem) 0 0;
  scroll-margin-top: 1.5rem;
}

main section:last-child { padding-bottom: clamp(2.5rem, 6vw, 4.5rem); }

/* --- buttons ------------------------------------------------------------ */

.cta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: stretch;
  max-width: none;
  margin: 1.75rem 0 2.5rem;
}

.cta-inline { margin: 0 0 1rem; }

.hero .cta {
  justify-content: space-between;
  margin: 1.75rem 0 0.5rem;
}

.btn {
  display: block;
  padding: 0.85rem 1.4rem;
  border: 3px solid var(--light-cyan);
  background: var(--black);
  box-shadow: 5px 5px 0 var(--blue);
  color: var(--yellow);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
}

.btn:hover,
.btn:focus-visible {
  background: var(--yellow);
  border-color: var(--yellow);
  box-shadow: 7px 7px 0 var(--blue);
  color: var(--black);
  transform: translate(-2px, -2px);
}

.btn-sub {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: none;
  color: var(--gray);
}

.btn:hover .btn-sub,
.btn:focus-visible .btn-sub { color: var(--blue); }

.btn-ghost {
  align-self: flex-start;
  border-color: var(--light-green);
  color: var(--light-green);
  box-shadow: 5px 5px 0 var(--green);
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  background: var(--light-green);
  border-color: var(--light-green);
  box-shadow: 7px 7px 0 var(--green);
  color: var(--black);
}

/* --- screenshots -------------------------------------------------------- */

.shot { margin: 0; }

.shot img {
  display: block;
  width: 100%;
  height: auto;
  border: 2px solid var(--blue);
  background: var(--black);
  image-rendering: pixelated;
}

.hero-shot img { border-color: var(--black); }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 1.75rem;
  margin-bottom: 1.25rem;
}

.gallery .shot img { cursor: zoom-in; }

.gallery .shot img:hover { border-color: var(--yellow); }

figcaption { margin-top: 0.6rem; }

/* --- lists -------------------------------------------------------------- */

.features,
.plain {
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 0.55rem 2rem;
}

.features li,
.plain li {
  position: relative;
  padding-left: 1.5rem;
  max-width: 46rem;
}

.plain li { margin-bottom: 0.7rem; }

.features li::before,
.plain li::before {
  content: "\25AA";
  position: absolute;
  left: 0;
  color: var(--light-cyan);
}

.plain li::before { color: var(--light-green); }

.plain strong { color: var(--white); }

/* --- controls table ----------------------------------------------------- */

.keys {
  width: 100%;
  max-width: 46rem;
  border-collapse: collapse;
  text-align: left;
}

.keys th {
  width: 1%;
  padding: 0.85rem 1.5rem 0.85rem 0;
  border-top: 1px solid var(--dark-gray);
  vertical-align: top;
  white-space: nowrap;
  font-weight: normal;
  line-height: 2;
  color: var(--yellow);
}

.keys td {
  padding: 0.85rem 0;
  border-top: 1px solid var(--dark-gray);
  vertical-align: top;
  color: var(--gray);
}

kbd {
  display: inline-block;
  padding: 0.05em 0.4em;
  border: 2px solid var(--light-cyan);
  background: var(--black);
  color: var(--light-cyan);
  font-size: 0.85em;
  line-height: 1.4;
  white-space: nowrap;
}

.term {
  max-width: 46rem;
  margin: 1rem 0 1.5rem;
  padding: 1rem 1.2rem;
  border: 2px solid var(--light-cyan);
  background: var(--black);
  color: var(--light-cyan);
  overflow-x: auto;
}

.term code { font: inherit; }

/* --- footer ------------------------------------------------------------- */

footer {
  margin-top: 2rem;
}

footer .wrap {
  padding-top: 2rem;
  padding-bottom: 3rem;
}

footer .credits { max-width: 48rem; }

footer strong { color: var(--light-red); }

/* --- lightbox ----------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0.75rem, 3vw, 2.5rem);
  background: var(--black);
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border: 2px solid var(--blue);
  image-rendering: pixelated;
}

/* --- narrow screens ----------------------------------------------------- */

/* Below this there is no gutter left to decorate. */
@media (max-width: 84rem) {
  .margin-art { display: none; }
}

@media (max-width: 40rem) {
  .cast { gap: 1rem; }
  .hicon { margin-right: 0.5rem; }

  /* The frame takes the whole width, so the screenshot keeps what it can. */
  .spider-frame { margin-left: -1.25rem; margin-right: -1.25rem; }

  .keys th,
  .keys td {
    display: block;
    width: auto;
    padding: 0;
  }

  .keys th {
    border-top: 1px solid var(--dark-gray);
    padding-top: 0.85rem;
  }

  .keys td {
    padding-bottom: 0.85rem;
    border-top: 0;
  }

  .btn { width: 100%; }

  h1 { text-shadow: 3px 3px 0 var(--blue); }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  .btn { transition: transform 0.08s steps(2), background-color 0.08s; }
}
