/* Brand Identity & Color Adjustments */
:root {
  --brand-red: #ed2024;
  --brand-red-muted: rgba(237, 32, 36, 0.1);
  --primary: light-dark(#3f3f46, #fafafa); /* Subtler primary than pure black in light mode */
}

/* HTMX page transitions */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
#main-content { animation: fadeIn 250ms ease-out; }
.htmx-swapping > #main-content, #main-content.htmx-swapping { opacity: 0; transition: opacity 150ms ease-in; }

/* HTMX indicator pattern */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; align-items: center; }

/* Thumbnail base — keeps a stable 16:9 box */
img[data-thumb] {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--faint);
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Video card: uniform height and contained zoom */
article.video-card { 
  padding: 0; 
  overflow: hidden; 
  transition: border-color 0.3s ease;
  height: 100%; /* Ensure card takes full height of col */
  display: flex;
  flex-direction: column;
  position: relative; /* Base for stretched-link */
}

/* Entire card clickable pattern */
.stretched-link::after {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  content: "";
}

/* Image container to clip the zoom */
article.video-card .img-wrapper {
  overflow: hidden;
  position: relative;
  aspect-ratio: 16/9;
}

article.video-card:hover {
  border-color: var(--brand-red);
}

article.video-card:hover img[data-thumb] {
  transform: scale(1.04);
}

article.video-card a { text-decoration: none; color: inherit; display: block; }
article.video-card a img { border-radius: 0; }

article.video-card > header { 
  padding: var(--space-4) var(--space-4) 0; 
  flex-grow: 1; /* Pushes footer to bottom */
}

article.video-card > header > h3 { 
  font-size: var(--text-6); 
  margin: 0; 
  line-height: 1.4; 
  font-weight: var(--font-semibold);
  /* Fixed 2-line height */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.8em; /* 1.4 line-height * 2 lines */
}

article.video-card > footer { 
  padding: var(--space-2) var(--space-4) var(--space-4); 
  margin: 0; 
  color: var(--muted-foreground); 
  font-size: var(--text-7); 
}

/* Hero card: bigger title, more cinematic */
article.video-hero > header > h2 { 
  font-size: var(--text-3); 
  margin: 0; 
  line-height: 1.2; 
  padding: var(--space-4) var(--space-4) 0; 
  font-weight: var(--font-bold);
}

/* Site logo in the topnav */
.site-logo { 
  display: inline-flex; 
  align-items: center; 
  gap: .75rem; 
  font-weight: var(--font-bold); 
  text-decoration: none; 
  color: inherit; 
  transition: opacity 0.2s ease;
}
.site-logo:hover { color: inherit; opacity: .8; }

nav[data-topnav] { 
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-4);
}

nav[data-topnav] > .site-logo { grid-column: 1; }
nav[data-topnav] > .nav-center { grid-column: 2; justify-self: center; width: 100%; max-width: 600px; }
nav[data-topnav] > .nav-right { grid-column: 3; display: flex; align-items: center; gap: var(--space-4); }

nav[data-topnav] a { font-weight: var(--font-medium); }

/* Responsive Nav */
@media (max-width: 768px) {
  nav[data-topnav] {
    grid-template-columns: 1fr auto;
    row-gap: var(--space-2);
  }
  nav[data-topnav] > .nav-center {
    grid-column: 1 / span 2;
    grid-row: 2;
    order: 3;
    max-width: none;
  }
  nav[data-topnav] > .nav-right {
    grid-column: 2;
    grid-row: 1;
    font-size: var(--text-7);
    gap: var(--space-2);
  }
}

/* Breadcrumb */
nav.breadcrumb ol { list-style: none; padding: 0; margin: 0 0 var(--space-6); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-7); color: var(--muted-foreground); }
nav.breadcrumb a { color: inherit; transition: color 0.2s ease; }
nav.breadcrumb a:hover { color: var(--foreground); }
nav.breadcrumb svg { display: inline-block; vertical-align: middle; opacity: 0.5; }

