/* ==========================================================================
   Glide post carousel
   Tokens are overridable from the URL (theme, accent) via carousel.js.
   ========================================================================== */

:root {
  /* Color */
  --page-bg: #391709;               /* dark-brown canvas matching the Glide embed */
  --surface: #ffffff;
  --ink: #1b1f27;
  --ink-soft: #5c6474;
  --line: rgba(27, 31, 39, 0.10);
  --placeholder: rgba(255, 255, 255, 0.10);
  --placeholder-hi: rgba(255, 255, 255, 0.16);
  --accent: #3b5bdb;

  /* Fluid sizing: every value scales with the iframe width */
  --edge: clamp(4px, 1.2vw, 12px);          /* outer padding */
  --gap: clamp(6px, 1.6vw, 18px);           /* space between cards */
  --radius-card: clamp(9px, 1.5vw, 16px);
  --pad: clamp(6px, 1.2vw, 12px);
  --per-view: 3;                             /* updated by JS on resize */
  --title-size: clamp(11px, 3.5vw, 14px);   /* fluid — scales with iframe width */
  --title-lh: 1.28;
  --btn: clamp(28px, 6.5vw, 36px);

  /* Motion */
  --slide-dur: 560ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --interval: 5000ms;                       /* set from JS */

  --ratio: 4 / 3;                           /* used only in fixed-ratio mode */

  color-scheme: light;
}

:root[data-theme="dark"] {
  --surface: #1e222b;
  --ink: #eef0f4;
  --ink-soft: #a3aab8;
  --line: rgba(238, 240, 244, 0.12);
  --placeholder: #2a2f3a;
  --placeholder-hi: #333948;
  --accent: #8ea6ff;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --surface: #1e222b;
    --ink: #eef0f4;
    --ink-soft: #a3aab8;
    --line: rgba(238, 240, 244, 0.12);
    --placeholder: #2a2f3a;
    --placeholder-hi: #333948;
    --accent: #8ea6ff;
    color-scheme: dark;
  }
}

/* --------------------------------------------------------------------------
   Base: fill the iframe exactly, never scroll
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--page-bg);
}

body {
  font: 400 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  padding: var(--edge);
  padding-left: max(var(--edge), env(safe-area-inset-left, 0px));
  padding-right: max(var(--edge), env(safe-area-inset-right, 0px));
}

/* --------------------------------------------------------------------------
   Carousel
   -------------------------------------------------------------------------- */

.carousel {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.2vw, 12px);
}

.viewport {
  overflow: hidden;
  touch-action: pan-y;
  /* Room for focus rings and hover lift without clipping */
  padding: 3px;
  margin: -3px;
}

.track {
  position: relative;               /* makes slide.offsetLeft relative to the track */
  height: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
  transform: translate3d(0, 0, 0);
  transition: transform var(--slide-dur) var(--ease);
  will-change: transform;
}

.track.no-anim { transition: none; }

.is-few .track { justify-content: center; }

.slide {
  flex: 0 0 calc((100% - (var(--per-view) - 1) * var(--gap)) / var(--per-view));
  min-width: 0;
  display: flex;
}

.card {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: transparent;
  border: none;
  border-radius: var(--radius-card);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  outline: none;
}

a.card { cursor: pointer; }

a.card:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Fixed ratio makes height predictable — no dead background space below the carousel */
.media {
  position: relative;
  aspect-ratio: 4 / 3;
  flex: none;
  min-height: 0;
  background: var(--placeholder);
  overflow: hidden;
  border-radius: var(--radius-card);
}

.ratio-mode .media {
  aspect-ratio: var(--ratio);
}

.media img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 280ms ease, transform 400ms var(--ease);
  -webkit-user-drag: none;
}

.media.is-loaded img { opacity: 1; }

@media (hover: hover) {
  a.card:hover .media.is-loaded img { transform: scale(1.035); }
}

/* Loading shimmer */
.media.is-loading::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, var(--placeholder-hi) 50%, transparent 70%) 0 0 / 250% 100%;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer { to { background-position: -250% 0; } }

