/* ==========================================================================
   IndieFounder polish layer — loads LAST.
   Fixes found in a full-site visual review (desktop 1280px + mobile 390px):
   hero legibility, mobile header, product-card overlap, horizontal overflow,
   conflicting learn-hub rules, lesson sidebar spacing, focus states, tap targets.
   Uses existing design tokens only (theme.css), so light/dark both work.
   ========================================================================== */

/* ---------- Global resilience ---------- */
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h, 64px) + 16px); }
img, svg, video, canvas { max-width: 100%; }
img { height: auto; }
body { overflow-x: clip; }
main { min-width: 0; }
h1, h2, h3, h4 { text-wrap: balance; overflow-wrap: break-word; }
p, li { overflow-wrap: break-word; }
pre { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { max-width: 100%; }
.prose table, .article-body table, .docs-content table { display: block; overflow-x: auto; }

/* Consistent keyboard focus */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
:where(input, textarea, select):focus-visible { outline-offset: 0; }

/* Broken avatar / logo images degrade to a neutral tile instead of a broken-image icon */
img[alt]:where(.author-avatar, .avatar, .launch-logo, .launch-icon-box img) { background: var(--surface-2); }

/* ---------- Home hero: legible subtitle over the halftone ---------- */
.hm-hero-inner { position: relative; text-align: left; }
.hm-hero-inner::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 -2rem;
  width: min(46rem, 100% + 2rem);
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse 80% 90% at 20% 50%,
    color-mix(in srgb, var(--bg) 88%, transparent) 0%,
    color-mix(in srgb, var(--bg) 70%, transparent) 55%,
    transparent 100%);
}
.hm-sub { color: var(--ink-soft); margin-left: 0; margin-right: 0; }
.hm-actions { flex-wrap: wrap; }

/* ---------- Header: tidy mobile navigation ---------- */
@media (max-width: 720px) {
  .site-header .bar { flex-wrap: wrap; row-gap: 0; padding-block: 8px 0; min-height: 0; }
  .site-header .brand { order: 1; }
  .site-header .bar-actions { order: 2; margin-left: auto; }
  .site-header .main-nav {
    order: 3;
    flex: 1 0 100%;
    margin: 6px calc(var(--gutter, 14px) * -1) 0;
    padding: 0 var(--gutter, 14px) 8px;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(90deg, transparent 0, #000 var(--gutter, 14px), #000 calc(100% - 28px), transparent 100%);
  }
  .site-header .main-nav::-webkit-scrollbar { display: none; }
  .site-header .main-nav a {
    flex: 0 0 auto;
    padding: 9px 12px;
    font-size: .92rem;
    letter-spacing: 0;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }
  .palette-trigger, .theme-toggle { min-width: 40px; min-height: 40px; }
}

/* ---------- Product directory ---------- */
.launches-cat-time-row { max-width: 100%; box-sizing: border-box; }
.launches-cat-nav-wrap { max-width: 100vw; overflow-x: clip; }
.launch-card, .launch-content { min-width: 0; }
.launch-name-link { min-width: 0; }
.launch-name { overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .launch-title-row,
  .launches-main-col .launch-title-row {
    flex-wrap: wrap;
    row-gap: 6px;
    align-items: flex-start;
  }
  .launch-title-row .launch-name-link,
  .launches-main-col .launch-title-row .launch-name-link { flex: 0 1 auto !important; min-width: 0; max-width: 100%; }
  .launch-title-row .launch-cat-pill,
  .launches-main-col .launch-title-row .launch-cat-pill {
    position: static !important;
    flex: 0 0 auto !important;
    margin-left: 0 !important;
    max-width: 100%;
    white-space: normal;
  }
  .launch-description { -webkit-line-clamp: 3; }
  .launch-upvote-btn, .launch-vote-box button { min-width: 44px; min-height: 44px; }
}

/* ---------- Learn hub: one coherent explorer panel ----------
   pages.css centred it, docs.css made a grid and site-layout-more.css (!important) made it a
   padding-less flex row, so the copy sat flush against the border. Settle on one grid. */
.learn-explorer {
  display: grid !important;
  grid-template-columns: minmax(0, 1.05fr) minmax(280px, 1fr);
  align-items: center !important;
  gap: 12px 28px !important;
  text-align: left !important;
  margin: 0 0 24px !important;
  padding: clamp(16px, 3vw, 24px) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-l, 16px);
  background: linear-gradient(135deg, var(--surface), var(--card-bg));
}
.learn-explorer-copy { margin-bottom: 0 !important; min-width: 0; }
.learn-explorer h2 { margin: 6px 0 0 !important; font-size: clamp(1.35rem, 2.4vw, 1.75rem) !important; }
.learn-explorer p { margin-top: 8px !important; max-width: 34rem; }
.learn-search-box { max-width: none !important; margin-inline: 0 !important; width: 100%; }
.learn-search-meta { grid-column: 2; margin-top: 0 !important; justify-content: flex-start !important; }
@media (max-width: 760px) {
  .learn-explorer { grid-template-columns: minmax(0, 1fr); }
  .learn-search-meta { grid-column: 1; }
}
.courses-hub-head { max-width: none !important; }

/* ---------- Lesson sidebar: breathing room for the progress card ---------- */
.docs-progress-wrap { padding: 14px; display: grid; gap: 10px; }
.docs-progress-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.docs-progress-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.docs-progress-actions > * { justify-content: center; text-align: center; min-height: 40px; white-space: nowrap; }
.docs-progress-wrap .tool-muted { margin: 0 !important; line-height: 1.45; }

