/* =========================================================
   CINEVERSE - RESPONSIVE STYLES
   Breakpoint-specific layout and accessibility adaptations.
   ========================================================= */

/* Tablet: compact header spacing and keep the inline search usable. */
@media (max-width: 900px) {
  .header-container {
    gap: 0.75rem;
  }

  .header-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
  }

  .header-search {
    flex: 1 1 auto;
    width: auto;
    max-width: 100%;
    margin-left: 0.25rem;
    margin-right: 0.25rem;
    border-radius: 0.8rem;
    box-shadow: 0 6px 14px rgba(2, 6, 23, 0.35);
  }

  .header-search-input {
    max-width: none;
    width: 100%;
  }

  .header-search-history {
    width: min(100%, 19rem);
  }
}

/* Small tablet: let the header search use the available width. */
@media (max-width: 720px) {
  .header-search {
    width: 100%;
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    border-radius: 0.8rem;
    box-shadow: 0 6px 14px rgba(2, 6, 23, 0.35);
  }

  .header-search-input {
    min-width: 0;
    width: calc(100% - 3.2rem);
  }
}

/* Small tablet: stack footer columns and expand contact actions. */
@media (max-width: 720px) {
  .footer-container {
    grid-template-columns: 1fr;
    gap: 1.2rem;
  }
  .contact-actions {
    width: 100%;
  }
  .contact-actions .btn {
    flex: 1 1 calc(50% - 0.6rem);
    justify-content: center;
  }
}

/* Tablet and below: collapse the footer into one main column. */
@media (max-width: 980px) {
  .footer-container {
    grid-template-columns: 1fr;
    gap: 1.6rem;
    padding-top: 2.5rem;
    padding-bottom: 2.5rem;
  }

  .footer-brand {
    max-width: 100%;
  }

  .footer-brand p {
    max-width: 100%;
    line-height: 1.7;
    font-size: 0.95rem;
  }

  .footer-navigation {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
  }
}

/* Phone: center footer content and move the back-to-top link into flow. */
@media (max-width: 720px) {
  /* Move back-to-top into normal flow and center it on small screens */
  .footer-bottom {
    text-align: center;
  }

  .back-to-top {
    position: static;
    right: auto;
    top: auto;
    transform: none;
    display: inline-block;
    margin-left: 0.5rem;
    margin-top: 0.5rem;
  }

  .footer-column h3 {
    font-size: 0.95rem;
  }

  .footer-brand p {
    max-width: 100%;
  }
}

