/* ==============================================================
   EXPLORE — styles
   ------------------------------------------------------------
   RESPONSIVE STRATEGY (read this before editing)

   1. Nothing is ever sized in fixed px that can exceed a small
      viewport. Type, spacing, and radii use clamp() so they
      scale fluidly between a 320px phone and a 1440px desktop
      instead of being "tuned" to one device.
   2. Every flex/grid child that holds text has min-width: 0.
      Flex children default to min-width: auto, which means they
      refuse to shrink below their content's natural width — that
      is the #1 cause of sideways scrolling in flex layouts, and
      it is fixed at the source here, not patched with
      overflow-x: hidden.
   3. Every text-bearing element that can contain an unpredictable
      or unbreakable string (titles, filenames, tags, URLs) gets
      overflow-wrap: anywhere so long words break instead of
      pushing the card wider.
   4. The ONLY things allowed to scroll horizontally are chip
      rows and data tables — both explicitly, both intentionally,
      both with -webkit-overflow-scrolling: touch and a hidden
      scrollbar. Nothing else may introduce horizontal scroll.
   5. Button rows and meta rows use flex-wrap: wrap, so on a
      narrow screen items drop to a new line instead of
      overflowing or squashing.
   6. A final safety-net section pins html/body to 100% width
      with overflow-x: hidden as a last-resort backstop — it
      should never actually have to do any work if 1–5 hold.
   ============================================================== */

/* ==============================================================
   1. VARIABLES — color, fluid type scale, fluid spacing
   ============================================================== */

:root {
  /* --- brand --- */
  --forest: #0F3D2E;
  --forest-deep: #0A2C21;
  --forest-soft: #E7F0EA;
  --amber: #E8A33D;
  --amber-soft: #FBEBD2;

  /* --- surface (light, default) --- */
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-sunken: #F4F3EF;
  --border: #E7E4DC;
  --border-strong: #D8D4C8;

  /* --- text (light) --- */
  --ink: #1B221E;
  --ink-soft: #5B655F;
  --ink-faint: #8A928C;
  --on-forest: #F4F8F5;

  /* --- semantic --- */
  --like: #E0453F;
  --like-soft: #FBE4E2;
  --shadow: 0 1px 2px rgba(15, 61, 46, 0.04), 0 8px 24px rgba(15, 61, 46, 0.06);
  --shadow-lift: 0 4px 10px rgba(15, 61, 46, 0.07), 0 16px 32px rgba(15, 61, 46, 0.09);

  /* --- type --- */
  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  /* fluid type scale — clamp(min, preferred, max) so nothing is
     tuned to one phone; preferred value uses vw so it scales
     smoothly between the min and max bounds */
  --fs-h1:        clamp(22px, 5.6vw, 34px);
  --fs-subtitle:  clamp(12.5px, 3.2vw, 14px);
  --fs-title:     clamp(16.5px, 4.2vw, 21px);
  --fs-body:      clamp(14px, 3.6vw, 15px);
  --fs-meta:      clamp(11.5px, 2.9vw, 12.5px);
  --fs-chip:      clamp(12.5px, 3.2vw, 14px);
  --fs-chip-sm:   clamp(12px, 3vw, 13px);
  --fs-action:    clamp(12.5px, 3.1vw, 13.5px);
  --fs-nav:       clamp(10px, 2.6vw, 10.5px);

  /* fluid spacing / radii */
  --gutter:  clamp(12px, 4vw, 24px);
  --r-card:  clamp(14px, 3.6vw, 20px);
  --r-sm:    clamp(8px, 2.2vw, 10px);
  --r-pill:  100px;
  --col-max: 555px; /* LinkedIn-style mid column — mobile ignores this via min(100%, …) */
  --nav-size: 72px;
}

/* Dark mode is opt-in only, via the toggle — never auto from OS. */
[data-theme="dark"] {
  --bg: #0D1712;
  --surface: #142019;
  --surface-sunken: #0F1913;
  --border: #223229;
  --border-strong: #2C3F33;

  --ink: #EDF3EE;
  --ink-soft: #A9B6AE;
  --ink-faint: #718077;
  --on-forest: #F4F8F5;

  --forest-soft: #16261F;
  --amber-soft: #2C2318;
  --like-soft: #301B19;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-lift: 0 4px 10px rgba(0, 0, 0, 0.22), 0 20px 40px rgba(0, 0, 0, 0.32);
}