/* Prev/next nav under video detail */
nav.prevnext { display: flex; gap: var(--space-4); justify-content: space-between; margin-top: var(--space-8); padding: var(--space-6) 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
nav.prevnext a { display: block; color: inherit; text-decoration: none; max-width: 48%; }
nav.prevnext a:hover { color: var(--brand-red); }
nav.prevnext a:last-child { text-align: end; margin-inline-start: auto; }
nav.prevnext small { color: var(--muted-foreground); text-transform: uppercase; letter-spacing: 0.05em; font-weight: var(--font-bold); }
nav.prevnext strong { display: block; margin-top: var(--space-1); line-height: 1.3; }

/* Video detail: play overlay (dark translucent YouTube style) */
.play-overlay { 
  position: absolute; 
  bottom: 1.5rem; 
  left: 1.5rem; 
  background: rgba(0, 0, 0, 0.7); 
  color: #fff; 
  padding: 0.75rem 1.5rem; 
  border-radius: var(--radius-full); 
  font-weight: var(--font-bold); 
  text-decoration: none; 
  display: inline-flex; 
  align-items: center; 
  gap: 0.75rem; 
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.2s ease, background 0.2s ease;
}
.play-overlay:hover { 
  background: rgba(0, 0, 0, 0.85); 
  color: #fff; 
  transform: scale(1.05); 
}

/* Badges on detail page */
.badge.outline { border-color: var(--border); font-weight: var(--font-medium); }
.badge.outline b { color: var(--muted-foreground); font-weight: var(--font-normal); margin-right: 0.25rem; }

/* Markdown content pages */
.prose { max-width: 70ch; margin: 0 auto; line-height: 1.7; }
.prose h1, .prose h2, .prose h3 { margin-top: 2em; }
.prose ul, .prose ol { padding-inline-start: 1.5em; margin-bottom: 1.5em; }
.prose li { margin-bottom: 0.5em; }

/* Utility classes */
.text-light { color: var(--muted-foreground); font-size: 0.9em; font-weight: var(--font-normal); }
.ml-2 { margin-inline-start: var(--space-2); }
.mr-2 { margin-inline-end: var(--space-2); }
.mt-8 { margin-top: var(--space-8); }
.no-underline { text-decoration: none; }
.no-underline:hover { text-decoration: underline; }
.block { display: block; }

/* Nav search input */
input.small { 
  width: 100%;
  padding-top: var(--space-1); 
  padding-bottom: var(--space-1); 
  font-size: var(--text-7);
  height: auto;
}

/* Shared button width: matches a single card column.
   Mobile (< 768px, .row collapses to 4 cols → col-4 is full-width)  →  100%
   Desktop (≥ 768px, .row is 12 cols → col-4 is 1/3)                 →  ~1/3 minus two gap widths
   inline-flex so any icon + label span align centred on the same axis
   instead of dropping to the text baseline. Used by the load-more
   button on /videos and the "More videos →" CTA on the homepage. */
.btn-col {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
}
@media (min-width: 768px) {
  .btn-col { width: calc((100% - 2 * var(--space-4)) / 3); }
}
#load-more-btn {
  transition: all 0.2s ease;
  border-width: 2px;
}
#load-more-btn:hover { border-color: var(--brand-red); color: var(--brand-red); background: var(--brand-red-muted); }

/* Search bar magnifier icon — absolutely positioned inside the form,
   text-indented input so the placeholder/value clears the icon. */
.search-form { position: relative; }
.search-form > .search-icon {
  position: absolute;
  left: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-foreground);
  pointer-events: none;
}
.search-form > input[type="search"] {
  padding-left: calc(var(--space-2) * 2 + 16px);
}

/* ---------- Error pages (404 / 500 / 503 / …) ---------- */
.error-page {
  max-width: 40rem;
  margin: var(--space-6) auto;
}
.error-page h1 {
  font-size: var(--text-3);
  margin-bottom: var(--space-2);
}
.error-page > p { color: var(--muted-foreground); }

/* ---------- Location filter input (used on /map) ---------- */
.location-filter-wrap {
  position: relative;
}
.location-filter-wrap input[type="text"] {
  padding-right: 2.25rem;  /* room for the X button */
}
.location-filter-clear {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  font-size: var(--text-7);
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  display: none;  /* shown when input has a value */
}
.location-filter-wrap.has-value .location-filter-clear { display: inline-flex; align-items: center; justify-content: center; }
.location-filter-clear:hover { background: var(--faint); color: var(--foreground); }

