/* Pause anywhere — page styles, after the psychoscript website (warm paper, ink outlines, hard offset shadows,
   pink / teal / orange / yellow). Light mode only. Tokens first; demos should use these instead of raw values. */

:root {
  color-scheme: light;

  /* color */
  --paper: #f9eed6; /* page */
  --paper-2: #f6e3bd; /* cards, figure stages (the site's cream) */
  --paper-3: #efd39e; /* pressed, hover fills */
  --ink: #1d1614; /* text and every outline */
  --ink-2: #4a3a30; /* secondary text */
  --ink-3: #7d6a55; /* captions, labels */
  --ink-4: #b19c7f; /* faint marks, disabled */
  --rule: rgb(29 22 20 / 0.16); /* hairlines */
  --accent: #c44d0c; /* readable orange for text on paper */
  --accent-soft: rgb(242 106 33 / 0.18);
  --orange: #f26a21;
  --yellow: #f9bb2d;
  --pink: #ee5a8f;
  --teal: #1fa7a0;
  --mint: #6cc7b6;
  --green: #7cb83a;
  --purple: #7b3fa6;
  --ok: #138a7e; /* status: running */
  --warn: #c44d0c; /* status: paused */
  --err: #b4232a; /* status: error */

  /* type */
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --serif: var(--sans); /* kept for older demo code; the page is set in --sans */
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --text-size: 1.125rem; /* 18px */
  --leading: 1.65;
  --small: 0.875rem;
  --tiny: 0.75rem;

  /* layout */
  --column: 640px; /* text column */
  --wide: 960px; /* demo figures break out to this */
  --gutter: 22px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 40px;
  --space-7: 64px;
  --radius: 14px;
  --radius-sm: 8px;
  --line: 2.5px; /* the ink outline */
  --shadow: 5px 5px 0 var(--ink);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-pop: cubic-bezier(0.2, 0.9, 0.3, 1.25);
}

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

[hidden] {
  display: none !important;
}

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  position: relative;
  margin: 0;
  color: var(--ink);
  font: 500 var(--text-size) / var(--leading) var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* The paper's grain, as on the psychoscript site. */
body::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("art/paper.svg");
  mix-blend-mode: multiply;
  opacity: 0.2;
  pointer-events: none;
  z-index: 50;
}

::selection {
  background: var(--yellow);
  color: var(--ink);
}

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

/* --- the header: stickers in the corners, a plain title --- */

.masthead {
  position: relative;
  overflow: hidden;
  padding: clamp(120px, 16vw, 176px) var(--gutter) clamp(64px, 8vw, 96px);
  border-bottom: 3px solid var(--ink);
  text-align: center;
}
.masthead__sky,
.masthead__sun,
.masthead__flower {
  position: absolute;
  height: auto;
  pointer-events: none;
  user-select: none;
}
.masthead__sky {
  left: clamp(-6px, 0.6vw, 18px);
  top: clamp(4px, 1.4vw, 22px);
  width: clamp(210px, 24vw, 330px);
}
.masthead__sun {
  right: -70px;
  bottom: -80px;
  width: clamp(170px, 24vw, 330px);
  animation: sun-turn 60s linear infinite;
}
.masthead__flower {
  left: -44px;
  bottom: -56px;
  width: clamp(110px, 14vw, 200px);
  animation: flower-sway 7s ease-in-out infinite;
  transform-origin: 50% 80%;
}
@keyframes sun-turn {
  to {
    rotate: 360deg;
  }
}
@keyframes flower-sway {
  50% {
    rotate: 8deg;
  }
}
.masthead h1 {
  position: relative;
  max-width: 14em;
  margin: 0 auto;
  font-size: clamp(2.2rem, 6vw, 4rem);
  font-weight: 800;
  line-height: 1.04;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.masthead .subtitle {
  position: relative;
  max-width: 26em;
  margin: var(--space-5) auto 0;
  color: var(--ink-2);
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  font-weight: 600;
  line-height: 1.4;
  text-wrap: balance;
}
.masthead .byline {
  position: relative;
  margin: var(--space-5) 0 0;
  color: var(--ink-3);
  font-size: var(--small);
}

/* --- page grid: everything sits in the text column; .wide and .demo break out --- */

.essay {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--gutter), 1fr)
    [wide-start] minmax(0, calc((var(--wide) - var(--column)) / 2))
    [text-start] min(var(--column), 100% - 2 * var(--gutter))
    [text-end] minmax(0, calc((var(--wide) - var(--column)) / 2))
    [wide-end] minmax(var(--gutter), 1fr)
    [full-end];
  padding-block: var(--space-7) 40px;
}

.essay > * {
  grid-column: text;
}

.essay > .wide,
.essay > .demo {
  grid-column: wide;
}

/* --- text --- */

.essay p {
  margin: 0 0 1.15em;
  text-wrap: pretty;
}

