/* ===================== TERMINAL — living console ========================== */
/* Phosphor palette: ink-teal. Space Mono / DM Mono throughout.              */
/* All colour via tokens — reads as paper-terminal on light palettes too.    */

/* ── Root & phosphor scanline texture (pure CSS, very restrained) ── */

.pg-terminal {
  font-family: 'Space Mono', var(--font-mono);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    color-mix(in srgb, var(--ink) 2%, transparent) 3px,
    color-mix(in srgb, var(--ink) 2%, transparent) 4px
  );
}

/* ── Session titlebar ── */

.pg-terminal .tm-session {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem clamp(1rem, 3cqw, 1.8rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-titlebar {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-width: 0;
  overflow: hidden;
}

.pg-terminal .tm-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}
/* Hard-coded macOS traffic-light colours — intentional brand element, not palette */
.pg-terminal .tm-dot-r { background: #ff5f57; }
.pg-terminal .tm-dot-y { background: #febc2e; }
.pg-terminal .tm-dot-g { background: #28c840; }

.pg-terminal .tm-session-label {
  font: 400 11px/1 'Space Mono', var(--font-mono);
  color: var(--muted);
  letter-spacing: .03em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pg-terminal .tm-logo {
  max-height: 30px;
  flex-shrink: 0;
  opacity: .85;
}

/* ── Shared prompt motif ── */

.pg-terminal .tm-prompt {
  font: 400 12px/1.5 'Space Mono', var(--font-mono);
  color: var(--muted);
  letter-spacing: .02em;
  margin-bottom: .5rem;
}

.pg-terminal .tm-ps1 {
  color: var(--accent);
  font-weight: 700;
}

.pg-terminal .tm-path {
  font: 400 10px/1 'Space Mono', var(--font-mono);
  color: color-mix(in srgb, var(--accent) 70%, var(--muted));
  letter-spacing: .04em;
  margin-bottom: .5rem;
  opacity: .8;
}

/* Section output header — "## name (N results)" */
.pg-terminal .tm-out-head {
  font: 700 11px/1.5 'Space Mono', var(--font-mono);
  color: var(--accent);
  letter-spacing: .04em;
  text-shadow: 0 0 18px color-mix(in srgb, var(--accent) 40%, transparent);
  margin: .4rem 0 .8rem;
}

/* ── Identity / typewriter name ── */

.pg-terminal .tm-identity {
  padding: clamp(3rem, 8cqw, 5.4rem) clamp(1rem, 3.4cqw, 2.4rem) clamp(2.4rem, 6cqw, 4rem);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-name-wrap {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  margin: 1rem 0 1.4rem;
}

/* CSS typewriter: width 0 → calc(N * 1ch) in N steps.                       */
/* 1ch = advance width of '0' in Space Mono — exactly one character wide.    */
/* --len is set via inline style from JS (name.length). Default 20 fallback. */
.pg-terminal h1.tm-name {
  --len: 20;
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  vertical-align: bottom;
  max-width: 100%;
  font: 400 clamp(2.6rem, 9.5cqw, 6rem)/1 'Space Mono', var(--font-mono);
  letter-spacing: -.02em;
  color: var(--ink);
  text-shadow: 0 0 40px color-mix(in srgb, var(--accent) 26%, transparent);
  /* Animation */
  width: 0;
  animation-name: tm-type;
  animation-duration: calc(var(--len) * 65ms);
  animation-timing-function: steps(var(--len), end);
  animation-delay: .6s;
  animation-fill-mode: both;
}

@keyframes tm-type {
  to { width: calc(var(--len, 20) * 1ch); }
}

/* Blinking block caret — phosphor glow */
.pg-terminal .tm-caret {
  display: inline-block;
  width: .55em;
  height: clamp(2rem, 7.4cqw, 4.6rem);
  background: var(--accent);
  vertical-align: bottom;
  margin-left: .05em;
  flex-shrink: 0;
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 55%, transparent);
  animation: tm-blink 1.1s step-end infinite;
}

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

/* Reduced-motion: skip animation, show full name immediately */
@media (prefers-reduced-motion: reduce) {
  .pg-terminal h1.tm-name {
    width: calc(var(--len, 20) * 1ch);
    max-width: 100%;
    animation: none;
  }
  .pg-terminal .tm-caret { animation: none; }
}

.pg-terminal .tm-tagline {
  font: 400 12px/1.65 'Space Mono', var(--font-mono);
  color: var(--muted);
  letter-spacing: .04em;
  max-width: 68ch;
  margin-top: .4rem;
}

.pg-terminal .tm-cmt {
  color: var(--accent);
  opacity: .5;
  margin-right: .3em;
}

/* ── Status bar ── */

.pg-terminal .tm-status {
  padding: clamp(2rem, 5cqw, 3.4rem) clamp(1rem, 3.4cqw, 2.4rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-stat-row {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  margin-top: .6rem;
  overflow: hidden;
}

.pg-terminal .tm-stat {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding: 1.1rem clamp(.8rem, 2cqw, 1.6rem);
  border-right: 1px solid var(--line);
  min-width: 0;
}

.pg-terminal .tm-stat:last-child { border-right: 0; }

.pg-terminal .tm-stat b {
  font: 700 clamp(1.6rem, 4.4cqw, 2.6rem)/1 'Space Mono', var(--font-mono);
  color: var(--accent);
  text-shadow: 0 0 22px color-mix(in srgb, var(--accent) 45%, transparent);
  letter-spacing: -.02em;
}

.pg-terminal .tm-stat span {
  font: 400 9px/1 'Space Mono', var(--font-mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Bio ── */

.pg-terminal .tm-bio {
  padding: clamp(2.4rem, 6cqw, 4rem) clamp(1rem, 3.4cqw, 2.4rem);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-output p {
  font: 400 clamp(.82rem, 1.7cqw, .96rem)/1.82 'Space Mono', var(--font-mono);
  color: var(--ink);
  max-width: 72ch;
  margin-top: .6rem;
}

/* ── Hero image — framed preview ── */

.pg-terminal .tm-hero-img {
  padding: clamp(1.8rem, 4.5cqw, 3rem) clamp(1rem, 3.4cqw, 2.4rem);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-hero-frame {
  border: 1px solid var(--line);
  overflow: hidden;
  margin-top: .4rem;
}

.pg-terminal .tm-hero-frame img {
  width: 100%;
  max-height: clamp(280px, 48cqh, 520px);
  object-fit: cover;
  display: block;
  filter: saturate(.9) contrast(1.04);
  transition: filter .3s ease;
}

.pg-terminal .tm-hero-frame:hover img {
  filter: saturate(1.02) contrast(1.07);
}

/* ── Productions — ASCII tree ── */

.pg-terminal .tm-productions {
  padding: clamp(2.4rem, 6cqw, 4rem) clamp(1rem, 3.4cqw, 2.4rem);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-tree-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-bottom: 0;
}

.pg-terminal .tm-line {
  display: grid;
  grid-template-columns: 2ch 3.5ch 1fr;
  gap: .6rem;
  align-items: center;
  min-height: 42px;
  padding: .45rem 1rem;
  border-bottom: 1px solid var(--line);
  font: 400 12px/1.4 'Space Mono', var(--font-mono);
  color: var(--ink);
  transition: background .12s ease, color .12s ease;
}

.pg-terminal .tm-line:hover {
  background: var(--accent);
  color: var(--bg);
}

.pg-terminal .tm-tree {
  color: var(--accent);
  font-size: 14px;
  user-select: none;
  transition: color .12s ease;
}

.pg-terminal .tm-line:hover .tm-tree {
  color: var(--bg);
}

.pg-terminal .tm-num {
  font: 400 9px/1 'Space Mono', var(--font-mono);
  color: var(--muted);
  letter-spacing: .06em;
  transition: color .12s ease;
}

.pg-terminal .tm-line:hover .tm-num {
  color: color-mix(in srgb, var(--bg) 70%, transparent);
}

/* Shared "+N more" / continuation line */
.pg-terminal .tm-more {
  font: 400 10px/1 'Space Mono', var(--font-mono);
  letter-spacing: .06em;
  color: var(--muted);
  padding: .6rem 1rem;
  border: 1px solid var(--line);
  border-top: 0;
  margin: 0;
}

/* ── Tracks — playlist queue ── */

.pg-terminal .tm-tracks {
  padding: clamp(2.4rem, 6cqw, 4rem) clamp(1rem, 3.4cqw, 2.4rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

/* Override shared track styles to stay in mono voice */
.pg-terminal .tm-queue .track-row {
  font-family: 'Space Mono', var(--font-mono);
}

.pg-terminal .tm-queue .track-row strong {
  font-family: 'Space Mono', var(--font-mono);
  font-weight: 400;
}

/* ── YouTube reel ── */

.pg-terminal .tm-reel-wrap {
  padding: clamp(2rem, 5cqw, 3.4rem) clamp(1rem, 3.4cqw, 2.4rem);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-yt {
  border: 1px solid var(--line);
  margin-top: .5rem;
}

/* ── Image gallery — terminal preview grid ── */

.pg-terminal .tm-gallery {
  padding: clamp(2.4rem, 6cqw, 4rem) clamp(1rem, 3.4cqw, 2.4rem);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-img-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: .6rem;
}

.pg-terminal .tm-frame {
  display: grid;
  gap: 4px;
}

.pg-terminal .tm-frame img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border: 1px solid var(--line);
  filter: saturate(.85) contrast(1.05);
  transition: filter .2s ease, border-color .2s ease;
}

.pg-terminal .tm-frame:hover img {
  filter: saturate(1.05) contrast(1.08);
  border-color: var(--accent);
}

.pg-terminal .tm-frame figcaption {
  font: 400 8px/1 'Space Mono', var(--font-mono);
  color: var(--muted);
  letter-spacing: .04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Extra columns: works / publishers / territories ── */

.pg-terminal .tm-extra {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}

.pg-terminal .tm-extra-col {
  padding: clamp(2rem, 5cqw, 3.2rem) clamp(1rem, 3.4cqw, 2.4rem);
  border-right: 1px solid var(--line);
}

.pg-terminal .tm-extra-col:last-child { border-right: 0; }

.pg-terminal .tm-col-head {
  font: 700 11px/1 'Space Mono', var(--font-mono);
  color: var(--accent);
  letter-spacing: .06em;
  margin: 0 0 1rem;
  text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 35%, transparent);
}

.pg-terminal .tm-extra-col ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pg-terminal .tm-extra-col li {
  display: grid;
  grid-template-columns: 1ch 1fr;
  gap: .6rem;
  align-items: baseline;
  padding: .45rem 0;
  border-bottom: 1px solid var(--line);
  font: 400 11px/1.4 'Space Mono', var(--font-mono);
  color: var(--ink);
}

.pg-terminal .tm-extra-col li::before {
  content: '>';
  color: var(--accent);
  opacity: .55;
  font-size: 10px;
}

/* ── Footer ── */

.pg-terminal .tm-foot {
  padding: clamp(2.4rem, 6cqw, 4rem) clamp(1rem, 3.4cqw, 2.4rem);
  background: var(--surface);
}

.pg-terminal .tm-exit {
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2rem;
}

.pg-terminal .tm-contact {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem 1.6rem;
  margin-top: 1rem;
  font: 400 12px/1.5 'Space Mono', var(--font-mono);
  font-style: normal;
}

.pg-terminal .tm-contact a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  transition: text-decoration-color .15s ease;
}

.pg-terminal .tm-contact a:hover {
  text-decoration-color: var(--accent);
}

.pg-terminal .tm-soc {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem 1.4rem;
  margin-top: 1.2rem;
}

/* ── Container queries ── */

@container page (max-width: 620px) {
  .pg-terminal .tm-img-grid { grid-template-columns: repeat(3, 1fr); }
  .pg-terminal .tm-extra { grid-template-columns: 1fr; }
  .pg-terminal .tm-extra-col { border-right: 0; border-bottom: 1px solid var(--line); }
  .pg-terminal .tm-extra-col:last-child { border-bottom: 0; }
  .pg-terminal .tm-line { gap: .4rem; }
}

@container page (max-width: 390px) {
  .pg-terminal .tm-stat-row { flex-direction: column; }
  .pg-terminal .tm-stat { border-right: 0; border-bottom: 1px solid var(--line); }
  .pg-terminal .tm-stat:last-child { border-bottom: 0; }
  .pg-terminal .tm-img-grid { grid-template-columns: repeat(2, 1fr); }
  .pg-terminal .tm-line { grid-template-columns: 2ch 1fr; padding: .4rem .6rem; }
  .pg-terminal .tm-num { display: none; }
  .pg-terminal .tm-session-label { display: none; }
}

/* ══════════════════════════════════════════════════════════════
   TERMINAL: motion polish
   ══════════════════════════════════════════════════════════════ */

/* ── Selection colour ──────────────────────────────────────────── */

.pg-terminal ::selection {
  background: var(--accent);
  color: var(--bg);
}

/* ── 1 · Scanline drift — CRT step-shift, 10 s period ─────────── */

@keyframes tm-scan-drift {
  from { background-position: 0 0; }
  to   { background-position: 0 4px; }
}

@media (prefers-reduced-motion: no-preference) {
  /* 4 discrete 1 px steps over 10 s mirrors a real raster refresh */
  .pg-terminal {
    background-position: 0 0;
    animation: tm-scan-drift 10s steps(4, end) infinite;
  }
}

/* ── 2 · Row hover: selection-highlight sweeps from the left ───── */

/* ::before provides the fill so we can slide it in instead of
   flashing background instantly */
.pg-terminal .tm-line {
  position: relative;
  overflow: hidden;
}

.pg-terminal .tm-line::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  pointer-events: none;
  z-index: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .pg-terminal .tm-line::before {
    transition: transform .19s cubic-bezier(.4, 0, .2, 1);
  }
}

/* Sweep in; remove the direct background so ::before owns the fill */
.pg-terminal .tm-line:hover { background: transparent; }
.pg-terminal .tm-line:hover::before { transform: scaleX(1); }

/* Keep text grid children above the sweep layer */
.pg-terminal .tm-line > * { position: relative; z-index: 1; }

/* ── 3 · Per-line output stagger when .tm-productions enters view ─ */

@media (prefers-reduced-motion: no-preference) {
  .stage.animate .pg-terminal .tm-tree-list .tm-line {
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity .22s ease, transform .22s cubic-bezier(.2,.7,.2,1);
  }
  .stage.animate .pg-terminal .tm-productions.in .tm-tree-list .tm-line {
    opacity: 1;
    transform: none;
  }
  /* 20 lines × 30 ms = 600 ms total — snappy typewriter cadence */
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(1)  { transition-delay:  30ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(2)  { transition-delay:  60ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(3)  { transition-delay:  90ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(4)  { transition-delay: 120ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(5)  { transition-delay: 150ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(6)  { transition-delay: 180ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(7)  { transition-delay: 210ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(8)  { transition-delay: 240ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(9)  { transition-delay: 270ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(10) { transition-delay: 300ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(11) { transition-delay: 330ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(12) { transition-delay: 360ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(13) { transition-delay: 390ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(14) { transition-delay: 420ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(15) { transition-delay: 450ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(16) { transition-delay: 480ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(17) { transition-delay: 510ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(18) { transition-delay: 540ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(19) { transition-delay: 570ms; }
  .stage.animate .pg-terminal .tm-productions.in .tm-line:nth-child(20) { transition-delay: 600ms; }
}

/* ── xsec flex zone — terminal voice ────────────────────────────────────── */
.pg-terminal .tm-sections-wrap {
  padding: clamp(2rem, 6cqw, 3.4rem) clamp(1rem, 5cqw, 2.4rem) 0;
}
.pg-terminal .xsec-zone {
  padding: 1.2rem 0 0;
  gap: 1.8rem;
}
.pg-terminal .xsec-h {
  font-family: 'Space Mono', var(--font-mono);
  font-size: clamp(1rem, 2.8cqw, 1.35rem);
  font-weight: 400;
  color: var(--accent);
  border: none;
  padding: 0;
}
.pg-terminal .xsec-h::before { content: '## '; opacity: .55; }
.pg-terminal .xsec-title {
  font-family: 'Space Mono', var(--font-mono);
  font-size: .72rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}
.pg-terminal .xsec-title::before { content: '### '; opacity: .55; }
.pg-terminal .xsec-list li,
.pg-terminal .xsec-text p {
  font-family: 'Space Mono', var(--font-mono);
  font-size: .82rem;
  line-height: 1.7;
}