/* ---------- Reading comfort ---------- */
@media (max-width: 640px) {
  .wrap { width: min(100% - 28px, 1080px); }
  .button, .button-quiet { min-height: 44px; }
}

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

/* ---------- Utilities that were referenced in markup but never defined ---------- */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Stories header: pages.css centred the inner block while site-layout.css
   left-aligned the text, leaving the copy and buttons indented ---------- */
.stories-listing-head-inner { margin-inline: 0 !important; max-width: 44rem; }
.stories-listing-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
@media (max-width: 760px) {
  .stories-listing-head { display: block; }
  .stories-listing-stats { margin-top: 18px; }
}

/* Hero/page action rows follow the left-aligned headings */
.pg-actions { justify-content: flex-start !important; margin-inline: 0 !important; }
@media (max-width: 640px) { .pg-actions .pg-btn { justify-content: center; } }

/* ==========================================================================
   Topic slug pages (/topics/[slug]/ — fix crushed article titles
   articles.css put .entries in a multi-column card grid; site-layout forced
   each .entry into a 3-col row. Inside a ~360px card that left ~116px for the
   title, so words stacked vertically. Force full-width list rows here.
   ========================================================================== */
.page-topic {
  padding-top: 8px !important;
  padding-bottom: 3rem !important;
}
.page-topic .topic-hero.page-head,
.page-topic header.topic-hero {
  text-align: left !important;
  max-width: 100% !important;
  margin: 0 0 1.25rem !important;
  padding: 20px 22px !important;
  border: 1px solid var(--line) !important;
  border-radius: 14px !important;
  background: var(--tc-bg, var(--surface)) !important;
}
.page-topic .topic-hero h1,
.page-topic .topic-hero.page-head h1 {
  max-width: none !important;
  font-size: clamp(1.75rem, 4vw, 2.35rem) !important;
  letter-spacing: -0.04em !important;
  margin: 0 0 8px !important;
  line-height: 1.15 !important;
}
.page-topic .topic-hero .lead {
  max-width: 42rem !important;
  margin: 0 !important;
  font-size: 0.98rem !important;
  line-height: 1.55 !important;
  color: var(--muted) !important;
}
.page-topic .topic-purpose {
  margin: 6px 0 0 !important;
  max-width: 42rem !important;
  font-size: 0.9rem !important;
  color: var(--muted) !important;
}
.page-topic .topic-resource-links {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 10px 16px !important;
  margin: 0 0 1.25rem !important;
}
.page-topic .learning-path {
  margin: 0 0 1.5rem !important;
  padding: 16px 18px !important;
  border: 1px solid var(--line) !important;
  border-radius: 14px !important;
  background: var(--surface) !important;
  box-shadow: none !important;
}
.page-topic .learning-step {
  grid-template-columns: 40px minmax(0, 1fr) !important;
  gap: 12px !important;
  padding: 12px 0 !important;
}
.page-topic .learning-step h3 {
  font-size: 1rem !important;
  letter-spacing: -0.02em !important;
}
.page-topic .learning-step p {
  font-size: 0.86rem !important;
  margin-top: 4px !important;
}

/* Full-width article list (not multi-col cards) */
.page-topic .entries {
  display: flex !important;
  flex-direction: column !important;
  gap: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  border: 1px solid var(--line) !important;
  border-radius: 14px !important;
  overflow: hidden !important;
  background: var(--surface) !important;
  grid-template-columns: none !important;
}
.page-topic .entry {
  display: grid !important;
  grid-template-columns: 120px minmax(0, 1fr) auto !important;
  align-items: center !important;
  gap: 14px !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 12px 14px !important;
  border: 0 !important;
  border-bottom: 1px solid var(--line) !important;
  border-radius: 0 !important;
  background: var(--surface) !important;
  box-shadow: none !important;
  transform: none !important;
}
.page-topic .entry:last-child { border-bottom: 0 !important; }
.page-topic .entry:hover {
  background: var(--rank-soft) !important;
  transform: none !important;
  box-shadow: none !important;
}
.page-topic .entry-media {
  width: 100% !important;
  aspect-ratio: 16 / 10 !important;
  min-height: 0 !important;
  border-radius: 10px !important;
  overflow: hidden !important;
  border: 1px solid var(--line) !important;
  background: var(--surface-2) !important;
}
.page-topic .entry-media img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}
.page-topic .entry-body {
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 4px !important;
  padding: 0 !important;
}
.page-topic .entry-body h2,
.page-topic .entry-body h3 {
  margin: 0 !important;
  font-size: 1rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.02em !important;
  line-height: 1.35 !important;
  overflow-wrap: break-word !important;
}
.page-topic .entry-body h2 a,
.page-topic .entry-body h3 a {
  color: var(--ink) !important;
  text-decoration: none !important;
}
.page-topic .entry:hover .entry-body h2 a,
.page-topic .entry:hover .entry-body h3 a {
  color: var(--accent-text) !important;
}
.page-topic .entry-foot {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
  gap: 2px !important;
  font-size: 0.72rem !important;
  color: var(--muted) !important;
  white-space: nowrap !important;
  padding: 0 !important;
  border: 0 !important;
}
.page-topic .page-actions {
  margin-top: 1.25rem !important;
  padding-top: 1rem !important;
  border-top: 1px solid var(--line) !important;
}

@media (max-width: 640px) {
  .page-topic .entry,
  .page-topic .entry.is-lead {
    grid-template-columns: 72px minmax(0, 1fr) !important;
    gap: 10px !important;
    padding: 10px 12px !important;
  }
  .page-topic .entry-foot { display: none !important; }
  .page-topic .topic-hero.page-head,
  .page-topic header.topic-hero {
    padding: 14px 16px !important;
  }
}
