/* ==========================================================================
   Browse by subject — Windsor Books
   Concept: a library card catalog. Departments are numbered drawers;
   topics are indexed like entries in a subject list — label on the
   left, arrow on the right. Warm paper tones
   replace flat white. Cards sit in a two-column grid so each row's pair
   starts and ends on the same line; a faint ruled-paper texture fills any
   leftover space in a shorter card instead of leaving a blank void.
   ========================================================================== */

   body.subjects-page turbo-frame#site-main {
    display: block;
    overflow: visible;
  }
  
  @media (prefers-reduced-motion: no-preference) {
    html:has(body.subjects-page) {
      scroll-behavior: smooth;
    }
  }
  
  body.subjects-page {
    --paper: #faf6ec;
    --paper-deep: #f1ead9;
    --card: #fffdf8;
    --ink: #1d4d3f;
    --ink-dark: #12332a;
    --ink-soft: #e9efe9;
    --gold: #b5813a;
    --gold-deep: #8f6526;
    --line: #e2d8bd;
    --text: #2b2a24;
    --text-muted: #746d5c;
  
    background: var(--paper);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
  }
  
  body.subjects-page .subjects-dept__title,
  body.subjects-page .subjects-intro__title,
  body.subjects-page .subjects-catalog__empty {
    font-family: "Fraunces", Georgia, serif;
  }
  
  /* ---- Page top (no hero) ---- */
  .subjects-page-top {
    max-width: var(--wb-content-width, 1200px);
    margin: 0 auto;
    padding: 0.35rem 1.5rem 0;
  }
  
  .subjects-search-strip {
    display: block;
    width: 100%;
    max-width: none;
    margin: 0.2rem auto 1.15rem;
  }

  .subjects-page-search {
    width: 100%;
    margin: 0 !important;
  }

  .subjects-page-search .input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
    overflow: hidden;
    box-shadow: 0 2px 0 var(--line), 0 10px 26px rgba(28, 43, 34, 0.08);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
  }

  .subjects-page-search .input-group:focus-within {
    border-color: var(--gold);
    box-shadow: 0 2px 0 var(--line), 0 10px 26px rgba(181, 129, 58, 0.16);
  }

  .subjects-page-search .form-control {
    flex: 1 1 auto;
    min-width: 0;
    width: 1%;
    border: none;
    height: 48px;
    padding: 0 1.15rem;
    font-family: "Inter", sans-serif;
    font-size: 0.94rem;
    color: var(--text);
    background: transparent;
    box-shadow: none !important;
  }
  
  .subjects-page-search .form-control::placeholder {
    color: var(--text-muted);
  }
  
  .subjects-page-search__submit {
    flex-shrink: 0;
    background: var(--wb-green, #1d4d3f) !important;
    border: none !important;
    color: #fff !important;
    font-weight: 700;
    font-size: 0.9rem;
    padding: 0 1.65rem;
    letter-spacing: 0.01em;
    border-radius: 0 999px 999px 0 !important;
    transition: background 0.18s ease;
  }

  .subjects-page-search__submit:hover {
    background: var(--wb-green-dark, #163d32) !important;
  }

  /* ---- Department picker dropdown ---- */
  .subjects-picker {
    margin-bottom: 1.35rem;
    position: relative;
    z-index: 50;
  }

  .subjects-picker__label {
    display: block;
    margin-bottom: 0.45rem;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--gold-deep);
  }

  .subjects-picker__control {
    position: relative;
  }

  .subjects-picker__trigger {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.8rem 1rem;
    font-family: "Inter", sans-serif;
    font-size: 0.94rem;
    font-weight: 600;
    color: var(--ink-dark);
    text-align: left;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 2px 0 var(--line), 0 8px 22px rgba(28, 43, 34, 0.07);
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
  }

  .subjects-picker__trigger:hover {
    border-color: var(--gold);
  }

  .subjects-picker__trigger[aria-expanded="true"] {
    border-color: var(--gold);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: 0 2px 0 var(--line);
  }

  .subjects-picker__trigger-icon {
    font-size: 1.2rem;
    line-height: 1;
    flex-shrink: 0;
  }

  .subjects-picker__trigger-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .subjects-picker__chevron {
    width: 1.1rem;
    height: 1.1rem;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.2s ease;
  }

  .subjects-picker__trigger[aria-expanded="true"] .subjects-picker__chevron {
    transform: rotate(180deg);
    color: var(--ink);
  }

  .subjects-picker__menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.35rem;
    list-style: none;
    max-height: min(18rem, 50vh);
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--gold);
    border-top: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 14px 32px rgba(28, 43, 34, 0.12);
    z-index: 60;
  }

  .subjects-picker__menu:not([hidden]) {
    display: block;
  }

  .subjects-picker__item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.55rem 0.65rem;
    font-family: "Inter", sans-serif;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.14s ease, color 0.14s ease;
  }

  .subjects-picker__item:hover,
  .subjects-picker__item:focus-visible {
    background: var(--paper);
    color: var(--ink-dark);
    outline: none;
  }

  .subjects-picker__item.is-active {
    background: var(--ink);
    color: #fff;
  }

  .subjects-picker__item.is-active .subjects-picker__item-meta {
    color: rgba(255, 255, 255, 0.75);
  }

  .subjects-picker__item-icon {
    font-size: 1.05rem;
    line-height: 1;
    flex-shrink: 0;
  }

  .subjects-picker__item-text {
    flex: 1;
    min-width: 0;
  }

  .subjects-picker__item-meta {
    flex-shrink: 0;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  /* ---- Scroll to top (bottom-left) ---- */
  .subjects-scroll-top {
    position: fixed;
    right: 1.25rem;
    left: auto;
    bottom: 1.25rem;
    z-index: 400;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: var(--ink);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 3px 0 var(--ink-dark), 0 10px 24px rgba(29, 46, 36, 0.22);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease, background 0.18s ease;
  }

  .subjects-scroll-top.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .subjects-scroll-top:hover {
    background: var(--ink-dark);
  }

  .subjects-scroll-top:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 3px;
  }

  @media (max-width: 768px) {
    .subjects-scroll-top {
      right: 1rem;
      bottom: 1rem;
      width: 2.75rem;
      height: 2.75rem;
    }
  }
  
  /* ---- Catalog ---- */
  .subjects-catalog {
    margin-bottom: 3rem;
    padding-top: 1.5rem;
  }
  
  .subjects-intro {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.25rem;
    margin-bottom: 1.75rem;
    padding: 1.6rem 1.75rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 4px;
    position: relative;
  }
  
  .subjects-intro::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--gold);
    border-radius: 4px 0 0 4px;
  }
  
  .subjects-intro__eyebrow {
    display: block;
    margin-bottom: 0.5rem;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold-deep);
  }
  
  .subjects-intro__title {
    margin: 0 0 0.4rem;
    font-size: clamp(1.35rem, 2.4vw, 1.75rem);
    font-weight: 600;
    font-style: italic;
    color: var(--ink-dark);
    letter-spacing: -0.01em;
  }
  
  .subjects-intro__lead {
    margin: 0;
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--text-muted);
  }
  
  .subjects-intro__filter-wrap {
    flex: 1 1 240px;
    max-width: 300px;
  }
  
  .subjects-intro__filter-label {
    display: block;
    margin-bottom: 0.4rem;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
  }
  
  .subjects-intro__filter {
    width: 100%;
    padding: 0.65rem 1rem;
    font-family: "Inter", sans-serif;
    font-size: 0.9rem;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  }
  
  .subjects-intro__filter::placeholder {
    color: var(--text-muted);
  }
  
  .subjects-intro__filter:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(181, 129, 58, 0.16);
    background: var(--card);
  }
  
  /* ---- Department cards ("drawers") ----
     A real two-column grid, not a reflowing masonry — this keeps your
     original left-to-right department order (masonry columns fill top
     to bottom first, which silently reordered pairs). Grid's default
     stretch makes each row's two cards start and end at the same line;
     .subjects-dept is a column flexbox internally so the shorter card's
     body actually fills that shared height instead of leaving it inert. */
  .subjects-catalog__list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.1rem;
    align-items: start;
  }
  
  .subjects-dept {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(29, 46, 36, 0.04);
    transition: transform 0.22s ease, box-shadow 0.22s ease;
  }
  
  .subjects-dept:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 28px rgba(29, 46, 36, 0.12);
  }
  
  @media (prefers-reduced-motion: no-preference) {
    .subjects-dept {
      animation: subjectsCardIn 0.5s ease both;
      animation-delay: calc(var(--i, 0) * 30ms);
    }
  }
  
  @keyframes subjectsCardIn {
    from {
      opacity: 0;
      transform: translateY(14px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  .subjects-dept.is-hidden {
    display: none !important;
  }
  
  .subjects-dept.is-highlight {
    box-shadow: 0 0 0 3px rgba(181, 129, 58, 0.35);
  }
  
  /* the numbered drawer plate — the one signature flourish */
  .subjects-dept__plate {
    position: absolute;
    top: -0.5rem;
    left: 1rem;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.4rem;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: #fff;
    background: var(--gold);
    border-radius: 3px;
    box-shadow: 0 2px 6px rgba(143, 101, 38, 0.35);
  }

  .subjects-dept__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 1rem 0.75rem;
    background: var(--ink) !important;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
  }
  
  .subjects-dept__header-main {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
  }

  .subjects-dept__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.16);
    border-radius: 6px;
  }
  
  .subjects-dept__header-text {
    min-width: 0;
  }
  
  .subjects-dept__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff !important;
    line-height: 1.2;
  }

  .subjects-dept__meta {
    margin: 0.15rem 0 0;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.64rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.78);
  }

  .subjects-dept__cta {
    display: inline-flex;
    flex-shrink: 0;
    padding: 0.38rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink) !important;
    text-decoration: none !important;
    background: #fff;
    border: 1px solid transparent;
    border-radius: 999px;
    transition: background 0.16s ease, transform 0.16s ease;
  }
  
  .subjects-dept__cta:hover {
    background: var(--paper) !important;
    transform: translateY(-1px);
  }
  
  .subjects-dept__body {
    flex: 1;
    display: flex;
    background: var(--card);
    max-height: 10.5rem;
    overflow-y: auto;
  }

  .subjects-dept__topics {
    display: grid;
    flex: 1;
    align-content: start;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    margin: 0;
    padding: 0.2rem 0 0.35rem;
    list-style: none;
    width: 100%;
  }
  
  .subjects-dept__topic {
    margin: 0;
    padding: 0;
  }
  
  .subjects-dept__topic a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-height: 1.9rem;
    padding: 0.28rem 0.85rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text) !important;
    text-decoration: none !important;
    border-left: 2px solid transparent;
    border-bottom: 1px solid rgba(226, 216, 189, 0.55);
    transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
  }

  .subjects-dept__topic a:hover {
    background: var(--paper-deep);
    border-left-color: var(--gold);
    color: var(--ink-dark) !important;
  }

  .subjects-dept__topic a:hover .subjects-dept__topic-arrow {
    opacity: 1;
    transform: translateX(0);
  }

  .subjects-dept__topic-label {
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.35;
  }

  .subjects-dept__topic-arrow {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--gold-deep);
    opacity: 0;
    transform: translateX(-3px);
    transition: opacity 0.14s ease, transform 0.14s ease;
  }
  
  .subjects-catalog__empty {
    margin: 0;
    padding: 2.5rem 2rem;
    text-align: center;
    font-size: 1.05rem;
    font-style: italic;
    color: var(--text-muted);
    background: var(--card);
    border: 1px dashed var(--line);
    border-radius: 4px;
  }
  
  .subjects-catalog__empty a {
    color: var(--ink) !important;
    font-weight: 600;
    font-style: normal;
  }
  
  /* Departments drop to a single column once a card can no longer
     comfortably fit two columns of topics inside half the page width. */
  @media (max-width: 900px) {
    .subjects-catalog__list {
      grid-template-columns: 1fr;
    }
  }
  
  @media (max-width: 768px) {
    .subjects-page-top {
      padding-left: 1rem;
      padding-right: 1rem;
    }

    .subjects-intro {
      flex-direction: column;
      align-items: stretch;
      padding: 1.35rem 1.35rem 1.5rem;
    }
  
    .subjects-intro__filter-wrap {
      max-width: none;
    }
  
    .subjects-dept__header {
      flex-direction: column;
      align-items: flex-start;
    }
  
    .subjects-dept__cta {
      width: 100%;
      justify-content: center;
      text-align: center;
    }
  }
  
  @media (max-width: 600px) {
    .subjects-dept__topics {
      grid-template-columns: 1fr;
    }

    .subjects-dept__body {
      max-height: 11rem;
    }

    .subjects-dept__plate {
      left: 1rem;
    }
  }
