@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono-700.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0a0e0a;
  --accent: #39ff6a;
  --soft: #a9d9b5;
  --muted: #6aa97f;
  --line: #2a9a48;
  --glitch-red: #ff2b6d;
  --glitch-cyan: #29ffe0;
  --edge: clamp(1rem, 2.5vw, 2.25rem);
  --top: clamp(1rem, 3vh, 2rem);
  --corner-h: 1.75rem;
  color-scheme: dark;
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  color: var(--accent);
  font-family: 'JetBrains Mono', 'Cascadia Mono', Consolas, ui-monospace, monospace;
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Faint grid, then CRT scanlines, over the whole page. */
body::before,
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

body::before {
  background-image:
    linear-gradient(rgb(57 255 106 / 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgb(57 255 106 / 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
}

body::after {
  background-image: repeating-linear-gradient(to bottom, transparent 0 2px, rgb(0 0 0 / 0.22) 2px 3px);
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Screen sequence (brief §6) */

.screens {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  display: grid;
  touch-action: pinch-zoom;
}

.screen {
  grid-area: 1 / 1;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: calc(var(--top) + var(--corner-h) + 1.5rem) var(--edge) 2rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.screen--current {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.corner {
  position: absolute;
  top: var(--top);
  left: var(--edge);
  margin: 0;
  font-size: 1.125rem;
  font-weight: 400;
  line-height: var(--corner-h);
}

.corner--prompt {
  font-size: 0.875rem;
  color: var(--soft);
}

/* Hero */

.hero {
  display: grid;
  justify-items: center;
  text-align: center;
}

.glitch {
  position: relative;
  isolation: isolate;
  margin: 0;
  color: var(--accent);
  font-size: clamp(4rem, 12vw, 9rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-shadow: 0 0 1.5rem rgb(57 255 106 / 0.35);
}

/* Colour channels sit behind the wordmark with a constant fringe, then snap
   to offset bands for a few frames near the end of each cycle. */
.glitch::before,
.glitch::after {
  content: attr(data-text);
  content: attr(data-text) / '';
  position: absolute;
  inset: 0;
  z-index: -1;
  text-shadow: none;
}

.glitch::before {
  color: var(--glitch-red);
  transform: translate(-0.025em, 0);
  animation: glitch-shift-1 2.6s steps(2, jump-none) infinite;
}

.glitch::after {
  color: var(--glitch-cyan);
  transform: translate(0.025em, 0);
  animation: glitch-shift-2 3.1s steps(2, jump-none) infinite;
}

@keyframes glitch-shift-1 {
  0%, 92%, 100% { transform: translate(-0.025em, 0); clip-path: inset(0); }
  93%           { transform: translate(-0.06em, 0);  clip-path: inset(10% 0 40% 0); }
  95%           { transform: translate(0.04em, 0);   clip-path: inset(60% 0 5% 0); }
  97%           { transform: translate(-0.03em, 0);  clip-path: inset(30% 0 30% 0); }
}

@keyframes glitch-shift-2 {
  0%, 90%, 100% { transform: translate(0.025em, 0);  clip-path: inset(0); }
  91%           { transform: translate(0.06em, 0);   clip-path: inset(5% 0 60% 0); }
  94%           { transform: translate(-0.04em, 0);  clip-path: inset(50% 0 10% 0); }
  98%           { transform: translate(0.03em, 0);   clip-path: inset(20% 0 40% 0); }
}

.tagline {
  margin: 1.25rem 0 0;
  font-size: clamp(1rem, 2.2vw, 1.375rem);
  font-weight: 700;
  text-wrap: balance;
}

.prompt {
  margin: 1.75rem 0 0;
  color: var(--soft);
}

.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1.15em;
  margin-left: 1ch;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: blink 1.06s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Chapters: copy column beside the frame, alternating sides (brief §2.2) */

.chapter {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 1fr;
  align-items: center;
  gap: clamp(2rem, 4vw, 4rem);
  max-width: 1400px;
  width: 100%;
  padding: 0 4rem;
}

.chapter--reverse {
  grid-template-columns: 1fr minmax(240px, 340px);
}

.chapter--reverse .chapter__copy { order: 2; }
.chapter--reverse .terminal-frame { order: 1; }

.chapter__copy {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chapter__copy p {
  margin: 0;
}

.chapter__eyebrow {
  color: var(--accent);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.8;
}

.chapter__copy p:not(.chapter__eyebrow) {
  color: var(--muted);
  line-height: 1.6;
  max-width: 32ch;
}

/* Last word + cursor never split, so the cursor can't wrap onto a line alone. */
.chapter__tail {
  white-space: nowrap;
}

.chapter__copy .cursor {
  margin-left: 0;
}

/* Phones and narrow portrait windows: stack copy above the frame. */
@media (max-width: 900px) and (orientation: portrait) {
  .chapter,
  .chapter--reverse {
    grid-template-columns: 1fr;
    gap: 1.25rem;
    padding: 0;
  }

  .chapter--reverse .chapter__copy { order: 0; }
}

.terminal-frame {
  justify-self: center;
  width: min(100%, 1320px);
  width: min(100%, 1320px, calc((100svh - var(--top) - var(--corner-h) - 6rem) * 1100 / 700));
  margin: 0;
  border: 1px solid var(--line);
  background: var(--bg);
}

.terminal-frame__bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.5rem;
  padding: 0 0.875rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.875rem;
}

.dot {
  width: 0.625rem;
  height: 0.625rem;
  border: 1px solid var(--accent);
  border-radius: 50%;
}

.terminal-frame__title {
  margin-left: 0.625rem;
}

.terminal-frame__img {
  display: block;
  width: 100%;
  height: auto;
}

.dots {
  position: fixed;
  top: var(--top);
  right: var(--edge);
  z-index: 10;
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  visibility: hidden;
}

.dot-btn {
  display: grid;
  place-items: center;
  width: var(--corner-h);
  height: var(--corner-h);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.dot-btn::before {
  content: '';
  width: 0.75rem;
  height: 0.75rem;
  border: 1px solid var(--accent);
  border-radius: 50%;
}

.dot-btn.on::before {
  background: var(--accent);
}

.dot-btn:focus-visible {
  outline-offset: 0;
}

/* Footer */

.screen--footer {
  padding-inline: 0;
  justify-items: stretch;
}

.site-footer {
  padding: clamp(3rem, 15vh, 9rem) var(--edge) 0;
  border-top: 1px solid var(--accent);
  text-align: center;
}

.repo {
  display: inline-grid;
  justify-items: center;
  gap: 1rem;
  color: var(--accent);
  font-size: clamp(1.125rem, 2.4vw, 1.75rem);
  font-weight: 700;
  text-decoration: none;
}

.repo__icon {
  width: 3.5rem;
  height: 3.5rem;
  fill: currentColor;
}

.repo:hover .repo__cmd {
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

/* Authorship line (brief §7): the quietest element on the page. */
.site-footer__colophon {
  color: var(--muted);
  font-size: 0.75rem;
  opacity: 0.65;
  margin: 1.5rem 0 0;
}

.site-footer__colophon a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-footer__colophon a:hover,
.site-footer__colophon a:focus-visible {
  color: var(--accent);
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .glitch::before,
  .glitch::after,
  .cursor {
    animation: none;
  }
}
