/* ==========================================================
   GXXXN.LIVE — CORE UI FIX
   Functional interface layer only.
   World/channel atmosphere remains controlled elsewhere.
   ========================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

img,
video,
iframe {
  max-width: 100%;
}


/* ==========================================================
   TOP BAR
   ========================================================== */

.topbar {
  position: relative;
  z-index: 50;

  display: flex;
  align-items: center;
  gap: 14px;

  width: 100%;
  min-width: 0;
  padding-inline:
    clamp(10px, 2.5vw, 28px);
}

.topbar > * {
  min-width: 0;
}

.topbar .brand {
  flex: 0 0 auto;
}


/* ==========================================================
   SEARCH + SOURCE
   ========================================================== */

#searchSourceBlock,
.search-source-block {
  flex: 1 1 720px;

  display: grid !important;
  grid-template-columns:
    minmax(260px, 1fr)
    minmax(190px, 235px);

  gap: 7px 10px;
  align-items: stretch;

  min-width: 0;
  max-width: 960px;
}


/* Search bar */

#searchSourceBlock #searchForm,
.search-source-block #searchForm,
#searchForm.search {
  display: grid !important;
  grid-template-columns:
    auto minmax(0, 1fr) auto auto;

  align-items: center;

  width: 100% !important;
  min-width: 0 !important;
  min-height: 50px;

  margin: 0 !important;

  overflow: hidden;
}


#searchForm .search-icon {
  flex: 0 0 auto;
}


#searchInput {
  display: block;

  width: 100% !important;
  min-width: 0 !important;

  font-size: 16px !important;

  overflow: hidden;
  text-overflow: ellipsis;
}


#searchForm button,
#searchForm [type="submit"] {
  min-height: 38px;
  white-space: nowrap;
}


/* Source selector */

#searchSourceBlock .source-control,
.search-source-block .source-control {
  display: grid !important;
  grid-template-rows:
    auto 1fr;

  width: 100% !important;
  min-width: 0 !important;

  margin: 0 !important;
  padding: 0 !important;

  overflow: hidden;

  border:
    1px solid
    color-mix(
      in srgb,
      var(--world-accent, #ff4ca8) 48%,
      rgba(255,255,255,.16)
    ) !important;

  border-radius: 8px;

  background:
    rgba(8, 8, 12, .91);
}


#sourceLabel {
  display: block !important;

  padding:
    5px 11px 1px !important;

  color:
    var(--world-accent, #ff70bd) !important;

  font-size: .58rem !important;
  font-weight: 900 !important;
  line-height: 1.15;

  letter-spacing: .13em;
  text-transform: uppercase;
}


#providerSelect {
  display: block !important;

  width: 100% !important;
  min-width: 0 !important;
  height: 38px !important;

  margin: 0 !important;
  padding:
    2px 10px 7px !important;

  border: 0 !important;
  outline: 0;

  background:
    rgba(0,0,0,.12) !important;

  color: #fff !important;

  font-size: .88rem !important;
  font-weight: 800 !important;

  cursor: pointer;
}


#providerSelect:focus-visible {
  outline:
    2px solid
    var(--world-accent, #ff4ca8);

  outline-offset: -2px;
}


/* Metadata/source note */

.search-source-note {
  grid-column: 1 / -1;

  display: flex !important;
  align-items: center;
  flex-wrap: wrap;

  gap: 5px 8px;

  width: 100%;
  min-width: 0;
  min-height: 18px;

  padding-inline: 2px;

  color:
    rgba(255,255,255,.58);

  font-size: .61rem;
  line-height: 1.35;
}


.search-source-note strong {
  color:
    rgba(255,255,255,.82);

  font-size: .59rem;
  letter-spacing: .08em;
}


.source-note-dot {
  color:
    var(--world-accent, #ff4ca8);
}


#sourceNoteText {
  min-width: 0;
  overflow-wrap: anywhere;
}


.source-result-count {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;

  margin-left: auto;
  padding: 3px 8px;

  border:
    1px solid
    color-mix(
      in srgb,
      var(--world-accent, #ff4ca8) 40%,
      rgba(255,255,255,.12)
    );

  border-radius: 999px;

  white-space: nowrap;
}


.source-result-count b {
  color:
    var(--world-accent, #ff70bd);

  font-size: .72rem;
}


.source-result-count small {
  color:
    rgba(255,255,255,.52);

  font-size: .51rem;
  letter-spacing: .08em;
}


/* ==========================================================
   DISCOVERY CONTROLS
   ========================================================== */

.controls {
  min-width: 0;
}

.controls,
.control-stack,
.chip-row,
#sortChips {
  max-width: 100%;
}

.control-stack {
  min-width: 0 !important;
}

.chip-row,
#sortChips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}


/* ==========================================================
   FEED
   ========================================================== */

#feed {
  min-width: 0;
}


.feed-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  flex-wrap: wrap;

  gap: 10px;

  min-width: 0;
}


#feedTitle,
#resultsMeta {
  min-width: 0;
  overflow-wrap: anywhere;
}


#resultsMeta {
  color:
    rgba(255,255,255,.6);

  font-size: .72rem;
}


