@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');

/* === CUSTOM PROPERTIES === */
:root {
  --text: rgba(0, 0, 0, 0.84);
  --text-secondary: #6B6B6B;
  --text-muted: #999;
  --bg: #fff;
  --divider: rgba(0, 0, 0, 0.15);
  --code-bg: #F2F2F2;
  --content-width: 680px;
  --wide-width: 960px;
  --font-serif: Georgia, Cambria, "Times New Roman", Times, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --grid-padding: 48px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  font-size: clamp(18px, 1.25vw + 10px, 20px);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* === GRID LAYOUT === */
.article {
  display: grid;
  grid-template-columns: 1fr min(var(--content-width), calc(100% - var(--grid-padding))) 1fr;
  padding-bottom: 80px;
}
.article > * { grid-column: 2; }

.article .full-bleed,
.article .quote-card,
.article .diagram,
.article .comparison-table,
.article .stats-row {
  grid-column: 1 / -1;
  max-width: var(--wide-width);
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  padding-left: 8px;
  padding-right: 8px;
}

/* === HERO === */
.hero {
  grid-column: 2;
  padding-top: clamp(40px, 5vw, 60px);
  margin-bottom: 40px;
}
.hero h1 {
  font-family: var(--font-sans);
  font-size: clamp(28px, 3.5vw + 10px, 42px);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #242424;
  margin-bottom: 16px;
}
.hero .subtitle {
  font-family: var(--font-sans);
  font-size: clamp(18px, 1.5vw + 8px, 22px);
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-secondary);
  margin-bottom: 24px;
}
.hero .meta {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-muted);
}
.hero .meta a { color: var(--text-muted); }

/* === TYPOGRAPHY === */
h2 {
  font-family: var(--font-sans);
  font-size: clamp(22px, 2.5vw + 6px, 32px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: #242424;
  margin-top: clamp(36px, 4vw, 56px);
  margin-bottom: 16px;
}
h3 {
  font-family: var(--font-sans);
  font-size: clamp(18px, 1.5vw + 6px, 24px);
  font-weight: 700;
  line-height: 1.3;
  color: #242424;
  margin-top: clamp(28px, 3vw, 40px);
  margin-bottom: 12px;
}
p { margin-bottom: 1.5em; }
strong { font-weight: 700; }
a { color: inherit; text-decoration: underline; }
hr {
  border: none;
  border-top: 1px solid var(--divider);
  margin: clamp(32px, 4vw, 48px) auto;
  width: 100px;
}

/* === FIGURES === */
figure { margin: 36px 0; }
figure img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
}
figcaption {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 10px;
  padding: 0 8px;
}

/* === QUOTE CARDS === */
.quote-card {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  padding: 36px 48px;
  margin-top: 40px;
  margin-bottom: 40px;
  background: #fafafa;
  border-radius: 8px;
}
.quote-card .portrait { flex-shrink: 0; width: 180px; }
.quote-card .portrait img { width: 100%; border-radius: 6px; mix-blend-mode: multiply; }
.quote-card .quote-body { flex: 1; }
.quote-card .quote-body p {
  font-family: var(--font-sans);
  font-size: clamp(18px, 1.2vw + 8px, 20px);
  font-weight: 300;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 12px;
}
.quote-card .quote-body .attribution {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-muted);
}

/* === DIAGRAMS === */
.diagram {
  background: #fff;
  border-radius: 12px;
  padding: 0;
  margin-top: 36px;
  margin-bottom: 36px;
  overflow: hidden;
  border: 1px solid var(--divider);
}
.diagram svg {
  width: 100%;
  height: auto;
  display: block;
  min-width: 600px;
}
.diagram iframe {
  width: 100%;
  min-height: 500px;
  height: 600px;
  border: none;
  border-radius: 12px;
  display: block;
  background: #fff;
}
.diagram-caption {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 12px;
}

