/* ==========================================================================
   The Programs -- the library beside the tenets
   Same type as tenets.css (Cardo body, Cormorant SC display, system-bold
   entries). The organ becomes an archive: one tape per program, piled on
   dark wood in earthy shelf colors. Click a tape to jump to its entry.
   ========================================================================== */

:root {
  --pg-bg: #0d0907;
  --pg-bg-soft: #17110d;
  --pg-ink: #ddd2bd;
  --pg-ink-bright: #f3e9d4;
  --pg-ink-dim: #9a8b70;
  --pg-rule: #33261c;
  --pg-gold: #c9a24a;
  --pg-wood-dark: #2a1a10;
  --pg-wood: #4a2f1c;
  --pg-wood-light: #6b452a;

}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--pg-bg);
  color: var(--pg-ink);
}

body {
  font-family: 'Cardo', Georgia, 'Times New Roman', serif;
  font-size: 18px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
  /* Lamplight from above, falling off into the stacks. */
  background:
    radial-gradient(ellipse 70% 45% at 50% 0%, rgba(201, 162, 74, 0.09), transparent 70%),
    radial-gradient(ellipse 90% 60% at 50% 30%, rgba(110, 63, 122, 0.07), transparent 75%),
    var(--pg-bg);
  background-attachment: fixed;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}


/* --- Header ---------------------------------------------------------- */

.programs-header {
  display: flex;
  align-items: center;
  padding: 20px 32px;
  border-bottom: 1px solid var(--pg-rule);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--pg-ink);
  text-decoration: none;
  font-family: 'Cormorant SC', serif;
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  transition: color 0.2s;
}
.back-link:hover { color: var(--pg-ink-bright); }
.back-link svg { display: block; }

/* --- Main layout ------------------------------------------------------ */

/* The archive and the shelves in full run the full screen width. The intro
   and footer keep the tenets' 1200px box, padded inside it. */
.programs-main {
  padding: 80px 0 120px;
}

.programs-intro,
.programs-footer {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 32px;
  padding-right: 32px;
}

/* --- Intro ------------------------------------------------------------- */

.programs-intro {
  text-align: center;
  margin-bottom: 64px;
}

.programs-title {
  font-family: 'Cormorant SC', serif;
  font-weight: 500;
  font-size: clamp(2.2rem, 4.4vw, 3.4rem);
  letter-spacing: 0.16em;
  color: var(--pg-ink-bright);
  margin: 0 0 10px;
  line-height: 1.1;
}

.programs-kicker {
  font-style: italic;
  font-size: 1.05rem;
  color: var(--pg-ink-dim);
  margin: 0 auto;
  max-width: 560px;
  letter-spacing: 0.02em;
}

/* --- The archive ------------------------------------------------------- */

.library {
  margin: 0 0 120px;
  padding: 0 clamp(16px, 3vw, 64px);
}

/* Stacks across the full width, bottom-aligned on their planks.
   Big screen: all six in one row. Laptop: three. Tablet portrait: two.
   Phone: one. */
.stacks {
  --stack-cols: 3;
  --stack-gap: clamp(24px, 2.4vw, 48px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 64px var(--stack-gap);
}

/* Each stack is a size container, so the tape type scales to the column
   and the longest title always fits on one line. */
.stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  /* Fixed share of the row, so a short last row centers instead of
     stretching. */
  flex: 0 0 calc((100% - (var(--stack-cols) - 1) * var(--stack-gap)) / var(--stack-cols));
  container-type: inline-size;
}

.stack-tapes {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0 6px;
}

.plank {
  height: 16px;
  border-radius: 2px;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.0) 0 11px, rgba(0,0,0,0.12) 11px 12px, rgba(0,0,0,0) 12px 29px, rgba(255,220,170,0.04) 29px 30px),
    linear-gradient(180deg, var(--pg-wood-light) 0%, var(--pg-wood) 35%, var(--pg-wood-dark) 100%);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 220, 170, 0.12);
}

.stack-label {
  margin: 18px 0 0;
  text-align: center;
  font-family: 'Cormorant SC', serif;
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  color: var(--pg-ink-dim);
  line-height: 1.2;
}

.stack-count {
  display: block;
  margin-top: 4px;
  font-size: 0.8rem;
  opacity: 0.6;
}

