/* ===== VARIABLES ===== */
:root {
  --bg-color: #f8f3e9;
  --text-color: #3b2f24;
  --accent: #c1664a;
  --nav-bg: rgba(93, 64, 55, 0.85); /* brown glass */
  --card-bg: #fdf9f3;
  --focus-outline: #a67c52;
  --glass-border: rgba(255, 255, 255, 0.2);
}

/* ===== BASE STYLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: 'Manrope', sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  position: relative;
  /* Allow horizontal scrolling if something still overflows unexpectedly */
  /* overflow-x: hidden; -> Removed to allow temporary debugging if needed */
  /* Keep it hidden if layout is fixed properly */
  overflow-x: hidden;
}

/* Coffee stain background (subtle) */
.coffee-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Ccircle cx='100' cy='100' r='4' fill='%23d7c9b8' opacity='0.03'/%3E%3Ccircle cx='300' cy='300' r='6' fill='%23c9b8a6' opacity='0.02'/%3E%3C/svg%3E"),
    radial-gradient(circle at 15% 25%, rgba(198, 163, 130, 0.04) 1px, transparent 1px),
    radial-gradient(circle at 85% 75%, rgba(160, 120, 90, 0.03) 2px, transparent 2px);
  pointer-events: none;
  z-index: -1;
}

/* ===== NAVBAR (Glass Brown) ===== */
.navbar {
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* Reduced padding on small screens */
  padding: 0 1rem; /* Changed from 1.5rem */
  /* Added padding to prevent edge touching */
  padding-left: env(safe-area-inset-left, 1rem);
  padding-right: env(safe-area-inset-right, 1rem);
}

.logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.8rem; /* Consider reducing further on very small screens */
  font-weight: 600;
  color: white;
  white-space: nowrap; /* Prevent logo wrapping */
  overflow: hidden; /* Hide overflow if too long */
  text-overflow: ellipsis; /* Show ellipsis if truncated */
  max-width: 40%; /* Limit logo width */
}
.logo span {
  color: #e8c3ab;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  /* Make the form container flexible */
  flex-grow: 1;
  /* Align items vertically if needed */
  align-items: center;
  /* Add max-width to prevent excessive stretching */
  max-width: calc(100% - 120px); /* Subtract estimated logo width and gap */
  /* Adjust based on your logo size */
}

.search-input {
  padding: 0.5rem 1rem;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 20px;
  background: rgba(255,255,255, 0.15);
  color: white;
  font-family: 'Manrope', sans-serif;
  /* Make input flexible */
  flex: 1;
  /* Set minimum width to prevent collapsing completely */
  min-width: 100px;
  /* Remove fixed width */
  width: auto;
  transition: all 0.3s ease;
  /* Adjust font size if necessary */
  font-size: 0.9rem; /* Slightly smaller on mobile */
}
.search-input::placeholder {
  color: rgba(255,255,255,0.7);
}
.search-input:focus {
  outline: none;
  background: rgba(255,255,255, 0.25);
  border-color: rgba(255,255,255, 0.6);
  /* Keep width dynamic */
  width: auto;
}

.search-btn {
  background: rgba(255,255,255, 0.2);
  border: 1px solid rgba(255,255,255, 0.3);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0; /* Prevent button from shrinking */
}

/* ===== CONTENT LAYOUT ===== */
.content {
  max-width: 1400px;
  margin: 2rem auto;
  /* Reduced padding on small screens */
  padding: 0 1rem; /* Changed from 1.5rem */
  /* Add safe area padding */
  padding-left: env(safe-area-inset-left, 1rem);
  padding-right: env(safe-area-inset-right, 1rem);
}

.section-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 2rem;
  margin: 2rem 0 1.5rem;
  text-align: center;
  color: var(--text-color);
}

.subsection-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.5rem; /* Consider reducing on mobile */
  margin: 2.2rem 0 1.2rem;
  color: #5a4a3f;
}

/* Media Grid */
.media-grid {
  display: grid;
  /* Adjust minmax value for smaller screens */
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); /* Reduced min width */
  gap: 1rem; /* Slightly reduced gap */
  list-style: none;
}

