/* ============================================================
   Articles — page-specific styles
   Depends on /assets/site.css for tokens, navbar, ambient, footer
============================================================ */

/* ============================================================
   LISTING PAGE
============================================================ */
.listing-hero {
  max-width: 900px;
  margin: 0 auto;
  padding: 180px 24px 60px;
  text-align: center;
}
.listing-hero .eyebrow { margin-bottom: 24px; }
.listing-hero h1 {
  font-size: clamp(2.6rem, 6vw, 4.4rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin-bottom: 20px;
  background: var(--heading-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.listing-hero p {
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  color: var(--muted);
  max-width: 600px;
  margin: 0 auto;
}

/* Series eyebrow above each grid */
.series-eyebrow {
  max-width: 1200px;
  margin: 64px auto 0;
  padding: 0 24px;
  display: flex; align-items: center; gap: 10px;
  font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
}
.series-eyebrow .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(124,156,255,0.6);
}

/* Listing cards grid */
.articles-listing {
  max-width: 1200px;
  margin: 24px auto 0;
  padding: 0 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.listing-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  display: flex; flex-direction: column;
  backdrop-filter: blur(8px);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
              border-color 0.2s, box-shadow 0.3s;
}
.listing-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-strong);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.5);
}
.listing-card .cover {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #0a0a0c;
}
.listing-card .cover img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}
.listing-card:hover .cover img { transform: scale(1.04); }
.listing-card .body {
  padding: 24px;
  display: flex; flex-direction: column; gap: 12px;
  flex: 1;
}
.listing-card .meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.78rem;
  color: var(--muted);
}
.part-badge {
  padding: 3px 10px;
  background: rgba(124, 156, 255, 0.12);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.75rem;
}
.listing-card .tags {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: -2px;
}
.tag {
  padding: 3px 9px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  text-transform: lowercase;
}
.tag[data-stack="dart"]    { background: rgba( 64, 196, 255, 0.10); border-color: rgba( 64, 196, 255, 0.22); color: #5cc8ff; }
.tag[data-stack="flutter"] { background: rgba( 84, 180, 255, 0.10); border-color: rgba( 84, 180, 255, 0.22); color: #6fb8ff; }
.tag[data-stack="ble"]     { background: rgba(124, 156, 255, 0.10); border-color: rgba(124, 156, 255, 0.22); color: #9bb1ff; }
.tag[data-stack="security"]{ background: rgba(255, 138, 128, 0.10); border-color: rgba(255, 138, 128, 0.22); color: #ff9d8a; }
.tag[data-stack="crypto"]  { background: rgba(167, 139, 250, 0.10); border-color: rgba(167, 139, 250, 0.22); color: #b89dff; }
.tag[data-stack="async"]   { background: rgba(110, 231, 183, 0.10); border-color: rgba(110, 231, 183, 0.22); color: #7eedc0; }
.tag[data-stack="arch"]    { background: rgba(251, 191, 114, 0.10); border-color: rgba(251, 191, 114, 0.22); color: #ffc987; }

:root[data-theme="light"] .tag {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
  color: #555;
}
:root[data-theme="light"] .tag[data-stack="dart"]    { background: rgba(  0, 145, 220, 0.08); border-color: rgba(  0, 145, 220, 0.22); color: #006fa8; }
:root[data-theme="light"] .tag[data-stack="flutter"] { background: rgba( 30, 120, 220, 0.08); border-color: rgba( 30, 120, 220, 0.22); color: #155aa8; }
:root[data-theme="light"] .tag[data-stack="ble"]     { background: rgba( 74, 108, 255, 0.08); border-color: rgba( 74, 108, 255, 0.22); color: #2a3fb8; }
:root[data-theme="light"] .tag[data-stack="security"]{ background: rgba(220,  80,  60, 0.08); border-color: rgba(220,  80,  60, 0.22); color: #b04030; }
:root[data-theme="light"] .tag[data-stack="crypto"]  { background: rgba(120,  90, 210, 0.08); border-color: rgba(120,  90, 210, 0.22); color: #6a48b8; }
:root[data-theme="light"] .tag[data-stack="async"]   { background: rgba( 30, 160, 110, 0.08); border-color: rgba( 30, 160, 110, 0.22); color: #1e7a55; }
:root[data-theme="light"] .tag[data-stack="arch"]    { background: rgba(200, 130,  30, 0.08); border-color: rgba(200, 130,  30, 0.22); color: #a06410; }
.listing-card h2 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
}
.listing-card .excerpt {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
  flex: 1;
}
.listing-card .read-more {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent);
  font-size: 0.9rem; font-weight: 600;
  margin-top: 4px;
}
.listing-card .read-more::after { content: '→'; transition: transform 0.2s; }
.listing-card:hover .read-more::after { transform: translateX(4px); }

/* ============================================================
   ARTICLE PAGE
============================================================ */

/* Hero cover */
.article-cover {
  position: relative;
  max-width: 1100px;
  margin: 130px auto 0;
  padding: 0 24px;
}
.article-cover img {
  width: 100%;
  border-radius: 24px;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  aspect-ratio: 1200 / 628;
  object-fit: cover;
  display: block;
}

.article-header {
  margin-bottom: 8px;
}
.article-back {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 24px;
  transition: color 0.15s;
}
.article-back:hover { color: var(--text); }

.read-time { font-size: 0.85rem; color: var(--muted); }

.article-meta {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--muted);
}
.subtitle {
  font-size: 1.2rem;
  color: var(--muted);
  line-height: 1.55;
  max-width: 680px;
  margin-top: 20px;
  margin-bottom: 0;
}
.article-header h1 {
  font-size: clamp(2.2rem, 4.8vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.08;
  margin-bottom: 0;
  background: var(--heading-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Layout with sticky TOC */
.article-layout {
  max-width: 1100px;
  margin: 56px auto 0;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 60px;
  align-items: start;
}
.article-layout > main { min-width: 0; }

.toc {
  position: sticky;
  top: 100px;
  align-self: start;
  font-size: 0.85rem;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  padding-right: 4px;
}
.toc-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 16px;
}
.toc ul { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.toc a {
  display: block;
  padding: 6px 12px;
  color: var(--muted);
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  border-radius: 0 6px 6px 0;
  line-height: 1.4;
}
.toc a:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(124, 156, 255, 0.06);
}

/* Mobile TOC (collapsible) */
.toc-mobile {
  display: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 32px;
  overflow: hidden;
  backdrop-filter: blur(8px);
}
.toc-mobile-toggle {
  width: 100%;
  padding: 14px 18px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.9rem; font-weight: 600;
  color: var(--text);
  background: transparent;
}
.toc-mobile-toggle .arrow {
  transition: transform 0.2s;
  color: var(--muted);
}
.toc-mobile.open .toc-mobile-toggle .arrow { transform: rotate(180deg); }
.toc-mobile-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.toc-mobile.open .toc-mobile-list { max-height: 600px; }
.toc-mobile-list ul {
  list-style: none;
  padding: 4px 8px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.toc-mobile-list a {
  display: block;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 0.88rem;
  border-radius: 8px;
}
.toc-mobile-list a:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }

/* ============================================================
   ARTICLE TYPOGRAPHY
============================================================ */
.article-content {
  font-size: 1.05rem;
  color: var(--text-soft);
  line-height: 1.75;
}
.article-content > *:first-child { margin-top: 0; }
.article-content p,
.article-content ul,
.article-content ol {
  margin-bottom: 18px;
}
.article-content ul,
.article-content ol {
  padding-left: 24px;
}
.article-content li { margin-bottom: 6px; }
.article-content li::marker { color: var(--muted-2); }
.article-content strong { color: var(--text); font-weight: 600; }
.article-content em { color: var(--text-soft); }
.article-content a {
  color: var(--accent);
  border-bottom: 1px solid rgba(124, 156, 255, 0.3);
  transition: color 0.15s, border-color 0.15s;
}
.article-content a:hover { color: var(--accent-2); border-bottom-color: var(--accent-2); }

.article-content h2 {
  margin-top: 56px;
  margin-bottom: 18px;
  font-size: clamp(1.5rem, 2.8vw, 1.9rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
  scroll-margin-top: 100px;
}
.article-content h3 {
  margin-top: 36px;
  margin-bottom: 12px;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}
.article-content h2 .anchor,
.article-content h3 .anchor {
  color: var(--muted-2);
  margin-right: 8px;
  text-decoration: none;
  border-bottom: none;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.article-content h2:hover .anchor,
.article-content h3:hover .anchor { opacity: 1; }
.article-content h2 .anchor:hover,
.article-content h3 .anchor:hover { color: var(--accent); }

.article-content hr {
  margin: 56px auto;
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
  max-width: 200px;
}

.article-content blockquote {
  margin: 24px 0;
  padding: 18px 22px;
  border-left: 3px solid var(--accent);
  background: linear-gradient(90deg, rgba(124, 156, 255, 0.08), transparent);
  border-radius: 0 12px 12px 0;
  color: var(--text);
  font-style: normal;
}
.article-content blockquote p:last-child { margin-bottom: 0; }

/* Inline code (not inside <pre> code blocks) */
.article-content :not(pre) > code {
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.88em;
  padding: 2px 7px;
  background: rgba(124, 156, 255, 0.12);
  color: var(--accent);
  border-radius: 6px;
  border: 1px solid rgba(124, 156, 255, 0.18);
}
:root[data-theme="light"] .article-content :not(pre) > code {
  background: rgba(74, 108, 255, 0.08);
  border-color: rgba(74, 108, 255, 0.20);
  color: #2a3fb8;
}

/* ─── Code block ─── */
.code-block {
  position: relative;
  margin: 24px 0;
  background: linear-gradient(160deg, #15151b 0%, #0d0d11 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}
.code-block::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(124, 156, 255, 0.4), transparent);
}
.code-block pre {
  margin: 0;
  padding: 22px 24px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.86rem;
  line-height: 1.7;
  color: #d4d4dc;
}
.code-block pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.copy-btn {
  position: absolute;
  top: 12px; right: 12px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-strong);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 8px;
  opacity: 0;
  transition: all 0.15s;
}
.code-block:hover .copy-btn { opacity: 1; }
.copy-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}
.copy-btn.copied {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
}

/* Custom scrollbar for code blocks */
.code-block pre::-webkit-scrollbar { height: 6px; }
.code-block pre::-webkit-scrollbar-track { background: transparent; }
.code-block pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

/* ─── Diagram block (terminal-style) ─── */
.diagram-block {
  margin: 24px 0;
  background: linear-gradient(160deg, #0d0d11 0%, #08080b 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}
.diagram-dots {
  display: flex; gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.diagram-dots span {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}
.diagram-dots span:nth-child(1) { background: #ff5f57; }
.diagram-dots span:nth-child(2) { background: #febc2e; }
.diagram-dots span:nth-child(3) { background: #28c840; }
.diagram-block pre {
  margin: 0;
  padding: 22px 24px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  color: #7ee8fa;
  white-space: pre;
}
.diagram-block pre::-webkit-scrollbar { height: 6px; }
.diagram-block pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08); border-radius: 3px;
}

/* Tables */
.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 0.9rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.article-content thead { background: rgba(255, 255, 255, 0.02); }
.article-content th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.article-content td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-soft);
}
.article-content tbody tr:last-child td { border-bottom: none; }
.article-content tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

/* ============================================================
   SERIES NAVIGATION (prev / next at article bottom)
============================================================ */
.series-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 80px;
  padding-top: 40px;
  border-top: 1px solid var(--border);
}
.series-nav a {
  padding: 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex; flex-direction: column; gap: 6px;
  transition: transform 0.25s, border-color 0.2s;
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.series-nav a:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}
.series-nav .nav-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}
.series-nav .nav-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.series-nav .next { text-align: right; }
.series-nav .placeholder {
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted-2);
  font-size: 0.85rem;
  padding: 24px;
}

/* ============================================================
   RESPONSIVE
============================================================ */
@media (max-width: 900px) {
  .article-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .toc { display: none; }
  .toc-mobile { display: block; }
}

/* Prevent any descendant from breaking the page width on mobile */
html, body { overflow-x: hidden; }

@media (max-width: 600px) {
  .article-cover { margin-top: 100px; padding: 0 16px; }
  .article-cover img { border-radius: 16px; }
  .article-layout { margin-top: 36px; padding: 0 16px; }
  .article-header h1 { font-size: clamp(1.7rem, 7vw, 2.4rem); word-break: break-word; hyphens: auto; }
  .subtitle { font-size: 1rem; margin-top: 14px; }
  .article-meta { flex-wrap: wrap; gap: 8px; }
  .article-content { font-size: 1rem; }
  .article-content h2 { font-size: 1.4rem; margin-top: 44px; word-wrap: break-word; }
  .article-content h3 { font-size: 1.08rem; margin-top: 28px; word-wrap: break-word; }
  .article-content blockquote { padding: 14px 16px; }
  .article-content code { word-break: break-word; }
  .code-block pre,
  .diagram-block pre { font-size: 0.78rem; padding: 18px 18px; }
  .copy-btn { opacity: 1; } /* always visible on touch */
  /* Tables: enable horizontal scroll inside the card so wide grids do not break layout */
  .article-content table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .article-content img,
  .article-content svg { max-width: 100%; height: auto; }
  .series-nav { grid-template-columns: 1fr; margin-top: 56px; padding-top: 28px; }
  .series-nav .next { text-align: left; }
  .series-nav a { padding: 18px; }
  .series-nav .placeholder { display: none; }

  /* Listings */
  .listing-hero { padding: 100px 20px 40px; }
  .listing-hero h1 { font-size: clamp(1.9rem, 8vw, 2.6rem); }
  .listing-hero p { font-size: 0.98rem; }
  .series-eyebrow { margin-top: 40px; padding: 0 20px; font-size: 0.72rem; }
  .articles-listing { padding: 0 20px; gap: 16px; }
  .listing-card .body { padding: 20px; }
  .listing-card h2 { font-size: 1.1rem; }

  /* Site footer */
  .site-footer { padding: 32px 20px; flex-direction: column; text-align: center; gap: 12px; }
  .site-footer .footer-links { gap: 16px; }
}
