/* Discover rail: curated collections + editor's picks beside the paper grid.
   The rail markup is only emitted when there is content, so an empty database
   (e.g. production before curation) renders the grid full-width as before. */

.home-layout {
  max-width: 1400px;
  /* own top spacing: must work with AND without the discover sections above
     (production starts uncurated, so nothing renders between hero and toolbar) */
  margin: 28px auto 0 auto;
  padding: 0 40px;
  display: flex;
  align-items: flex-start;
  gap: 28px;
}
.home-main {
  flex: 1 1 auto;
  min-width: 0;
}
/* neutralize the grid's own page paddings when nested in the layout */
.home-layout .grid-container {
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

.home-rail {
  flex: 0 0 320px;
  width: 320px;
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.rail-block {
  background: white;
  border: 1px solid #e6eaf0;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 2px 10px rgba(16, 42, 78, 0.06);
}
.rail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.rail-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #33445c;
}
.rail-head h3 i { color: var(--ais-blue); margin-right: 6px; }
.rail-more {
  font-size: 12px;
  font-weight: 600;
  color: var(--ais-blue);
  text-decoration: none;
}
.rail-more:hover { text-decoration: underline; }

/* --- Collection cards --- */
.rail-col-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e6eaf0;
  margin-bottom: 12px;
  background: white;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.rail-col-card:last-child { margin-bottom: 0; }
.rail-col-card:hover {
  transform: translateY(-2px);
  border-color: var(--ais-blue);
  box-shadow: 0 8px 20px rgba(16, 42, 78, 0.14);
}
.rail-col-mosaic {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 58px;
  gap: 2px;
  background: #dfe6ee;
}
.rail-col-mosaic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(0.92);
}
.rail-col-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(13, 30, 56, 0) 30%, rgba(13, 30, 56, 0.55) 100%);
  pointer-events: none;
}
.rail-col-flag {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: white;
  background: rgba(214, 92, 33, 0.95);
  padding: 3px 8px;
  border-radius: 20px;
}
.rail-col-flag i { margin-right: 3px; }
.rail-col-body { padding: 12px 14px 13px 14px; }
.rail-col-name {
  font-size: 14.5px;
  font-weight: 700;
  color: #1c2c44;
  line-height: 1.25;
}
.rail-col-desc {
  margin-top: 4px;
  font-size: 12px;
  color: #63718a;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rail-col-meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: #63718a;
}
.rail-ring { flex: 0 0 auto; transform: rotate(-90deg); }
.rail-ring-bg { fill: none; stroke: #e2e8f1; stroke-width: 3; }
.rail-ring-fg {
  fill: none;
  stroke: var(--ais-green, #3f9d4e);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease;
}
.rail-col-progress { font-weight: 600; color: #3d4c66; }
.rail-col-count { margin-left: auto; }

/* --- Editor's picks --- */
.rail-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease;
}
.rail-pick:hover { background: #f2f6fb; }
.rail-pick-thumb {
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 9px;
  object-fit: cover;
  border: 1px solid #e6eaf0;
}
.rail-pick-txt { min-width: 0; }
.rail-pick-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #24344e;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rail-pick-meta {
  margin-top: 2px;
  font-size: 11px;
  color: #7b88a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail-pick-play {
  margin-left: auto;
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #eef4fb;
  color: var(--ais-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}
.rail-pick.is-listened .rail-pick-play {
  background: #e5f4e8;
  color: #3f9d4e;
}

/* --- Mobile / narrow: rail becomes a horizontal discover strip above the grid --- */
@media (max-width: 1100px) {
  .home-layout {
    flex-direction: column;
  }
  .home-rail {
    order: -1;
    position: static;
    width: 100%;
    flex: 1 1 auto;
  }
  .rail-collections-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }
  .rail-collections-scroll .rail-col-card {
    flex: 0 0 240px;
    margin-bottom: 0;
  }
  .rail-picks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 4px;
  }
}

/* align the layout padding with the rest of the page, which switches to 15px only below 768px */
@media (max-width: 768px) {
  .home-layout {
    padding: 0 15px;
  }
}

/* ---------- library toolbar (replaces stacked filter bars + big search) ---------- */

.lib-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin: 2px 0 10px 0;
}
.lib-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #1c2c44;
}
.lib-count {
  font-weight: 600;
  font-size: 12.5px;
  color: #7b88a0;
  margin-left: 2px;
}
.lib-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0;
}
.lib-search {
  width: 200px;
  padding: 7px 13px;
  font-size: 13px;
  border: 1px solid #d8dfe8;
  border-radius: 18px;
  background: #fff;
  color: #33445c;
}
.lib-search::placeholder { color: #97a3b6; }
.lib-search:focus { outline: 2px solid rgba(0, 79, 128, 0.22); border-color: var(--ais-blue, #004f80); }
.lib-tools select {
  padding: 6px 10px;
  border-radius: 18px;
  border: 1px solid #d8dfe8;
  background: white;
  font-size: 12.5px;
  color: #33445c;
  cursor: pointer;
  max-width: 170px;
}
.lib-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
  padding: 2px 0 10px 0;
  margin-bottom: 8px;
  scrollbar-width: thin;
}
.lib-chips .topic-chip { flex: 0 0 auto; }
@media (max-width: 768px) {
  .lib-search { flex: 1 1 140px; width: auto; }
}

/* ---------- discover sections: stacked full-width variant (replaces the side rail) ---------- */

.discover-wrap {
  max-width: 1400px;
  margin: 0 auto;
  /* small bottom padding only — the toolbar below brings its own 28px top margin */
  padding: 20px 40px 2px 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.disc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.disc-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #33445c;
}
.disc-head h3 i { color: var(--ais-blue); margin-right: 6px; }
.disc-collections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}
.disc-collections .rail-col-card { margin-bottom: 0; }
.disc-picks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 8px 14px;
}
.disc-picks .rail-pick {
  background: white;
  border: 1px solid #e6eaf0;
}
.disc-picks .rail-pick:hover { background: #f2f6fb; }
@media (max-width: 900px) {
  .disc-collections {
    display: flex;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }
  .disc-collections .rail-col-card { flex: 0 0 240px; }
}
@media (max-width: 768px) {
  .discover-wrap { padding: 14px 15px 2px 15px; }
}
