/*
 * Tafrah web app system — listening pages (WEB_APP_PLAN.md, step W5).
 * Home, discover, search, show, episode and the expanded player, composed
 * from the shared components in system.css. Same `system` layer.
 */
@layer system {
  /* ------------------------------- home -------------------------------- */
  /* Sections are separated by space, not rules. */
  .editorial-page .sheet > .section {
    border: 0;
    padding-block-start: 0;
  }

  .editorial-page .sheet {
    gap: var(--page-gap);
  }

  .home-page .home-masthead .greeting {
    font-size: var(--fs-title);
    line-height: var(--lh-title);
    letter-spacing: -0.01em;
  }

  .home-page .home-masthead .hero-search {
    min-height: 2.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--subtle);
    padding-inline: var(--space-4);
  }

  .home-page .home-masthead .hero-search svg {
    color: var(--subtle);
  }

  .mobile-header .icon-button {
    border: 0;
    background: var(--surface-raised);
    color: var(--text);
  }

  /*
   * The lead card wears its artwork's colour (src/tint.js sets --tint-*).
   * The gradient is darkest behind the text; tint.js caps the luminance of
   * --tint-mid so white text keeps at least 7:1 on any hue. Without a tint
   * (demo, generated or failed artwork) the card stays brand navy.
   */
  .editorial-page .editorial-feature {
    --feature-muted: rgb(255 255 255 / 76%);
    --feature-accent: #ffb4a3;
    position: relative;
    isolation: isolate;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius-xl);
    background: radial-gradient(
      120% 140% at 12% 0%,
      var(--tint-mid, #1f3566) 0%,
      var(--tint-deep, #111b30) 58%,
      #080b11 100%
    );
    box-shadow: var(--shadow-sm);
    color: #fff;
  }

  .editorial-feature__label {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    gap: var(--space-2);
    color: var(--feature-accent);
    font-size: var(--fs-12);
    font-weight: 700;
  }

  .editorial-feature__label::before {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: currentColor;
    content: '';
  }

  .editorial-feature__art .cover-frame {
    border-radius: var(--radius-lg);
    box-shadow: 0 30px 60px -24px rgb(0 0 0 / 80%);
  }

  .editorial-page .editorial-feature h2,
  .editorial-page.discover-page .discover-lead h3 {
    font-size: clamp(1.25rem, 1rem + 1vi, 1.75rem);
  }

  /* The lead title's link takes the heading size; it stays a 44px target without moving play down. */
  .editorial-page.discover-page .discover-lead h3 button {
    padding-block: 0.5rem;
    margin-block: -0.5rem;
    font-size: inherit;
    font-weight: 700;
  }

  /* Short phones keep play above the tab bar. */
  @media (max-width: 39.99rem) and (max-height: 48rem) {
    .editorial-page.discover-page .discover-lead h3 {
      font-size: var(--fs-18);
    }
  }

  .editorial-page .editorial-feature h2 {
    color: #fff;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-wrap: balance;
  }

  .editorial-feature__heading > p,
  .editorial-feature__heading > span,
  .editorial-feature__description,
  .editorial-feature__progress {
    color: var(--feature-muted);
  }

  .editorial-feature__actions {
    gap: var(--space-3);
  }

  .editorial-feature__actions .primary-button,
  :where(body:not([data-route='admin'])) .editorial-feature__actions .primary-button {
    min-height: var(--action-height);
    border: 0;
    background: #fff;
    color: #121621;
    padding-inline: 1.5rem;
  }

  .editorial-feature__actions .primary-button svg {
    fill: currentColor;
  }

  .editorial-feature__actions .text-button,
  :where(body:not([data-route='admin'])) .editorial-feature__actions .text-button {
    min-height: var(--action-height);
    border-radius: var(--radius-pill);
    background: rgb(255 255 255 / 14%);
    color: #fff;
    padding-inline: var(--space-5);
  }

  .editorial-page .editorial-feature :focus-visible {
    outline-color: #fff;
  }

  @media (hover: hover) and (pointer: fine) {
    .editorial-feature__actions .primary-button:not(:disabled):hover {
      background: #e8ecf4;
    }

    .editorial-feature__actions .text-button:not(:disabled):hover {
      background: rgb(255 255 255 / 22%);
      text-decoration: none;
    }
  }

  /* Continue cards wear their artwork's colour too: pale in light, deep in dark. */
  .hero-block__title {
    font-size: var(--fs-20);
  }

  .continue-card,
  .home-page .continue-card {
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--tint-soft, var(--surface-raised));
    color: var(--text);
    padding: var(--space-3);
  }

  :root[data-theme='dark'] .continue-card {
    background: var(--tint-deep, var(--surface-raised));
  }

  .continue-card[data-tinted] {
    color: #111722;
  }

  :root[data-theme='dark'] .continue-card[data-tinted] {
    color: #f4f6fa;
  }

  .continue-card small {
    color: inherit;
    opacity: 0.78;
  }

  .continue-card .cover-frame {
    border-radius: var(--radius-sm);
  }

  .continue-card .progress-track {
    background: color-mix(in srgb, currentColor 18%, transparent);
  }

  .continue-card .progress-track span {
    background: currentColor;
  }

  /* Categories are filter pills, never cut-off tiles. */
  .category-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .category-cloud .category-tile,
  .category-tile {
    display: inline-flex;
    width: auto;
    min-height: 2.75rem;
    aspect-ratio: auto;
    align-items: center;
    gap: var(--space-2);
    overflow: visible;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--surface-raised);
    color: var(--text-soft);
    padding: var(--space-2) var(--space-5);
    font-size: var(--fs-14);
  }

  .category-tile__art {
    display: none;
  }

  .category-tile strong {
    position: static;
    color: inherit;
    font-size: inherit;
    font-weight: 600;
    text-shadow: none;
  }

  .category-tile[aria-pressed='true'] {
    background: var(--primary);
    color: var(--on-primary);
  }

  @media (hover: hover) and (pointer: fine) {
    .category-tile:not([aria-pressed='true']):hover {
      background: var(--surface-hover);
    }
  }

  /* Guests keep their reserved layout (late profiles must not move the next shelf). */
  .guest-discovery__search {
    border-radius: var(--radius-pill);
    background: var(--surface-raised);
    color: var(--text);
    padding-inline: var(--space-4);
  }

  /* ------------------------------ discover ----------------------------- */
  /* The page's own paper palette is retired: it reads the system tokens. */
  body[data-route='discover'] {
    --dx-paper: var(--bg);
    --dx-ink: var(--text);
    --dx-muted: var(--muted);
    --dx-rule: var(--border);
    --dx-rule-strong: var(--border-strong);
    --dx-raised: var(--surface-raised);
    --dx-ink-soft: var(--text-soft);
    --dx-coral-text: var(--coral-text);
    --dx-cobalt: var(--primary);
    --dx-cobalt-hover: var(--primary-fill-hover);
    --dx-cobalt-text: var(--primary-text);
    --dx-on-cobalt: var(--on-primary);
    --sys-surface: var(--surface);
    --sys-surface-hover: var(--surface-hover);
  }

  .editorial-page.discover-page {
    --surface: var(--sys-surface);
    --surface-hover: var(--sys-surface-hover);
  }

  .editorial-page.discover-page .discover-masthead {
    gap: 1.25rem;
    border: 0;
    padding-block: var(--space-2) 0;
  }

  .editorial-page.discover-page .discover-masthead h1 {
    font-size: var(--fs-title);
    line-height: var(--lh-title);
    letter-spacing: -0.01em;
  }

  .editorial-page.discover-page .discover-search {
    min-height: 2.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--subtle);
  }

  /* One filter row of chips; it wraps on wide screens and scrolls on phones. */
  .editorial-page.discover-page .discover-filter {
    gap: var(--space-2);
    border: 0;
  }

  .editorial-page.discover-page
    :is(.discover-section, .discover-guests:not([hidden]), .discover-links) {
    border: 0;
    padding-block-start: 0;
  }

  .editorial-page.discover-page .discover-panel {
    gap: var(--page-gap);
  }

  .editorial-page.discover-page .discover-section .section-heading h2,
  .editorial-page.discover-page .discover-guests h2 {
    font-size: var(--fs-20);
    font-weight: 700;
  }

  .editorial-page.discover-page .discover-section .section-heading > a {
    color: var(--text);
  }

  /* The lead release: the same tinted card as Home, artwork beside the text. */
  .editorial-page.discover-page .discover-lead {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    align-items: center;
    border-radius: var(--radius-xl);
    background: radial-gradient(
      120% 140% at 12% 0%,
      var(--tint-mid, #1f3566) 0%,
      var(--tint-deep, #111b30) 58%,
      #080b11 100%
    );
    box-shadow: var(--shadow-sm);
    color: #fff;
    padding: clamp(1rem, 3vw, 2rem);
  }

  .editorial-page.discover-page .discover-lead :is(h3, h3 button) {
    color: #fff;
  }

  .editorial-page.discover-page
    .discover-lead
    :is(.discover-kicker, .discover-lead__dek, .discover-meta) {
    color: rgb(255 255 255 / 76%);
  }

  .editorial-page.discover-page .discover-lead__art .cover-frame {
    border-radius: var(--radius-lg);
    box-shadow: 0 30px 60px -24px rgb(0 0 0 / 80%);
  }

  .editorial-page.discover-page .discover-play {
    min-height: var(--action-height);
    background: #fff;
    color: #121621;
    padding-inline: 1.5rem;
  }

  .editorial-page.discover-page .discover-lead :focus-visible {
    outline-color: #fff;
  }

  /* Smaller releases: episode rows with the same solid play disc. */
  .editorial-page.discover-page .discover-releases__list {
    gap: var(--space-1);
    border: 0;
  }

  .editorial-page.discover-page .discover-release {
    border: 0;
    border-radius: var(--radius-lg);
    padding: var(--space-2) var(--space-3);
    transition: background-color 180ms var(--ease-toggle);
  }

  .editorial-page.discover-page .discover-release .cover-frame {
    border-radius: var(--radius-sm);
  }

  .editorial-page.discover-page .discover-release__play {
    width: 44px;
    height: 44px;
    border: 0;
    background: var(--play-fill);
    color: var(--on-play);
  }

  /* The show chart: rows with a rank, the artwork and its numbers. */
  .editorial-page.discover-page .discover-rank-list {
    gap: var(--space-1) var(--space-6);
  }

  .editorial-page.discover-page .discover-rank {
    border: 0;
    border-radius: var(--radius-lg);
    padding: var(--space-2) var(--space-3);
    transition: background-color 180ms var(--ease-toggle);
  }

  .editorial-page.discover-page .discover-rank__number.is-top {
    color: var(--coral-text);
  }

  @media (min-width: 64rem) {
    .editorial-page.discover-page .discover-releases__grid {
      grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
      gap: var(--space-6);
    }

    /* Artwork beside the text, never a full-width poster that pushes the title down. */
    .editorial-page.discover-page .discover-lead {
      grid-template-columns: minmax(0, 1fr) minmax(9rem, 15rem);
    }

    .editorial-page.discover-page .discover-lead__art {
      order: 2;
      max-inline-size: 15rem;
    }

    .editorial-page.discover-page .discover-lead__copy {
      order: 1;
    }
  }

  @media (hover: hover) and (pointer: fine) {
    .editorial-page.discover-page :is(.discover-release, .discover-rank):hover {
      background: var(--surface);
    }
  }

  /* ------------------------ show and episode heroes ------------------------ */
  /*
   * The detail hero is the same tinted card as Home's lead. Inside it the
   * tokens switch to white-on-colour, so every shared component (buttons,
   * people chips, stat line) follows without page-specific rules. Menus that
   * open from the hero switch back to the page's tokens.
   */
  .detail-page {
    --page-text: var(--text);
    --page-text-soft: var(--text-soft);
    --page-muted: var(--muted);
    --page-muted-strong: var(--muted-strong);
    --page-subtle: var(--subtle);
    --page-primary: var(--primary);
    --page-on-primary: var(--on-primary);
    --page-primary-fill-hover: var(--primary-fill-hover);
    --page-primary-text: var(--primary-text);
    --page-primary-hover: var(--primary-hover);
    --page-control-border: var(--control-border);
    --page-surface: var(--surface);
    --page-surface-raised: var(--surface-raised);
    --page-surface-hover: var(--surface-hover);
    --page-border: var(--border);
    --page-border-strong: var(--border-strong);
    --page-coral-text: var(--coral-text);
  }

  .podcast-detail-hero,
  .episode-detail-hero,
  .guest-profile,
  .collection-hero,
  :where(body[data-route='user']) .person-hero,
  .show-page > .show-identity {
    --text: #ffffff;
    --text-soft: rgb(255 255 255 / 92%);
    --muted: rgb(255 255 255 / 78%);
    --muted-strong: rgb(255 255 255 / 86%);
    --subtle: rgb(255 255 255 / 72%);
    --primary: #ffffff;
    --on-primary: #121621;
    --primary-fill-hover: #e8ecf4;
    --primary-text: #ffffff;
    --primary-hover: #ffffff;
    --control-border: rgb(255 255 255 / 42%);
    --surface: rgb(255 255 255 / 10%);
    --surface-raised: rgb(255 255 255 / 14%);
    --surface-hover: rgb(255 255 255 / 22%);
    --border: rgb(255 255 255 / 18%);
    --border-strong: rgb(255 255 255 / 32%);
    --coral-text: #ffb4a3;
    --play-fill: #ffffff;
    --on-play: #121621;
    position: relative;
    isolation: isolate;
    border-radius: var(--radius-xl);
    background: radial-gradient(
      120% 140% at 12% 0%,
      var(--tint-mid, #1f3566) 0%,
      var(--tint-deep, #111b30) 58%,
      #080b11 100%
    );
    box-shadow: var(--shadow-sm);
    color: #fff;
    padding: clamp(1.25rem, 3vw, 2.25rem);
  }

  :is(.podcast-detail-hero, .episode-detail-hero, .guest-profile, .collection-hero, .person-hero)
    :focus-visible {
    outline-color: #fff;
  }

  :is(.podcast-detail-hero, .episode-detail-hero) > .cover-frame,
  .show-page > .show-identity > .cover-frame {
    border-radius: var(--radius-lg);
    box-shadow: 0 30px 60px -24px rgb(0 0 0 / 80%);
  }

  :is(.podcast-detail-hero, .episode-detail-hero) .detail-actions > .icon-button,
  :is(.podcast-detail-hero, .episode-detail-hero) .episode-more > .icon-button {
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--surface-raised);
    color: #fff;
  }

  :is(.podcast-detail-hero, .episode-detail-hero)
    .detail-actions
    > .icon-button[data-active='true'] {
    color: #ffb4a3;
  }

  :is(.podcast-detail-hero, .episode-detail-hero, .guest-profile) .detail-actions .primary-button {
    padding-inline: 1.5rem;
    white-space: nowrap;
  }

  /* Phones: one row of hero actions — the label must not wrap beside three round buttons. */
  @media (max-width: 39.99rem) {
    .podcast-detail-hero,
    .episode-detail-hero,
    .guest-profile,
    .collection-hero,
    :where(body[data-route='user']) .person-hero,
    .show-page > .show-identity {
      padding: 16px;
    }

    :is(.podcast-detail-hero, .episode-detail-hero) .detail-actions {
      gap: 8px;
    }

    :is(.podcast-detail-hero, .episode-detail-hero, .guest-profile)
      .detail-actions
      .primary-button {
      padding-inline: 16px;
    }
  }

  :is(.podcast-detail-hero, .episode-detail-hero, .guest-profile)
    .detail-actions
    .primary-button
    svg {
    fill: currentColor;
  }

  /* A menu opened from the hero is a page surface again. */
  :is(.podcast-detail-hero, .episode-detail-hero) :is(.episode-more__panel, .popup) {
    --text: var(--page-text);
    --text-soft: var(--page-text-soft);
    --muted: var(--page-muted);
    --muted-strong: var(--page-muted-strong);
    --subtle: var(--page-subtle);
    --primary: var(--page-primary);
    --on-primary: var(--page-on-primary);
    --primary-fill-hover: var(--page-primary-fill-hover);
    --primary-text: var(--page-primary-text);
    --primary-hover: var(--page-primary-hover);
    --control-border: var(--page-control-border);
    --surface: var(--page-surface);
    --surface-raised: var(--page-surface-raised);
    --surface-hover: var(--page-surface-hover);
    --border: var(--page-border);
    --border-strong: var(--page-border-strong);
    --coral-text: var(--page-coral-text);
    --play-fill: var(--page-text);
    --on-play: var(--bg);
    color: var(--page-text);
  }

  :is(.podcast-detail-hero, .episode-detail-hero) :is(.episode-more__panel, .popup) :focus-visible {
    outline-color: var(--page-primary-hover);
  }

  .episode-reading-page .episode-detail-hero {
    align-content: center;
    border-block-end: 0;
  }

  /* --------------------------- episode: cards --------------------------- */
  /*
   * Below the hero every section is one card with one heading: the same box,
   * radius and inset in both columns, separated by space rather than rules.
   * The panels inside (src/episode-reviews.js, segmentsTab, commentsTab) add no
   * heading of their own.
   */
  .episode-reading-grid,
  .episode-reading-main,
  .episode-reading-community {
    gap: var(--space-4);
  }

  .episode-reading-community {
    border-inline-start: 0;
    padding-inline-start: 0;
  }

  .episode-reading-section,
  .episode-reading-section + .episode-reading-section {
    border: 0;
    border-radius: var(--radius-xl);
    background: var(--surface);
    padding: var(--space-5);
  }

  .episode-transcript-entry {
    border-radius: var(--radius-xl);
    padding: var(--space-4) var(--space-5);
  }

  .episode-section-heading {
    align-items: center;
    gap: var(--space-2) var(--space-4);
    margin-block-end: var(--space-4);
  }

  .episode-reading-section :is(.episode-section-heading, .section-heading) h2 {
    font-size: var(--fs-20);
    letter-spacing: -0.005em;
  }

  .episode-reading-section :is(.episode-section-heading, .section-heading) p {
    color: var(--subtle);
    font-size: var(--fs-14);
    line-height: 1.7;
  }

  /* The heading's action and "see all" are the quiet pill every section uses. */
  .episode-section-heading > .text-button,
  .episode-section-more {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: var(--space-1);
    border-radius: var(--radius-pill);
    background: var(--surface-raised);
    color: var(--text);
    padding-inline: var(--space-4) var(--space-3);
    font-size: var(--fs-12);
    font-weight: 600;
  }

  .episode-section-heading > .text-button svg,
  .episode-section-more svg {
    width: 1rem;
    height: 1rem;
  }

  .episode-section-more {
    margin-block-start: var(--space-4);
  }

  /* Two tools in one card (marks and clips) each get a small heading. */
  .episode-subheading {
    display: grid;
    gap: var(--space-1);
    margin-block-end: var(--space-3);
  }

  .episode-subheading h3 {
    font-size: var(--fs-16);
  }

  .episode-subheading p {
    color: var(--subtle);
    font-size: var(--fs-12);
  }

  .segment-zone + .episode-subheading {
    margin-block-start: var(--space-6);
  }

  .episode-section-tools {
    margin-block: var(--space-4) var(--space-3);
  }

  /* The invitation to rate: one row, the button wraps under the copy when narrow. */
  .rating-prompt {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
  }

  .rating-prompt__icon {
    display: grid;
    width: 2.75rem;
    height: 2.75rem;
    flex-shrink: 0;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--primary-text);
  }

  .rating-prompt__icon svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .rating-prompt__copy {
    display: grid;
    flex: 1 1 12rem;
    gap: var(--space-1);
    min-width: 0;
  }

  .rating-prompt__copy strong {
    font-size: var(--fs-16);
  }

  .rating-prompt__copy small {
    color: var(--muted-strong);
    font-size: var(--fs-14);
    line-height: 1.7;
    text-wrap: balance;
  }

  .rating-prompt .primary-button {
    flex: 0 0 auto;
  }

  .episode-reading-section .review-list {
    gap: var(--space-4);
    margin-block-start: var(--space-4);
  }

  .episode-reading-section .review-card + .review-card {
    border-block-start: 1px solid var(--border);
    padding-block-start: var(--space-4);
  }

  /* Boxes inside a card are a step raised, without an outline. */
  .episode-reading-section :is(.review-card--mine, .capture-control--page, .clip-create) {
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--surface-raised);
  }

  .episode-reading-section .review-form {
    background: none;
    padding: 0;
  }

  .episode-reading-section .capture-button {
    border-radius: var(--radius-pill);
  }

  .episode-reading-section .capture-button:not(.is-live) {
    border-color: transparent;
    background: var(--surface);
  }

  @media (hover: hover) and (pointer: fine) {
    .episode-reading-section .capture-button:not(.is-live):hover,
    .episode-section-heading > .text-button:hover,
    .episode-section-more:hover {
      background: var(--surface-hover);
    }
  }

  @media (max-width: 35rem) {
    .episode-reading-section,
    .episode-reading-section + .episode-reading-section {
      padding: var(--space-4);
    }

    .episode-transcript-entry {
      padding-inline: var(--space-4);
    }
  }

  .editorial-page.discover-page .discover-rank-list {
    border: 0;
  }

  /* ------------------------------- search ------------------------------- */
  .suggestions {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--popup-surface);
    padding: var(--space-1);
  }

  .suggestions button {
    border-radius: var(--radius-sm);
  }

  .search-box .search-filter {
    background: var(--surface-raised);
    color: var(--text);
  }

  /* ------------------------------- player ------------------------------- */
  /* The expanded player's tabs share the width; the system's fit-content would cut their labels. */
  .now-playing__panel .tab-bar {
    width: 100%;
  }

  /* The main transport button is the accent, as in the mini and docked player. */
  .transport__main {
    background: var(--primary);
    color: var(--on-primary);
  }

  .detail-topbar .icon-button {
    background: var(--surface-raised);
    color: var(--text);
  }

  @media (min-width: 68rem) {
    /* Shelves use the width as a grid on desktop instead of scrolling sideways. */
    .home-page .horizontal-shelf {
      grid-auto-flow: row;
      grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
      gap: var(--space-5) var(--space-4);
      overflow: visible;
      margin-inline: 0;
      padding-inline: 0;
    }

    /* Story circles are a phone pattern; desktop already lists the newest episodes. */
    .home-page .home-stories {
      display: none;
    }

    .home-page .continue-row {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
      overflow: visible;
      margin-inline: 0;
      padding-inline: 0;
    }

    .home-page .continue-card {
      width: auto;
    }
  }
}
