/*
 * Tafrah web preview — core styles.
 *
 * Values follow the "Tafrah App" Figma file (dark origin): the Neutral and
 * PrimaryBlue ramps, the DM Sans type scale, 12px controls and 24px sheets.
 * Frame references and the token table live in design/README.md.
 *
 * This file declares the layer order and holds tokens, the shell and the
 * shared components. pages.css, player.css and covers.css reopen these layers.
 */
@layer reset, tokens, base, layout, components, pages, responsive, motion;

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

  html {
    color-scheme: dark;
    scroll-behavior: smooth;
  }

  html[data-theme='light'] {
    color-scheme: light;
  }

  body,
  h1,
  h2,
  h3,
  p,
  figure {
    margin: 0;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
  }

  button,
  a {
    -webkit-tap-highlight-color: transparent;
  }

  img,
  svg {
    display: block;
  }
}

@layer tokens {
  :root {
    /* DM Sans is the Figma face and has no Arabic; Arabic falls through to Alexandria. */
    --font-ar: 'Alexandria', 'DM Sans', 'Noto Sans Arabic', sans-serif;
    --font-latin: 'DM Sans', sans-serif;

    /* Figma: Neutral ramp */
    --neutral-10: #151a22;
    --neutral-20: #1f2530;
    --neutral-30: #2d3542;
    --neutral-40: #474f5c;
    --neutral-50: #5f6776;
    --neutral-60: #838a98;
    --neutral-70: #959ca9;
    --neutral-80: #bdc2cc;
    --neutral-90: #eaedf3;

    /* Figma: PrimaryBlue ramp */
    --blue-200: #bccaeb;
    --blue-300: #6f97f8;
    --blue-500: #2861f3;
    --blue-600: #184dd4;
    --blue-700: #17388d;

    --coral-400: #f2836b;
    --green-400: #4fce8b;
    --amber-400: #f5a13c;
    --red-400: #ef6a62;
    --violet-400: #a78bfa;
    --teal-400: #3fc7c0;

    --bg: var(--neutral-10);
    --bg-deep: #10141b;
    --surface: var(--neutral-20);
    --surface-raised: var(--neutral-30);
    --surface-hover: #262d39;
    --surface-soft: #1b2740;
    --border: var(--neutral-30);
    --border-strong: var(--neutral-40);
    --text: #f5f7fc;
    --text-soft: var(--neutral-90);
    --muted: var(--neutral-70);
    --muted-strong: var(--neutral-80);
    --primary: var(--blue-500);
    --primary-hover: var(--blue-300);
    --primary-deep: var(--blue-700);
    --on-primary: #ffffff;
    --coral: var(--coral-400);
    --success: var(--green-400);
    --warning: var(--amber-400);
    --danger: var(--red-400);

    /* The blue header behind Home, Discover and Search. */
    --hero-top: #17458a;
    --hero-mid: #0c2e62;
    --hero-text: #ffffff;
    --hero-text-soft: #ffffffcc;
    --hero-text-muted: #ffffff99;
    --hero-fill: #ffffff1a;
    --hero-line: #ffffff33;

    /* Segment types on the seek bar (layer 8.4's seven types). */
    --seg-intro: var(--blue-300);
    --seg-outro: var(--violet-400);
    --seg-ad: var(--coral-400);
    --seg-highlight: var(--green-400);
    --seg-key_quote: var(--amber-400);
    --seg-self_promo: var(--teal-400);
    --seg-not_useful: var(--neutral-60);

    --shadow-sm: 0 8px 24px #05070b33;
    --shadow-lg: 0 24px 64px #05070b73;
    --focus-ring: 0 0 0 3px #6f97f873;

    /* Figma type scale: Headline 3–7, Body small, Body xs. */
    --fs-24: 1.5rem;
    --fs-20: 1.25rem;
    --fs-18: 1.125rem;
    --fs-16: 1rem;
    --fs-14: 0.875rem;
    --fs-12: 0.75rem;

    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --gutter: 1rem;
    --sidebar-width: 15.5rem;
    --nav-height: 4.25rem;
    --player-height: 4.5rem;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-toggle: cubic-bezier(0.65, 0, 0.35, 1);
  }

  /* The Figma file is dark-only; the light theme reuses its ramps inverted. */
  :root[data-theme='light'] {
    --bg: #f6f7fa;
    --bg-deep: #eceff4;
    --surface: #ffffff;
    --surface-raised: var(--neutral-90);
    --surface-hover: #e1e5ec;
    --surface-soft: #e4ebfd;
    --border: #dde1e8;
    --border-strong: var(--neutral-80);
    --text: var(--neutral-10);
    --text-soft: var(--neutral-30);
    --muted: var(--neutral-50);
    --muted-strong: var(--neutral-40);
    --primary-hover: var(--blue-600);
    --primary-deep: #c9d7fb;
    --hero-top: #2861f3;
    --hero-mid: #1a4fd6;
    --seg-intro: var(--blue-500);
    --seg-outro: #7c5ce0;
    --seg-ad: #d9553c;
    --seg-highlight: #1f9a5c;
    --seg-key_quote: #c27710;
    --seg-self_promo: #13908a;
    --seg-not_useful: var(--neutral-60);
    --success: #1f9a5c;
    --warning: #c27710;
    --danger: #d43d35;
    --shadow-sm: 0 8px 24px #1f253014;
    --shadow-lg: 0 24px 64px #1f25302e;
  }
}

