:root {
  --text: #f2f4ff;
  --accent: #9ec5ff;
  --header-bg: rgba(5, 8, 20, 0.55);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { height: 100%; overflow-x: clip; }

body {
  margin: 0;
  overflow-x: clip;       /* never scroll sideways, whatever overflows */
  min-height: 100%;       /* grows with its content, so short screens scroll to the bottom */
  display: flex;
  flex-direction: column;
  background: #05070f;
  color: var(--text);
  font-family: Verdana, Geneva, sans-serif;
}

/* Parallax layers: both are centered, "cover"-sized, and oversized so
   js/parallax.js can shift them without exposing an edge. They live in a fixed,
   clipped box (.bg) so the overscan can't make the page scroll sideways on phones. */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.bg::before,
.bg::after {
  content: "";
  position: absolute;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  will-change: transform;
}

.bg::before {
  inset: -6%;
  background-image: url("../images/space.webp");
  transform: translate3d(var(--space-x, 0px), var(--space-y, 0px), 0);
}

.bg::after {
  inset: -3%;
  background-image: url("../images/planet.webp");
  /* Shift down by half the header so the planet centers in the space below it */
  transform: translate3d(var(--planet-x, 0px), calc(var(--planet-y, 0px) + var(--header-h, 6.5rem) / 2), 0) scale(0.8649);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  padding: 1.25rem 1.5rem 1rem;
  background: var(--header-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.site-header .site-name {
  font-family: Inconsolata, monospace;
  font-weight: 400;
  text-transform: uppercase;
  font-size: 1.3rem;
  letter-spacing: 0.2em;
  color: #fff;
  text-decoration: none;
}

.site-header .site-name:hover,
.site-header .site-name:focus-visible {
  color: #fff;
}

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 4rem;
}

.site-header a {
  font-family: Inconsolata, monospace;
  font-weight: 400;
  text-transform: uppercase;
  font-size: 1rem;
  color: rgba(242, 244, 255, 0.8);
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: color 0.2s;
}

.site-header a:hover,
.site-header a:focus-visible,
.site-header a[aria-current="page"] {
  color: var(--accent);
}

main { flex: 1; padding: 2rem 1.5rem; }

/* About page: text flanking the planet. The planet is ~37% of the viewport cover width
   width and the background is "cover", so size the gap from the same math. */
.about {
  display: grid;
  grid-template-columns: 1fr calc(0.344 * max(100vw, 177.78vh)) 1fr;
  align-items: center;
  gap: 0 1rem;
  padding-inline: 4vw;
}

.about-left { grid-column: 1; }
.about-right { grid-column: 3; }

.about-text {
  font-family: Inconsolata, monospace;
  font-size: 1.05rem;
  text-transform: none;
  line-height: 1.4;
  text-shadow: 2px 3px 4px rgba(0, 0, 0, 0.9);
}

.about-text p { margin: 0 0 1em; }
.about-text p:last-child { margin-bottom: 0; }

@media (max-width: 900px) {
  .about {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    min-height: 0;
  }
  .about-left, .about-right { grid-column: 1; }

  /* Room below the text so the last lines clear the log device's bezel and the browser's bottom bar */
  .about { padding-bottom: calc(6rem + env(safe-area-inset-bottom)); }

  /* One extra blank line after every block of text, including the break inside the first block */
  .about { gap: calc(1.5rem + 1.47rem); }
  .about-text p { margin-bottom: calc(1em + 1.4em); }
  .about-text p:last-child { margin-bottom: 0; }
  .about-text br + br { display: block; content: ""; margin-top: 1.4em; }

  /* Text shadow 21% heavier than desktop (10% twice) */
  .about-text { text-shadow: 2.4px 3.6px 4.8px rgba(0, 0, 0, 1); }

  /* Planet 10% smaller than desktop (0.8649 * 0.9) */
  .bg::after {
    inset: -3% -50%;   /* wide box: the planet is cropped by the box, so shrinking must not expose its edges */
    transform: translate3d(var(--planet-x, 0px), calc(var(--planet-y, 0px) + var(--header-h, 6.5rem) / 2), 0) scale(0.7784);
  }
}

/* ---- Retro-futurist log device (bottom of the page) ----
   Only its top bezel shows at rest; hover/focus/tap raises the top half. */
.log-device {
  --h: 240px;            /* device height */
  --rest: 14px;          /* bezel visible at rest */
  --raise: 0.5;          /* fraction of the device visible when raised */
  --green: #00ff41;
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(540px, calc(100vw - 2rem));
  height: var(--h);
  padding: 34px 36px 36px;   /* thick metal edge around the screen */
  border-radius: 24px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.07) 0 4px, transparent 4px 10px),
    linear-gradient(160deg, #8da39c 0%, #6e847e 35%, #576c65 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -3px 6px rgba(0, 0, 0, 0.3),
    inset 2px 0 3px rgba(255, 255, 255, 0.2),
    inset -2px 0 3px rgba(0, 0, 0, 0.2),
    0 -2px 0 rgba(0, 0, 0, 0.55),
    0 -10px 28px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, calc(100% - var(--rest)));
  transition: transform 0.35s cubic-bezier(0.22, 0.8, 0.3, 1);
}

