/* ============================================================
   Latest Advances in AI - Stylesheet
   Modern editorial / tech-publication aesthetic
   Mobile-first touch-friendly (P0–P2 mobile audit fix)
   ============================================================ */

:root {
  --bg: #f7f6f3;
  --bg-elev: #ffffff;
  --ink: #0f1419;
  --ink-2: #2a2f36;
  --muted: #5c6470;
  --muted-2: #8b94a3;
  --line: #e6e4dd;
  --line-2: #efece4;
  --accent: #d33f00;
  --accent-soft: #fff2eb;
  --tag-bg: #f1eee5;
  --tag-ink: #4a4f57;
  --shadow-sm: 0 1px 2px rgba(15, 20, 25, 0.05);
  --shadow-md: 0 6px 18px rgba(15, 20, 25, 0.08);
  --shadow-lg: 0 20px 40px rgba(15, 20, 25, 0.10);
  --radius: 6px;
  --radius-lg: 14px;
  --serif: "Source Serif Pro", "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --max-w: 1180px;
  --tap-min: 44px;        /* Apple HIG / WCAG 2.5.5 minimum touch target */
  --header-h: 64px;
}

/* Kill iOS tap highlight globally — looks unprofessional on cards. */
* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Avoid sticky header covering anchor targets on small screens */
  scroll-padding-top: calc(var(--header-h) + 12px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--ink);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover { color: var(--accent); }

img {
  max-width: 100%;
  display: block;
}

/* Touch / click latency: remove 300ms double-tap-to-zoom delay. */
a, button, .nav-toggle, .article-card, .article-card .thumb {
  touch-action: manipulation;
}

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 28px;
}

/* ============ Header ============ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(247, 246, 243, 0.92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  gap: 16px;
}

/* New-style logo (text + glyph mark, no image) */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.logo-text { white-space: nowrap; }

/* Legacy-style logo (image + text). Same visual + same flex behavior. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.brand img { width: 28px; height: 28px; flex-shrink: 0; }

/* Shared nav styling — both .nav-primary (new) and .site-nav (legacy).
   Either form must look and behave identically. */
.nav-primary,
.site-nav {
  display: flex;
  align-items: center;
  gap: 28px;
}
.nav-primary a,
.site-nav a {
  font-size: 15px;
  color: var(--ink-2);
  font-weight: 500;
  /* Touch target: pad vertically + horizontally without changing visual size.
     Padding pushes bbox to >= 36px on desktops, >=44px on mobile. */
  padding: 10px 4px;
}
.nav-primary a:hover,
.site-nav a:hover { color: var(--accent); }

/* Visible focus ring for keyboard users (a11y + tablet focus-within) */
.nav-primary a:focus-visible,
.site-nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 3px;
}

/* ============ Hamburger toggle (mobile only) ============ */
.nav-toggle {
  display: none;          /* hidden on desktop by default */
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  width: 44px;            /* >= 44px touch target even on dense layouts */
  height: 44px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.nav-toggle-bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  border-radius: 1.5px;
  transition: transform 0.2s ease, opacity 0.15s ease;
}
/* Animated X when open */
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ============ Hero ============ */
.hero {
  padding: 72px 0 48px;
  border-bottom: 1px solid var(--line);
}
.hero .eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 18px;
}
.hero .eyebrow::before {
  content: "";
  width: 22px;
  height: 1.5px;
  background: var(--accent);
}
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(38px, 6vw, 64px);
  line-height: 1.04;
  letter-spacing: -0.025em;
  margin: 0 0 22px;
  color: var(--ink);
  max-width: 880px;
}
.hero .lede {
  font-size: 19px;
  line-height: 1.55;
  color: var(--ink-2);
  max-width: 720px;
  margin: 0 0 26px;
}
.hero-meta {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--muted);
}
.hero-meta span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ============ Section Headers ============ */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin: 56px 0 26px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.section-head h2 {
  font-family: var(--serif);
  font-size: 30px;
  letter-spacing: -0.02em;
  margin: 0;
  font-weight: 600;
}
.section-head .sub {
  color: var(--muted);
  font-size: 15px;
}