/* ==============================================================
   2. GLOBAL RESET + BOX-SIZING
   ============================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  min-width: 0; /* flex/grid children shrink instead of overflowing */
}

html {
  -webkit-text-size-adjust: 100%;
  width: 100%;
}

body {
  margin: 0;
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

h1, h2, h3, p { margin: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  max-width: 100%;
}

/* images/svg never exceed their box, and never carry intrinsic
   width past a small viewport */
img, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

table { border-collapse: collapse; width: 100%; }

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==============================================================
   3. LAYOUT CONTAINER
   ============================================================== */

.app-shell {
  width: 100%;
  max-width: 100%;
  padding-bottom: calc(var(--nav-size) + 8px);
}

/* ==============================================================
   4. PRIMARY NAVIGATION
   Mobile: fixed bottom tab bar.
   Desktop (≥860px): becomes a left-hand rail; .app-shell shifts.
   ============================================================== */

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 2px;
  width: 100%;
  max-width: 100vw;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px min(6px, 2vw) calc(6px + env(safe-area-inset-bottom, 0));
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1 1 0;
  min-width: 0;
  max-width: 110px;
  min-height: 52px;
  padding: 6px min(10px, 2.5vw);
  border-radius: 14px;
  color: var(--ink-faint);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item svg { width: 21px; height: 21px; flex-shrink: 0; }
.nav-item span {
  font-size: var(--fs-nav);
  font-weight: 600;
  white-space: nowrap;
}

.nav-item:hover { color: var(--ink-soft); }
.nav-item.is-active {
  color: var(--forest);
  background: var(--forest-soft);
}
[data-theme="dark"] .nav-item.is-active { color: var(--amber); background: var(--amber-soft); }

@media (min-width: 860px) {
  .nav {
    top: 0;
    right: auto;
    bottom: 0;
    width: var(--nav-size);
    max-width: var(--nav-size);
    flex-direction: column;
    justify-content: flex-start;
    padding: 22px 10px;
    gap: 8px;
    border-top: none;
    border-right: 1px solid var(--border);
  }
  .nav-item { width: 100%; max-width: 100%; min-height: 56px; }
  .app-shell { padding-bottom: 0; padding-left: var(--nav-size); }
}

/* ==============================================================
   5. TOP BAR — compact mobile header + scrollable chips
   ============================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  width: 100%;
  max-width: 100%;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0);
}

.topbar-inner {
  width: 100%;
  max-width: calc(var(--col-max) + var(--gutter) * 2);
  margin: 0 auto;
  padding: clamp(12px, 3.5vw, 18px) var(--gutter) 0;
}

.topbar-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: clamp(10px, 2.6vw, 14px);
}

.heading-text {
  min-width: 0;
  flex: 1 1 auto;
}

.heading-text h1 {
  font-size: var(--fs-h1);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--forest);
  line-height: 1.1;
}
[data-theme="dark"] .heading-text h1 { color: var(--on-forest); }

.heading-text p {
  margin-top: 2px;
  font-size: var(--fs-subtitle);
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Very narrow phones (≤359px): drop the subtitle so the compact
   header never eats more vertical space than the chips below it
   need. Title + toggle + chips still fully intact. */
@media (max-width: 359px) {
  .heading-text p { display: none; }
}

.theme-toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  color: var(--forest);
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; color: var(--amber); }

/* ==============================================================
   6. FILTER CHIPS — the only page elements besides data tables
      that are allowed to scroll sideways, and only within their
      own box.
   ============================================================== */

.chip-row {
  display: flex;
  width: 100%;
  max-width: 100%;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  /* fade the scroll edge instead of a hard clip */
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
          mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
}
.chip-row::-webkit-scrollbar { display: none; height: 0; }

.chip-row--primary { padding-top: 2px; }
.chip-row--topic { padding-bottom: 16px; }