/* ---------- /map page (Leaflet) ---------- */
/* Container — shorter so the locations list under it is visible without
   immediate scrolling. */
.map-container {
  height: 55vh;
  min-height: 360px;
  border-radius: var(--radius-medium);
  border: 1px solid var(--border);
  overflow: hidden;
}
/* Hide markers instantly during zoom (no CSS transition — Leaflet's zoom
   animation is ~250ms and a 150ms opacity transition just kept the dots
   visible for most of the slide). */

/* Marker popup — compact for 1-2 videos, 3-column for larger cities. */
#map .leaflet-popup-pane {
  z-index: 900;
}
#map .leaflet-popup {
  z-index: 900;
}
.map-popup {
  width: 100%;
}
.map-popup--1 { width: 178px; }
.map-popup--2 { width: 258px; }
.map-popup--3 { width: 348px; }
.map-popup h4 { margin: 0 0 var(--space-2); font-size: var(--text-6); }
.map-popup h4 a {
  color: var(--brand-red);
  text-decoration: none;
}
.map-popup h4 a:hover { text-decoration: underline; }
.map-popup-grid {
  display: grid;
  gap: 4px;
}
.map-popup--1 .map-popup-grid { grid-template-columns: 1fr; }
.map-popup--2 .map-popup-grid { grid-template-columns: repeat(2, 1fr); }
.map-popup--3 .map-popup-grid { grid-template-columns: repeat(3, 1fr); }
.map-popup-thumb {
  display: block;
  position: relative;
  line-height: 0;
}
.map-popup-thumb img {
  width: 100%;
  height: auto;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}
.map-popup-thumb:hover img { outline: 2px solid var(--brand-red); }
.map-popup-date {
  position: absolute;
  left: 4px;
  bottom: 4px;
  padding: 1px 5px;
  font-size: 10px;
  line-height: 1.4;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border-radius: 3px;
  font-weight: var(--font-medium, 500);
}
.map-popup-more {
  display: inline-block;
  margin-top: var(--space-2);
  font-size: var(--text-7);
  color: var(--brand-red);
}

/* Ranked city labels. JS places only a capped, non-overlapping subset
   after zoom/pan settles; the marker dot stays as the visual anchor. */
.popmap-label-overlay {
  position: absolute;
  inset: 0;
  z-index: 620;
  pointer-events: none;
  overflow: hidden;
  transition: opacity 120ms ease;
}
.popmap-label-overlay.is-hidden {
  opacity: 0;
}
.popmap-label-overlay.is-hidden .popmap-label {
  pointer-events: none;
}
.popmap-label {
  position: absolute;
  transform: translate3d(-9999px, -9999px, 0);
  opacity: 0;
  pointer-events: none;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  border: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  white-space: nowrap;
  will-change: transform;
  transition: opacity 90ms ease;
}
.popmap-label.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.popmap-label:hover {
  background: #fff;
  color: var(--brand-red);
  z-index: 2;
}

/* ---------- Shorts (portrait 9:16) ---------- */
/* Override the 16:9 thumbnail rule for shorts. The short-card .img-wrapper
   gets a 9:16 box; the <img> still fills the wrapper, just in a different
   aspect-ratio container. */
article.short-card {
  padding: 0;
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: border-color 0.3s ease;
}
article.short-card .img-wrapper {
  aspect-ratio: 9/16;
  overflow: hidden;
  position: relative;
}
/* The wrapper enforces 9:16 via aspect-ratio. The <a> intermediary is
   stretched over the box so the <img> has a sized parent to fill, and
   object-fit:cover center-crops YouTube's 16:9 thumbnail into the
   portrait frame. Don't fight YouTube on this. */