/* A tape: the end face of an oversized cartridge, lying flat in the pile.
   Grip ridges on the left, a label in the shelf color carrying the title,
   a reel window and a status light on the right. Each tape sits a little
   off true (--dx, --tilt) so the pile reads as handled. */
.tape {
  --c: var(--pg-gold);
  position: relative;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) 54px;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  /* Title size follows the stack's width; the tape's thickness follows the
     title. A title too long for one line makes a double tape (two lines,
     one and a half times as thick); programs.js decides which. */
  --tf: clamp(18px, calc(100cqi / 13), 26px);
  height: calc(var(--tf) * 2.3);
  margin-top: 3px;
  padding: 5px 8px 5px 6px;
  border: 1px solid #3a2b20;
  border-radius: 4px;
  cursor: pointer;
  color: var(--pg-ink-bright);
  text-align: left;
  font: inherit;
  background:
    linear-gradient(180deg, rgba(255, 230, 190, 0.07) 0%, rgba(255, 230, 190, 0) 30%, rgba(0, 0, 0, 0.35) 100%),
    linear-gradient(180deg, #241a13 0%, #15100c 100%);
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.08), 0 3px 6px rgba(0, 0, 0, 0.55);
  transform: translateX(var(--dx, 0px)) rotate(var(--tilt, 0deg));
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1), filter 0.2s, box-shadow 0.2s;
}

.tape-grip {
  border-radius: 2px;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,0.55) 0 2px, rgba(255,230,190,0.10) 2px 4px);
}

.tape-label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 0 10px;
  border-radius: 2px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--c) 90%, #fff 10%) 0 2px, transparent 2px),
    linear-gradient(180deg, color-mix(in srgb, var(--c) 58%, #0d0907 42%) 0%, color-mix(in srgb, var(--c) 40%, #0d0907 60%) 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.tape-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Cormorant SC', serif;
  font-weight: 600;
  font-size: var(--tf);
  letter-spacing: var(--tape-track, 0.1em);
  line-height: 1;
  padding-top: 1px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
}

.tape--double { height: calc(var(--tf) * 3.5); }

.tape--double .tape-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: normal;
  text-wrap: balance;
  line-height: 1.1;
  padding: 2px 0 0;
}

.tape-code {
  flex: 0 0 auto;
  font-family: 'Cormorant SC', serif;
  font-weight: 600;
  font-size: calc(var(--tf) * 0.62);
  letter-spacing: 0.06em;
  line-height: 1;
  padding-top: 2px;
  color: rgba(243, 233, 212, 0.7);
}

/* Reel window and status light. */
.tape-window {
  position: relative;
  border-radius: 2px;
  background:
    radial-gradient(circle at 34% 50%, #3a2c22 0 4px, #0a0706 4.5px 6px, transparent 6.5px),
    linear-gradient(180deg, #070504, #120d0a);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.08);
}

.tape-window::after {
  content: '';
  position: absolute;
  right: 7px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--c);
  opacity: 0.5;
  box-shadow: 0 0 6px var(--c);
  transition: opacity 0.2s;
}

.tape:hover,
.tape:focus-visible {
  transform: translateX(calc(var(--dx, 0px) + 18px)) rotate(0deg);
  filter: brightness(1.15);
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.1), 0 6px 18px rgba(0, 0, 0, 0.6), 0 0 16px color-mix(in srgb, var(--c) 40%, transparent);
  outline: none;
}
.tape:hover .tape-window::after,
.tape:focus-visible .tape-window::after { opacity: 1; }

.tape.pulled { transform: translateX(calc(var(--dx, 0px) + 30px)) rotate(0deg); filter: brightness(1.25); }
.tape.pulled .tape-window::after { opacity: 1; }

.library-legend {
  text-align: center;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--pg-ink-dim);
  margin: 48px 0 0;
}

/* --- Tape tooltip ------------------------------------------------------- */

.tape-tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  padding: 6px 12px;
  background: var(--pg-bg);
  border: 1px solid var(--shelf-color, var(--pg-rule));
  border-radius: 4px;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--pg-ink-bright);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease-out;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}
.tape-tooltip.visible { opacity: 1; }

/* --- Shelves in full (the tenets' chambers, re-dressed) ---------------- */