/* Card Animation (Desktop Only) */
@media (min-width: 768px) {
  .media-card {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.6s forwards;
  }

  .media-card:nth-child(1) { animation-delay: 0.1s; }
  .media-card:nth-child(2) { animation-delay: 0.15s; }
  .media-card:nth-child(3) { animation-delay: 0.2s; }
  .media-card:nth-child(4) { animation-delay: 0.25s; }
  .media-card:nth-child(5) { animation-delay: 0.3s; }
  .media-card:nth-child(6) { animation-delay: 0.35s; }
  .media-card:nth-child(7) { animation-delay: 0.4s; }
  .media-card:nth-child(8) { animation-delay: 0.45s; }
  .media-card:nth-child(9) { animation-delay: 0.5s; }
  .media-card:nth-child(10) { animation-delay: 0.55s; }
  .media-card:nth-child(11) { animation-delay: 0.6s; }
  .media-card:nth-child(12) { animation-delay: 0.65s; }
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Card Styles */
.media-card {
  background: var(--card-bg);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  aspect-ratio: 2 / 3;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.media-card:focus {
  outline: 3px solid var(--focus-outline);
  outline-offset: 4px;
  transform: scale(1.04);
  z-index: 2;
}

.media-poster {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter 0.3s ease;
}

.media-card:hover .media-poster {
  filter: brightness(1.05);
}

.media-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(248, 243, 233, 0.92);
  padding: 0.45rem 0.6rem;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid rgba(198, 163, 130, 0.2);
}

/* Footer */
.site-footer {
  text-align: center;
  margin-top: 3.5rem;
  padding: 1.8rem 0;
  font-size: 0.92rem;
  color: #7a6a5d;
  /* Add safe area padding */
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

/* --- MOBILE RESPONSIVENESS --- */

/* Small phones (e.g., iPhone SE) */
@media (max-width: 400px) {
  .nav-content {
    padding: 0 0.75rem;
  }
  .content {
    padding: 0 0.75rem;
  }
  .logo {
    font-size: 0.6rem; /* Smaller logo */
  }
  .section-title {
    font-size: 1.8rem; /* Smaller title */
  }
  .subsection-title {
    font-size: 1.3rem; /* Smaller subtitle */
    margin: 1.8rem 0 1rem; /* Adjusted margins */
  }
  .media-grid {
    grid-template-columns: repeat(2, 1fr); /* Force 2 columns */
    gap: 0.75rem; /* Further reduce gap */
  }
  .search-input {
    font-size: 0.85rem; /* Even smaller text */
    padding: 0.4rem 0.8rem; /* Smaller padding */
  }
}

/* Larger phones and small tablets (e.g., iPhone 12 Pro Max, Galaxy Tab S7+) */
@media (min-width: 401px) and (max-width: 767px) {
  .nav-content {
    padding: 0 1rem;
  }
  .content {
    padding: 0 1rem;
  }
  .logo {
    font-size: 0.7rem; /* Slightly smaller logo */
  }
  .section-title {
    font-size: 1.9rem; /* Slightly smaller title */
  }
  .subsection-title {
    font-size: 1.4rem; /* Slightly smaller subtitle */
    margin: 2rem 0 1.1rem; /* Adjusted margins */
  }
  /* Keep media-grid at 3 columns as per original rule below */
  .search-input {
    font-size: 0.88rem; /* Slightly smaller text */
  }
}

/* Tablets and larger (e.g., iPad, small laptops) */
@media (min-width: 768px) and (max-width: 1023px) {
  .nav-content {
    padding: 0 1.25rem;
  }
  .content {
    padding: 0 1.25rem;
  }
  .section-title {
    font-size: 2rem; /* Keep desktop size or slightly smaller */
  }
  .subsection-title {
    font-size: 1.5rem; /* Keep desktop size or slightly smaller */
  }
  /* Adjust grid for medium screens if needed, maybe 4-5 columns */
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); /* Adjust min width */
    gap: 1.2rem; /* Adjust gap */
  }
  /* Keep desktop animations */
}

/* Default rule for 3 columns on small screens (kept for compatibility) */
@media (max-width: 767px) {
  .media-grid {
    grid-template-columns: repeat(3, 1fr); /* This overrides the general grid rule */
  }
}

/* General rule for smaller base card size (applies up to tablet) */
@media (max-width: 1023px) {
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); /* Further reduce base min width */
    gap: 0.9rem;
  }
}

.movie-details {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

#movie-player {
  width: 80%;
  height: 450px;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
