/* =====================================================================
   Slate — central responsive rules.
   All breakpoint behaviour lives here rather than scattered across the
   component stylesheets. Loaded last so these rules win on override.

   Breakpoints:
     Landing page   : 980 / 860 / 640 / 420px (its own tiers — a long
                       marketing page with wide mockups; see the block below)
     Auth screen    : max-width 860px  (its own tier — the hero pane and the
                       440px form column need more room than the generic
                       tablet tier gives them)
     Tablet & below : max-width 768px  (off-canvas drawer nav, tuned grids)
     Mobile         : max-width 480px  (1–2 col grids, full-width modals)
   ===================================================================== */

/* Dynamic viewport height avoids the mobile URL-bar height jump. */
@supports (height: 100dvh) {
  .app {
    height: 100dvh;
  }
  .auth-screen {
    min-height: 100dvh;
  }
}

/* The mobile nav controls are hidden on desktop. */
.menu-toggle,
.sidebar-backdrop {
  display: none;
}

/* =============================== LANDING PAGE =============================== */
@media (max-width: 980px) {
  .lp-hero {
    grid-template-columns: minmax(0, 1fr);
    gap: 40px;
    min-height: 0;
    padding: 40px 0 70px;
    text-align: center;
  }

  .lp-hero-lede {
    margin: 0 auto;
  }

  .lp-hero-ctas {
    justify-content: center;
  }

  .lp-hero-board {
    width: min(560px, 100%);
    margin: 0 auto;
  }
}

@media (max-width: 860px) {
  .lp-problems,
  .lp-things {
    grid-template-columns: minmax(0, 1fr);
    gap: 30px;
    max-width: 520px;
  }

  .lp-problem:nth-child(2) {
    margin-top: 0;
  }
}

@media (max-width: 640px) {
  .lp-nav-inner,
  .lp-hero,
  .lp-section,
  .lp-footer-inner {
    width: calc(100% - 32px);
  }

  .lp-section {
    padding-top: 96px;
  }

  /* Phone hero board: three polaroids across, the stat strip under them,
     the note tucked top-right instead of over the strip. */
  .lp-hero-board {
    aspect-ratio: 1 / 1.12;
  }

  .lp-hb-note {
    top: 0;
    right: 0;
    bottom: auto;
    width: 44%;
    padding: 12px 12px 10px;
  }

  .lp-hb-note p {
    font-size: 15px;
  }

  .lp-hb-a {
    top: 22%;
  }

  .lp-hb-b {
    top: 14%;
  }

  .lp-hb-c {
    top: 24%;
  }

  .lp-hb-stub {
    top: 4%;
  }

  .lp-hb-strip {
    bottom: 0;
  }

  .lp-hb-stub strong {
    font-size: 18px;
  }

  /* The hero's stat strip: two segments per row, like the app's own on a
     phone. */
  .landing-screen .hstats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 2px 0;
    width: 100%;
  }

  .landing-screen .hs-item {
    padding: 10px 14px;
  }

  .landing-screen .hs-item + .hs-item {
    border-left: 0;
  }

  .landing-screen .hs-item:nth-child(even) {
    border-left: 2px dashed rgba(13, 12, 21, 0.22);
  }

  .landing-screen .hs-item:nth-child(n + 3) {
    border-top: 2px dashed rgba(13, 12, 21, 0.22);
  }

  .landing-screen .hs-item:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .landing-screen .hs-label {
    white-space: normal;
  }

  .lp-hb-strip {
    left: 4%;
    right: 4%;
    width: auto;
  }

  .lp-letter {
    padding: 36px 24px 32px;
    font-size: 20px;
    line-height: 34px;
    background:
      repeating-linear-gradient(transparent 0 33px, rgba(13, 12, 21, 0.1) 33px 34px) 0 32px,
      var(--paper);
  }

  .lp-final {
    flex-direction: column;
  }

  .lp-final-stub {
    flex-basis: auto;
    padding: 16px 0;
  }

  .lp-final-stub span {
    writing-mode: horizontal-tb;
    transform: none;
  }

  .lp-final-stub::after {
    top: auto;
    right: 0;
    bottom: -7px;
    left: 0;
    width: auto;
    height: 14px;
    background: radial-gradient(circle at 10px 7px, var(--bg) 4px, transparent 4.5px) 0 0 / 20px 14px repeat-x;
  }

  .lp-final-body {
    padding: 36px 26px 38px;
  }
}

@media (max-width: 420px) {
  .lp-brand-name {
    display: none;
  }

  .lp-nav-actions {
    gap: 10px;
  }

  .lp-hero-ctas .lp-btn {
    width: 100%;
  }
}

/* =============================== AUTH SCREEN (≤860px) =============================== */
@media (max-width: 860px) {
  .auth-screen {
    flex-direction: column;
  }

  .auth-hero {
    flex: none;
    min-height: 0;
    padding: 44px 28px 32px;
  }

  .auth-hero-title {
    font-size: 40px;
  }

  /* The stacked hero starts with the logo top-left; keep clear of it. */
  .auth-back {
    top: 18px;
    left: auto;
    right: 20px;
  }

  .auth-hero-copy {
    max-width: none;
  }

  /* The collage needs the hero's full height to scatter across — gone once
     that height collapses to its content, and there's no library yet to
     make a smaller version of it worth keeping. */
  .auth-hero-collage {
    display: none;
  }

  .auth-panel {
    flex: 1;
    min-height: 0;
    padding: 36px 28px 48px;
  }
}

