/* ==========================================================================
   Episode library (episodes/index.html) and episode pages (episodes/*.html).
   Pages are written by tools/build_episodes.py. Shared look comes from main.css;
   this file only adds the library grid, cards, filters, player and chapters.
   ========================================================================== */

/* Series accent, used on card labels and the eyebrow */
[data-series] { --accent: var(--cyan); }
[data-series="operators-manual"] { --accent: var(--amber); }
[data-series="ai-os"] { --accent: #7FBDF0; }
[data-series="ai-roundtable"] { --accent: var(--orange-hover); }
[data-series="could-you-should-you"] { --accent: #E6EEF6; }

/* ---------- Library hero and filters -------------------------------------- */
/* overflow stays visible so the glows fade into the grid below instead of ending in a hard edge (main clips sideways) */
.lib-hero { position: relative; isolation: isolate; padding: calc(var(--nav-h) + clamp(56px, 8vw, 120px)) 0 clamp(24px, 3vw, 40px); }
.lib-hero .h1 { margin-top: 22px; max-width: 1040px; }
.lib-hero .lede { margin-top: 26px; max-width: 660px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 40px; }
.filter {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid rgba(91, 212, 255, .28); background: rgba(10, 31, 61, .6);
  color: var(--body); font-size: 15px; font-weight: 700; cursor: pointer;
  transition: background var(--fast), border-color var(--fast), color var(--fast);
}
.filter:hover { border-color: rgba(91, 212, 255, .6); color: var(--white); }
.filter[aria-pressed="true"] { background: var(--cyan); border-color: var(--cyan); color: var(--navy-deep); }
.filter__n { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: rgba(91, 212, 255, .12); color: var(--slate); }
.filter[aria-pressed="true"] .filter__n { background: rgba(0, 24, 56, .16); color: var(--navy-deep); }
html:not(.js) .filters { display: none; }

/* ---------- Episode cards -------------------------------------------------- */
.ep-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(20px, 2vw, 28px); }
.lib-list { padding-top: clamp(24px, 3vw, 40px); }
.ep-card {
  display: flex; flex-direction: column; overflow: hidden; color: inherit;
  -webkit-backdrop-filter: none; backdrop-filter: none;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);
  transition: transform var(--fast) var(--ease), border-color var(--fast), box-shadow var(--fast);
}
.ep-card:hover { color: inherit; transform: translateY(-3px); border-color: rgba(91, 212, 255, .6); box-shadow: 0 24px 60px rgba(0, 0, 0, .45), 0 0 40px rgba(61, 155, 217, .16); }
.ep-card__thumb { position: relative; display: block; aspect-ratio: 16 / 9; overflow: hidden; background: var(--navy-card); border-bottom: 1px solid rgba(91, 212, 255, .14); }
/* hqdefault is 4:3 with letterbox bars; cover-cropping to 16:9 trims exactly the bars */
.ep-card__thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 600ms var(--ease); }
.ep-card:hover .ep-card__thumb img { transform: scale(1.04); }
.ep-card__play {
  position: absolute; right: 14px; bottom: 14px; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0, 15, 38, .78) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23fff' d='M9 7v10l8-5z'/%3E%3C/svg%3E") 55% 50% / 22px no-repeat;
  border: 1px solid rgba(255, 255, 255, .25); transition: background-color var(--fast);
}
.ep-card:hover .ep-card__play { background-color: var(--orange); }
.ep-card__body { display: flex; flex-direction: column; gap: 10px; flex: 1; padding: 20px 22px 22px; }
.ep-card__series .nw { white-space: nowrap; }
.ep-card__series { font-size: 12px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.ep-card__title { font-size: 19px; font-weight: 800; line-height: 1.3; letter-spacing: -.01em; color: var(--white); text-wrap: balance; }
.ep-card__date { margin-top: auto; padding-top: 4px; font-size: 14px; color: var(--slate); }

/* ---------- Episode page --------------------------------------------------- */
.ep-hero { position: relative; isolation: isolate; padding: calc(var(--nav-h) + clamp(32px, 4vw, 56px)) 0 clamp(32px, 4vw, 56px); }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 14px; color: var(--slate); }
.crumbs li { display: inline-flex; align-items: center; gap: 10px; }
.crumbs li + li::before { content: "/"; color: #4A6080; }
.crumbs a { color: var(--body); font-weight: 600; }
.crumbs a:hover { color: var(--white); }
.crumbs [aria-current] { color: var(--slate); }
.ep-eyebrow { margin-top: 28px; color: var(--accent); }
.ep-eyebrow:hover { color: var(--white); }
.ep-title { margin-top: 14px; max-width: 1080px; font-weight: 900; color: var(--white); font-size: clamp(34px, 4.2vw, 64px); line-height: 1.04; letter-spacing: -.03em; text-wrap: balance; }
.ep-meta { margin-top: 18px; font-size: 15px; color: var(--slate); font-weight: 500; }

.ep-stage { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(280px, 1fr); gap: clamp(20px, 2.4vw, 32px); margin-top: clamp(28px, 3.4vw, 44px); align-items: stretch; }
.player { aspect-ratio: 16 / 9; overflow: hidden; border-radius: var(--radius-lg); -webkit-backdrop-filter: none; backdrop-filter: none; background: #000; }
.player__facade { position: relative; display: block; width: 100%; height: 100%; }
.player__facade img { width: 100%; height: 100%; object-fit: cover; transition: transform 700ms var(--ease), filter var(--base); }
.player__facade::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(0, 15, 38, 0) 40%, rgba(0, 15, 38, .45) 100%); }
.player__play { position: absolute; left: 50%; top: 50%; z-index: 1; width: clamp(64px, 7vw, 92px); transform: translate(-50%, -50%); transition: transform var(--fast) var(--ease); filter: drop-shadow(0 8px 24px rgba(0, 0, 0, .5)); }
.player__play svg { width: 100%; height: auto; display: block; }
.player__bg { fill: var(--orange); transition: fill var(--fast); }
.player__facade:hover img { transform: scale(1.02); }
.player__facade:hover .player__play { transform: translate(-50%, -50%) scale(1.08); }
.player__facade:hover .player__bg, .player__facade:focus-visible .player__bg { fill: var(--orange-hover); }
.player__facade:focus-visible { outline-offset: -4px; }
.player iframe { display: block; width: 100%; height: 100%; border: 0; }