/* Invisible strip above the bezel so the hover target isn't just 14px */
.log-device::before {
  content: "";
  position: absolute;
  inset: -18px 0 auto;
  height: 18px;
}

.log-device.open,
.log-device:has(:focus-visible) {
  transform: translate(-50%, calc(100% - var(--h) * var(--raise)));
}

@media (hover: hover) {
  .log-device:hover { transform: translate(-50%, calc(100% - var(--h) * var(--raise))); }
}

/* Three slots on the bezel; the top one is a status light that lights up while audio plays */
.log-slots {
  position: absolute;
  top: 8px;
  right: 44px;
  display: grid;
  gap: 3px;
  width: 44px;   /* grows leftward from the fixed right edge */
}

.log-slots i {
  display: block;
  height: 4px;
  border-radius: 2px;
  background: #2c3a36;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.35);
}

.log-device.playing .log-led {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

/* The recessed screen: black glass */
.log-screen {
  position: relative;
  height: 100%;
  padding: 14px 18px;
  border-radius: 14px;
  background: #000;
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.95),
    inset 0 0 0 1px rgba(0, 0, 0, 0.9),
    0 1px 0 rgba(255, 255, 255, 0.5);
}

.log-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.log-device button {
  font: inherit;
  border: 0;
  cursor: pointer;
}

.log-play {
  flex: none;
  position: relative;
  width: 40px;
  height: 36px;
  background: none;
}

.log-play::before {            /* play triangle */
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  border-style: solid;
  border-width: 11px 0 11px 18px;
  border-color: transparent transparent transparent var(--green);
  transform: translate(-40%, -50%);
}

.log-device.playing .log-play::before {   /* pause bars */
  width: 16px;
  height: 22px;
  border: 0;
  background: linear-gradient(90deg, var(--green) 0 5px, transparent 5px 11px, var(--green) 11px 16px);
  transform: translate(-50%, -50%);
}

.log-title {
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px 2px;
  background: none;
  color: var(--green);
  font-family: Inconsolata, monospace;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-play:hover,
.log-play:focus-visible { opacity: 0.7; }
.log-title:hover,
.log-title:focus-visible { text-decoration: underline; text-underline-offset: 4px; }
.log-device button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.log-progress {
  width: 60%;
  margin-left: 56px;   /* play button 40 + gap 14 + title padding 2: lines up with the title's first letter */
  height: 6px;
  margin-top: 4px;
  border-radius: 3px;
  background: rgba(0, 255, 65, 0.2);
  overflow: hidden;
}

.log-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  transform-origin: left;
  transform: scaleX(var(--progress, 0));
}

@media (prefers-reduced-motion: reduce) {
  .log-device { transition: none; }
}

/* ---- Research papers: three portrait devices that fan out on hover ----
   Metal and screen match the log device. Each screen holds a PDF (data-pdf). */
.research {
  display: flex;
  align-items: center;
  justify-content: center;
}

.papers {
  --w: min(420px, 23vw, 38vh);
  --zoom: 1.4;                   /* hover scale */
  /* Gap between fanned cards: leaves 2.5rem clear even when a neighbor zooms (it grows (zoom-1)/2 * w per side) */
  --gap: calc(var(--w) * (var(--zoom) - 1) / 2 + 2.5rem);
  position: relative;
  width: 100%;
  height: calc(var(--w) * 1.45 + 3rem);
  pointer-events: none;            /* only the cards react until the stack is fanned */
}

.papers.fanned { pointer-events: auto; }