@layer base {
  html {
    min-width: 20rem;
    background: var(--bg);
  }

  body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ar);
    font-size: var(--fs-14);
    font-weight: 400;
    line-height: 1.6;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  button {
    border: 0;
  }

  button,
  [role='button'] {
    cursor: pointer;
  }

  h1,
  h2,
  h3 {
    font-weight: 700;
    line-height: 1.4;
  }

  :focus-visible {
    outline: 2px solid var(--primary-hover);
    outline-offset: 3px;
  }

  ::selection {
    background: var(--primary);
    color: var(--on-primary);
  }

  .skip-link {
    position: fixed;
    z-index: 1000;
    inset-block-start: var(--space-3);
    inset-inline-start: var(--space-3);
    transform: translateY(-160%);
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: var(--on-primary);
    padding: var(--space-3) var(--space-4);
    transition: transform 180ms var(--ease-out);
  }

  .skip-link:focus {
    transform: translateY(0);
  }

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

  .icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
  }

  svg {
    width: 1.5rem;
    height: 1.5rem;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.6;
  }
}

@layer layout {
  .app-shell {
    min-height: 100vh;
    min-height: 100dvh;
  }

  /* A column, so a page's sheet can stretch to the bottom of a short screen. */
  .site-column {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    flex-direction: column;
  }

  /*
   * Home, Discover and Search open on the blue header. The page's `.sheet`
   * covers everything below it. Keep the header blue for its entire height:
   * fading to the light page colour made white labels lose their contrast.
   */
  body[data-route='home'] .site-column,
  body[data-route='discover'] .site-column,
  body[data-route='search'] .site-column {
    background: linear-gradient(180deg, var(--hero-top), var(--hero-mid) 42rem);
  }

  .sidebar,
  .site-topbar {
    display: none;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 4rem;
    padding: max(var(--space-3), env(safe-area-inset-top)) var(--gutter) var(--space-2);
  }

  .mobile-header__actions,
  .topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  #main-content {
    display: flex;
    width: min(100%, 86rem);
    flex: 1 0 auto;
    flex-direction: column;
    margin-inline: auto;
    padding: var(--space-2) var(--gutter) calc(var(--nav-height) + var(--space-12));
  }

  #main-content > * {
    flex: 1 0 auto;
  }

  #main-content:focus {
    outline: none;
  }

  body.has-player #main-content {
    padding-block-end: calc(var(--nav-height) + var(--player-height) + var(--space-12));
  }

  .page {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: var(--space-8);
  }

  .page:has(> .sheet) {
    grid-template-rows: auto 1fr;
    align-content: stretch;
  }

  /* A Figma screen title: 20/24 bold, with an optional line under it. */
  .page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .page-copy {
    max-width: 44rem;
  }

  .page-kicker {
    display: block;
    color: var(--primary-hover);
    font-size: var(--fs-12);
    font-weight: 700;
  }

  .page-title {
    font-size: var(--fs-24);
  }

  .page-lead {
    max-width: 62ch;
    margin-block-start: var(--space-1);
    color: var(--muted-strong);
  }

  /* The rounded panel that slides over the blue header. */
  .sheet {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: var(--space-8);
    margin-inline: calc(var(--gutter) * -1);
    margin-block-end: calc((var(--nav-height) + var(--space-12)) * -1);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    background: var(--bg);
    padding: var(--space-6) var(--gutter) calc(var(--nav-height) + var(--space-12));
  }

  body.has-player .sheet {
    margin-block-end: calc((var(--nav-height) + var(--player-height) + var(--space-12)) * -1);
    padding-block-end: calc(var(--nav-height) + var(--player-height) + var(--space-12));
  }

  .section {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
  }

  .section-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
  }

  .section-heading h2 {
    font-size: var(--fs-20);
  }

  .section-heading p {
    color: var(--muted);
    font-size: var(--fs-12);
  }

  .section-heading > a,
  .section-heading > button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: var(--space-1);
    color: var(--muted-strong);
    font-size: var(--fs-14);
  }

  /* Shelves bleed to the screen edge so the next card peeks in, as in Figma. */
  .horizontal-shelf {
    display: grid;
    grid-auto-columns: 8.75rem;
    grid-auto-flow: column;
    gap: var(--space-4);
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    margin-inline: calc(var(--gutter) * -1);
    padding-inline: var(--gutter);
    scroll-padding-inline: var(--gutter);
    scroll-snap-type: inline proximity;
    scrollbar-width: none;
  }

  .horizontal-shelf::-webkit-scrollbar {
    display: none;
  }

  .horizontal-shelf > * {
    scroll-snap-align: start;
  }

  .horizontal-shelf--wide {
    grid-auto-columns: min(15.25rem, 72vw);
  }

  .content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8.75rem, 1fr));
    gap: var(--space-6) var(--space-4);
  }
}

