/* One-pane home: no top nav, header inside the pane. */
#topBar { display: none !important; }
main {
  padding: env(safe-area-inset-top, 0) 0 0 !important;
  max-width: none !important;
}

#homeView {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 20px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  box-sizing: border-box;
}
#homeView .home-zone,
#homeView .discover { min-width: 0; }

#homeView .home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 8px;
}
#homeView .home-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

/* Re-host the #menu inside the header (no longer floating). */
#homeView .home-header > #menu {
  position: relative !important;
  top: auto !important;
  right: auto !important;
  transform: none !important;
  margin: 0 !important;
}
#homeView .home-header #menu[hidden] { display: block !important; }
#homeView .home-header > #menu > summary {
  min-width: 0;
  min-height: 0;
  padding: 4px 8px;
  background: transparent;
}

#homeView .home-zone.pending { opacity: 0.55; }

/* Hero — next episode (widget-style) */
#homeView .home-hero {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #3b1e54 0%, #1b3a5b 60%, #0f2a44 100%);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  min-height: 120px;
}

#homeView .home-hero.secondary { opacity: 0.92; }

#homeView .home-hero .hero-img {
  display: block;
  width: 100%;
  height: auto;
}

#homeView .home-hero .hero-shade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 45%;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(23, 34, 56, 0) 0%, rgba(23, 34, 56, 0.85) 100%);
}

#homeView .heroes-row { display: flex; flex-direction: column; gap: 12px; }

/* When the heroes row holds multiple watching-show posters, it scrolls
   horizontally like the other rows. */
#homeView .heroes-row.is-scroll {
  flex-direction: row;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  scrollbar-width: none;
  min-width: 0;
}
#homeView .heroes-row.is-scroll::-webkit-scrollbar { display: none; }
#homeView .heroes-row.is-scroll > * {
  flex: 0 0 calc((100% - 10px) / 2);
  scroll-snap-align: start;
}

#homeView .home-hero .badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  color: var(--fresh);
  font-weight: 600;
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 999px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

#homeView .home-hero .meta {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

#homeView .home-hero .title { font-size: 1.05rem; font-weight: 700; margin: 0 0 2px; }
#homeView .home-hero .ep { font-size: 0.82rem; color: var(--muted); margin: 0; }

#homeView .home-hero .check {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

#homeView .home-hero .check svg {
  width: 22px; height: 22px;
  stroke: currentColor; stroke-width: 2.4;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}

/* Poster grids and scrollers */
#homeView .poster-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

#homeView .poster-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  padding-bottom: 4px;
  scrollbar-width: none;
  min-width: 0;
}
#homeView .poster-scroll::-webkit-scrollbar { display: none; }
#homeView .poster-scroll > * {
  flex: 0 0 calc((100% - 20px) / 3);
  scroll-snap-align: start;
}

/* No watchlist/watched/watching badges on the home (matches the old next view). */
#homeView .poster-status--watchlist,
#homeView .poster-status--watched,
#homeView .poster-status--watching,
#homeView .add-watchlist-btn,
#homeView .more-like-btn,
#homeView .poster-top { display: none !important; }

/* Tablet — keep single column but breathe more. */
@media (min-width: 720px) and (max-width: 1099px) {
  #homeView {
    max-width: 880px;
    padding: 28px 24px 32px;
    gap: 20px;
  }
  #homeView .home-hero { aspect-ratio: 21/9; }
  #homeView .home-hero.secondary { aspect-ratio: 21/7; }
  #homeView .home-hero .title { font-size: 1.25rem; }
  #homeView .home-hero .ep { font-size: 0.9rem; }
  #homeView .poster-row { grid-template-columns: repeat(5, 1fr); }
  #homeView .poster-scroll > * { flex: 0 0 calc((100% - 4 * 10px) / 5); }
  #homeView .home-title { font-size: 1.4rem; }
}

/* Desktop overrides moved to the bottom of this file so they win the cascade
   over the base rules above. */

/* Placeholder gradient swatches */
#homeView .g1 { background: linear-gradient(160deg, #be123c, #1f1147); }
#homeView .g2 { background: linear-gradient(160deg, #0e7490, #0f172a); }
#homeView .g3 { background: linear-gradient(160deg, #b45309, #1c1917); }
#homeView .g4 { background: linear-gradient(160deg, #4338ca, #082f49); }
#homeView .g5 { background: linear-gradient(160deg, #166534, #052e16); }
#homeView .g6 { background: linear-gradient(160deg, #7c2d12, #1c1917); }
#homeView .g7 { background: linear-gradient(160deg, #6d28d9, #0c0a09); }
#homeView .g8 { background: linear-gradient(160deg, #0369a1, #082f49); }

/* Discovery: moods + trending */
#homeView .discover { display: flex; flex-direction: column; gap: 10px; }