article.short-card .img-wrapper > a {
  position: absolute;
  inset: 0;
  display: block;
}
article.short-card img[data-thumb] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  aspect-ratio: auto;
}
article.short-card:hover { border-color: var(--brand-red); }
article.short-card:hover img[data-thumb] { transform: scale(1.04); }
article.short-card a { text-decoration: none; color: inherit; display: block; }
article.short-card > header {
  padding: var(--space-2) var(--space-3);
  flex-grow: 1;
}
article.short-card > header > h3,
article.short-card > header > h4 {
  font-size: var(--text-7);
  font-weight: var(--font-semibold);
  margin: 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
article.short-card > footer {
  padding: var(--space-1) var(--space-3) var(--space-2);
  margin: 0;
  color: var(--muted-foreground);
  font-size: var(--text-7);
}

/* Hero: a single centred short, with a wide LQIP-coloured ambient backdrop
   spanning the full content width. The backdrop reuses the decoded LQIP
   gradient (via static/lqip.css) on the .shorts-hero-bg layer, blurred
   and desaturated so the centred frame still pops above it. */
.shorts-hero {
  position: relative;
  display: flex;
  justify-content: center;
  margin-top: var(--space-4);
  padding: var(--space-6) var(--space-4);
  border-radius: var(--radius-medium);
  overflow: hidden;
  isolation: isolate;
}
.shorts-hero-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  /* Push the gradient out a bit so blurred edges don't reveal the cut. */
  margin: -10%;
  filter: blur(60px) saturate(1.3);
  opacity: 0.75;
  pointer-events: none;
}
.shorts-hero-frame {
  position: relative;
  z-index: 1;
  /* Width is the most-restrictive of:
       95vw  – leave a small gutter on narrow viewports
       calc(60vh * 9 / 16) – cap the 9:16 thumbnail so the whole hero
                              card (image + title + date) stays in view
       360px – YouTube's typical short width, the ceiling on widescreens */
  width: min(95vw, calc(60vh * 9 / 16), 360px);
}
.shorts-hero .short-card > header > h2 {
  font-size: var(--text-5);
  font-weight: var(--font-bold);
  margin: 0;
  line-height: 1.25;
}
/* A shorts playlist on /shorts is one card: the clickable header at the
   top, then the horizontal row of tiles. They live inside .shorts-playlist-card
   so the visual chrome is a single box. */
.shorts-playlist-card {
  padding: var(--space-3);
  margin-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.shorts-playlist-card .playlist-body { margin: 0; }

/* Clickable header link — thumb + meta side-by-side. No nested border
   anymore (the outer card carries it). */
.playlist-header {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius-medium);
  transition: background-color 0.2s ease;
}
.playlist-header:hover { background: var(--faint); }
.playlist-header:hover .playlist-meta > h3 { color: var(--brand-red); }
/* The orphan card has no playlist destination — keep the visual chrome
   but skip the hover affordance so it doesn't suggest interactivity. */
.playlist-header.playlist-header-static { cursor: default; }
.playlist-header.playlist-header-static:hover { background: transparent; }
.playlist-header.playlist-header-static:hover .playlist-meta > h3 { color: inherit; }
.playlist-header .playlist-thumb {
  flex: 0 0 240px;
  aspect-ratio: 16/9;
  overflow: hidden;
  border-radius: var(--radius-medium);
  border: 1px solid var(--border);
}
.playlist-header .playlist-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  aspect-ratio: auto;
}
.playlist-header .playlist-meta { flex: 1; min-width: 0; }
.playlist-header .playlist-meta > h3 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-5);
  transition: color 0.2s ease;
}
.playlist-header .playlist-meta > p {
  margin: 0;
  color: var(--muted-foreground);
}
@media (max-width: 640px) {
  .playlist-header { flex-direction: column; }
  .playlist-header .playlist-thumb { flex: 0 0 auto; width: 100%; max-width: 360px; }
}

/* Shorts row — Swiffy Slider markup with our tile sizing.
   Swiffy's CSS already provides the swipe + snap behaviour; we override
   the list/item defaults so the cards keep their look. */
.shorts-row.swiffy-slider {
  /* Positioning context for the nav buttons (relative is Swiffy's default
     but we make it explicit since our card padding nests differently). */
  position: relative;
}
.shorts-row .slider-container {
  list-style: none;
  padding-left: 0;
  margin: 0;
  gap: var(--space-3);
  padding-bottom: var(--space-2);
}
.shorts-row .slider-container > li.short-tile {
  list-style: none;
}
/* Tile width is responsive so the row shows "as many as fit":
     mobile (<640px)   →  ~1 tile + a peek of the next (signals scrollability)
     small (640–1023)  →  3 tiles per row
     desktop (≥1024)   →  5 tiles per row
   Swiffy's .slider-container is `display: grid; grid-auto-columns: 100%`,
   so we override grid-auto-columns directly — flex/basis rules wouldn't
   apply in a grid context. */