@media (max-width: 480px) {
  .auth-hero {
    padding: 36px 22px 26px;
  }


  .auth-hero-title {
    font-size: 32px;
  }

  .auth-card {
    padding: 28px 22px 24px;
  }
}

/* =========================== TABLET & BELOW (≤768px) =========================== */
@media (max-width: 768px) {
  /* ---------- Off-canvas sidebar drawer ---------- */

  /* Toggle sits below modal z-indexes (90+) so it never floats over a modal;
     when the drawer is open the sidebar (z 100) covers it, and the drawer is
     dismissed by tapping the backdrop, a nav item, or Escape. */
  .menu-toggle {
    display: flex;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 70;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  }

  .menu-toggle-bar {
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: var(--text);
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: min(280px, 82vw);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  /* Brand clears the floating toggle. */
  .sidebar-brand {
    padding-left: 52px;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 96;
    background: rgba(8, 6, 14, 0.6);
    backdrop-filter: blur(1px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .app.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Content spans full width; top padding clears the floating toggle. */
  .content {
    padding: 64px 20px 28px;
  }

  .section-header {
    flex-wrap: wrap;
  }

  /* ---------- Card grids: tablet 2–3 columns ---------- */
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
  }

  [data-density="compact"] .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
  }

  /* Collection booklets (spine, collage, progress footer) get too cramped
     at compact widths on small screens, so they keep their normal size. */
  [data-density="compact"] #grid-collections {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
  }

  /* ---------- Forms & touch targets ---------- */

  /* 16px prevents iOS Safari from zooming in on focus. */
  .field-input,
  .modal-search input {
    font-size: 16px;
    padding: 12px 14px;
  }

  .modal-close {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  .nav-btn,
  .ticket,
  .logout-btn,
  .subtab-btn,
  .status-tab,
  .sort-btn,
  .add-btn,
  .surprise-btn,
  .trailer-btn,
  .modal-search-btn,
  .complete-btn,
  .cancel-btn,
  .delete-btn,
  .edit-btn,
  .info-add-btn,
  .result-info-btn,
  .auth-submit {
    min-height: 44px;
  }

  /* ---------- Detail modal ---------- */
  .detail-panel {
    padding: 24px 20px;
  }
}

/* =============================== MOBILE (≤480px) =============================== */
@media (max-width: 480px) {
  .content {
    padding: 60px 14px 24px;
  }

  .section-header {
    margin-bottom: 20px;
    gap: 10px;
  }

  /* The open-collection header now carries 4 buttons (Surprise Me, Edit,
     Delete, + Add) — too many to stay on one row at this width. */
  .header-actions {
    flex-wrap: wrap;
  }

  .section-header h1 {
    font-size: 22px;
  }

  /* ---------- Card grids: 2 columns ---------- */
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  [data-density="compact"] .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  [data-density="compact"] #grid-collections {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  [data-density="compact"] .card {
    gap: 5px;
    padding: 6px 6px 9px;
  }

  [data-density="compact"] .card-title {
    font-size: 13px;
  }

  /* Leaves room for two theme swatches per row. */
  .settings-tile {
    padding: 20px 18px;
  }

  .theme-swatches {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  /* Label on top, control full-width underneath. */
  .settings-row {
    flex-wrap: wrap;
  }

  .settings-select-wrap,
  .settings-segmented {
    flex: 1 1 100%;
  }

  .settings-segmented button {
    flex: 1;
  }

  .profile-favorites {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .profile-username-wrap {
    max-width: none;
  }

  .settings-select {
    width: 100%;
    min-width: 0;
  }

  .ghost-card {
    min-height: 180px;
  }

  /* ---------- Modals: near full-width with small margins ---------- */
  .modal {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 24px);
    padding: 16px;
  }

  .detail-layout {
    width: calc(100vw - 20px);
  }

  .detail-poster-img {
    width: 150px;
  }

  .detail-title {
    font-size: 22px;
  }

  .detail-panel {
    padding: 20px 16px;
  }

  .detail-head {
    padding-right: 32px;
    gap: 12px;
  }

  /* Action rows stack full-width for comfortable tapping. */
  .update-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .update-actions-right {
    width: 100%;
  }

  .update-actions-right .cancel-btn,
  .update-actions-right .modal-search-btn {
    flex: 1;
  }

  .update-actions > .delete-btn {
    width: 100%;
  }

  /* Stretched full-width, the stickers' scattered tilt just reads as crooked. */
  .update-actions .delete-btn,
  .update-actions .cancel-btn,
  .update-actions .modal-search-btn {
    transform: none;
  }

  .confirm-actions .cancel-btn,
  .confirm-actions .delete-btn-solid {
    flex: 1;
  }

  .detail-actions {
    flex-wrap: wrap;
  }

  /* Larger touch targets for pickers and rating input. */
  .emoji-option {
    padding: 10px 0;
    font-size: 22px;
  }

  .update-modal {
    padding-left: 8px;
    padding-right: 8px;
  }

  .stars.stars-input {
    font-size: 37px;
    letter-spacing: 0;
  }

  /* Only here, where the 10-star row is wide enough to need the line to
     itself, does the value drop below it — on desktop it stays right next
     to the stars (see .rating-row:has(.stars-input) .stars-value). */
  .rating-row:has(.stars-input) .stars-value {
    flex-basis: 100%;
  }
}

/* A 10-star row this wide has nowhere left to shrink to on genuinely tiny
   screens (old iPhone SE and similar, ~320px) without overflowing past the
   modal's edge — step it back down there rather than let it visibly clip. */
@media (max-width: 340px) {
  .stars.stars-input {
    font-size: 31px;
  }
}