/* ============ Article Grid ============ */
.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 32px;
}
.article-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  display: flex;
  flex-direction: column;
}
/* Desktop hover (no-op on touch devices without :hover support) */
.article-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--line);
}
/* Touch / keyboard alternative so the visual feedback also works on mobile tap. */
.article-card:active,
.article-card:focus-within {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.article-card .thumb {
  display: block;
  aspect-ratio: 16/9;
  background: var(--line-2);
  overflow: hidden;
}
.article-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}
@media (hover: hover) {
  .article-card:hover .thumb img { transform: scale(1.04); }
}

.article-card .body {
  padding: 22px 24px 26px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.cat-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.article-card h3 {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.22;
  letter-spacing: -0.015em;
  margin: 0 0 10px;
  font-weight: 600;
  color: var(--ink);
}
.article-card h3 a { color: inherit; }
.article-card .deck {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  margin: 0 0 18px;
  flex: 1;
}
.article-card .meta {
  font-size: 13px;
  color: var(--muted-2);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============ MGID Widget Slot ============ */
.mg-slot {
  /* Reserve room on desktop, shrink on mobile so the ad does not eat the
     first viewport.  min-height keeps CLS=0 even before the iframe loads. */
  min-height: 300px;
  margin: 0;
  padding: 0;
  background: transparent;
}

/* ============ Article Page ============ */
.article-main { padding: 32px 0 64px; }
.article {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 36px 0 0;
}
.breadcrumb {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 24px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); }

.article-header {
  margin: 0 auto 28px;
  max-width: 780px;
}
.article-header .article-meta {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.article-header .cat-badge { font-size: 12px; margin-bottom: 0; }
.article-header h1 {
  font-family: var(--serif);
  font-size: clamp(32px, 5vw, 46px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 18px;
  color: var(--ink);
}
.article-deck {
  font-size: 19px;
  color: var(--ink-2);
  line-height: 1.55;
  margin: 0;
}
/* Cover image: 920px wide so it sits in a 1.28x ratio against the 720px
   reading column -- the standard magazine visual hierarchy.
   Centered via auto margins instead of the negative "bleed" that previously
   pushed the cover to a full 1180px (64% wider than the body). */
.article-cover {
  margin: 36px auto;
  max-width: 920px;
  padding: 0 8px;
}
.article-cover img {
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: cover;
  border-radius: 0;
}
.article-cover figcaption {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 12px 8px 0;
}
.article-body {
  max-width: 720px;
  margin: 0 auto;
  font-size: 18px;
  line-height: 1.72;
  color: var(--ink-2);
}
.article-body p { margin: 0 0 1.4em; }

/* Inline figures inside <article-body>.  They break the long-form reading
   cadence -- size and spacing deliberately echo .article-cover, so a reader
   scrolling through the body sees a consistent rhythm of "text -> figure ->
   text -> figure -> text".  max-width 920px matches the cover cap so layout
   doesn't jump. */
.article-body .inline-img {
  margin: 2.4em auto;
  max-width: 920px;
}
.article-body .inline-img img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: cover;
  border-radius: var(--radius);
}
.article-body .inline-img figcaption {
  margin-top: 8px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 0;
}
.article-body .lead {
  font-size: 21px;
  font-weight: 500;
  line-height: 1.55;
  color: var(--ink);
  margin-bottom: 1.6em;
}
.article-body h2 {
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: -0.018em;
  margin: 2em 0 0.6em;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.2;
}
.article-body h2 + p { margin-top: 0; }
.article-body strong { color: var(--ink); font-weight: 600; }
.article-body em { font-style: italic; }

.article-footer {
  max-width: 720px;
  margin: 48px auto 0;
  padding: 28px 0 0;
  border-top: 1px solid var(--line);
}
.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  background: var(--tag-bg);
  color: var(--tag-ink);
  padding: 5px 12px;
  border-radius: 999px;
}
.related-prompt {
  font-size: 15px;
  color: var(--muted);
  margin: 0;
}
.related-prompt strong { color: var(--ink-2); }
.related-prompt a { color: var(--accent); font-weight: 500; }

/* ============ About ============ */
.about-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 0 64px;
}
.about-page h1 {
  font-family: var(--serif);
  font-size: 42px;
  letter-spacing: -0.02em;
  margin: 16px 0 20px;
}
.about-page p {
  font-size: 18px;
  line-height: 1.7;
  color: var(--ink-2);
  margin: 0 0 1.3em;
}
.about-page h2 {
  font-family: var(--serif);
  font-size: 26px;
  margin: 1.8em 0 0.6em;
}
.about-page ul {
  font-size: 17px;
  color: var(--ink-2);
  padding-left: 22px;
}
.about-page li { margin-bottom: 8px; }

