/**
 * Adaptive layout foundation.
 * Surfaces:
 * - standard phone: single-column, full-height radio
 * - fold/unfolded/tablet: split primary + secondary radio shell
 * - desktop/web: centered app canvas with docked secondary panels
 */

.chirp-apk-body .radio-layout {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.chirp-apk-body .radio-layout__primary {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.chirp-apk-body .radio-layout__secondary {
  min-width: 0;
  position: relative;
}

/* --- Standard phone: keep one continuous column --- */
.layout-phone .chirp-apk-body .radio-layout,
.layout-compact .chirp-apk-body .radio-layout {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.layout-phone .chirp-apk-body .radio-layout__secondary,
.layout-compact .chirp-apk-body .radio-layout__secondary {
  flex: 0 0 auto;
  max-height: none;
  overflow: visible;
}

.layout-phone .chirp-apk-body .phone--apk-fullbleed .radio-unit__face,
.layout-compact .chirp-apk-body .phone--apk-fullbleed .radio-unit__face {
  display: flex;
  flex-direction: column;
}

.layout-phone .chirp-apk-body .radio-layout__primary,
.layout-compact .chirp-apk-body .radio-layout__primary {
  min-height: 0;
}

/* --- Wide: more breathing room --- */
@media (min-width: 600px) {
  .chirp-apk-body {
    --apk-masthead-h: clamp(6.5rem, 12dvh, 7.6rem);
    --apk-nav-clearance: clamp(3rem, 5.6dvh, 3.3rem);
  }

  .chirp-apk-body .phone--apk-fullbleed .radio-unit__face {
    padding-left: clamp(0.65rem, 2vw, 1rem);
    padding-right: clamp(0.65rem, 2vw, 1rem);
  }

  .chirp-apk-body .station-hero__name {
    font-size: clamp(2rem, 5vw, 2.8rem);
  }

  .chirp-apk-body .phone--apk-fullbleed .now-playing,
  .chirp-apk-body .phone--apk-fullbleed .radio-controls-deck {
    max-width: min(460px, 72vw);
  }

  .chirp-apk-body .feed-panel__input {
    font-size: 0.78rem;
  }

  .chirp-apk-body .station-library-dropdown__panel {
    max-height: min(58vh, 30rem);
  }
}

/* --- Fold / unfolded / tablet: split radio shell (class-gated so phone/TWA stays single-column until wide) --- */
@media (min-width: 720px) {
  html.layout-wide .chirp-apk-body .radio-layout,
  html.layout-unfolded .chirp-apk-body .radio-layout,
  html.layout-desktop .chirp-apk-body .radio-layout,
  html.chirp-apk-native .chirp-apk-body .radio-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(280px, 0.95fr);
    gap: clamp(0.65rem, 1.6vw, 1rem);
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
  }

  html.layout-wide .chirp-apk-body .radio-layout__primary,
  html.layout-unfolded .chirp-apk-body .radio-layout__primary,
  html.layout-desktop .chirp-apk-body .radio-layout__primary,
  html.chirp-apk-native .chirp-apk-body .radio-layout__primary {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  html.layout-wide .chirp-apk-body .radio-layout__secondary,
  html.layout-unfolded .chirp-apk-body .radio-layout__secondary,
  html.layout-desktop .chirp-apk-body .radio-layout__secondary,
  html.chirp-apk-native .chirp-apk-body .radio-layout__secondary {
    min-width: 0;
    max-height: calc(100dvh - var(--apk-safe-top) - var(--apk-masthead-h) - var(--apk-nav-clearance) - 0.75rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }

  html.layout-wide .chirp-apk-body .radio-unit__face,
  html.layout-unfolded .chirp-apk-body .radio-unit__face,
  html.layout-desktop .chirp-apk-body .radio-unit__face,
  html.chirp-apk-native .chirp-apk-body .radio-unit__face {
    margin: 0;
    overflow: hidden;
  }

  html.layout-wide .chirp-apk-body .radio-unit__face:not(.is-schedule-expanded),
  html.layout-unfolded .chirp-apk-body .radio-unit__face:not(.is-schedule-expanded),
  html.layout-desktop .chirp-apk-body .radio-unit__face:not(.is-schedule-expanded),
  html.chirp-apk-native .chirp-apk-body .radio-unit__face:not(.is-schedule-expanded) {
    display: flex;
    flex-direction: column;
  }

  html.layout-wide .chirp-apk-body .phone--apk-fullbleed .radio-face-main,
  html.layout-unfolded .chirp-apk-body .phone--apk-fullbleed .radio-face-main,
  html.layout-desktop .chirp-apk-body .phone--apk-fullbleed .radio-face-main,
  html.chirp-apk-native .chirp-apk-body .phone--apk-fullbleed .radio-face-main {
    justify-content: flex-start;
    gap: clamp(0.25rem, 0.8dvh, 0.45rem);
  }

  html.layout-wide .chirp-apk-body .phone--apk-fullbleed .station-row,
  html.layout-unfolded .chirp-apk-body .phone--apk-fullbleed .station-row,
  html.layout-desktop .chirp-apk-body .phone--apk-fullbleed .station-row,
  html.chirp-apk-native .chirp-apk-body .phone--apk-fullbleed .station-row {
    max-width: min(100%, 520px);
  }

  html.layout-wide .chirp-apk-body .phone--apk-fullbleed .now-playing,
  html.layout-wide .chirp-apk-body .phone--apk-fullbleed .radio-controls-deck,
  html.layout-unfolded .chirp-apk-body .phone--apk-fullbleed .now-playing,
  html.layout-unfolded .chirp-apk-body .phone--apk-fullbleed .radio-controls-deck,
  html.layout-desktop .chirp-apk-body .phone--apk-fullbleed .now-playing,
  html.layout-desktop .chirp-apk-body .phone--apk-fullbleed .radio-controls-deck,
  html.chirp-apk-native .chirp-apk-body .phone--apk-fullbleed .now-playing,
  html.chirp-apk-native .chirp-apk-body .phone--apk-fullbleed .radio-controls-deck {
    width: min(100%, 520px);
    max-width: 520px;
  }

  html.layout-wide .chirp-apk-body .schedule-section,
  html.layout-unfolded .chirp-apk-body .schedule-section,
  html.layout-desktop .chirp-apk-body .schedule-section,
  html.chirp-apk-native .chirp-apk-body .schedule-section {
    flex-shrink: 0;
  }

  html.layout-wide .chirp-apk-body .radio-unit__face.is-schedule-expanded .schedule-section,
  html.layout-unfolded .chirp-apk-body .radio-unit__face.is-schedule-expanded .schedule-section,
  html.layout-desktop .chirp-apk-body .radio-unit__face.is-schedule-expanded .schedule-section,
  html.chirp-apk-native .chirp-apk-body .radio-unit__face.is-schedule-expanded .schedule-section {
    flex: 1 1 auto;
    flex-shrink: 1;
    min-height: 0;
  }
}

/* --- Desktop / web: center the app and give the radio more horizontal room --- */
@media (min-width: 1180px) {
  .demo-wrap {
    grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
    gap: clamp(1.5rem, 3vw, 3rem);
    max-width: 1480px;
    margin: 0 auto;
  }

  .fold-stage {
    width: 100%;
  }

  .fold-stage__devices {
    justify-content: center;
    align-items: start;
    gap: clamp(1rem, 2.2vw, 2rem);
  }

  .fold-stage[data-layout="cover"] .phone-frame--cover,
  .fold-stage[data-layout="inner"] .phone-frame--inner {
    transform: scale(1);
    transform-origin: top center;
  }

  .chirp-apk-body {
    background:
      radial-gradient(circle at top left, rgba(255, 255, 255, 0.06), transparent 34rem),
      #0a0c0f;
  }

  .chirp-apk-body .phone.phone--apk-fullbleed {
    max-width: min(100vw, 1440px);
    margin: 0 auto;
  }

  .chirp-apk-body .radio-layout {
    grid-template-columns: minmax(480px, 0.95fr) minmax(360px, 0.75fr);
    gap: clamp(1rem, 2vw, 1.5rem);
  }

  .chirp-apk-body .radio-layout__primary,
  .chirp-apk-body .radio-layout__secondary {
    min-height: 0;
  }

  .chirp-apk-body .phone--apk-fullbleed .radio-unit__face {
    padding-left: clamp(1rem, 2vw, 1.5rem);
    padding-right: clamp(1rem, 2vw, 1.5rem);
  }
}

/* Class-based layout (mock viewport / future fold posture) */
html.layout-wide.chirp-apk-native .chirp-apk-body .radio-layout,
html.layout-unfolded.chirp-apk-native .chirp-apk-body .radio-layout,
html.layout-wide:not(.chirp-apk-native):not(.chirp-web) .radio-layout,
html.layout-unfolded:not(.chirp-apk-native):not(.chirp-web) .radio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(280px, 0.95fr);
  gap: clamp(0.65rem, 1.6vw, 1rem);
  align-items: stretch;
}

html.layout-wide.chirp-apk-native .chirp-apk-body .radio-layout__primary,
html.layout-unfolded.chirp-apk-native .chirp-apk-body .radio-layout__primary {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

html.layout-wide.chirp-apk-native .chirp-apk-body .radio-layout__secondary,
html.layout-unfolded.chirp-apk-native .chirp-apk-body .radio-layout__secondary {
  min-width: 0;
  max-height: calc(100dvh - var(--apk-safe-top) - var(--apk-masthead-h) - var(--apk-nav-clearance) - 0.5rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

html.layout-desktop.chirp-apk-native .chirp-apk-body .radio-layout,
html.layout-desktop:not(.chirp-apk-native):not(.chirp-web) .radio-layout {
  grid-template-columns: minmax(480px, 0.95fr) minmax(360px, 0.75fr);
  gap: clamp(1rem, 2vw, 1.5rem);
}

/* Docked station library on wide/unfolded */
.layout-wide .station-library-dropdown.is-open.is-docked,
.layout-unfolded .station-library-dropdown.is-open.is-docked {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.layout-wide .station-library-dropdown.is-open.is-docked[hidden],
.layout-unfolded .station-library-dropdown.is-open.is-docked[hidden] {
  display: none !important;
}

.layout-wide .station-library-dropdown.is-docked .station-library-dropdown__backdrop,
.layout-unfolded .station-library-dropdown.is-docked .station-library-dropdown__backdrop {
  display: none;
}

.layout-wide .station-library-dropdown.is-docked .station-library-dropdown__panel,
.layout-unfolded .station-library-dropdown.is-docked .station-library-dropdown__panel {
  position: relative;
  margin: 0;
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  animation: none;
}

.layout-wide .station-library-dropdown:not(.is-open),
.layout-unfolded .station-library-dropdown:not(.is-open) {
  display: none;
}

/* Compact overlay dropdown polish */
@media (max-width: 839px) {
  .station-library-dropdown.is-open {
    position: relative;
    z-index: 45;
  }

  .station-library-dropdown.is-open .station-library-dropdown__panel {
    max-height: min(52vh, 26rem);
    margin-bottom: 0.35rem;
  }

  .station-library-dropdown__backdrop {
    position: fixed;
    inset: 0;
    z-index: 44;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .station-library-dropdown.is-closing .station-library-dropdown__panel {
    animation: station-lib-sheet-out 0.28s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  }
}

/* Safe-area / clipping guards */
.chirp-apk-body .station-hero__name {
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.12;
}

.chirp-apk-body .feed-panel__chips {
  max-width: 100%;
}

.chirp-apk-body .feed-panel__chip {
  max-width: 100%;
}

.chirp-apk-body .station-lib-queue__meta {
  overflow-wrap: anywhere;
}

.chirp-apk-body .feed-panel__item-title,
.chirp-apk-body .feed-panel__item-meta,
.chirp-apk-body .station-lib-queue__title {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Hide mock provider hint in APK unless diagnostics */
.chirp-apk-native .feed-panel__mode {
  display: none;
}

.chirp-apk-native.is-dev-provider-hint .feed-panel__mode {
  display: inline;
}

/* --- Other app tabs adapt with the same surface classes --- */
.layout-tablet .stations-layout,
.layout-unfolded .stations-layout,
.layout-desktop .stations-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  min-height: 0;
}

.layout-tablet .stations-pane--preview,
.layout-unfolded .stations-pane--preview,
.layout-desktop .stations-pane--preview {
  display: block;
  min-height: 0;
  overflow: auto;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.layout-tablet .stations-scroll,
.layout-unfolded .stations-scroll,
.layout-desktop .stations-scroll {
  padding-right: 0.85rem;
}

.layout-tablet .schedules-layout,
.layout-unfolded .schedules-layout,
.layout-desktop .schedules-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(0.7rem, 1.4vw, 1rem);
}

.layout-desktop .schedules-layout {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.layout-tablet .profile-scroll,
.layout-unfolded .profile-scroll,
.layout-desktop .profile-scroll,
.layout-tablet .schedules-scroll,
.layout-unfolded .schedules-scroll,
.layout-desktop .schedules-scroll,
.layout-tablet .stations-scroll,
.layout-unfolded .stations-scroll,
.layout-desktop .stations-scroll {
  scrollbar-width: thin;
}

.layout-desktop .profile-scroll,
.layout-desktop .schedules-scroll,
.layout-desktop .stations-scroll {
  max-width: 1180px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.layout-desktop .pref-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Desktop web keeps touch targets large, but stops cards from stretching too far. */
.layout-desktop .station-card {
  min-height: 108px;
}

.layout-desktop .station-card__name {
  font-size: clamp(1rem, 1.3vw, 1.25rem);
}