/* ==========================================================
   VIDEO GRID
   ========================================================== */

#videoGrid {
  display: grid !important;

  grid-template-columns:
    repeat(
      auto-fill,
      minmax(
        min(220px, 100%),
        1fr
      )
    );

  gap:
    clamp(10px, 1.4vw, 17px) !important;

  width: 100%;
  min-width: 0;
}


#videoGrid > * {
  min-width: 0;
}


.video-card,
.tpdb-card {
  min-width: 0;
  max-width: 100%;

  overflow: hidden;

  contain:
    layout paint;
}


.video-card img,
.tpdb-card img,
.video-card .thumb img,
.tpdb-thumb img {
  display: block;

  width: 100%;
  height: auto;

  aspect-ratio: 16 / 9;

  object-fit: cover;
}


.video-card button,
.video-card a,
.tpdb-card button,
.tpdb-card a {
  max-width: 100%;
}


.video-card h2,
.video-card h3,
.video-card .title,
.tpdb-title {
  overflow-wrap: anywhere;
}


/* TPDB metadata cards should visually belong in same feed */

.tpdb-card {
  border-color:
    color-mix(
      in srgb,
      var(--world-accent, #ff4ca8) 24%,
      rgba(255,255,255,.14)
    ) !important;
}


.tpdb-info {
  padding: 10px !important;
}


.tpdb-meta,
.tpdb-performers,
.tpdb-tags {
  max-width: 100%;
}


/* ==========================================================
   LOAD MORE — MANUAL PAGINATION
   ========================================================== */

#loadMoreButton {
  display: block;

  width:
    min(
      430px,
      calc(100% - 24px)
    );

  min-height: 50px;

  margin:
    26px auto 42px !important;

  padding:
    12px 22px !important;

  border:
    1px solid
    var(--world-accent, #ff4ca8) !important;

  border-radius: 7px;

  background:
    color-mix(
      in srgb,
      var(--world-accent, #ff4ca8) 9%,
      rgba(7,7,10,.95)
    ) !important;

  color: #fff;

  font-size: .78rem !important;
  font-weight: 900 !important;

  letter-spacing: .1em;

  cursor: pointer;
}


#loadMoreButton:hover {
  background:
    color-mix(
      in srgb,
      var(--world-accent, #ff4ca8) 16%,
      rgba(7,7,10,.95)
    ) !important;
}


#loadMoreButton[hidden] {
  display: none !important;
}


/* ==========================================================
   HERO — PREVENT LAYOUT FIGHTS
   ========================================================== */

.hero {
  min-width: 0;
}

.hero-copy-wrap,
.hero-sign,
.hero-actions {
  min-width: 0;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}


/* ==========================================================
   ACCESSIBILITY
   ========================================================== */

button,
select,
input,
a {
  -webkit-tap-highlight-color:
    transparent;
}


button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline:
    2px solid
    var(--world-accent, #ff4ca8);

  outline-offset: 2px;
}


/* ==========================================================
   TABLET
   ========================================================== */

@media (max-width: 1050px) {

  .topbar {
    flex-wrap: wrap;
  }

  #searchSourceBlock,
  .search-source-block {
    flex: 1 1 100%;
    order: 10;

    width: 100%;
    max-width: none;
  }
}


/* ==========================================================
   MOBILE
   ========================================================== */

@media (max-width: 680px) {

  .topbar {
    gap: 9px;
    padding-inline: 9px;
  }


  #searchSourceBlock,
  .search-source-block {
    grid-template-columns: 1fr;
    gap: 7px;
  }


  #searchSourceBlock #searchForm,
  .search-source-block #searchForm {
    grid-column: 1;
  }


  #searchSourceBlock .source-control,
  .search-source-block .source-control {
    grid-column: 1;
  }


  .search-source-note {
    grid-column: 1;
  }


  .source-result-count {
    margin-left: 0;
  }


  #videoGrid {
    grid-template-columns:
      repeat(2, minmax(0, 1fr));

    gap: 9px !important;
  }


  .video-card .info,
  .tpdb-info {
    padding: 8px !important;
  }


  #loadMoreButton {
    width:
      calc(100% - 18px);

    min-height: 52px;
  }
}


/* Very narrow phones */

@media (max-width: 420px) {

  #videoGrid {
    grid-template-columns: 1fr;
  }


  #searchForm button,
  #searchForm [type="submit"] {
    padding-inline: 9px;
  }
}


/* ==========================================================
   REDUCED MOTION
   ========================================================== */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}


/* GXXXN MIXED FEED METADATA */
.video-card.metadata-card {
  border-color: color-mix(in srgb, var(--world-accent, #ff4ca8) 36%, rgba(255,255,255,.16)) !important;
}

.video-card.metadata-card .provider-badge {
  letter-spacing: .06em;
}

.video-card.metadata-card .save-button {
  display: none !important;
}

/* Dynamic feed utilities */
.feed-utility-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}
#autoLoadButton.active {
  border-color: var(--world-accent, #ff4ca8);
}
@media (max-width: 680px) {
  .feed-utility-actions {
    width: 100%;
    justify-content: stretch;
  }
  .feed-utility-actions > button {
    flex: 1 1 auto;
  }
}