/* ============ Footer ============ */
.site-footer {
  background: #0f1419;
  color: #cfd3da;
  padding: 48px 0 36px;
  margin-top: 48px;
  /* Honor iOS notch safe-area at the bottom */
  padding-bottom: calc(36px + env(safe-area-inset-bottom, 0));
}
.site-footer p { margin: 0 0 6px; font-size: 14px; }
.site-footer p:last-child { margin: 0; }
.site-footer .muted { color: #8b94a3; font-size: 13px; }

/* ============================================================
   Mobile / small-screen adaptations
   ============================================================ */

/* --- ≤ 760px: phones & small tablets ----------------------------- */
@media (max-width: 760px) {
  :root { --header-h: 56px; }
  body { font-size: 16px; }
  .container { padding: 0 16px; }

  /* Show hamburger, hide nav by default; JS toggles .open on the nav */
  .nav-toggle { display: inline-flex; }
  .nav-primary,
  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-elev);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-md);
    padding: 6px 0 8px;
  }
  .nav-primary.open,
  .site-nav.open {
    display: flex;
  }
  .nav-primary a,
  .site-nav a {
    padding: 14px 18px;          /* >= 44px tap target */
    border-top: 1px solid var(--line-2);
    font-size: 16px;
  }
  .nav-primary a:first-child,
  .site-nav a:first-child { border-top: 0; }

  /* Header inner: position relative so the absolute nav anchors under it */
  .header-inner { position: relative; }

  /* Logo: shrink slightly on dense mobile */
  .logo, .brand { font-size: 15px; gap: 8px; }
  .logo-mark, .brand img { width: 24px; height: 24px; }
  .logo-mark { font-size: 14px; border-radius: 6px; }

  /* Hero */
  .hero { padding: 40px 0 32px; }
  .hero h1 { font-size: clamp(28px, 8vw, 38px); }
  .hero .lede { font-size: 17px; }
  .hero-meta { font-size: 13px; gap: 14px; }

  /* Sections */
  .section-head { margin: 36px 0 18px; }
  .section-head h2 { font-size: 22px; }

  /* Cards: single column, tighter gap */
  .article-grid { grid-template-columns: 1fr; gap: 22px; }
  .article-card .body { padding: 18px 18px 22px; }
  .article-card h3 { font-size: 19px; }
  .article-card .deck { font-size: 14px; }

  /* Article page */
  .article { padding: 12px 0 0; }
  .article-header h1 { font-size: 28px; letter-spacing: -0.018em; }
  .article-deck { font-size: 17px; }
  .article-body { font-size: 17px; }
  .article-body .lead { font-size: 19px; }
  .article-body h2 { font-size: 23px; }
  /* Mobile cover: bleed edge-to-edge (magazine style), but keep the
     the inner padding so caption has room.  The max-width:920px default
     no longer constrains us on screens narrower than 920px. */
  .article-cover { margin: 0 -16px 28px; padding: 0; }

  /* Inline figures: bleed edge-to-edge, drop the radius for full-bleed look */
  .article-body .inline-img {
    margin: 1.6em -16px;
    max-width: none;
  }
  .article-body .inline-img img {
    max-height: 360px;
    border-radius: 0;
  }
  .article-body .inline-img figcaption {
    padding: 0 16px;
  }

  /* About */
  .about-page h1 { font-size: 30px; }
  .about-page p, .about-page ul { font-size: 16px; }

  /* MGID slot: shrink so first viewport isn't dominated by the banner */
  .mg-slot { min-height: 100px; }

  /* Footer */
  .site-footer { margin-top: 32px; padding: 36px 0 24px; }
}

/* --- ≤ 380px: very small (iPhone SE 1 / older Androids) --------- */
@media (max-width: 380px) {
  body { font-size: 15px; }
  .hero h1 { font-size: 26px; }
  .hero .lede { font-size: 16px; }
  .article-header h1 { font-size: 24px; }
  .article-body { font-size: 16px; line-height: 1.65; }
  .article-body .lead { font-size: 17px; }
  .logo-text, .brand > span { font-size: 14px; }
  /* Nav drawer still has 14px link padding so tap targets stay 44px+ */
}

/* --- Reduce motion ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print */
@media print {
  .site-header, .site-footer, .nav-toggle, .mg-slot { display: none; }
  body { background: white; }
}
