@import url('https://fonts.googleapis.com/css2?family=Jost:wght@400;500;600&family=Source+Sans+3:wght@400;500;600;700&display=swap');

:root {
  --ink: #49236d;
  --ink-soft: #70508b;
  --purple: #6b4388;
  --purple-deep: #4a2468;
  --lavender: #eee3f2;
  --lavender-line: #e2d1eb;
  --paper: #fffdfd;
  --sage: #6e8e69;
  --sage-deep: #55704f;
  --sage-soft: #ecf3e8;
  --sage-line: #d3dfcd;
  --muted: #897a91;

  /* One radius scale, used everywhere */
  --r-card: 4px;
  --r-ctrl: 4px;
  --r-pill: 999px;
  --ctrl-h: 38px;
}

* { box-sizing: border-box; }

body {
  margin: 0; color: var(--ink);
  background: radial-gradient(ellipse at 88% 75%, rgba(224,235,219,.36), transparent 30rem),
              linear-gradient(135deg, #f3eaf6 0%, #fffafa 48%, #f5edf6 100%);
  font-family: "Source Sans 3", Arial, sans-serif;
}

h1, h2, p { margin-top: 0; }

:focus-visible { outline: 2px solid #8a6aa6; outline-offset: 2px; }

/* ---------- Header + banner ---------- */
.topbar {
  height: 56px; padding: 0 max(36px, calc((100% - 1840px) / 2)); display: flex; align-items: center;
  justify-content: space-between; background: rgba(255,251,255,.94);
  border-bottom: 1px solid #e5d7eb; box-shadow: 0 3px 14px rgba(63,35,77,.07);
}
.brand {display: flex; align-items: center; gap: 20px;}
.brand-mark {width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 38px;}
.brand-mark img {width: 100%; height: 100%; object-fit: contain; display: block;}
.brand-title { font: 400 24px/1.1 Georgia, "Times New Roman", Times, serif; }
.brand-subtitle { margin-top: 3px; color: #8b7698; font: 500 10px "Jost", "Source Sans 3", sans-serif; letter-spacing: 2.4px; text-transform: uppercase; }

.forest-banner {
  height: 174px; position: relative; overflow: hidden;
  background-image: linear-gradient(0deg, rgba(31,24,43,.20), rgba(45,29,55,.04)),
    url("https://images.unsplash.com/photo-1588397290247-777ef23e6e49");
  background-size: cover; background-position: center 52%; background-color: #51445e;
}

/* ---------- Layout ---------- */
.page-layout {
  width: min(1840px, calc(100% - 72px)); margin: 0 auto; padding: 22px 0 34px;
  display: grid; grid-template-columns: minmax(0, 1fr) clamp(300px, 22vw, 400px); gap: 40px; align-items: start;
}
.library-column { min-width: 0; }

.panel, .story-card {
  background: rgba(255,253,253,.88);
  border: 1px solid var(--lavender-line);
  box-shadow: 0 5px 20px rgba(76,44,91,.055);
}

/* ---------- Buttons, selects, inputs (shared 38px control height) ---------- */
.ao3-button {
  min-height: var(--ctrl-h); padding: 0 16px; cursor: pointer;
  border: 1px solid #cbbfd3; border-radius: var(--r-ctrl);
  color: #493b55; background: linear-gradient(#fff, #f1eef4);
  box-shadow: 0 1px 2px rgba(46,31,56,.08);
  font: 600 13px "Source Sans 3", sans-serif;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.ao3-button:hover { background: linear-gradient(#fff, #e8e1ee); border-color: #a894b5; }
.ao3-button.active { color: #fff; border-color: #62417d; background: linear-gradient(#7a5b93, #5f3b7b); }

select, input {
  height: var(--ctrl-h);
  border: 1px solid #d7c5e1;
  border-radius: var(--r-ctrl);
  color: #4e3267;
  background-color: #fffdfd;
  font: 600 13px "Source Sans 3", sans-serif;
}
select {
  appearance: none; -webkit-appearance: none;
  min-width: 0; padding: 0 34px 0 13px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236b4388' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 12px;
}
select:hover, input:hover { border-color: #b49bc4; }
input[type="search"] {
  padding: 0 14px 0 38px; font-weight: 500;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23806b8d' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 13px center; background-size: 16px;
}
input::placeholder { color: #9a8aa5; font-weight: 400; }

/* ---------- Sort / filter bar + search: matching deep-purple pair ---------- */
.toolbar, .search-form {
  padding: 14px 18px;
  border-radius: var(--r-card);
  background: linear-gradient(135deg, #5d3979 0%, #47245f 100%);
  border: 1px solid #3d1f53;
  box-shadow: 0 8px 22px rgba(63,35,87,.22);
}
.toolbar {
  position: sticky; top: 12px; z-index: 20;
  margin-bottom: 14px;
  display: flex; flex-wrap: wrap; align-items: stretch; justify-content: center; gap: 14px 0;
}
.control-group {
  flex: 1 1 auto; display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 12px;
  padding: 0 16px;
}
.control-group:first-child { padding-left: 0; }
.control-group:last-child { padding-right: 0; }
.control-group + .control-group { border-left: 1px solid rgba(255,255,255,.16); }
.control-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.control-label {
  color: #cdbddb; font: 700 11px "Source Sans 3", sans-serif;
  letter-spacing: 1.4px; text-transform: uppercase; white-space: nowrap; text-align: center;
}
.toolbar select, .search-form input { border-color: transparent; background-color: #fff; }
.toolbar select:hover, .search-form input:hover { border-color: #b8e0b1; }
.segmented { display: flex; gap: 6px; }
.segmented .ao3-button {
  min-height: var(--ctrl-h); padding: 0 12px;
  border: 1px solid rgba(255,255,255,.26); border-radius: var(--r-ctrl);
  background: rgba(255,255,255,.13); box-shadow: none; color: #f1e9f7;
}
.segmented .ao3-button:not(.active):hover { background: rgba(255,255,255,.22); border-color: rgba(255,255,255,.42); }
.segmented .ao3-button.active {
  color: #fff; border-color: #9bbd95;
  background: linear-gradient(#88aa82, #648860);
  box-shadow: 0 1px 4px rgba(20,40,18,.35);
}

.search-form { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.search-form input { flex: 1; min-width: 0; }
.search-form .search-button {
  color: #fff; border-color: #587b55; padding: 0 18px;
  background: linear-gradient(#88aa82, #648860);
}
.search-form .search-button:hover { background: linear-gradient(#94b58e, #6b9267); }

.results-group { flex: 0 0 auto; }
.results-group p { margin: 0; color: #e6dcef; font-size: 13px; font-weight: 600; white-space: nowrap; }

.empty-state {
  padding: 28px 20px; text-align: center; color: var(--ink-soft);
  border: 1px dashed #cdb6dc; border-radius: var(--r-card); background: rgba(255,253,253,.7);
}
.empty-state[hidden] { display: none; }

/* ---------- Story cards ---------- */
.story-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

.story-card {
  padding: 18px 18px 16px 22px; border-radius: 0;
  display: flex; gap: 18px; position: relative;
  background: linear-gradient(110deg, rgba(255,253,253,.97), rgba(250,245,250,.92));
  transition: transform .18s ease, box-shadow .18s ease;
}
.story-card[hidden] { display: none; }
.story-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(76,44,91,.10); }

.story-main { min-width: 0; flex: 1; display: flex; flex-direction: column; }

/* Title, author next to it, status at the far right */
.story-title-line { display: flex; align-items: baseline; gap: 10px; min-height: 30px; }
.story-title-line h2 {
  margin: 0; min-width: 0; flex: 0 1 auto;
  font: 700 23px/1.3 "Source Sans 3", Arial, sans-serif;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.story-title-line h2 a { color: var(--purple-deep); text-decoration: none; }
.story-title-line h2 a:hover,
.story-title-line h2 a:focus-visible { color: #2f1546; text-decoration: none; }
.author {
  flex: 0 1 auto; min-width: 0; max-width: 38%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--purple); font-size: 14px; font-weight: 500; font-style: normal;
}
.status {
  position: absolute; top: 26px; right: 26px; z-index: 2;
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px;
  border-radius: var(--r-ctrl); color: #fff; border: 1px solid transparent;
  font: 700 10px "Source Sans 3", sans-serif; text-transform: uppercase; letter-spacing: .8px;
  box-shadow: 0 1px 4px rgba(20,12,28,.35);
}
.status.complete { border-color: #587b55; background: linear-gradient(#7c9b77, #5f805c); }
.status.wip { border-color: #62417d; background: linear-gradient(#7a5b93, #5f3b7b); }

/* Tags: a single row when collapsed, "View N more" sits at the end of that row */
.tag-line { display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; margin-top: 10px; height: 26px; overflow: hidden; }
.tag-line.open { flex-wrap: wrap; height: auto; overflow: visible; }
.tag {
  flex: none; height: 26px; display: inline-flex; align-items: center; padding: 0 11px;
  border-radius: var(--r-ctrl); color: #6a527b; background: #f2ebf6;
  border: 1px solid transparent; font-size: 12px; white-space: nowrap;
}
.tag.tag-hidden { display: none; }
.tag.rating-tag { color: #4a2468; background: #fff; border-color: #cdb6dc; font-weight: 700; }

/* Original-style text toggles */
.text-toggle {
  padding: 0; border: 0; background: transparent; color: #79518f; cursor: pointer;
  font: 600 12px "Source Sans 3", sans-serif; text-decoration: underline; text-underline-offset: 2px;
}
.text-toggle:hover { color: #512875; }
.tags-toggle { flex: none; margin-left: 4px; white-space: nowrap; }
.tags-toggle[hidden] { display: none; }
.summary-toggle { align-self: flex-start; margin-top: 4px; line-height: 18px; }
.text-toggle.is-idle { visibility: hidden; }

/* Summary: always reserves exactly two lines */
.summary { margin: 12px 0 0; color: #5f5368; font-size: 15px; line-height: 1.5; min-height: 3em; }
.summary.clamped { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.summary.open { white-space: pre-line; }

.metadata {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 16px;
  margin-top: auto; padding-top: 10px; color: #76578c; font-size: 12px;
}
.metadata span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.meta-icon { flex: none; color: #8a63a3; }

.story-art {
  flex: 0 0 120px;
  width: 120px;
  height: 1900px;
  min-height: 190px;
  max-height: 190px;
  align-self: start;
  border-radius: 0;
  overflow: hidden;
  background-color: #70617b;
  background-size: cover;
  background-position: center;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(64,39,77,.10);
}
.story-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(38,27,49,.18), transparent 65%); }

/* ---------- Sidebar ---------- */
.sidebar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; position: sticky; top: 12px; align-self: start; }
.eyebrow { margin: 0 0 5px; color: #9a7ba8; font: 700 10px "Source Sans 3", sans-serif; letter-spacing: 2px; }

.recommend-card {
  position: relative; overflow: hidden; text-align: center; padding: 22px 18px 20px;
  border-radius: var(--r-card); border-color: #cddfc4;
  background: linear-gradient(155deg, #f3f8ef 0%, #e0ebd8 100%);
}
.recommend-card > :not(.sprig) { position: relative; z-index: 1; }
.sprig { position: absolute; width: 100px; height: 143px; opacity: .34; pointer-events: none; overflow: visible; z-index: 0; }
.sprig-a { left: -10px; bottom: -22px; transform: scaleX(-1); }
.sprig-b { right: -10px; top: -22px; transform: scaleY(-1); }
.recommend-card h2 { margin: 7px 0 17px; color: #542b79; font: 700 21px/1.25 "Source Sans 3", Arial, sans-serif; }
.recommend-card h2 span { color: #795b8e; }
.green-button { color: #fff; border-color: #3f6339; background: linear-gradient(#6d9168,#4d7449); padding: 0 20px; }
.green-button:hover { background: linear-gradient(#789b72,#55804f); border-color: #3f6339; }

.popular-card { padding: 19px 18px 22px; border-radius: var(--r-card); position: relative; overflow: hidden; }
.popular-card h2 { margin: 0 0 15px; font: 700 21px "Source Sans 3", Arial, sans-serif; }
.tag-section { position: relative; z-index: 1; }
.tag-section + .tag-section { margin-top: 20px; padding-top: 18px; border-top: 1px solid #e6d9ee; }
.popular-tags { display: flex; flex-flow: row wrap; align-items: flex-start; gap: 7px; position: relative; z-index: 1; }
.popular-tag { max-width: 100%; padding: 6px 12px; border: 1px solid #e2d7e7; border-radius: var(--r-ctrl);
  color: #3e3948; font-size: 12px; white-space: nowrap; }
.popular-tag small { color: #766681; margin-left: 5px; font-size: 11px; }
.popular-tag.lavender { background: #f0e7f3; }
.popular-tag.sage { background: #eaf0e6; border-color: #d8e2d1; }
.popular-tag.stone { background: #f0eeee; border-color: #e2dede; }
.vine-stem { fill: none; stroke: #839c78; stroke-width: 3; stroke-linecap: round; }
.vine-leaf { fill: #91a987; stroke: #718b68; stroke-width: 1.1; }

.rec-note { margin: 0; text-align: center; color: var(--ink-soft); font-size: 13px; }
.rec-note a { color: var(--purple); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.rec-note a:hover { color: var(--purple-deep); }

footer { padding: 15px 20px 25px; text-align: center; color: #9a87a2; font-size: 11px; }
footer span { color: #8a6a9d; padding: 0 7px; }

/* ---------- Responsive ---------- */
@media (max-width: 1050px) {
  .page-layout { grid-template-columns: minmax(0,1fr) 280px; gap: 17px; width: calc(100% - 32px); }
  .control-group { padding: 0 14px; }
  .topbar { padding-inline: 16px; }
}

@media (max-width: 780px) {
  .topbar { height: 68px; padding-inline: 12px; }
  .forest-banner { height: 125px; }
  .page-layout { grid-template-columns: 1fr; width: calc(100% - 24px); padding-top: 14px; }

  .toolbar { position: static; flex-direction: column; align-items: stretch; gap: 12px; }
  .control-group { flex-direction: row; justify-content: space-between; padding: 0; }
  .control-group + .control-group { border-left: 0; border-top: 1px solid rgba(255,255,255,.16); padding-top: 12px; }
  .control-group .control-row { flex: 1; justify-content: flex-end; }
  .control-group select { flex: 1; max-width: 180px; }
  .results-group { justify-content: center; }

  .sidebar { position: static; grid-template-columns: 1fr 1fr; }
  .search-form { grid-column: 1 / -1; }
}

@media (max-width: 540px) {
  .brand-mark { width: 38px; height: 38px; flex-basis: 38px; }
  .brand-mark img { width: 100%; }
  .brand-title { font-size: 20px; }
  .brand-subtitle { font-size: 9px; }

  .story-card { padding: 14px; gap: 12px; }
  .story-title-line h2 {
  font-size: 14px;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
}

.story-title-line {
  flex-wrap: wrap;
  gap: 2px 6px;
  min-height: 0;
}

.author {
  font-size: 12px;
  max-width: 100%;
  white-space: normal;
}

.summary {
  font-size: 12px;
}
  .tag {
  font-size: 12px;
  padding: 0 6px;
  height: 22px;
}

.tag-line {
  height: 22px;
  gap: 4px;
  margin-top: 6px;
}

.tag-line.open {
  height: auto;
}

.story-art { flex-basis: 72px; }
  .status { top: 20px; right: 20px; height: 20px; padding: 0 7px; font-size: 8.5px; letter-spacing: .4px; }

  .metadata { display: grid; grid-template-columns: 1fr 1fr; }

  .sidebar { grid-template-columns: 1fr; }
}
/* ---------- Shared application styles ---------- */

[hidden] {
  display: none !important;
}

.topbar {
  gap: 20px;
}

.story-card {
  padding-bottom: 18px;
  min-height: 226px;
}

.story-card .story-main {
  padding-bottom: 4px;
}

.story-card .story-art {
  display: block;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 100;
  max-width: min(420px, calc(100vw - 44px));
  padding: 13px 18px;
  color: #fff;
  background: #4a2468;
  box-shadow: 0 5px 20px #38204444;
}

@media (max-width: 780px) {
  .topbar {
    height: auto;
    min-height: 68px;
    flex-wrap: wrap;
    padding-block: 10px;
  }
}
.story-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.tag,
.popular-tag {
  font-family: "Source Sans 3", Arial, sans-serif;
  font-size: 12px;
  font-weight: 400;
}
.popular-tag {
  cursor: pointer;
  font-family: inherit;
  background-color: #f0eeee;
}

/* Selected popular tags */
.popular-tag.active {
  color: #fff;
  border-color: transparent;
  box-shadow: none;
  font-weight: 700;
}

/* Purple tags */
.popular-tag.lavender.active {
  background-color: #79518f;
}

/* Green tags */
.popular-tag.sage.active {
  background-color: #557b55;
}

/* Neutral tags */
.popular-tag.stone.active {
  background-color: #77716f;
}

/* Load more button */

#load-more-container {
  display: flex;
  justify-content: center;
  padding: 16px 0 32px;
}

#load-more-container[hidden] {
  display: none;
}

#load-more-button {
  color: #fff;
  background: linear-gradient(#a184b5, #79518f);
  border: 1px solid #79518f;
  border-radius: 12px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

#load-more-button:hover {
  background: linear-gradient(#ad92c0, #89619f);
}

/* Two-stage sticky header (desktop) */
.toolbar-cat { display: none; }
#toolbar-scroll-marker { height: 0; }

@media (min-width: 781px) {
  .brand {
    margin-left: 19px;
  }

  .topbar {
    position: sticky;
    top: var(--header-shift, 0px);
    z-index: 30;
    background: #fffbff;
  }
  .toolbar, .sidebar {
    top: var(--controls-top, 12px);
  }
  body.compact-header .toolbar-cat {
    display: block;
    width: 38px;
    height: 38px;
    object-fit: contain;
    filter: invert(1);
    flex: 0 0 38px;
    align-self: center;
    margin-right: 12px;
  }
  .toolbar .control-group:nth-child(2) { padding-left: 0; }
}

/* Clickable work tags */

.story-card .tag {
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.story-card .tag:hover {
  background: #e2d1eb;
  border-color: #cdb6dc;
}

.story-card .tag.active {
  background: #79518f;
  border-color: #79518f;
  color: #fff;
}


/* Active tag filters in the toolbar */

.results-group {
  flex-wrap: wrap;
  gap: 8px;
}

#active-tag-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 5px 10px;
  border: 1px solid #d9c8e4;
  border-radius: var(--r-ctrl);
  background: #eee3f2;
  color: #49236d;
  font: 600 12px "Source Sans 3", sans-serif;
  cursor: pointer;
}

.active-filter-chip:hover {
  background: #e2d1eb;
}

.filter-chip-label {
  overflow-wrap: anywhere;
}

.filter-chip-cross {
  font-size: 17px;
  line-height: 1;
}


/* Clear indicator on selected Popular and Events tags */

.popular-tag.active::after {
  content: "×";
  margin-left: 8px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
}

/* Recommended story card */

/* ---------- Mobile library controls ---------- */

.mobile-controls {
  display: none;
}

@media (max-width: 780px) {

  .mobile-controls {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
  }

  .mobile-button-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1.6fr;
    gap: 8px;
  }

  .mobile-button-row button {
    min-width: 0;
    min-height: 38px;
    padding: 8px 6px;
    border: 1px solid #3d1f53;
    border-radius: var(--r-ctrl);
    background: linear-gradient(135deg, #5d3979, #47245f);
    color: #fff;
    font: 600 13px "Source Sans 3", sans-serif;
    cursor: pointer;
  }

  .mobile-button-row button.active {
    background: linear-gradient(#9875af, #79518f);
    border-color: #79518f;
  }

  #mobile-recommend-button {
    background: linear-gradient(#6d9168, #4d7449);
    border-color: #3f6339;
  }

  /* Search bar */
  #mobile-search-slot .search-form {
    padding: 10px;
    margin: 0;
  }

  /* Hide filters until requested */
  .toolbar {
    display: none;
  }

  .toolbar.mobile-open {
    display: flex;
    margin-bottom: 12px;
  }

  /* Hide the original sidebar */
  .sidebar {
    display: none;
  }

  /* Mobile tags panel */
  #mobile-tags-slot .popular-card {
    margin: 0;
  }

  /* Active filter chips */
  #mobile-active-filters-slot {
    min-width: 0;
  }

  #mobile-active-filters-slot:empty {
    display: none;
  }

  #mobile-active-filters-slot:has(
    #active-tag-filters[hidden]
  ) {
    display: none;
  }

}

.story-card.recommended-card {
  background: linear-gradient(
    135deg,
    #f5f8f0 0%,
    #e5eedc 55%,
    #d8e6cf 100%
  );
  border-color: #b9cdae;
}
/* Rating filter buttons */

.rating-filters {
  gap: 4px;
}

.rating-filters .ao3-button {
  width: 30px;
  min-width: 30px;
  padding: 0;
}

.rating-group {
  gap: 8px;
}

/* Clear all filters */

.results-count-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.clear-filters-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: #e6dcef;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  white-space: nowrap;
}

.clear-filters-button:hover {
  color: #ffffff;
}

.mobile-clear-filters-row {
  display: none;
}

@media (max-width: 780px) {
  #clear-filters {
    display: none;
  }

  .mobile-clear-filters-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  #mobile-active-filters-slot {
    flex: 1;
    min-width: 0;
  }

  #mobile-clear-filters {
    flex-shrink: 0;
    margin-left: auto;
  }

  .mobile-clear-filters-row:has(button[hidden]) {
    display: none;
  }

  #mobile-clear-filters {
    color: var(--purple);
  }

  #mobile-clear-filters:hover {
    color: var(--purple-deep);
  }
}

/* ---------- Whiskers' favorites ---------- */

.popular-tag.steel-blue {
  background-color: #e3edf4;
  border-color: #cbdce8;
  color: #426681;
}

.popular-tag.steel-blue:hover {
  background-color: #d2e2ed;
}

.popular-tag.steel-blue.active {
  background-color: #426681;
  border-color: #426681;
  color: #ffffff;
}

/* Stack active filter chips on desktop */
@media (min-width: 781px) {
  .results-group {
    flex-wrap: nowrap;
    align-items: center;
  }

  #active-tag-filters {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 4px;
  }

  .active-filter-chip {
    padding: 3px 8px;
    white-space: nowrap;
  }
}

/* Compact mobile tags panel */
@media (max-width: 780px) {

    /* Compact mobile filter panel */

  .toolbar.mobile-open {
    --ctrl-h: 26px;
    padding: 12px 10px;
    gap: 8px;
  }

  .toolbar .control-group {
    gap: 8px;
  }

  .toolbar .control-group + .control-group {
    padding-top: 8px;
  }

  .toolbar .control-label {
    font-size: 10px;
    letter-spacing: 1px;
  }

  .toolbar select {
    font-size: 11px;
    padding: 0 22px 0 8px;
    background-position: right 7px center;
    background-size: 10px;
  }

  .toolbar .segmented {
    gap: 4px;
  }

  .toolbar .segmented .ao3-button {
    font-size: 11px;
    padding: 0 8px;
  }

  .toolbar .rating-filters .ao3-button {
    width: 26px;
    min-width: 26px;
    padding: 0;
  }

  .toolbar .results-group p {
    font-size: 11px;
  }
    .active-filter-chip {
    font-size: 11px;
    line-height: 1.3;
    font-weight: 400;
    padding: 4px 6px;
    gap: 4px;
  }

  .filter-chip-cross {
    font-size: 12px;
    line-height: 1;
  }

  .story-card .tag {
    font-size: 10px;
    height: 20px;
    padding: 0 5px;
  }

  .story-card .tag-line {
    height: 20px;
    gap: 4px;
  }

  .story-card .tag-line.open {
    height: auto;
  }

  .story-card .tags-toggle {
    font-size: 10px;
  }

  #mobile-tags-slot .popular-card {
    padding: 12px 10px;
  }

  #mobile-tags-slot .popular-card h2 {
    font-size: 16px;
    line-height: 1.2;
    margin-bottom: 8px;
  }

  #mobile-tags-slot .popular-tags {
    gap: 4px;
  }

  #mobile-tags-slot .popular-tag {
    font-size: 11px;
    line-height: 1.3;
    padding: 4px 6px;
  }

  #mobile-tags-slot .tag-section + .tag-section {
    margin-top: 12px;
    padding-top: 10px;
  }

  #mobile-tags-slot .popular-tag.active::after {
    font-size: 12px;
    margin-left: 4px;
  }
}

/* ---------- Mobile sticky header and search ---------- */

#mobile-search-slot {
  display: none;
}

@media (max-width: 780px) {

  /* Keep the white header visible */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: #fffbff;
  }

  /* Keep search directly below the white header */
  #mobile-search-slot {
    display: block;
    position: sticky;
    top: var(--mobile-header-height, 68px);
    z-index: 30;

    margin: -14px -12px 0;
    padding: 14px 12px 10px;

    background: #f3edf5;
  }

  /* Preserve the existing search styling */
  #mobile-search-slot .search-form {
    margin: 0;
  }

  /* Everything else scrolls normally */
  .mobile-controls,
  .toolbar.mobile-open,
  #mobile-tags-slot {
    position: static;
  }

  /* Banner scrolls out of view */
  .forest-banner {
    position: relative;
  }
}

/* Compact mobile sorting dropdowns */
@media (max-width: 780px) {
  .toolbar #sort-by,
  .toolbar #sort-direction {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
    padding: 0 22px 0 8px;
  }
}