h2 {
  margin: var(--space-7) 0 var(--space-4);
  font-size: clamp(1.7rem, 3.4vw, 2.4rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.eyebrow {
  margin: var(--space-7) 0 0 !important;
  color: var(--accent);
  font-size: var(--tiny);
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.eyebrow + h2 {
  margin-top: var(--space-2);
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--orange);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
a:hover {
  background: var(--yellow);
}

em {
  font-style: italic;
}

code {
  padding: 0.08em 0.36em;
  border-radius: 4px;
  background: rgb(29 22 20 / 0.08);
  font: 600 0.86em/1.3 var(--mono);
}

kbd,
.kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 0.4em;
  border: 1.5px solid var(--ink);
  border-radius: 5px;
  box-shadow: 0 2px 0 var(--ink);
  background: var(--paper-2);
  font: 700 0.78em/1.5 var(--mono);
  text-align: center;
}

.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-7);
  padding-top: var(--space-6);
  border-top: 3px solid var(--ink);
  color: var(--ink-2);
  font-size: var(--small);
  text-align: center;
}
.footer .wordmark {
  display: block;
  width: min(240px, 60vw);
  height: auto;
  transition: rotate 0.3s var(--ease-pop), scale 0.3s var(--ease-pop);
}
.footer a:hover {
  background: none;
}
.footer a:hover .wordmark {
  rotate: -3deg;
  scale: 1.05;
}
.essay .footer p {
  margin: 0;
}

/* --- demos --- */

.demo {
  position: relative;
  margin: var(--space-6) 0 var(--space-6);
}

.demo-placeholder {
  display: grid;
  place-items: center;
  min-height: 220px;
  margin: 0;
  border: var(--line) dashed var(--ink-4);
  border-radius: var(--radius);
  color: var(--ink-3);
  font: 600 var(--small) var(--mono);
}

.demo-stage {
  position: relative;
  overflow: hidden;
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: var(--shadow);
}

.demo-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.demo-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin-top: var(--space-4);
  font: 600 var(--small) var(--sans);
}
.demo-controls .spacer {
  flex: 1;
}

.demo-panel {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper-2);
}

.demo-caption {
  margin: var(--space-5) 0 0 !important;
  color: var(--ink-2);
  font-size: var(--small);
  line-height: 1.55;
}
.demo-caption b,
.demo-caption strong {
  color: var(--ink);
  font-weight: 800;
}

.demo-error {
  margin: 0;
  color: var(--err);
  font: 600 var(--small) / 1.5 var(--mono);
  white-space: pre-wrap;
}

/* Pill buttons, as on the psychoscript site: dark ones, cream ones, all inked. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 20px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--paper-2);
  box-shadow: 0 3px 0 var(--ink);
  color: var(--ink);
  font: 800 15px/1 var(--sans);
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, color 0.15s, translate 0.12s, box-shadow 0.12s;
}
.btn:hover {
  background: var(--yellow);
  translate: 0 -1px;
  box-shadow: 0 4px 0 var(--ink);
}
.btn:active {
  translate: 0 2px;
  box-shadow: 0 1px 0 var(--ink);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
  translate: none;
  box-shadow: 0 3px 0 var(--ink);
  background: var(--paper-2);
}
.btn-primary {
  background: var(--ink);
  color: var(--paper-2);
}
.btn-primary:hover {
  background: var(--orange);
  color: var(--ink);
}
.btn-accent {
  background: var(--pink);
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--ink-2);
}
.btn-ghost:hover {
  border-color: var(--ink);
  background: var(--paper-2);
  box-shadow: 0 3px 0 var(--ink);
}
.btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.label {
  color: var(--accent);
  font: 800 var(--tiny) / 1.2 var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stat {
  color: var(--ink-2);
  font: 600 var(--small) / 1.4 var(--mono);
  font-variant-numeric: tabular-nums;
}

.stat-accent {
  color: var(--ink);
  font-weight: 800;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px 0 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font: 700 var(--tiny) / 1 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.status::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--ink-4);
}
.status[data-status="playing"]::before,
.status[data-status="live"]::before {
  background: var(--mint);
  animation: pulse 1.4s ease-in-out infinite;
}
.status[data-status="paused"]::before {
  background: var(--yellow);
}
.status[data-status="error"]::before {
  background: var(--err);
}
.status[data-status="done"]::before {
  background: var(--pink);
}
@keyframes pulse {
  50% {
    scale: 0.7;
  }
}

.hexdump {
  margin: 0;
  overflow-x: auto;
  color: var(--ink-2);
  font: 500 11.5px/1.6 var(--mono);
  white-space: pre;
}
.hexdump .offset {
  color: var(--ink-4);
}
.hexdump .ascii {
  color: var(--accent);
}

.demo-code {
  margin: 0;
  padding: var(--space-4) var(--space-4);
  overflow-x: auto;
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: #f6e3bd;
  font: 500 13px/1.6 var(--mono);
  tab-size: 2;
  white-space: pre;
}
.demo-code .comment {
  color: #a8957c;
  font-style: italic;
}
.demo-code .kw {
  color: var(--pink);
}
.demo-code .num {
  color: var(--yellow);
}
.demo-code .fn {
  color: var(--mint);
}
.demo-code .hl {
  border-radius: 3px;
  background: var(--yellow);
  color: var(--ink);
}

.muted {
  color: var(--ink-3);
}
.accent {
  color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 640px) {
  :root {
    --text-size: 1.0625rem;
    --radius: 12px;
  }
  .masthead__sky {
    width: 170px;
  }
  .masthead__sun {
    right: -46px;
    bottom: -52px;
    width: 140px;
  }
  .masthead__flower {
    left: -30px;
    bottom: -36px;
    width: 96px;
  }
  .btn {
    height: 40px;
    padding: 0 16px;
  }
}

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

/* Keyboard hints only where there's likely a keyboard. */
@media (hover: none) {
  .kbd-hint {
    display: none;
  }
}