/* === COMPARISON TABLE (desktop) === */
.comparison-table {
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  margin-top: 1.5em;
  margin-bottom: 1.5em;
}
.comparison-table th {
  text-align: left;
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 2px solid #242424;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}
.comparison-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
  vertical-align: top;
}
.comparison-table tr:last-child td { border-bottom: none; }

/* === TABLE → CARDS (mobile, generated by JS) === */
.table-cards {
  display: none;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  margin-top: 1.5em;
  margin-bottom: 1.5em;
  grid-column: 1 / -1;
  max-width: var(--wide-width);
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  padding-left: 8px;
  padding-right: 8px;
}
.table-card {
  background: #fafafa;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}
.table-card-header {
  font-weight: 700;
  font-size: 1rem;
  color: #242424;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--divider);
}
.table-card-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  gap: 12px;
}
.table-card-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.table-card-value {
  font-size: 1rem;
  color: var(--text);
  text-align: right;
}

/* === STATS ROW === */
.stats-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 32px;
  margin-bottom: 32px;
  font-family: var(--font-sans);
  flex-wrap: wrap;
  background: #fafafa;
  border-radius: 12px;
  padding: 24px 32px;
  border: 1px solid var(--divider);
}
.stat {
  text-align: center;
  flex: 1;
  min-width: 0;
}
.stat .number {
  font-size: clamp(28px, 2.5vw + 8px, 36px);
  font-weight: 700;
  color: #242424;
  line-height: 1;
}
.stat .label {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* === KEY TAKEAWAYS === */
.key-takeaways {
  font-family: var(--font-sans);
  margin-top: 8px;
  margin-bottom: 40px;
}
.key-takeaways .takeaways-label {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.key-takeaways ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  counter-reset: takeaway;
}
.key-takeaways li {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: #fafafa;
  border-radius: 12px;
  padding: 24px 24px 28px;
  position: relative;
  counter-increment: takeaway;
  border: 1px solid var(--divider);
}
.key-takeaways li::before {
  content: counter(takeaway);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: #242424;
  color: #fff;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 14px;
}

/* === CODE === */
code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85em;
}
pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 20px 24px;
  border-radius: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.5em 0;
  font-size: 1rem;
  line-height: 1.6;
  position: relative;
}
pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
}

/* === LIGHTBOX === */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.92);
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.lightbox.active { display: flex; }
.lightbox img, .lightbox svg {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}
.lightbox .close-hint {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 24px;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: rgba(255,255,255,0.5);
  pointer-events: none;
}
.lightbox .close-btn {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  color: #fff;
  font-size: 24px;
  font-family: var(--font-sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 10000;
  -webkit-tap-highlight-color: transparent;
}
.lightbox .close-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* === MARGIN COMMENTS === */
.comment-highlight {
  background: rgba(37, 99, 235, 0.08);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.15s;
}
.comment-highlight:hover,
.comment-highlight.active {
  background: rgba(37, 99, 235, 0.15);
}
.comment-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-sans);
  margin-left: 3px;
  vertical-align: middle;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s;
  /* Expand touch target */
  position: relative;
}
.comment-indicator::before {
  content: "";
  position: absolute;
  top: -13px;
  left: -13px;
  right: -13px;
  bottom: -13px;
}
.comment-indicator:hover {
  transform: scale(1.15);
}
.comment-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1000;
}
.comment-overlay.active {
  display: block;
}
.comment-popover {
  position: absolute;
  z-index: 1001;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  padding: 16px 18px;
  max-width: 340px;
  min-width: 260px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.comment-popover.active {
  opacity: 1;
  pointer-events: auto;
}
.comment-popover .comment-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.comment-popover .comment-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-sans);
  flex-shrink: 0;
}
.comment-popover .comment-meta {
  display: flex;
  flex-direction: column;
}
.comment-popover .comment-name {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.2;
}
.comment-popover .comment-role {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.3;
}
.comment-popover .comment-text {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
}