.chip {
  flex: 0 0 auto;
  padding: 9px clamp(12px, 3.4vw, 16px);
  min-height: 38px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: var(--fs-chip);
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip-row--topic .chip {
  font-weight: 500;
  padding: 7px clamp(10px, 3vw, 14px);
  min-height: 32px;
  font-size: var(--fs-chip-sm);
}

.chip.is-active {
  background: var(--forest);
  border-color: var(--forest);
  color: var(--on-forest);
}
.chip-row--topic .chip.is-active {
  background: var(--forest-soft);
  border-color: var(--forest);
  color: var(--forest);
}
[data-theme="dark"] .chip-row--topic .chip.is-active { color: var(--amber); border-color: var(--amber); background: var(--amber-soft); }

/* ==============================================================
   7. FEED / LAYOUT COLUMN
   ============================================================== */

.feed-wrap {
  width: 100%;
  max-width: min(100%, calc(var(--col-max) + var(--gutter) * 2));
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-block: clamp(16px, 4vw, 20px) 48px;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 3.6vw, 20px);
  width: 100%;
}

.feed-empty, .feed-end {
  text-align: center;
  padding: 40px 16px;
  color: var(--ink-faint);
}
.feed-empty p { font-size: 16px; font-weight: 700; color: var(--ink-soft); }
.feed-empty span { font-size: 14px; }

.feed-end { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; }
.feed-end-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }

/* ==============================================================
   8. POST CARD — base
   ============================================================== */

.post-card {
  width: 100%;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: clamp(16px, 4.2vw, 24px);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  overflow: hidden; /* clips any rogue child, belt-and-braces */
}

@media (min-width: 720px) {
  .post-card:hover {
    box-shadow: var(--shadow-lift);
    transform: translateY(-2px);
  }
}

.post-author {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  min-width: 0;
}

.post-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.post-avatar--fallback {
  display: grid;
  place-items: center;
  background: var(--forest-soft);
  color: var(--forest);
  font-size: 13px;
  font-weight: 800;
}
[data-theme="dark"] .post-avatar--fallback {
  background: var(--amber-soft);
  color: var(--amber);
}

.post-author-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1 1 auto;
}
.post-author-info strong {
  font-size: clamp(13.5px, 3.4vw, 14.5px);
  font-weight: 700;
  overflow-wrap: anywhere;
}
.post-author-info span {
  font-size: clamp(12px, 3vw, 13px);
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}

.post-title {
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.35;
  margin-bottom: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.post-blocks {
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 3vw, 14px);
  width: 100%;
  min-width: 0;
}

/* ==============================================================
   9. CONTENT BLOCK VARIANTS
   ============================================================== */

.block { width: 100%; max-width: 100%; min-width: 0; }

/* ---- text ---- */

.block-text {
  font-size: var(--fs-body);
  line-height: 1.6;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}
.block-text > * { white-space: normal; }
.block-text p { margin: 0 0 0.9em; }
.block-text p:last-child { margin-bottom: 0; }
.block-text h2,
.block-text h3,
.block-text h4 {
  margin: 1.1em 0 0.45em;
  color: var(--ink);
  font-family: var(--font-display);
  line-height: 1.25;
}
.block-text h2:first-child,
.block-text h3:first-child,
.block-text h4:first-child { margin-top: 0; }
.block-text h2 { font-size: 1.35em; }
.block-text h3 { font-size: 1.2em; }
.block-text h4 { font-size: 1.08em; }
.block-text ul,
.block-text ol { margin: 0.7em 0 0.9em; padding-left: 1.5em; }
.block-text li + li { margin-top: 0.3em; }
.block-text blockquote {
  margin: 0.9em 0;
  padding: 0.2em 0 0.2em 1em;
  border-left: 3px solid var(--amber);
  color: var(--ink-soft);
}
.block-text a {
  color: var(--forest);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 38%, transparent);
  text-underline-offset: 0.18em;
}
[data-theme="dark"] .block-text a { color: var(--amber); }
.block-text code {
  padding: 0.12em 0.34em;
  border-radius: 4px;
  background: var(--surface-sunken);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.9em;
}
.block-text pre {
  margin: 0.9em 0;
  padding: 12px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
  white-space: pre;
}
.block-text pre code { padding: 0; background: transparent; }
.block-text hr { margin: 1.1em 0; border: 0; border-top: 1px solid var(--border); }