/* Tablet and below: replace desktop navigation with the menu button and adapt movie rails. */
@media (max-width: 900px) {
  .main-navigation {
    display: none;
  }

  .menu-toggle {
    display: grid;
  }

  .movie-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr));
  }

  .hero-section {
    min-height: 38rem;
  }

  .hero-background {
    background: linear-gradient(
      180deg,
      rgba(7, 8, 13, 0.25) 0%,
      rgba(7, 8, 13, 0.8) 65%,
      var(--color-bg) 100%
    );
  }

  .hero-container {
    justify-content: flex-end;
  }

  .footer-container {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }

  .footer-navigation {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Phone: switch core layouts to single-column and horizontal touch-friendly rails. */
@media (max-width: 600px) {
  :root {
    --content-padding: 1rem;
  }

  body {
    padding-bottom: 4.5rem;
  }

  .site-header {
    position: sticky;
  }

  .header-container {
    min-height: 4rem;

    gap: 0.5rem;
  }

  .logo {
    font-size: 1.05rem;
  }

  .notification-button {
    display: none;
  }

  .menu-toggle {
    display: grid;
  }

  .mobile-navigation {
    display: none;
    inset: 4rem 0 auto;
  }

  .search-form {
    flex-direction: column;
  }

  .search-button {
    width: 100%;
  }

  .hero-section {
    min-height: 34rem;
  }

  .hero-container {
    padding-top: 8rem;
    padding-bottom: 2.5rem;
  }

  .hero-title {
    max-width: 12ch;

    font-size: clamp(2.2rem, 11vw, 3.4rem);
  }

  .hero-description {
    display: -webkit-box;

    overflow: hidden;

    line-clamp: 3;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .hero-actions .button {
    width: 100%;
  }

  .movie-content {
    padding-top: 2.5rem;
    padding-bottom: 3rem;
  }

  .movie-section + .movie-section {
    margin-top: 3.5rem;
  }

  .section-header {
    align-items: center;
    gap: 0.8rem;
  }

  .tools-header,
  .section-header {
    flex-wrap: wrap;
  }

  .section-header > div {
    min-width: 0;
  }

  .section-link {
    max-width: 7.5rem;
    text-align: right;
  }

  /* Hide rail controls on mobile to avoid circular buttons clutter */
  .rail-controls {
    display: none;
  }

  .section-header .section-link {
    order: 3;
  }

  .rail-button {
    width: 2.15rem;
    height: 2.15rem;
    display: none; /* visually hide individual rail buttons on narrow screens */
    color: var(--color-text);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1;
    transition:
      background var(--transition-fast),
      border-color var(--transition-fast),
      transform var(--transition-fast);
  }

  /* hide visual arrows on small screens (they are shown via pseudo-elements on larger screens) */
  .rail-button::after {
    content: "";
  }

  .rail-button:active {
    transform: scale(0.94);
  }

  .rail-button:hover,
  .rail-button:focus-visible {
    background: var(--color-primary-dark);
    border-color: rgba(251, 113, 133, 0.58);
  }

  .section-title {
    font-size: 1.35rem;
  }

  .movie-grid {
    display: flex;

    overflow-x: auto;

    padding: 0 0.25rem 0.7rem;

    scroll-snap-type: x mandatory;
    scroll-padding-inline: 0.25rem;

    scrollbar-width: none;
  }

  .movie-grid::-webkit-scrollbar {
    display: none;
  }

  .movie-card {
    flex: 0 0 9.5rem;

    scroll-snap-align: start;
  }

  .movie-card:hover {
    transform: none;
  }

  .movie-card-body {
    padding: 0.7rem;
  }

  .movie-card-title {
    font-size: 0.82rem;
  }

  .movie-card-button {
    min-height: 2.2rem;
    padding: 0.45rem;
  }

  .movie-card-actions {
    grid-template-columns: 1fr;
  }

  .movie-card-save {
    width: 100%;
  }

  .inline-empty {
    flex: 1 0 100%;
  }

  .movie-details {
    grid-template-columns: 1fr;

    gap: 1rem;
    padding: 1rem;
  }

  .movie-details-poster {
    width: min(48%, 11rem);

    margin-inline: auto;
  }

  .movie-details-title {
    font-size: 1.65rem;
    line-height: 1.12;
    overflow-wrap: anywhere;
  }

  .movie-details-meta {
    gap: 0.55rem;
    font-size: 0.78rem;
  }

  .movie-details-overview {
    margin-top: 1rem;
    font-size: 0.88rem;
  }

  .movie-information > div {
    grid-template-columns: 1fr;
    gap: 0.15rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--color-border);
  }

  .movie-modal {
    width: calc(100% - 0.75rem);

    max-height: calc(100vh - 0.75rem);

    border-radius: var(--radius-lg);
  }

  .movie-modal-content {
    max-height: calc(100vh - 0.75rem);
  }

  .modal-header {
    padding: 0.75rem 0.9rem;
  }

  .footer-container {
    padding-top: 3rem;
    padding-bottom: 3rem;
  }

  .footer-navigation {
    grid-template-columns: 1fr;
  }

  .mobile-bottom-navigation {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;

    z-index: 200;

    display: grid;
    grid-template-columns: repeat(4, 1fr);

    min-height: 4.3rem;

    padding: 0.45rem 0.5rem calc(0.45rem + env(safe-area-inset-bottom));

    background: rgba(11, 13, 20, 0.9);

    border-top: 1px solid var(--color-border);

    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .toast-region {
    right: 0.75rem;
    bottom: 5rem;
    width: calc(100% - 1.5rem);
  }

  .bottom-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    gap: 0.15rem;

    color: var(--color-text-muted);

    font-size: 0.65rem;
    font-weight: 600;

    transition: color var(--transition-fast);
  }

  .bottom-nav-link span:first-child {
    font-size: 1.15rem;
    line-height: 1;
  }

  .bottom-nav-link:hover,
  .bottom-nav-link.active {
    color: var(--color-primary-light);
  }
}

/* Extra-small phone: reduce hero height and stack hero actions. */
@media (max-width: 400px) {
  .hero-section {
    min-height: 31rem;
  }

  .hero-actions {
    grid-template-columns: 1fr;
  }

  .hero-pagination {
    margin-top: 1.75rem;
  }

  .movie-card {
    flex-basis: 8.75rem;
  }

  .footer-navigation {
    grid-template-columns: 1fr;
  }
}

/* Large desktop: widen the container and show eight movie columns. */
@media (min-width: 1600px) {
  :root {
    --container-width: 1560px;
  }

  .hero-section {
    min-height: 48rem;
  }

  .movie-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
}

/* Ultra-wide desktop: increase page padding and show nine movie columns. */
@media (min-width: 1900px) {
  :root {
    --container-width: 1760px;
    --content-padding: 4rem;
  }

  .hero-section {
    min-height: 54rem;
  }

  .movie-grid {
    grid-template-columns: repeat(9, minmax(0, 1fr));
  }
}

/* Tablet and below: make discovery filters fit a two-column control grid. */
@media (max-width: 900px) {
  .controls-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-field:last-child {
    grid-column: 1 / -1;
  }
}

/* Tablet and below: make the movie details modal and cast grid fit narrower screens. */
@media (max-width: 900px) {
  .movie-modal {
    width: calc(100% - 1rem);
    max-height: calc(100vh - 1rem);
    border-radius: var(--radius-md);
  }

  .movie-details {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 1rem;
  }

  .movie-details-poster {
    width: min(48%, 14rem);
    margin-inline: auto;
    align-self: start;
  }

  .movie-details-poster img {
    width: 100%;
    height: auto;
    aspect-ratio: auto;
    object-fit: cover;
  }

  .movie-details-title {
    font-size: 1.6rem;
  }

  .movie-information > div {
    grid-template-columns: 1fr;
  }

  .cast-list {
    grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  }
}

/* Phone: stack discovery controls and make cast and detail actions touch-scroll friendly. */
@media (max-width: 600px) {
  .discover-tools {
    padding: 1rem;
  }

  .tools-header {
    align-items: center;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .control-field:last-child {
    grid-column: auto;
  }

  .featured-results-grid {
    display: flex;
  }

  .movie-card-overlay {
    display: none;
  }

  .cast-list {
    display: flex;
    overflow-x: auto;
    gap: 0.7rem;
    padding-bottom: 0.4rem;
    scrollbar-width: none;
  }

  .cast-list::-webkit-scrollbar {
    display: none;
  }

  .cast-card {
    flex: 0 0 7.5rem;
  }

  .movie-details-actions .button {
    width: 100%;
  }

  /* place poster above details on small screens for better layout */
  .movie-details {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.9rem;
  }

  .movie-details-poster {
    width: 100%;
    margin-inline: auto;
  }

  .movie-details-poster img {
    width: 100%;
    height: auto;
    border-radius: var(--radius-lg);
  }

  .movie-details-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  /* ensure modal has no horizontal overflow */
  .movie-modal-content {
    overflow-x: hidden;
  }

  /* Make modal full-width on small screens and ensure internal scrolling */
  .movie-modal {
    width: calc(100% - 0.5rem);
    max-height: calc(100vh - 0.5rem);
    border-radius: var(--radius-md);
    margin: 0.25rem;
  }

  .movie-modal-content {
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding-bottom: calc(env(safe-area-inset-bottom) + 1rem);
  }

  .movie-details {
    grid-template-columns: 1fr;
    gap: 0.8rem;
    padding: 0.8rem;
  }

  .movie-details-poster {
    width: 42%;
    min-width: 9rem;
    margin-inline: auto;
  }

  .movie-details-title {
    font-size: 1.45rem;
  }
}

/* Phone: simplify hero controls and hide pagination dots. */
@media (max-width: 600px) {
  .hero-controls {
    position: static;
    margin-top: 1rem;
  }

  /* Hide hero pagination dots on small screens to avoid visual clutter */
  .hero-pagination {
    display: none;
  }
}

/* Extra-small phone: keep hero controls close to the content. */
@media (max-width: 400px) {
  .hero-controls {
    margin-top: 0.75rem;
  }
}

/* Accessibility: honor reduced-motion preferences on every screen size. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
