.library-screen {
  min-height: 100vh;
  background:
    radial-gradient(circle at 90% 8%, rgba(2, 149, 170, 0.1), transparent 30rem),
    var(--paper);
}

.library-main {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: clamp(54px, 8vw, 104px) clamp(24px, 6vw, 88px) 90px;
}

.library-hero {
  max-width: 1040px;
  margin-bottom: clamp(44px, 6vw, 78px);
}

.library-hero h1 {
  margin: 18px 0 24px;
  font-size: clamp(3.4rem, 7vw, 7.8rem);
  font-weight: 860;
  letter-spacing: -0.065em;
  line-height: 0.92;
}

.library-hero h1 span {
  color: var(--teal);
}

.library-hero > p:last-child {
  max-width: 780px;
  margin: 0;
  color: var(--ink-soft);
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  line-height: 1.7;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.story-card {
  min-height: 390px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: clamp(24px, 3vw, 38px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: 0 18px 55px rgba(25, 34, 36, 0.055);
  text-align: left;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.story-card:hover {
  transform: translateY(-5px);
  border-color: rgba(2, 149, 170, 0.45);
  box-shadow: 0 26px 70px rgba(25, 34, 36, 0.09);
}

.story-card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 44px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.story-card-topline > span {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  color: var(--white);
  background: var(--ink);
  letter-spacing: 0;
}

.story-card h2 {
  margin: 14px 0 16px;
  font-size: clamp(1.75rem, 2.6vw, 2.8rem);
  line-height: 1.02;
  letter-spacing: -0.045em;
}

.story-card > p:not(.eyebrow) {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.65;
}

.story-card-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 34px;
  color: var(--teal-deep);
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.library-link,
.story-switch {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 254, 250, 0.78);
  padding: 0 14px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.story-switch {
  max-width: 170px;
  white-space: nowrap;
}

.story-context-mini {
  margin-top: auto;
  padding-top: 30px;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.story-context-mini small,
.story-context-mini strong {
  display: block;
}

.story-context-mini small {
  margin-bottom: 6px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.story-context-mini strong {
  color: #fff;
  font-size: 13px;
  line-height: 1.35;
}

/* Homepage only: FluencyLab brand board treatment. The Grammar Deep Dive route
   also uses .library-screen, so :has() keeps these changes isolated to the
   conversation library rather than quietly repainting the rest of the app. */
.library-screen:has(.story-grid[aria-label="Choose a conversation"]) {
  --fl-orange: #e55d2e;
  --fl-ivory: #f6f1e8;
  --fl-stone: #d4d1c8;
  --fl-charcoal: #1f2326;
  --fl-cloud: #a7b3b8;
  --fl-white: #fffdf8;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  color: var(--fl-charcoal);
  background:
    radial-gradient(circle at 82% 17%, rgba(167, 179, 184, 0.16) 0 16rem, transparent 16.2rem),
    linear-gradient(180deg, #faf7f0 0%, var(--fl-ivory) 56%, #f1ece3 100%);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"])::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 270px;
  right: -4vw;
  width: min(670px, 54vw);
  height: 1px;
  background: rgba(31, 35, 38, 0.18);
  transform: rotate(-8deg);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .intro-header {
  border-color: rgba(31, 35, 38, 0.14);
  background: rgba(246, 241, 232, 0.88);
  backdrop-filter: blur(16px);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .brand-mark {
  color: var(--fl-charcoal);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .brand-mark strong,
.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .eyebrow {
  color: var(--fl-orange);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-link {
  color: var(--fl-charcoal);
  border-color: rgba(31, 35, 38, 0.17);
  background: rgba(255, 253, 248, 0.7);
  text-decoration: none;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-link:hover {
  border-color: var(--fl-orange);
  background: var(--fl-white);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-main {
  position: relative;
  width: min(1520px, 100%);
  padding-top: clamp(62px, 8vw, 118px);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-main::before {
  content: "LISTEN   /   READ   /   REPAIR   /   NOTICE";
  position: absolute;
  top: 26px;
  right: clamp(24px, 6vw, 88px);
  color: rgba(31, 35, 38, 0.47);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.27em;
  white-space: pre;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero {
  position: relative;
  max-width: none;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.7fr);
  column-gap: clamp(38px, 7vw, 112px);
  align-items: center;
  margin-bottom: clamp(58px, 8vw, 104px);
  padding: clamp(30px, 4vw, 52px) 0 clamp(32px, 4vw, 54px);
  border-bottom: 1px solid rgba(31, 35, 38, 0.18);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-copy {
  min-width: 0;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 74px;
  height: 4px;
  background: var(--fl-orange);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero .eyebrow {
  margin-bottom: 16px;
  font-size: 10px;
  letter-spacing: 0.22em;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero h1 {
  margin: 0;
  max-width: 920px;
  color: var(--fl-charcoal);
  font-size: clamp(4.2rem, 8.2vw, 9.4rem);
  font-weight: 880;
  letter-spacing: -0.078em;
  line-height: 0.82;
  white-space: pre-line;
  text-wrap: balance;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-copy > p:last-child {
  max-width: 390px;
  margin: 28px 0 0;
  padding: 18px 0 0;
  border-top: 3px solid var(--fl-orange);
  color: var(--fl-charcoal);
  font-size: clamp(1rem, 1.25vw, 1.15rem);
  line-height: 1.68;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-art {
  width: 100%;
  max-width: 470px;
  height: clamp(390px, 43vw, 620px);
  justify-self: end;
  margin: 0;
  overflow: hidden;
  border: 1px solid rgba(31, 35, 38, 0.14);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-art img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-grid {
  gap: clamp(14px, 2vw, 24px);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card {
  position: relative;
  min-height: 410px;
  overflow: hidden;
  padding: clamp(26px, 3vw, 40px);
  border: 1px solid rgba(31, 35, 38, 0.14);
  border-radius: 4px;
  background: rgba(255, 253, 248, 0.82);
  box-shadow: none;
  color: var(--fl-charcoal);
  isolation: isolate;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background: var(--fl-orange);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card::after {
  content: "";
  position: absolute;
  z-index: -1;
  right: -68px;
  bottom: -88px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 28px solid rgba(167, 179, 184, 0.14);
  transition: transform 220ms ease, border-color 220ms ease;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:nth-child(2) {
  background: rgba(212, 209, 200, 0.31);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:nth-child(3) {
  background: var(--fl-charcoal);
  color: var(--fl-white);
  border-color: var(--fl-charcoal);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:nth-child(3)::after {
  border-color: rgba(246, 241, 232, 0.11);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:hover {
  transform: translateY(-7px);
  border-color: rgba(229, 93, 46, 0.72);
  box-shadow: 0 24px 60px rgba(31, 35, 38, 0.12);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:hover::after {
  transform: scale(1.12) translate(-6px, -5px);
  border-color: rgba(229, 93, 46, 0.18);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card-topline {
  margin-bottom: 48px;
  color: rgba(31, 35, 38, 0.6);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:nth-child(3) .story-card-topline,
.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:nth-child(3) > p:not(.eyebrow) {
  color: rgba(255, 253, 248, 0.66);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card-topline > span {
  color: var(--fl-white);
  background: var(--fl-orange);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card .eyebrow {
  color: var(--fl-orange);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card h2 {
  margin: 14px 0 18px;
  font-size: clamp(1.85rem, 2.7vw, 3.05rem);
  line-height: 0.98;
  letter-spacing: -0.052em;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card > p:not(.eyebrow) {
  color: rgba(31, 35, 38, 0.68);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card-action {
  padding-top: 38px;
  border-top: 1px solid rgba(31, 35, 38, 0.11);
  color: var(--fl-orange);
  letter-spacing: 0.09em;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:nth-child(3) .story-card-action {
  border-top-color: rgba(255, 253, 248, 0.14);
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card-action svg {
  transition: transform 180ms ease;
}

.library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card:hover .story-card-action svg {
  transform: translateX(5px);
}

@media (max-width: 1050px) {
  .story-grid {
    grid-template-columns: 1fr;
  }

  .story-card {
    min-height: 290px;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.72fr);
    gap: clamp(28px, 5vw, 58px);
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-art {
    height: clamp(360px, 52vw, 520px);
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card {
    min-height: 285px;
  }
}

@media (max-width: 760px) {
  .library-main {
    padding-top: 42px;
  }

  .library-hero h1 {
    font-size: clamp(3rem, 15vw, 5.3rem);
  }

  .story-card {
    min-height: 310px;
  }

  .story-switch span {
    display: none;
  }

  .story-switch {
    width: 42px;
    padding: 0;
    justify-content: center;
  }

  .story-context-mini {
    display: none;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"])::after {
    display: none;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-main {
    padding: 24px 18px 72px;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-main::before {
    display: none;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero {
    display: grid;
    min-height: min(680px, calc(100svh - 90px));
    grid-template-columns: 1fr;
    align-content: end;
    margin-bottom: 0;
    padding: 28px 20px 34px;
    border-bottom: 0;
    overflow: hidden;
    isolation: isolate;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-art {
    position: absolute;
    z-index: -2;
    inset: 0;
    max-width: none;
    height: 100%;
    border: 0;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-art img {
    object-position: center 42%;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero::after {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 28% 0 0;
    background: linear-gradient(180deg, transparent, rgba(246, 241, 232, 0.9) 42%, var(--fl-ivory) 72%);
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero::before {
    display: none;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero .eyebrow {
    margin-bottom: 12px;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-copy {
    padding-top: 290px;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero h1 {
    max-width: 100%;
    font-size: clamp(3rem, 15vw, 5rem);
    line-height: 0.88;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .library-hero-copy > p:last-child {
    max-width: 100%;
    margin-top: 24px;
    padding: 18px 0 0;
    border-top: 1px solid rgba(31, 35, 38, 0.18);
    border-left: 0;
    font-size: 0.98rem;
    line-height: 1.62;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-grid {
    margin-top: 92px;
  }

  .library-screen:has(.story-grid[aria-label="Choose a conversation"]) .story-card {
    min-height: 315px;
    border-radius: 3px;
  }
}