@layer components {
  /* ------------------------------- brand -------------------------------- */
  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    width: fit-content;
  }

  .brand-mark {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, 0.3rem);
    grid-template-rows: repeat(3, 0.3rem);
    gap: 0.18rem;
    width: 2.25rem;
    height: 2.25rem;
    align-content: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--primary);
  }

  .brand-mark i {
    display: block;
    height: 0.3rem;
    border-radius: 999px;
    background: var(--on-primary);
  }

  .brand-mark i:nth-child(1) {
    grid-column: 1 / 3;
  }

  .brand-mark i:nth-child(2) {
    grid-column: 3;
  }

  .brand-mark i:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
  }

  .brand-mark i:nth-child(4) {
    grid-column: 2 / 4;
    grid-row: 2;
  }

  .brand-mark i:nth-child(5) {
    grid-column: 1 / 3;
    grid-row: 3;
  }

  .brand-mark::after {
    position: absolute;
    inset-block-start: -0.16rem;
    inset-inline-end: -0.16rem;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--coral);
    content: '';
  }

  .brand-type {
    display: grid;
    line-height: 1;
  }

  .brand-type strong {
    font-family: 'Alexandria', var(--font-ar);
    font-size: var(--fs-20);
    font-weight: 700;
  }

  .brand-type small {
    margin-block-start: 0.3rem;
    color: var(--muted);
    font-family: var(--font-latin);
    font-size: 0.56rem;
    font-weight: 700;
    letter-spacing: 0.18em;
  }

  .brand--compact .brand-mark {
    width: 2rem;
    height: 2rem;
  }

  .brand--compact .brand-type strong {
    font-size: var(--fs-18);
  }

  /* ------------------------------ buttons ------------------------------- */
  .icon-button,
  .quiet-button,
  .primary-button,
  .secondary-button,
  .text-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    border-radius: var(--radius-md);
    transition:
      transform 140ms var(--ease-out),
      background-color 180ms var(--ease-toggle),
      color 180ms var(--ease-toggle),
      border-color 180ms var(--ease-toggle);
  }

  .primary-button,
  .secondary-button,
  .quiet-button {
    min-height: 3rem;
    padding: 0.75rem 1.5rem;
    font-size: var(--fs-16);
    font-weight: 700;
    line-height: 1.25;
  }

  .primary-button {
    background: var(--primary);
    color: var(--on-primary);
  }

  .secondary-button {
    background: var(--surface);
    color: var(--text);
  }

  .quiet-button {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-soft);
    font-weight: 500;
  }

  .icon-button {
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 auto;
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    padding: 0;
  }

  .text-button {
    min-height: 2.5rem;
    background: transparent;
    color: var(--primary-hover);
    padding: 0.4rem 0.1rem;
    font-size: var(--fs-14);
    font-weight: 500;
  }

  .primary-button svg,
  .secondary-button svg,
  .quiet-button svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .text-button svg {
    width: 1rem;
    height: 1rem;
  }

  .icon-button:active,
  .quiet-button:active,
  .primary-button:active,
  .secondary-button:active {
    transform: scale(0.97);
  }

  .primary-button[disabled],
  .secondary-button[disabled],
  .icon-button[disabled] {
    cursor: not-allowed;
    opacity: 0.45;
  }

  .text-button.is-danger,
  .icon-button.is-danger {
    color: var(--danger);
  }

  .text-button.is-on,
  .secondary-button.is-on,
  .icon-button.is-on,
  [data-active='true'] {
    color: var(--primary-hover);
  }

  [data-active='true'] > svg {
    fill: currentColor;
  }

  /* Header icons sit on the blue header: a ring instead of a fill (Figma bell). */
  .mobile-header .icon-button,
  .topbar-actions .icon-button {
    position: relative;
    border: 1px solid var(--border);
  }

  body[data-route='home'] .mobile-header .brand,
  body[data-route='discover'] .mobile-header .brand,
  body[data-route='search'] .mobile-header .brand {
    color: var(--hero-text);
  }

  body[data-route='home'] .mobile-header .icon-button,
  body[data-route='discover'] .mobile-header .icon-button,
  body[data-route='search'] .mobile-header .icon-button,
  body[data-route='home'] .topbar-actions .icon-button,
  body[data-route='discover'] .topbar-actions .icon-button,
  body[data-route='search'] .topbar-actions .icon-button {
    border-color: var(--hero-line);
    color: var(--hero-text);
  }

  .unread-badge {
    position: absolute;
    inset-block-start: -0.25rem;
    inset-inline-end: -0.25rem;
    min-width: 1.15rem;
    border-radius: 999px;
    background: var(--coral);
    color: var(--neutral-10);
    padding: 0 0.3rem;
    font-family: var(--font-latin);
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.15rem;
    text-align: center;
  }

  .brand-caption {
    margin: var(--space-2) var(--space-3) 0;
    color: var(--muted);
    font-size: var(--fs-12);
  }

  /* ------------------------------- text --------------------------------- */
  .eyebrow {
    color: var(--primary-hover);
    font-size: var(--fs-12);
    font-weight: 700;
  }

  .meta-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    color: var(--muted);
    font-size: var(--fs-12);
  }

  .meta-line > span + span::before {
    margin-inline-end: var(--space-2);
    content: '•';
  }

  .muted {
    color: var(--muted);
    font-size: var(--fs-12);
  }

  .hint {
    margin: var(--space-2) 0 0;
    color: var(--muted);
    font-size: var(--fs-12);
    line-height: 1.7;
  }

  .hint code,
  .notice code,
  .token-preview {
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
    padding: 0.1rem 0.35rem;
    font-family: var(--font-latin);
    font-size: var(--fs-12);
  }

  .token-preview {
    display: inline-block;
    margin-top: var(--space-2);
  }

  /* ------------------------------ artwork ------------------------------- */
  .cover-frame {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    aspect-ratio: 1;
    container-type: inline-size;
    border-radius: var(--radius-md);
    background: var(--surface);
  }

  .cover-frame img {
    position: absolute;
    z-index: 2;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .cover-frame--sm {
    width: 3rem;
    flex: none;
    border-radius: var(--radius-sm);
  }

  .generated-cover {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: linear-gradient(
      145deg,
      oklch(47% 0.12 var(--cover-hue)),
      oklch(22% 0.07 var(--cover-hue))
    );
    color: #f7f8fb;
  }

  .generated-cover::before,
  .generated-cover::after {
    position: absolute;
    z-index: 0;
    border: 2px solid currentColor;
    border-radius: 50%;
    content: '';
    opacity: 0.3;
  }

  .generated-cover::before {
    width: 78%;
    height: 78%;
    inset-block-end: -38%;
    inset-inline-start: -14%;
  }

  .generated-cover::after {
    width: 50%;
    height: 50%;
    inset-block-end: -24%;
    inset-inline-start: 0;
  }

  .cover-monogram {
    position: relative;
    z-index: 1;
    max-width: 82%;
    font-family: 'Alexandria', var(--font-ar);
    font-size: clamp(0.6rem, 14cqw, 3.5rem);
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
  }

  /* ---------------------------- podcast card ---------------------------- */
  .podcast-card {
    display: grid;
    width: 100%;
    min-width: 0;
    align-content: start;
    gap: var(--space-2);
    background: transparent;
    color: var(--text);
    padding: 0;
    text-align: start;
  }

  .podcast-card__art {
    position: relative;
    display: block;
    transition: transform 240ms var(--ease-out);
  }

  /* The blue play disc from Figma's "New Releases" cards. */
  .podcast-card__play,
  .play-disc {
    display: grid;
    width: 2rem;
    height: 2rem;
    place-items: center;
    border-radius: 50%;
    background: var(--primary);
    color: var(--on-primary);
  }

  .podcast-card__play svg,
  .play-disc svg {
    width: 0.9rem;
    height: 0.9rem;
    fill: currentColor;
  }

  .podcast-card__play {
    position: absolute;
    z-index: 4;
    inset-block-end: var(--space-2);
    inset-inline-start: var(--space-2);
    opacity: 0;
    transition: opacity 180ms var(--ease-out);
  }

  .podcast-card__body {
    display: grid;
    gap: 0.15rem;
  }

  .podcast-card h3 {
    display: -webkit-box;
    overflow: hidden;
    font-size: var(--fs-14);
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .podcast-card p {
    overflow: hidden;
    color: var(--muted);
    font-size: var(--fs-12);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .podcast-card .reason-chip {
    color: var(--primary-hover);
  }

  /* ----------------------------- episode row ---------------------------- */
  .episode-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
  }

  .episode-row {
    display: grid;
    grid-template-columns: 4.5rem minmax(0, 1fr) auto;
    align-items: start;
    gap: var(--space-4);
  }

  .episode-row .cover-frame {
    width: 4.5rem;
    border-radius: var(--radius-sm);
  }

  .episode-row__body {
    display: grid;
    min-width: 0;
    gap: var(--space-1);
  }

  .episode-cover,
  .episode-row__body {
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    padding: 0;
    text-align: start;
  }

  .episode-row h3 {
    display: -webkit-box;
    overflow: hidden;
    color: var(--text);
    font-size: var(--fs-18);
    line-height: 1.4;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .episode-row p {
    overflow: hidden;
    color: var(--muted);
    font-size: var(--fs-12);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Figma's trailing column: a solid blue play triangle. */
  .episode-row__action {
    color: var(--primary);
  }

  .episode-row__action svg {
    width: 1.35rem;
    height: 1.35rem;
    fill: currentColor;
  }

  .progress-track {
    display: block;
    overflow: hidden;
    width: 100%;
    height: 0.25rem;
    margin-block-start: var(--space-1);
    border-radius: 999px;
    background: var(--surface-raised);
  }

  .progress-track span {
    display: block;
    width: var(--progress, 0%);
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
  }

  /* -------------------------------- chips ------------------------------- */
  .chip-row {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    margin-inline: calc(var(--gutter) * -1);
    padding-inline: var(--gutter);
    scrollbar-width: none;
  }

  .chip-row::-webkit-scrollbar {
    display: none;
  }

  .chip-row--inline {
    flex-wrap: wrap;
    overflow: visible;
    margin-inline: 0;
    padding-inline: 0;
  }

  .chip {
    flex: 0 0 auto;
    min-height: 2.25rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-soft);
    padding: 0.4rem 1rem;
    font-size: var(--fs-14);
    font-weight: 500;
    transition:
      background-color 180ms var(--ease-toggle),
      color 180ms var(--ease-toggle);
  }

  .chip[aria-pressed='true'],
  .chip[aria-selected='true'],
  .chip.is-active {
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 700;
  }

  /* ------------------------------- status ------------------------------- */
  .status-dot {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--muted);
  }

  .status-dot.is-live {
    background: var(--success);
  }

  .status-dot.is-demo {
    background: var(--warning);
  }

  .status-dot.is-error {
    background: var(--danger);
  }

  .inline-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted-strong);
    padding: 0.3rem 0.75rem;
    font-size: var(--fs-12);
    font-weight: 500;
  }

  .status-chip {
    border-radius: 999px;
    background: var(--surface-raised);
    color: var(--muted-strong);
    padding: 0.15rem 0.6rem;
    font-size: var(--fs-12);
  }

  .status-chip.is-pending {
    color: var(--warning);
  }

  .status-chip.is-approved {
    color: var(--success);
  }

  .status-chip.is-rejected,
  .status-chip.is-duplicate {
    color: var(--danger);
  }

  .verified-badge {
    display: inline-flex;
    width: 1.2rem;
    height: 1.2rem;
    color: var(--success);
    vertical-align: middle;
  }

  .verified-badge svg {
    width: 100%;
    height: 100%;
  }

  .notice {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-soft);
    padding: var(--space-3) var(--space-4);
    font-size: var(--fs-12);
    line-height: 1.7;
  }

  .notice svg {
    width: 1.1rem;
    height: 1.1rem;
    margin-block-start: 0.1rem;
    color: var(--primary-hover);
  }

  .notice--warning svg {
    color: var(--warning);
  }

  .empty-state,
  .error-state {
    display: grid;
    min-height: 14rem;
    place-items: center;
    border-radius: var(--radius-lg);
    background: var(--surface);
    padding: var(--space-8) var(--space-6);
    text-align: center;
  }

  .empty-state__inner,
  .error-state__inner {
    display: grid;
    max-width: 28rem;
    justify-items: center;
    gap: var(--space-3);
  }

  .empty-state__icon,
  .error-state__icon {
    display: grid;
    width: 3.5rem;
    height: 3.5rem;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--primary-hover);
  }

  .error-state__icon {
    color: var(--danger);
  }

  .empty-state h2,
  .error-state h2 {
    font-size: var(--fs-18);
  }

  .empty-state p,
  .error-state p {
    color: var(--muted-strong);
  }

  .empty-state .secondary-button,
  .error-state .secondary-button {
    background: var(--bg);
  }

  .skeleton {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--surface);
  }

  .skeleton::after {
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 20%, var(--surface-hover) 50%, transparent 80%);
    content: '';
    transform: translateX(-100%);
    animation: skeleton-sheen 1.4s infinite;
  }

  .route-loading {
    display: grid;
    gap: var(--space-4);
  }

  .skeleton-kicker {
    width: 7rem;
    height: 0.8rem;
  }

  .skeleton-title {
    width: min(18rem, 70%);
    height: 2rem;
  }

  .skeleton-hero {
    height: 16rem;
    margin-block-start: var(--space-4);
    border-radius: var(--radius-lg);
  }

  /* ----------------------------- bottom nav ----------------------------- */
  .bottom-nav {
    position: fixed;
    z-index: 60;
    inset-inline: 0;
    inset-block-end: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-height: var(--nav-height);
    border-block-start: 1px solid var(--surface);
    background: var(--bg);
    padding: var(--space-2) var(--space-2) max(var(--space-2), env(safe-area-inset-bottom));
  }

  .bottom-nav a {
    display: grid;
    min-width: 0;
    place-items: center;
    align-content: center;
    gap: 0.15rem;
    color: var(--muted-strong);
    font-size: var(--fs-12);
    font-weight: 500;
  }

  .bottom-nav a[aria-current='page'] {
    color: var(--primary-hover);
  }

  .toast {
    position: fixed;
    z-index: 130;
    inset-inline: var(--space-4);
    inset-block-end: calc(var(--nav-height) + var(--space-4) + env(safe-area-inset-bottom));
    display: flex;
    max-width: 26rem;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    margin-inline: auto;
    border-radius: var(--radius-md);
    background: var(--neutral-90);
    box-shadow: var(--shadow-lg);
    color: var(--neutral-10);
    padding: var(--space-3) var(--space-4);
    font-weight: 500;
    text-align: center;
    animation: toast-in 300ms var(--ease-out) both;
  }

  .toast[hidden] {
    display: none;
  }

  .toast .text-button {
    min-height: 0;
    color: var(--blue-600);
    font-weight: 700;
  }

  body.has-player .toast {
    inset-block-end: calc(
      var(--nav-height) + var(--player-height) + var(--space-4) + env(safe-area-inset-bottom)
    );
  }

  /* -------------------------------- forms ------------------------------- */
  .field {
    display: grid;
    gap: var(--space-2);
    color: var(--text-soft);
    font-size: var(--fs-14);
    font-weight: 500;
  }

  .field input,
  .field textarea,
  .field select,
  .search-input,
  .comment-form textarea {
    width: 100%;
    min-height: 3rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    outline: none;
    background: var(--surface);
    color: var(--text);
    padding: 0.7rem 1rem;
    font-weight: 400;
    transition:
      border-color 160ms var(--ease-toggle),
      box-shadow 160ms var(--ease-toggle);
  }

  .field textarea,
  .comment-form textarea {
    resize: vertical;
  }

  .field input::placeholder,
  .field textarea::placeholder,
  .search-input::placeholder,
  .comment-form textarea::placeholder {
    color: var(--muted);
    opacity: 1;
  }

  .field input:focus,
  .field textarea:focus,
  .field select:focus,
  .search-input:focus,
  .comment-form textarea:focus {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
  }

  .checkbox {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-soft);
  }

  .checkbox input,
  .preference-table input {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
  }

  .inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-3);
    border-radius: var(--radius-lg);
    background: var(--surface);
    padding: var(--space-4);
  }

  .inline-form .field {
    flex: 1 1 10rem;
    min-width: 0;
  }

  .inline-form .field input,
  .inline-form .field select,
  .inline-form .field textarea {
    background: var(--bg);
  }

  .form-error {
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--danger) 18%, transparent);
    color: var(--text);
    padding: var(--space-3);
    font-size: var(--fs-12);
  }

  .row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
  }

  .row-actions--tight {
    flex-wrap: nowrap;
    gap: var(--space-1);
  }

  /* Figma's player tab bar: a rounded tray with one blue pill. */
  .segmented-control,
  .tab-bar {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    border-radius: var(--radius-lg);
    background: var(--surface);
    padding: var(--space-1);
    scrollbar-width: none;
  }

  .segmented-control button,
  .tab-bar button {
    min-height: 2.75rem;
    flex: 1 0 auto;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--muted-strong);
    padding: 0.5rem 1rem;
    font-weight: 500;
    white-space: nowrap;
  }

  .segmented-control button[aria-selected='true'],
  .tab-bar button[aria-selected='true'] {
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 700;
  }

  /* ------------------------------- dialog ------------------------------- */
  .auth-dialog {
    width: min(calc(100% - 2rem), 26rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    border: 0;
    border-radius: var(--radius-xl);
    background: var(--bg);
    box-shadow: var(--shadow-lg);
    color: var(--text);
    padding: var(--space-8) var(--space-6);
  }

  .auth-dialog::backdrop {
    background: #05070bb8;
  }

  .dialog-close {
    position: absolute;
    inset-block-start: var(--space-3);
    inset-inline-end: var(--space-3);
  }

  .dialog-brand {
    margin-block-end: var(--space-4);
  }

  .auth-dialog h2 {
    font-size: var(--fs-24);
  }

  .auth-dialog > p {
    margin-block-start: var(--space-1);
    color: var(--muted-strong);
  }

  .auth-dialog .segmented-control {
    margin-block: var(--space-6);
  }

  .auth-dialog form {
    display: grid;
    gap: var(--space-4);
  }

  .auth-submit {
    width: 100%;
    margin-block-start: var(--space-2);
  }

  /* ------------------------------- people ------------------------------- */
  .person-avatar {
    display: grid;
    width: 5rem;
    height: 5rem;
    flex: 0 0 auto;
    overflow: hidden;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--primary-hover);
    font-size: var(--fs-20);
    font-weight: 700;
  }

  .person-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .person-avatar--sm {
    width: 2.25rem;
    height: 2.25rem;
    font-size: var(--fs-12);
  }

  .person-avatar--lg {
    width: 6.5rem;
    height: 6.5rem;
    font-size: var(--fs-24);
  }

  .author-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: none;
    color: inherit;
    padding: 0;
    text-align: start;
  }

  .author-chip--gone {
    cursor: default;
    color: var(--muted);
  }

  .author-chip strong {
    display: block;
    font-size: var(--fs-14);
  }

  .author-chip small {
    display: block;
    color: var(--muted);
    font-size: var(--fs-12);
  }

  .star-rating {
    display: inline-flex;
    gap: 0.15rem;
  }

  .star,
  .star-rating button {
    width: 1.1rem;
    height: 1.1rem;
    background: none;
    color: var(--neutral-40);
    padding: 0;
    cursor: default;
  }

  .star-rating--input button {
    width: 1.75rem;
    height: 1.75rem;
    cursor: pointer;
  }

  .star svg,
  .star-rating button svg {
    width: 100%;
    height: 100%;
  }

  .star.is-on,
  .star-rating button.is-on,
  .star-rating button[aria-pressed='true'] {
    color: var(--warning);
  }

  .star.is-on svg,
  .star-rating button.is-on svg {
    fill: currentColor;
  }
}