#homeView .moods {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7em, 1fr));
  grid-auto-rows: 1fr;
  gap: 6px;
  min-width: 0;
}
#homeView .moods::-webkit-scrollbar { display: none; }
#homeView .moods button {
  position: relative;
  appearance: none;
  cursor: pointer;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 500;
  line-height: 1.2;
  background: var(--bg-2, #1e2d3d);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  display: grid;
  grid-template-columns: 1.3em 1fr;
  align-items: center;
  gap: 12px;
  text-align: left;
  width: auto;
  min-height: 2.8em;
  overflow: hidden;
}
#homeView .moods button .mood-icon {
  line-height: 1.2;
  text-align: center;
}
#homeView .moods button:hover { background: #243349; }
#homeView .moods .mood-icon {
  font-size: 1.1rem;
  line-height: 1;
  flex: 0 0 auto;
}
#homeView .describe-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 8px 12px;
  background: var(--bg-2, #1e2d3d);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}
#homeView .describe-form:focus-within {
  border-color: rgba(34, 197, 94, 0.6);
}
#homeView .describe-form .mood-icon {
  font-size: 1.1rem;
  flex: 0 0 auto;
}
#homeView .describe-input {
  flex: 1;
  min-width: 0;
  padding: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  resize: none;
  line-height: 1.35;
  max-height: 8em;
  overflow-y: auto;
}
#homeView .describe-input::placeholder { color: var(--muted); }
#homeView .describe-submit {
  flex: 0 0 auto;
  min-height: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #052e16;
}
#homeView .describe-submit svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Trending zone: section title + period tabs in one head row */
#homeView .trending-head {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 4px;
}
#homeView .trending-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

#homeView .trending-period {
  display: inline-flex;
  gap: 14px;
}
#homeView .trending-period button {
  appearance: none;
  cursor: pointer;
  padding: 4px 2px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  background: transparent;
  border: 0;
  color: var(--muted);
  position: relative;
}
#homeView .trending-period button.active {
  color: var(--text);
  font-weight: 600;
}
#homeView .trending-period button.active::after {
  content: "";
  position: absolute;
  left: 25%;
  right: 25%;
  bottom: -2px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

#homeView .row-label {
  margin: 8px 2px 0;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Desktop ── (kept at the bottom of the file so it wins the cascade) */
@media (min-width: 1100px) {
  main > #homeView:not([hidden]) {
    display: grid !important;
    flex-direction: row !important;
  }
  #homeView {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 20px clamp(20px, 3vw, 40px) 24px;
    grid-template-columns: minmax(0, 1fr) 320px;
    column-gap: 20px;
    row-gap: 18px;
  }
  #homeView > .home-header { grid-column: 1 / -1; }

  #homeView > .home-zone:nth-of-type(1) { grid-column: 1; grid-row: 2; }
  #homeView > .home-zone:nth-of-type(3) {
    grid-column: 2;
    grid-row: 2;
    align-self: stretch;
    min-width: 0;
  }
  #homeView > .home-zone:nth-of-type(2),
  #homeView > .home-zone:nth-of-type(4) { grid-column: 1 / -1; }

  #homeView .heroes-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
  }
  #homeView .home-hero.secondary { opacity: 1; }
  #homeView .home-hero .title { font-size: 1.15rem; }
  #homeView .home-hero .ep { font-size: 0.85rem; }
  #homeView .poster-scroll > * { flex: 0 0 calc((100% - 5 * 10px) / 6); }
  #homeView .home-title { font-size: 1.3rem; }

  /* Moods: 2-column grid filling the sidebar height */
  #homeView > .home-zone:nth-of-type(3) .discover {
    height: 100%;
  }
  #homeView .moods {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-flow: row;
    grid-auto-rows: 1fr;
    grid-template-rows: none;
    grid-auto-columns: auto;
    gap: 6px;
    overflow-x: visible;
    overflow-y: auto;
    height: 100%;
    min-height: 0;
  }
  #homeView .moods button {
    width: auto;
    height: auto;
    padding: 10px 10px;
    font-size: 0.92rem;
    border-radius: 10px;
  }
  #homeView .moods .mood-icon { font-size: 1.2rem; }
  #homeView .describe-form { padding: 14px 14px; align-items: flex-start; }
  #homeView .describe-input { font-size: 0.95rem; min-height: 2.6em; }
}

@media (min-width: 1500px) {
  #homeView .poster-scroll > * { flex: 0 0 calc((100% - 6 * 10px) / 7); }
}
@media (min-width: 1800px) {
  #homeView .poster-scroll > * { flex: 0 0 calc((100% - 7 * 10px) / 8); }
}

/* ── Similar-to picker dialog ── */
.similar-picker {
  inset: 0;
  width: 100vw;
  max-width: 100vw;
  height: var(--app-height);
  max-height: var(--app-height);
  border: 0;
  border-radius: 0;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  background: #1e2d3d;
  color: var(--text);
}
.similar-picker[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.similar-picker::backdrop { background: rgba(0, 0, 0, 0.55); }
.similar-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.similar-picker-head h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.similar-picker-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.similar-picker-grid {
  flex: 1;
  min-height: 0;
  grid-template-rows: repeat(var(--rows, 2), minmax(0, 1fr));
  grid-auto-columns: auto;
}
.similar-picker-grid .row-item {
  width: auto;
  height: 100%;
}
.similar-picker-grid .row-item .item-card {
  width: auto;
  height: 100%;
  aspect-ratio: 2 / 3;
}
.similar-picker-empty { padding: 16px; color: var(--muted); text-align: center; grid-column: 1 / -1; }