/* Missing or broken image */
.media.is-empty::after,
.media.is-broken::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a92a3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='2'/%3E%3Ccircle cx='9' cy='10' r='1.6'/%3E%3Cpath d='M21 16l-5-5-8 8'/%3E%3C/svg%3E") center / clamp(18px, 5vw, 36px) no-repeat;
  opacity: 0.75;
}

.title {
  margin: var(--pad);
  padding: 0;
  font-size: var(--title-size);
  font-weight: 600;
  line-height: var(--title-lh);
  letter-spacing: -0.005em;
  color: #ffffff;
  flex: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.no-titles .title { display: none; }

.is-dragging .card { cursor: grabbing; }

/* --------------------------------------------------------------------------
   Controls
   -------------------------------------------------------------------------- */

.controls {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.4vw, 10px);
}

.btn {
  width: var(--btn);
  height: var(--btn);
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

.btn svg {
  width: 46%;
  height: 46%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn .icon-play { fill: currentColor; stroke: none; }
.btn .icon-play { display: none; }
.btn[aria-pressed="true"] .icon-play { display: block; }
.btn[aria-pressed="true"] .icon-pause { display: none; }

.btn-quiet { border-color: transparent; background: transparent; color: rgba(255, 255, 255, 0.55); }

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: hover) {
  .btn:hover { border-color: var(--ink-soft); }
  .btn-quiet:hover { color: var(--ink); }
}

.dots {
  display: flex;
  align-items: center;
  visibility: hidden; /* pagination hidden — remove to show dots */
  pointer-events: none;
}

/* prev/next/pause buttons hidden — remove display:none to show them */
#prev,
#next,
#toggle {
  display: none;
}

/* 24px hit area, small visual mark */
.dot {
  min-width: 24px;
  height: 24px;
  padding: 0 3px;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}

.dot::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.45);
  opacity: 1;
  transition: width 300ms var(--ease), opacity 300ms ease;
}

/* The active dot becomes a pill that fills while the timer runs:
   it tells people when the next group will arrive. */
.dot[aria-current="true"]::after {
  width: 22px;
  opacity: 1;
  background:
    linear-gradient(var(--accent), var(--accent)) left / var(--fill, 100%) 100% no-repeat,
    color-mix(in srgb, var(--accent) 28%, transparent);
}

.carousel.is-playing .dot[aria-current="true"]::after {
  animation: fill var(--interval) linear forwards;
}

.carousel.is-paused .dot[aria-current="true"]::after {
  animation-play-state: paused;
}

@keyframes fill {
  from { background-size: 0% 100%, auto; }
  to   { background-size: 100% 100%, auto; }
}

.dot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 6px;
}

.counter {
  min-width: 4.5em;
  text-align: center;
  font-size: clamp(11px, 2.2vw, 13px);
  color: rgba(255, 255, 255, 0.55);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Empty / error state
   -------------------------------------------------------------------------- */

.state {
  flex: 1;
  margin: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  padding: 12px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.state-title { margin: 0; font-weight: 600; font-size: clamp(13px, 2.6vw, 15px); }
.state-detail { margin: 0; color: var(--ink-soft); font-size: clamp(12px, 2.3vw, 13px); max-width: 52ch; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------------------
   Very small embeds: drop secondary chrome
   -------------------------------------------------------------------------- */

@media (max-height: 150px) {
  .controls { display: none; }
}

/* --------------------------------------------------------------------------
   Single-card view: square images (applied via JS data attribute, not
   a media query, so it uses the actual embed width rather than the viewport)
   -------------------------------------------------------------------------- */

.carousel[data-per-view="1"] .media {
  aspect-ratio: 1 / 1;
}

.carousel[data-per-view="1"] .title {
  font-size: clamp(13px, 4vw, 16px);
  -webkit-line-clamp: 3;
}

/* --------------------------------------------------------------------------
   Reduced motion: instant changes, no shimmer, no zoom, static timer pill
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .track, .media img, .dot::after { transition: none !important; }
  .media.is-loading::before { animation: none; }
  a.card:hover .media.is-loaded img { transform: none; }
  .carousel.is-playing .dot[aria-current="true"]::after { animation: none; }
}