/* Chapters sit beside the player and never make the row taller than it */
.ep-chapters { display: flex; flex-direction: column; height: 0; min-height: 100%; padding: 22px 0 10px; -webkit-backdrop-filter: none; backdrop-filter: none; }
.ep-chapters__head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 24px 12px; border-bottom: 1px solid rgba(91, 212, 255, .14); }
.ep-chapters__head .label { color: var(--cyan); }
/* the list scrolls when it outgrows the player; the fade says there's more */
.ep-ch { list-style: none; overflow-y: auto; flex: 1; padding: 6px 10px 24px; -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(180deg, #000 calc(100% - 36px), transparent); scrollbar-width: thin; scrollbar-color: rgba(91, 212, 255, .3) transparent; }
.ep-ch a { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: baseline; padding: 10px 14px; border-radius: 10px; color: var(--body); transition: background var(--fast), color var(--fast); }
.ep-ch a:hover { background: rgba(91, 212, 255, .08); color: var(--white); }
.ep-ch__t { font-size: 14px; font-weight: 700; color: var(--cyan); font-variant-numeric: tabular-nums; }
.ep-ch__n { font-size: 15px; font-weight: 600; line-height: 1.4; }
.ep-chapters--none { padding: 28px; gap: 12px; justify-content: center; }

.ep-about { padding-top: clamp(8px, 2vw, 24px); }
.ep-split { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(280px, 1fr); gap: clamp(20px, 2.4vw, 32px); align-items: start; }
.ep-covers { max-width: 780px; }
.ep-covers .h3 { margin-top: 14px; }
.ep-covers > p { margin-top: 16px; font-size: 18px; line-height: 1.65; }
.prose .ep-covers__sub { margin-top: 36px; font-size: 13px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: var(--slate); }
.ep-covers .check-list { margin-top: 18px; padding-left: 0; }
.ep-covers .check-list li { margin-top: 0; color: var(--off-white); font-weight: 600; }
.ep-series { position: sticky; top: 96px; }
.ep-series .text-link { margin-top: 18px; }

.ep-rel__head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.ep-grid--rel { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ep-grid--rel .ep-card__title { font-size: 17px; }

.ep-cta__box { padding: clamp(28px, 3.4vw, 48px); }
.ep-cta__btns { justify-content: flex-end; }

/* ---------- Tablet and phone ---------------------------------------------- */
@media (max-width: 1100px) {
  .ep-grid, .ep-grid--rel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ep-stage, .ep-split { grid-template-columns: 1fr; }
  .ep-chapters { height: auto; min-height: 0; }
  .ep-ch { overflow: visible; padding-bottom: 6px; -webkit-mask-image: none; mask-image: none; }
  .ep-series { position: static; }
}

@media (max-width: 860px) {
  .section.ep-cta { padding: 56px 0 72px; }
  .ep-cta__btns { justify-content: stretch; flex-direction: column; align-items: stretch; }
}

@media (max-width: 640px) {
  .lib-hero .h1 { font-size: clamp(34px, 9.6vw, 48px); }
  /* One swipeable row of chips instead of five wrapped rows */
  .filters {
    flex-wrap: nowrap; gap: 8px; margin: 28px calc(var(--gutter) * -1) 0; padding: 2px var(--gutter) 6px;
    overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-inline: var(--gutter); scrollbar-width: none; -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent);
  }
  .filters::-webkit-scrollbar { display: none; }
  .filter { flex: 0 0 auto; scroll-snap-align: start; min-height: 42px; padding: 0 14px; font-size: 14px; white-space: nowrap; }
  .ep-grid, .ep-grid--rel { grid-template-columns: 1fr; gap: 14px; }
  /* Phone cards turn into compact rows: thumbnail left, text right */
  .ep-card { flex-direction: row; align-items: stretch; border-radius: 16px; }
  .ep-card__thumb { flex: 0 0 132px; aspect-ratio: auto; border-bottom: 0; border-right: 1px solid rgba(91, 212, 255, .14); }
  /* The tall row would show hqdefault's letterbox bars, so size the image off the
     row height: its 16:9 middle (75% of a 4:3 frame) fills the box, bars fall outside */
  .ep-card__thumb img { position: absolute; left: 50%; top: 50%; width: auto; height: 133.4%; max-width: none; object-fit: fill; transform: translate(-50%, -50%); }
  .ep-card:hover .ep-card__thumb img { transform: translate(-50%, -50%) scale(1.04); }
  .ep-card__play { width: 30px; height: 30px; right: 8px; bottom: 8px; background-size: 16px; }
  .ep-card__body { padding: 12px 14px; gap: 6px; }
  .ep-card__series { font-size: 10.5px; letter-spacing: .12em; }
  .ep-card__title, .ep-grid--rel .ep-card__title { font-size: 15px; line-height: 1.3; }
  .ep-card__date { font-size: 12.5px; padding-top: 0; }
  .ep-eyebrow { margin-top: 20px; font-size: 12px; letter-spacing: .16em; }
  .ep-title { font-size: clamp(28px, 8.4vw, 40px); }
  .ep-meta { font-size: 14px; }
  .player { border-radius: 14px; }
  .ep-chapters { padding: 18px 0 6px; }
  .ep-chapters__head { padding: 0 18px 10px; }
  .ep-ch { padding: 4px 4px; }
  .ep-ch a { grid-template-columns: 54px 1fr; gap: 8px; padding: 10px 12px; }
  .ep-ch__n { font-size: 14.5px; }
  .ep-covers > p { font-size: 16.5px; }
}