.shelves {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 80px clamp(48px, 5vw, 96px);
  padding: 0 clamp(16px, 3vw, 64px);
}

/* Two shelves side by side once each column has room for a full entry. */
@media (min-width: 1100px) {
  .shelves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.shelf {
  position: relative;
  padding-left: 32px;
  border-left: 1px solid var(--shelf-color, var(--pg-rule));
  scroll-margin-top: 40px;
}

.shelf-label {
  font-family: 'Cormorant SC', serif;
  font-weight: 600;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  letter-spacing: 0.18em;
  color: var(--pg-ink-bright);
  margin: 0 0 4px;
  line-height: 1;
}

.shelf-definition {
  font-style: italic;
  font-size: 1.05rem;
  color: var(--pg-ink-dim);
  margin: 0 0 32px;
  max-width: 620px;
}

.program {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 20px;
  padding: 20px 16px;
  border-top: 1px solid var(--pg-rule);
  border-radius: 4px;
  scroll-margin-top: 80px;
}
.program:first-of-type { border-top: none; padding-top: 8px; }

.program-code {
  font-family: 'Cormorant SC', serif;
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  padding-top: 2px;
  white-space: nowrap;
  color: color-mix(in srgb, var(--shelf-color) 70%, #fff 30%);
}

.program-name {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 1.32rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--pg-ink-bright);
  margin: 0;
}

.program-line {
  margin: 6px 0 0;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--pg-ink);
}
.program-line::before { content: '\201C'; }
.program-line::after { content: '\201D'; }

.program-meta {
  margin: 8px 0 0;
  font-family: 'Cormorant SC', serif;
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  color: var(--pg-ink-dim);
}

.program-note {
  margin: 8px 0 0;
  font-size: 0.98rem;
  color: var(--pg-ink-dim);
}

.program.flash {
  animation: programAnchorFlash 2.2s ease-out forwards;
}

@keyframes programAnchorFlash {
  0%   { background-color: rgba(255, 236, 200, 0.18); }
  30%  { background-color: rgba(255, 236, 200, 0.18); }
  100% { background-color: transparent; }
}

/* --- Footer ------------------------------------------------------------ */

.programs-footer {
  margin: 120px auto 0;
  padding-top: 40px;
  border-top: 1px solid var(--pg-rule);
  text-align: center;
}

.footer-note {
  font-family: 'Cormorant SC', serif;
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  color: var(--pg-ink-dim);
  margin: 0;
}

/* --- Motion ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .tape { transition: none; }
  .program.flash { animation: none; background-color: rgba(255, 236, 200, 0.12); }
}

/* --- Narrow ------------------------------------------------------------ */

@media (min-width: 1800px) {
  .stacks { --stack-cols: 6; }
}

@media (max-width: 1099px) {
  .stacks { --stack-cols: 2; }
}

@media (max-width: 640px) {
  .stacks { --stack-cols: 1; }
}

@media (min-width: 1800px) {
  .library, .shelves { padding: 0 24px; }
  .stacks { --stack-gap: 20px; }
}

/* Narrow stacks (six across, tablet, phone): slimmer chrome, the code moves
   to the tooltip, and tighter tracking, so the longest title holds its size. */
@container (max-width: 380px) {
  .tape {
    --tape-track: 0.08em;
    grid-template-columns: 8px minmax(0, 1fr) 34px;
    gap: 6px;
    padding-right: 6px;
  }
  .tape-label { padding: 0 8px; }
  .tape-code { display: none; }
  .tape-window::after { right: 5px; width: 5px; height: 5px; margin-top: -2.5px; }
  .tape-window { background:
    radial-gradient(circle at 30% 50%, #3a2c22 0 3px, #0a0706 3.5px 5px, transparent 5.5px),
    linear-gradient(180deg, #070504, #120d0a); }
}

@media (max-width: 640px) {
  .programs-header { padding: 16px; }
  .programs-main { padding: 48px 0 80px; }
  .programs-intro, .programs-footer { padding-left: 16px; padding-right: 16px; }
  .library { margin-bottom: 72px; }
  .stacks { row-gap: 48px; }
  .shelves { gap: 56px; }
  .shelf { padding-left: 20px; }
  .program { grid-template-columns: 52px 1fr; gap: 14px; padding: 16px 10px; }
  .program-name { font-size: 1.1rem; }
}