/* === ARTICLE FOOTER === */
.article-footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--divider);
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-muted);
}

/* === RESPONSIVE: Tablet (≤768px) === */
@media (max-width: 768px) {
  :root {
    --grid-padding: 32px;
  }
  .quote-card { flex-direction: column; gap: 16px; }
  .quote-card .portrait { width: 120px; }
  .stat { min-width: calc(50% - 8px); }
}

/* === RESPONSIVE: Phone (≤600px) === */
@media (max-width: 600px) {
  :root {
    --grid-padding: 24px;
  }

  .comparison-table { display: none; }
  .table-cards { display: block; }

  .quote-card {
    padding: 20px;
    margin-top: 28px;
    margin-bottom: 28px;
  }

  .key-takeaways ul {
    grid-template-columns: 1fr;
  }

  pre {
    padding: 16px;
    font-size: 1rem;
    border-radius: 0;
    margin-left: calc(var(--grid-padding) / -2);
    margin-right: calc(var(--grid-padding) / -2);
  }

  .diagram {
    border-radius: 0;
  }

  .comment-popover {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    max-width: 100%;
    width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  }
  .comment-popover.active {
    transform: translateY(0) !important;
  }
}

/* === RESPONSIVE: Small Phone (≤375px) === */
@media (max-width: 375px) {
  .stat { min-width: 100%; }
  .stats-row { gap: 12px; }

  .quote-card .portrait { width: 80px; }
  .quote-card { padding: 16px; gap: 12px; }

  .hero { margin-bottom: 28px; }

}

/* =============================================
   LANDING PAGE STYLES
   ============================================= */
.landing {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px 80px;
}
.landing-header {
  padding-top: clamp(40px, 5vw, 60px);
  margin-bottom: 48px;
}
.landing-header h1 {
  font-family: var(--font-sans);
  font-size: clamp(28px, 3vw + 10px, 40px);
  font-weight: 700;
  color: #242424;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}
.landing-header p {
  font-family: var(--font-sans);
  font-size: clamp(18px, 1.2vw + 8px, 20px);
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Featured article */
.featured-article {
  display: block;
  text-decoration: none;
  color: inherit;
  margin-bottom: 48px;
  border-radius: 8px;
  overflow: hidden;
  transition: box-shadow 0.2s;
}
.featured-article:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}
.featured-article img {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #f2f2f2;
}
.featured-article .featured-body {
  padding: 20px 0 0;
}
.featured-article .featured-title {
  font-family: var(--font-sans);
  font-size: clamp(22px, 2vw + 8px, 28px);
  font-weight: 700;
  color: #242424;
  line-height: 1.25;
  margin-bottom: 8px;
}
.featured-article .featured-subtitle {
  font-family: var(--font-sans);
  font-size: clamp(18px, 1vw + 8px, 18px);
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 8px;
}
.featured-article .featured-meta {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-muted);
}

/* Article list */
.article-list {
  list-style: none;
}
.article-list-item {
  border-top: 1px solid var(--divider);
}
.article-list-item a {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  padding: 24px 0;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s;
}
.article-list-item a:hover {
  background: rgba(0, 0, 0, 0.02);
  margin: 0 -12px;
  padding-left: 12px;
  padding-right: 12px;
  border-radius: 6px;
}
.article-list-thumb {
  width: 120px;
  height: 80px;
  flex-shrink: 0;
  border-radius: 4px;
  object-fit: cover;
  background: #f2f2f2;
}
.article-list-body { flex: 1; min-width: 0; }
.article-list-title {
  font-family: var(--font-sans);
  font-size: clamp(18px, 1vw + 8px, 20px);
  font-weight: 700;
  color: #242424;
  line-height: 1.3;
  margin-bottom: 4px;
}
.article-list-subtitle {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-list-meta {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .article-list-thumb {
    width: 80px;
    height: 56px;
  }
  .article-list-item a { gap: 14px; }
  .article-list-subtitle { display: none; }
}