/* ---- photo grid ---- */

.photogrid {
  display: grid;
  width: 100%;
  gap: 4px;
  border-radius: var(--r-sm);
  overflow: hidden;
}
.photogrid-item {
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--surface-sunken);
}
.photo-open {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: zoom-in;
  overflow: hidden;
}
.photogrid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease, filter 0.25s ease;
}
.photo-open:hover img,
.photo-open:focus-visible img {
  transform: scale(1.025);
  filter: brightness(0.82);
}
.photo-open-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 11px;
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 999px;
  background: rgba(12,16,14,0.72);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.photo-open:hover .photo-open-hint,
.photo-open:focus-visible .photo-open-hint {
  opacity: 1;
  transform: translate(-50%, 0);
}
.photo-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--ink-faint);
  font-size: var(--fs-meta);
  font-weight: 700;
}

.photogrid--single { grid-template-columns: 1fr; }
.photogrid--single .photogrid-item { aspect-ratio: 16 / 10; }
.photogrid--quad { grid-template-columns: 1fr 1fr; }
.photogrid--three { grid-template-columns: 1fr 1fr; }
.photogrid--three .photogrid-item:first-child { grid-row: span 2; aspect-ratio: 3 / 4; }

/* ---- full-resolution image viewer ---- */

body.viewer-open { overflow: hidden; }

.image-viewer[hidden] { display: none; }
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  opacity: 0;
  transition: opacity 0.22s ease;
}
.image-viewer.is-open { opacity: 1; }
.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 7, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.image-viewer-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1180px, 100%);
  height: min(860px, 100%);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  background: #111613;
  color: #f4f7f5;
  box-shadow: 0 30px 90px rgba(0,0,0,0.55);
  transform: translateY(14px) scale(0.985);
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}
.image-viewer.is-open .image-viewer-panel { transform: translateY(0) scale(1); }
.image-viewer-toolbar,
.image-viewer-footer {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 14px;
  background: rgba(17,22,19,0.96);
}
.image-viewer-toolbar { border-bottom: 1px solid rgba(255,255,255,0.1); }
.image-viewer-footer {
  border-top: 1px solid rgba(255,255,255,0.1);
  color: rgba(244,247,245,0.62);
  font-size: 12px;
}
.image-viewer-footer span:first-child {
  max-width: 70%;
  overflow: hidden;
  color: rgba(244,247,245,0.88);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-viewer-heading { display: grid; line-height: 1.2; }
.image-viewer-heading strong { font-size: 14px; }
.image-viewer-heading span { min-height: 15px; color: rgba(244,247,245,0.58); font-size: 11px; }
.image-viewer-controls { display: flex; align-items: center; gap: 6px; }
.image-viewer-controls button,
.image-viewer-controls a {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  background: rgba(255,255,255,0.06);
  color: #f4f7f5;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.image-viewer-controls button:hover,
.image-viewer-controls button:focus-visible,
.image-viewer-controls a:hover,
.image-viewer-controls a:focus-visible {
  border-color: rgba(232,163,61,0.72);
  background: rgba(232,163,61,0.16);
}
.image-viewer-controls .image-viewer-scale { min-width: 62px; font-size: 12px; }
.image-viewer-controls a { font-size: 12px; text-decoration: none; }
.image-viewer-controls .image-viewer-close { margin-left: 4px; font-size: 24px; font-weight: 400; }
.image-viewer-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.025) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.025) 75%),
    linear-gradient(45deg, rgba(255,255,255,0.025) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.025) 75%),
    #090c0a;
  background-position: 0 0, 12px 12px;
  background-size: 24px 24px;
}
.image-viewer-canvas {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
  cursor: zoom-in;
  user-select: none;
}
.image-viewer-canvas.is-zoomed { cursor: grab; }
.image-viewer-canvas.is-zoomed:active { cursor: grabbing; }
.image-viewer-canvas img {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: contain;
  opacity: 1;
  transform-origin: center;
  will-change: transform, opacity;
  transition: opacity 0.16s ease;
}
.image-viewer-canvas.is-loading img { opacity: 0; }
.image-viewer-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 56px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  background: rgba(8,12,10,0.72);
  color: #fff;
  font-size: 34px;
  cursor: pointer;
  transform: translateY(-50%);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.image-viewer-nav:hover,
