/* Version 1 mobile layout correction: full-width media cards with a vertical reading order. */
@media (max-width: 640px) {
  #resourceGrid {
    display: grid !important;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px !important;
  }

  #resourceGrid > .resource-card {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 9px !important;
    width: 100%;
    min-width: 0;
    min-height: 0 !important;
    height: auto !important;
    padding: 14px !important;
    border-radius: 18px !important;
    overflow: hidden;
    touch-action: manipulation;
  }

  #resourceGrid > .resource-card .res-thumb {
    flex: 0 0 auto !important;
    align-self: stretch !important;
    width: 100% !important;
    height: clamp(132px, 40vw, 168px) !important;
    margin: 0 0 2px !important;
    border-radius: 14px !important;
    background-position: center !important;
    background-size: cover !important;
  }

  #resourceGrid > .resource-card .watchlist-btn {
    position: absolute !important;
    inset: 24px 24px auto auto !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 42px !important;
    height: 42px !important;
    margin: 0 !important;
    border-radius: 50% !important;
    z-index: 5;
  }

  #resourceGrid > .resource-card .badge {
    align-self: flex-start !important;
    width: max-content;
    max-width: 100%;
    min-height: 28px;
    margin: 0 !important;
    display: inline-flex;
    align-items: center;
  }

  #resourceGrid > .resource-card h4 {
    margin: 0 !important;
    font-size: 1.08rem !important;
    line-height: 1.25 !important;
    overflow-wrap: anywhere;
  }

  #resourceGrid > .resource-card p {
    margin: 0 !important;
    max-width: none;
    font-size: .9rem !important;
    line-height: 1.48 !important;
    overflow-wrap: anywhere;
    display: block;
  }

  #resourceGrid > .resource-card .trend-badge {
    position: static !important;
    inset: auto !important;
    order: 4;
    align-self: flex-start !important;
    width: max-content;
    max-width: 100%;
    margin: 0 !important;
    white-space: normal;
    line-height: 1.25;
  }

  #resourceGrid > .resource-card .share-tools {
    position: static !important;
    inset: auto !important;
    order: 5;
    display: flex !important;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px !important;
    width: 100%;
    margin: 1px 0 0;
    opacity: 1 !important;
    transform: none !important;
  }

  #resourceGrid > .resource-card .share-btn {
    min-height: 42px;
    padding: .48rem .78rem !important;
    font-size: .78rem !important;
  }

  #resourceGrid > .resource-card:hover,
  #resourceGrid > .resource-card:hover .res-thumb {
    transform: none !important;
  }
}


/* Keep the mobile carousel's animated preview slides clear of the active slide copy. */
@media (max-width: 768px) {
  #carouselContainer {
    --mobile-preview-width: clamp(52px, 7vw, 68px);
    --mobile-preview-gap: 8px;
    width: calc(100vw - 24px) !important;
    height: clamp(320px, 53vw, 410px) !important;
    min-height: 320px !important;
  }

  #slide .item {
    top: 58% !important;
    width: var(--mobile-preview-width) !important;
    height: clamp(78px, 10vw, 104px) !important;
    border-radius: 10px !important;
    transform: translateY(-50%) !important;
  }

  #slide .item:nth-child(1),
  #slide .item:nth-child(2) {
    top: 0 !important;
    left: 0 !important;
    right: auto !important;
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
    border-radius: 0 !important;
  }

  #slide .item:nth-child(3) {
    left: auto !important;
    right: calc(12px + var(--mobile-preview-width) + var(--mobile-preview-gap)) !important;
    z-index: 3;
  }

  #slide .item:nth-child(4) {
    left: auto !important;
    right: 12px !important;
    z-index: 3;
  }

  #slide .item:nth-child(n + 5) {
    display: none !important;
  }

  .details {
    top: 42px !important;
    left: 18px !important;
    width: 52% !important;
    max-width: 52% !important;
    z-index: 40 !important;
  }

  .details .title {
    max-width: 100% !important;
    font-size: clamp(1.25rem, 4.8vw, 2rem) !important;
    line-height: 1.08 !important;
  }

  .details .description {
    max-width: 100% !important;
    font-size: clamp(.68rem, 1.6vw, .82rem) !important;
    line-height: 1.4 !important;
    margin-bottom: 14px !important;
  }

  .details .discover-btn {
    min-height: 44px;
    max-width: 100%;
    padding: .62rem .8rem;
    font-size: .72rem;
    white-space: nowrap;
  }

  #slide .item:nth-child(1)::before,
  #slide .item:nth-child(2)::before {
    background: linear-gradient(90deg, rgba(0, 0, 0, .96) 0%, rgba(0, 0, 0, .82) 48%, rgba(0, 0, 0, .28) 100%);
  }
}

@media (max-width: 360px) {
  #slide .item:nth-child(3) {
    display: none !important;
  }

  .details {
    width: 60% !important;
    max-width: 60% !important;
  }
}


/* Keep carousel progress, counter, and both touch controls on a single row. */
@media (max-width: 768px) {
  .bottom-bar {
    left: 14px !important;
    right: 14px !important;
    bottom: 16px !important;
    width: auto !important;
    gap: 8px;
  }

  .bottom-bar > div:first-child {
    display: flex !important;
    flex: 1 1 auto;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .bottom-bar .progress-line {
    flex: 1 1 120px;
    width: auto !important;
    min-width: 24px;
    max-width: min(42vw, 220px);
  }

  .bottom-bar .slide-counter {
    flex: 0 0 auto;
    white-space: nowrap;
    line-height: 1;
    font-size: .8rem;
  }

  .bottom-bar .navigation-arrows {
    display: flex !important;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
  }

  .bottom-bar .navigation-arrows button {
    flex: 0 0 36px;
    width: 36px !important;
    height: 36px !important;
    margin: 0 !important;
    padding: 0;
  }
}

@media (max-width: 360px) {
  .bottom-bar {
    left: 12px !important;
    right: 12px !important;
    bottom: 14px !important;
  }

  .bottom-bar .slide-counter {
    font-size: .76rem;
  }

  .bottom-bar .navigation-arrows button {
    flex-basis: 34px;
    width: 34px !important;
    height: 34px !important;
  }
}