.paper {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: var(--z);
  width: var(--w);
  aspect-ratio: 5 / 7;
  padding: 30px 24px 24px;
  border-radius: 22px;
  pointer-events: auto;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.07) 0 4px, transparent 4px 10px),
    linear-gradient(160deg, #8da39c 0%, #6e847e 35%, #576c65 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -3px 6px rgba(0, 0, 0, 0.3),
    inset 2px 0 3px rgba(255, 255, 255, 0.2),
    inset -2px 0 3px rgba(0, 0, 0, 0.2),
    0 -2px 0 rgba(0, 0, 0, 0.55),
    0 12px 28px rgba(0, 0, 0, 0.6);
  /* Rest state is a hand-of-cards fan: each card tilts about a pivot below it */
  transform-origin: 50% 130%;
  transform: translate(-50%, -50%) rotate(var(--r));
  transition: transform 0.6s cubic-bezier(0.22, 0.8, 0.3, 1);
  will-change: transform;          /* own compositor layer: the shadow is painted once, not per frame */
}

/* Hover: the fan opens out flat; side cards sit one card width plus --gap either side of center, upright */
.papers.fanned .paper {
  transform: translate(calc(-50% + var(--spread, 0px)), -50%) rotate(0deg);
  /* The zoomed pose. Zooming grows the card upward too; a small downward shift (0.07 of its width)
     offsets most of that so it stays clear of the header. The origin stays at the fan pivot
     (80% of the card height, 1.12 widths, below center), so the shift also cancels the extra
     upward drift of scaling about that point: (zoom - 1) * 1.12 * width. */
  --zoomed: translate(calc(-50% + var(--spread, 0px)), calc(-50% + var(--w) * (0.07 + (var(--zoom) - 1) * 1.12))) rotate(0deg) scale(var(--zoom));
}
.papers.fanned .paper:nth-child(1) { --spread: calc(-1 * (var(--w) + var(--gap))); }
.papers.fanned .paper:nth-child(2) { --spread: 0px; }
.papers.fanned .paper:nth-child(3) { --spread: calc(var(--w) + var(--gap)); }

/* Zoom the card under a mouse pointer, the one holding keyboard focus (a click's focus must not
   stick), or, on touch, the one tapped once (.zoomed, set by js/papers.js; a second tap opens
   it). :hover only counts for real hover devices, since it sticks after a tap on touch screens. */
.papers.fanned .paper:focus-visible,
.papers.fanned .paper:has(:focus-visible),
.papers.fanned .paper.zoomed {
  z-index: 5;
  transform: var(--zoomed);
}

@media (hover: hover) {
  .papers.fanned .paper:hover {
    z-index: 5;
    transform: var(--zoomed);
  }
}

.papers.fanned .paper:focus-visible,
.papers.fanned .paper:has(:focus-visible) { z-index: 4; }
.papers.fanned .paper:hover { z-index: 5; }

.paper-slots {
  position: absolute;
  top: 8px;
  right: 30px;
  display: grid;
  gap: 3px;
  width: 44px;
}

.paper-slots i {
  display: block;
  height: 4px;
  border-radius: 2px;
  background: #2c3a36;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.35);
}

.paper-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 8px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.95),
    inset 0 0 0 1px rgba(0, 0, 0, 0.9),
    0 1px 0 rgba(255, 255, 255, 0.5);
}

.paper-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.paper-pages {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);   /* image width never sizes the column */
  align-content: start;
  gap: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  cursor: pointer;
  border-radius: 4px;
  scrollbar-width: thin;
  scrollbar-color: #576c65 #000;
}

.paper-pages img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  background: #fff;
}

/* Narrow screens: no fanning at all; the devices sit in a plain column and the page scrolls.
   (js/papers.js never fans while this query matches.) */
@media (max-width: 700px) {
  .papers {
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr);   /* the column is exactly the page width, never the content's */
    justify-items: center;
    gap: 1.5rem;
    min-width: 0;
    pointer-events: auto;
  }
  .paper,
  .papers.fanned .paper {
    position: relative;
    top: auto;
    left: auto;
    width: min(372px, 93%);     /* 7% smaller than the full column (400px / 100%) */
    min-width: 0;
    transform: none;
    will-change: auto;
  }
  .paper-screen, .paper-body { min-width: 0; }
  /* Let a swipe that reaches the end of a PDF carry on scrolling the page */
  .paper-pages { overscroll-behavior: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .paper { transition: none; }
}