.image-viewer-nav:focus-visible { border-color: rgba(232,163,61,0.72); background: rgba(15,61,46,0.88); }
.image-viewer-prev { left: 12px; }
.image-viewer-next { right: 12px; }

@media (max-width: 640px) {
  .image-viewer { padding: 0; }
  .image-viewer-panel { width: 100%; height: 100%; border: 0; border-radius: 0; }
  .image-viewer-toolbar { align-items: flex-start; padding: max(10px, env(safe-area-inset-top)) 10px 10px; }
  .image-viewer-heading { max-width: 120px; }
  .image-viewer-controls { gap: 4px; }
  .image-viewer-controls button,
  .image-viewer-controls a { min-width: 34px; height: 34px; padding-inline: 8px; }
  .image-viewer-controls a { display: none; }
  .image-viewer-controls .image-viewer-scale { min-width: 54px; }
  .image-viewer-controls .image-viewer-close { margin-left: 0; }
  .image-viewer-footer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .image-viewer-footer span:last-child { display: none; }
  .image-viewer-footer span:first-child { max-width: 100%; }
  .image-viewer-nav { top: auto; bottom: 14px; width: 42px; height: 42px; transform: none; }
}

/* ---- map block ---- */

.map-block {
  position: relative;
  width: 100%;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--forest);
  aspect-ratio: 16 / 10;
}
.map-svg { width: 100%; height: 100%; display: block; }
.map-bg { fill: var(--forest); }
.map-terrain-a { fill: rgba(255,255,255,0.08); }
.map-terrain-b { fill: rgba(255,255,255,0.05); }
.map-line { stroke: rgba(255,255,255,0.35); stroke-width: 0.6; }