@layer responsive {
  @media (min-width: 40rem) {
    :root {
      --gutter: 2rem;
    }

    .horizontal-shelf {
      grid-auto-columns: 10.5rem;
      gap: var(--space-6);
    }

    .horizontal-shelf--wide {
      grid-auto-columns: 17rem;
    }

    .content-grid {
      grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
      gap: var(--space-8) var(--space-6);
    }
  }

  /* Desktop: the navigation moves to a sidebar and a search bar replaces the mobile header. */
  @media (min-width: 68rem) {
    :root {
      --gutter: 2.5rem;
      --nav-height: 0rem;
    }

    .app-shell {
      display: grid;
      grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    }

    .sidebar {
      position: sticky;
      z-index: 50;
      inset-block-start: 0;
      display: flex;
      height: 100vh;
      height: 100dvh;
      flex-direction: column;
      border-inline-end: 1px solid var(--surface);
      background: var(--bg-deep);
      padding: var(--space-8) var(--space-4) var(--space-6);
    }

    .sidebar .brand {
      padding-inline: var(--space-3);
    }

    .side-nav {
      display: grid;
      gap: var(--space-1);
      margin-block-start: var(--space-8);
    }

    .side-nav a {
      position: relative;
      display: flex;
      min-height: 3rem;
      align-items: center;
      gap: var(--space-3);
      border-radius: var(--radius-md);
      color: var(--muted-strong);
      padding: var(--space-3);
      font-weight: 500;
      transition:
        background-color 180ms var(--ease-toggle),
        color 180ms var(--ease-toggle);
    }

    .side-nav a[aria-current='page'] {
      background: var(--surface);
      color: var(--text);
      font-weight: 700;
    }

    .side-nav a[aria-current='page'] svg {
      color: var(--primary-hover);
    }

    .side-nav .unread-badge {
      position: static;
      margin-inline-start: auto;
    }

    .sidebar-spacer {
      flex: 1;
    }

    .connection-pill {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr) auto;
      align-items: center;
      gap: var(--space-3);
      width: 100%;
      border-radius: var(--radius-md);
      background: var(--surface);
      color: var(--text);
      padding: var(--space-3);
      text-align: start;
    }

    .connection-pill span:nth-child(2) {
      display: grid;
    }

    .connection-pill small {
      color: var(--muted);
      font-size: 0.68rem;
    }

    .connection-pill strong {
      overflow: hidden;
      font-size: var(--fs-12);
      font-weight: 500;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .connection-pill > svg {
      width: 1rem;
      height: 1rem;
      color: var(--muted);
    }

    .theme-toggle {
      width: 100%;
      min-height: 2.75rem;
      justify-content: flex-start;
      margin-block-start: var(--space-2);
      border-color: transparent;
      padding-inline: var(--space-3);
      font-size: var(--fs-14);
    }

    .mobile-header,
    .bottom-nav {
      display: none;
    }

    .site-topbar {
      display: flex;
      width: min(100%, 86rem);
      min-height: 5rem;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-6);
      margin-inline: auto;
      padding-inline: var(--gutter);
    }

    .site-topbar__search {
      display: flex;
      width: min(100%, 28rem);
      min-height: 2.75rem;
      align-items: center;
      gap: var(--space-3);
      border-radius: var(--radius-md);
      background: var(--surface);
      color: var(--muted-strong);
      padding-inline: var(--space-4);
    }

    .site-topbar__search svg {
      width: 1.25rem;
      height: 1.25rem;
    }

    .site-topbar__search kbd {
      margin-inline-start: auto;
      border: 1px solid var(--border);
      border-radius: 0.3rem;
      padding: 0 0.4rem;
      font-family: var(--font-latin);
      font-size: var(--fs-12);
    }

    body[data-route='home'] .site-topbar__search,
    body[data-route='discover'] .site-topbar__search,
    body[data-route='search'] .site-topbar__search {
      background: var(--hero-fill);
      color: var(--hero-text-soft);
    }

    body[data-route='home'] .site-topbar__search kbd,
    body[data-route='discover'] .site-topbar__search kbd,
    body[data-route='search'] .site-topbar__search kbd {
      border-color: var(--hero-line);
    }

    #main-content {
      padding-block: var(--space-4) var(--space-16);
    }

    body.has-player #main-content {
      padding-block-end: calc(var(--player-height) + var(--space-16));
    }

    .sheet {
      margin-block-end: calc(var(--space-16) * -1);
      padding: var(--space-8) var(--gutter) var(--space-16);
    }

    body.has-player .sheet {
      margin-block-end: calc((var(--player-height) + var(--space-16)) * -1);
      padding-block-end: calc(var(--player-height) + var(--space-16));
    }

    .page {
      gap: var(--space-12);
    }

    .page-title {
      font-size: 2rem;
    }

    .section-heading h2 {
      font-size: var(--fs-24);
    }

    .horizontal-shelf {
      grid-auto-columns: clamp(9rem, 13vw, 11rem);
      gap: var(--space-6);
    }

    .horizontal-shelf--wide {
      grid-auto-columns: 19rem;
    }

    .content-grid {
      grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
    }

    .toast,
    body.has-player .toast {
      inset-inline-start: calc(var(--sidebar-width) + var(--space-6));
      inset-block-end: calc(var(--player-height) + var(--space-6));
    }
  }

  @media (min-width: 80rem) {
    .episode-list {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      column-gap: var(--space-12);
    }

    .horizontal-shelf .episode-list,
    .episode-list--single {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  @media (hover: hover) and (pointer: fine) {
    .icon-button:hover,
    .quiet-button:hover {
      background: var(--surface);
      color: var(--text);
    }

    .secondary-button:hover {
      background: var(--surface-raised);
    }

    .primary-button:hover {
      background: var(--blue-600);
    }

    .chip:not([aria-pressed='true']):not([aria-selected='true']):hover {
      background: var(--surface-raised);
    }

    .podcast-card:hover .podcast-card__art {
      transform: translateY(-0.2rem);
    }

    .podcast-card:hover .podcast-card__play,
    .podcast-card:focus-visible .podcast-card__play {
      opacity: 1;
    }

    .episode-row__body:hover h3 {
      color: var(--primary-hover);
    }

    .side-nav a:hover {
      background: var(--surface);
      color: var(--text);
    }
  }
}

@layer motion {
  .page > *,
  .sheet > * {
    animation: content-enter 360ms var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 30ms);
  }

  @keyframes content-enter {
    from {
      opacity: 0;
      transform: translateY(0.6rem);
    }
  }

  @keyframes skeleton-sheen {
    to {
      transform: translateX(100%);
    }
  }

  @keyframes toast-in {
    from {
      opacity: 0;
      transform: translateY(0.7rem) scale(0.98);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      scroll-behavior: auto !important;
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* HTML hidden must win over field/grid component display rules. */
[hidden] {
  display: none !important;
}

@layer components {
  .auth-card {
    width: min(100%, 26rem);
    margin-inline: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-8) var(--space-6);
  }
  .auth-card h2 {
    font-size: var(--fs-24);
  }
  .auth-card > p {
    color: var(--muted-strong);
    margin-block: var(--space-2) var(--space-6);
  }
  .auth-card form {
    display: grid;
    gap: var(--space-4);
  }
  .auth-card .primary-button {
    width: 100%;
  }
  .auth-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-block-start: var(--space-4);
  }
  .auth-forgot {
    justify-self: start;
  }
  #auth-copy,
  .account-email {
    overflow-wrap: anywhere;
  }
  .field [aria-invalid='true'] {
    border-color: var(--danger);
  }
  .field textarea {
    resize: vertical;
    min-height: 6rem;
  }
  .account-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .field--wide,
  .account-form > .checkbox {
    grid-column: 1 / -1;
  }
  .form-feedback {
    color: var(--primary);
  }
  .profile-card {
    align-self: start;
  }
  .profile-grid > .section {
    margin-block-start: 0;
    min-width: 0;
  }
  .profile-identity > div {
    min-width: 0;
  }
  .profile-grid--guest {
    grid-template-columns: minmax(0, 36rem);
  }
  .auth-dialog {
    scroll-padding-block: 1rem;
  }
  .auth-dialog :focus {
    scroll-margin-block: 1rem;
  }
  #auth-tabs[hidden] + #auth-form {
    margin-block-start: 1rem;
  }
  .pagination {
    display: grid;
    justify-items: center;
    gap: var(--space-3);
    margin-block: var(--space-6);
  }
}
@layer responsive {
  @media (max-width: 560px) {
    .auth-dialog,
    .auth-card {
      padding: 2rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
    }
    .auth-dialog {
      max-height: calc(100dvh - 1rem);
      width: calc(100% - 1rem);
    }
    .auth-dialog input,
    .auth-card input,
    .account-form input,
    .account-form textarea {
      font-size: 16px;
      min-height: 48px;
    }
    .auth-dialog .primary-button,
    .auth-card .primary-button {
      min-height: 48px;
    }
    .account-form {
      grid-template-columns: minmax(0, 1fr);
    }
  }
}
