/* ---------------------------------------------------------------------------
   Friendly Memes — public feed
   Dark-first, with an automatic light theme. No inline styles anywhere:
   the CSP has no 'unsafe-inline'.
   --------------------------------------------------------------------------- */

:root {
  --bg: #0e0f13;
  --bg-elev: #16181f;
  --surface: #1c1f28;
  --line: #272b36;
  --text: #e8eaf0;
  --text-dim: #9aa1b1;
  --accent: #ffb454;
  --accent-ink: #2a1c05;
  --radius: 18px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .45);
  --bar-h: 58px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fa;
    --bg-elev: #ffffff;
    --surface: #ffffff;
    --line: #e3e6ee;
    --text: #171a21;
    --text-dim: #626a7d;
    --accent: #f0900a;
    --accent-ink: #ffffff;
    --shadow: 0 6px 24px rgba(23, 26, 33, .10);
  }
}

* { box-sizing: border-box; }

html {
  /* 'proximity', not 'mandatory': mandatory snapping fights short flick
     scrolls on iOS and can trap the user between two images. */
  scroll-snap-type: y proximity;
  scroll-behavior: smooth;
  scroll-padding-top: var(--bar-h);
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; scroll-snap-type: none; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  /* iOS overscroll reveals the page background behind the fixed bar. */
  overscroll-behavior-y: none;
}

/* ---------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.brand .dot { color: var(--accent); }

.bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.count {
  color: var(--text-dim);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 44px min target — thumb-friendly on a phone. */
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn[data-order="alpha"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

/* ---------------------------------------------- feed */

.wrap {
  /* One column, bounded width — AC4's "same width" guarantee lives here. */
  width: min(680px, 92vw);
  margin: 0 auto;
  padding: 0 0 20vh;
}

.feed { display: block; }

.item {
  margin: 0;
  /* Each item occupies roughly one screen, so a scroll gesture advances
     exactly one picture. dvh follows mobile browser chrome as it collapses;
     the vh line is the fallback for browsers without dvh. */
  min-height: calc(88vh - var(--bar-h));
  min-height: calc(88dvh - var(--bar-h));
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 24px 0;
  scroll-snap-align: center;
  scroll-snap-stop: normal;
}

.frame {
  /* The frame is the "thumbnail": every frame is the same width (AC4) so the
     column stays even. The image is centred inside it, which is what lets a
     small or very tall picture keep its own true size without stretching. */
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  line-height: 0; /* kill the inline-descender gap under the image */
}

.frame img {
  display: block;
  /* width/height are auto so the browser sizes from the intrinsic ratio it
     gets from the width/height attributes: no layout shift, no inline style
     for the CSP to block, and crucially no upscaling of a small picture.
     max-width caps a big image to the column; max-height caps a tall one and
     shrinks its width in proportion, so the painted pixels always fill the
     element box exactly — never stretched, never letterboxed (AC5). */
  width: auto;
  height: auto;
  max-width: 100%;
  /* Cap the tallest images so one picture still occupies about one screen. */
  max-height: 72vh;
  max-height: 72dvh;
  object-fit: contain;
}

.caption {
  width: 100%;
  margin: 0;
  padding: 0 4px;
  color: var(--text-dim);
  font-size: .95rem;
  text-align: center;
  overflow-wrap: anywhere;
}

/* An image that fails to load hides its whole item rather than showing a
   torn frame. Set by feed.js on the img error event. */
.item.is-broken { display: none; }

/* ---------------------------------------------- states */

.sentinel { height: 4px; }

.end,
.empty {
  padding: 48px 16px;
  color: var(--text-dim);
  text-align: center;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 60vh;
  justify-content: center;
}

.empty-icon {
  font-size: 3rem;
  color: var(--accent);
  line-height: 1;
}

.empty h2 {
  margin: 0;
  color: var(--text);
  font-size: 1.35rem;
}

.empty p { margin: 0; max-width: 32ch; }

.loading {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: .9rem;
}

/* ---------------------------------------------- small screens */

@media (max-width: 480px) {
  .wrap { width: 94vw; }
  .frame { border-radius: 14px; }
  .count { display: none; }
}