.map-block--heat .map-bg { fill: #47281C; }
.map-block--heat .map-terrain-a { fill: rgba(232,163,61,0.28); }
.map-block--heat .map-terrain-b { fill: rgba(232,163,61,0.14); }

.map-block--earth .map-bg { fill: #3A3327; }
.map-block--earth .map-terrain-a { fill: rgba(232,163,61,0.2); }
.map-block--earth .map-terrain-b { fill: rgba(255,255,255,0.06); }

.map-block--water .map-bg { fill: #103A4A; }
.map-block--water .map-terrain-a { fill: rgba(120,190,210,0.25); }
.map-block--water .map-terrain-b { fill: rgba(120,190,210,0.12); }

.map-pin-dot { fill: var(--amber); }
.map-pin-ring { fill: none; stroke: var(--amber); stroke-width: 0.6; opacity: 0.5; }

.map-caption {
  position: absolute;
  left: 10px;
  bottom: 10px;
  right: 10px;
  max-width: calc(100% - 20px);
  width: fit-content;
  font-size: clamp(11.5px, 2.9vw, 12.5px);
  font-weight: 600;
  color: var(--on-forest);
  background: rgba(10, 20, 16, 0.4);
  padding: 5px 10px;
  border-radius: var(--r-pill);
  backdrop-filter: blur(4px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- chart block ---- */

.chart-block {
  width: 100%;
  background: var(--surface-sunken);
  border-radius: var(--r-sm);
  padding: clamp(12px, 3.4vw, 16px) clamp(10px, 3vw, 14px) clamp(10px, 3vw, 14px);
}
.chart-svg { width: 100%; height: clamp(70px, 18vw, 90px); display: block; }
.chart-area { fill: var(--forest); opacity: 0.12; }
[data-theme="dark"] .chart-area { fill: var(--amber); opacity: 0.14; }
.chart-line { fill: none; stroke: var(--forest); stroke-width: 1.4; vector-effect: non-scaling-stroke; }
[data-theme="dark"] .chart-line { stroke: var(--amber); }
.chart-caption {
  display: block;
  margin-top: 10px;
  font-size: var(--fs-meta);
  font-weight: 600;
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}

/* ---- dataset block (with table preview) ----
   The table itself is allowed to be wider than the card — it
   scrolls INSIDE .dataset-scroll. The card never grows. */

.dataset-block {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.dataset-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: clamp(10px, 3vw, 12px) clamp(12px, 3.4vw, 14px);
  background: var(--surface-sunken);
  min-width: 0;
}
.dataset-head svg { width: 22px; height: 22px; color: var(--forest); flex-shrink: 0; }
[data-theme="dark"] .dataset-head svg { color: var(--amber); }
.dataset-meta { display: flex; flex-direction: column; min-width: 0; gap: 1px; flex: 1 1 auto; }
.dataset-meta strong {
  font-size: clamp(12.5px, 3.2vw, 13.5px);
  font-weight: 700;
  overflow-wrap: anywhere;
}
.dataset-meta span { font-size: var(--fs-meta); color: var(--ink-faint); font-family: var(--font-mono); }

.dataset-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.dataset-preview { font-size: var(--fs-meta); font-family: var(--font-mono); }
.dataset-preview th, .dataset-preview td {
  text-align: left;
  padding: 8px clamp(10px, 3vw, 14px);
  border-top: 1px solid var(--border);
  white-space: nowrap; /* intentional — this table scrolls, it doesn't wrap */
}
.dataset-preview th {
  color: var(--ink-faint);
  font-weight: 600;
  font-family: var(--font-body);
  font-size: 12px;
}

/* ---- graceful "ready for download" card (no preview) ---- */

.file-ready {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  padding: clamp(12px, 3.4vw, 14px);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
}
.file-ready svg { width: 24px; height: 24px; color: var(--forest); flex-shrink: 0; }
[data-theme="dark"] .file-ready svg { color: var(--amber); }
.file-ready-meta { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-width: 0; }
.file-ready-meta strong { font-size: clamp(12.5px, 3.2vw, 13.5px); font-weight: 700; overflow-wrap: anywhere; }
.file-ready-meta span { font-size: var(--fs-meta); color: var(--ink-faint); overflow-wrap: anywhere; }

/* ---- files block (multiple raw attachments) ---- */

.files-block { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
}
.file-row svg { width: 20px; height: 20px; color: var(--forest); flex-shrink: 0; }
[data-theme="dark"] .file-row svg { color: var(--amber); }
.file-meta { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-width: 0; }
.file-meta strong {
  font-size: clamp(12.5px, 3.2vw, 13px);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap; /* long filenames truncate, they don't push layout */
}
.file-meta span { font-size: clamp(11.5px, 2.8vw, 12px); color: var(--ink-faint); }

.file-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--forest);
  background: var(--forest-soft);
  padding: 4px 8px;
  border-radius: 6px;
}
[data-theme="dark"] .file-badge { color: var(--amber); background: var(--amber-soft); }

/* ---- publication block ---- */

.publication-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-width: 100%;
  padding: clamp(12px, 3.4vw, 16px);
  border-radius: var(--r-sm);
  background: var(--forest-soft);
  border-left: 3px solid var(--forest);
}
[data-theme="dark"] .publication-block { border-left-color: var(--amber); }
.publication-kicker { font-size: 11.5px; font-weight: 700; color: var(--forest); }
[data-theme="dark"] .publication-kicker { color: var(--amber); }
.publication-title { font-size: clamp(14px, 3.6vw, 15px); font-weight: 700; overflow-wrap: anywhere; }
.publication-authors { font-size: clamp(12px, 3vw, 12.5px); color: var(--ink-soft); overflow-wrap: anywhere; }

/* ==============================================================
   10. META ROW
   ============================================================== */

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px clamp(10px, 3vw, 16px);
  width: 100%;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: var(--fs-meta);
  color: var(--ink-faint);
}
.post-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
}
.post-meta-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.post-meta-tags {
  gap: 6px;
  flex-wrap: wrap;
  flex: 1 1 160px;
  overflow-wrap: anywhere;
}
.post-meta-tags span:not(:last-child)::after { content: "·"; margin-left: 6px; color: var(--border-strong); }
.post-meta-right { margin-left: auto; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }

/* ==============================================================
   11. ACTION ROW / BUTTONS
   ============================================================== */

.post-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin-top: 8px;
}

.action-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  font-size: var(--fs-action);
  font-weight: 600;
  color: var(--ink-faint);
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.action-btn svg { width: 19px; height: 19px; flex-shrink: 0; }
.action-btn:hover { background: var(--surface-sunken); color: var(--ink-soft); }
.action-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.action-download {
  margin-left: auto;
  color: var(--forest);
  border: 1px solid var(--border-strong);
}
[data-theme="dark"] .action-download { color: var(--amber); }
.action-download--all { padding: 0 14px; }

/* When space is too tight for the download button to sit on the
   same line, it wraps to its own row rather than overflowing —
   margin-left: auto simply stops applying once wrapped. */
@media (max-width: 359px) {
  .action-download { margin-left: 0; flex-basis: 100%; justify-content: center; }
}

/* ---------- LOVE BUTTON — the amazing one-shot tap ---------- */

.action-like { overflow: visible; }
.action-like.is-locked { cursor: default; }
.action-like .like-icon { position: relative; z-index: 2; transition: transform 0.15s ease; flex-shrink: 0; }
.action-like:not(.is-locked):active .like-icon { transform: scale(0.85); }

.like-ring {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 19px;
  height: 19px;
  margin-top: -9.5px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--like) 0%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}
.action-like.is-liked .like-ring {
  animation: likeRing 0.6s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
@keyframes likeRing {
  0% { opacity: 0.55; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(2.8); }
}

.like-particles {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 1;
}
.like-particles i {
  position: absolute;
  left: 0;
  top: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--amber);
  opacity: 0;
  transform: translate(-50%, -50%);
}
.action-like.is-liked .like-particles i {
  animation: likeParticle 0.55s ease-out forwards;
  animation-delay: 0.02s;
}
.like-particles i:nth-child(1) { --tx: 20px;  --ty: 0px;   background: var(--like); }
.like-particles i:nth-child(2) { --tx: 14px;  --ty: -14px; }
.like-particles i:nth-child(3) { --tx: 0px;   --ty: -20px; background: var(--like); }
.like-particles i:nth-child(4) { --tx: -14px; --ty: -14px; }
.like-particles i:nth-child(5) { --tx: -20px; --ty: 0px;   background: var(--like); }
.like-particles i:nth-child(6) { --tx: -14px; --ty: 14px; }
.like-particles i:nth-child(7) { --tx: 0px;   --ty: 20px;  background: var(--like); }
.like-particles i:nth-child(8) { --tx: 14px;  --ty: 14px; }
@keyframes likeParticle {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.3); }
}

.action-like.is-liked { color: var(--like); background: var(--like-soft); }
.action-like.is-liked .like-icon {
  fill: var(--like);
  stroke: var(--like);
  animation: heartPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes heartPop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.45); }
  60%  { transform: scale(0.9); }
  100% { transform: scale(1.08); }
}
.action-like.is-liked .like-count { font-weight: 800; }

/* ==============================================================
   12. TABLET BREAKPOINT
   ============================================================== */

@media (min-width: 768px) {
  .topbar-inner { padding-top: clamp(18px, 2.4vw, 24px); }
  .feed-wrap { padding-block-start: clamp(20px, 2.6vw, 28px); }
  .post-card { padding: clamp(20px, 2.6vw, 24px); }
  .chip-row { flex-wrap: wrap; overflow: visible; -webkit-mask-image: none; mask-image: none; }
}

/* ==============================================================
   13. DESKTOP BREAKPOINT
   ============================================================== */

@media (min-width: 1024px) {
  .post-card:hover {
    box-shadow: var(--shadow-lift);
    transform: translateY(-2px);
  }
}

/* ==============================================================
   14. SAFETY NET — last-resort backstop, should be inert
   ============================================================== */

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

.app-shell, .topbar, .post-card {
  max-width: 100%;
}