.shorts-row .slider-container {
  grid-auto-columns: 88%;
}
@media (min-width: 640px) {
  .shorts-row .slider-container {
    grid-auto-columns: calc((100% - 2 * var(--space-3)) / 3);
  }
}
@media (min-width: 1024px) {
  .shorts-row .slider-container {
    grid-auto-columns: calc((100% - 4 * var(--space-3)) / 5);
  }
}
/* Bring the prev/next buttons up to the tile vertical centre so they sit
   over the thumbnails, not the captions below them. */
.shorts-row .slider-nav {
  top: 0;
  bottom: auto;
  height: calc(100% - 3.5rem);  /* leave the caption area uncovered */
  z-index: 10;
  pointer-events: auto;
}

/* Short video detail page: 9:16 box that never overflows the viewport.
   Width is the MOST restrictive of three ceilings via min():
     * 95vw  – leaves a gutter so the box never touches the edges
     * calc(80vh * 9/16) – derived width when 80% of viewport height is the cap
     * 1080px – matches YouTube's native portrait width (=> height ≤ 1920px)
   Whichever caps the smallest wins, so even on a narrow-but-tall window
   (e.g. 600×1200) the box fits without page scroll.
   Applies to whatever direct child renders the player — the embedded
   YouTube <iframe> for shorts, or the click-through <a> fallback. */
/* Short detail page: the wrapper itself is sized to the player so an
   absolute-positioned caption inside is anchored to the video frame
   (not the page width). Width is the most restrictive of three ceilings:
     95vw  – leaves a gutter so the box never touches the edges
     calc(80vh * 9/16) – derived width from an 80vh height cap
     1080px – matches YouTube's native portrait width (=> height ≤ 1920px). */
.short-detail-thumb {
  position: relative;
  display: block;
  margin: 0 auto;
  width: min(95vw, calc(80vh * 9 / 16), 1080px);
  aspect-ratio: 9/16;
  border-radius: var(--radius-medium);
  overflow: hidden;
  background: var(--faint);
}
.short-detail-thumb > a,
.short-detail-thumb > iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  aspect-ratio: auto;  /* parent already enforces 9:16 */
}
.short-detail-thumb img[data-thumb] {
  width: 100%;
  height: 100%;
  object-fit: cover;
  aspect-ratio: auto;
}

.short-detail-layout {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.short-detail-layout .short-detail-thumb {
  margin: 0;
}
.short-detail-actions {
  gap: var(--space-2);
  flex-wrap: wrap;
}
.short-detail-description-desktop {
  display: none;
}
.short-description-dialog {
  width: min(92vw, 42rem);
  max-height: min(82vh, 44rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  background: light-dark(#fff, #18181b);
  color: var(--foreground);
}
.short-description-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.short-description-dialog-card {
  padding: var(--space-4);
  margin: 0;
  max-height: inherit;
  overflow: auto;
}
.short-description-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}
.short-description-dialog-header h2,
.short-detail-description-desktop h2 {
  margin: 0;
  font-size: var(--text-5);
}
.short-description-close {
  min-width: 2rem;
  padding-inline: 0.65rem;
}
.short-description-prose {
  max-width: none;
  margin: 0;
  font-size: var(--text-7);
  line-height: 1.55;
}
.short-description-prose p:last-child {
  margin-bottom: 0;
}

@media (min-width: 960px) {
  .short-detail-description-desktop {
    display: block;
    align-self: flex-end;
    width: min(30rem, calc((100vw - min(95vw, calc(80vh * 9 / 16), 1080px) - 6rem) / 2));
    min-width: 18rem;
    max-height: 80vh;
    overflow: auto;
    padding: var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-medium);
    background: light-dark(#fff, #18181b);
    color: var(--foreground);
  }
  .short-detail-description-desktop h2 {
    margin-bottom: var(--space-3);
  }
  .short-description-dialog-button {
    display: none;
  }
}

/* 'More Shorts' grid: auto-fill so the row count grows with the
   viewport width without bespoke breakpoints. Used for the catch-all
   list of shorts that aren't (yet) in any user playlist. */
.shorts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-3);
}
@media (min-width: 768px) {
  .shorts-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (min-width: 1280px) {
  .shorts-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
