/* ── Design tokens (Light — default) ── */
:root {
  --bg: #f7f7f8;
  --bg-nav: rgba(247, 247, 248, 0.82);
  --surface: #ffffff;
  --surface-hover: #f0f0f2;
  --border: #e4e4e9;
  --border-soft: #ececef;

  --text: #16161a;
  --text-secondary: #52525b;
  --text-muted: #8a8a94;

  --accent: #ff7a47;
  --accent-strong: #e8632e;
  --accent-soft: rgba(255, 122, 71, 0.1);
  --accent-border: rgba(255, 122, 71, 0.35);

  --code-comment: #7c7c86;
  --code-keyword: #d6336c;
  --code-string: #2f9e44;
  --code-number: #e8590c;
  --code-function: #1971c2;
  
  --code-class: #9c36b5;
  --code-tag: #0c8599;

  --scrollbar-thumb: #d4d4d9;
  --scrollbar-thumb-hover: #c2c2c8;

  --radius: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* ── Design tokens (Dark — system preference) ── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0d;
    --bg-nav: rgba(11, 11, 13, 0.82);
    --surface: #16161a;
    --surface-hover: #1c1c21;
    --border: #232329;
    --border-soft: #1a1a1f;

    --text: #e9e9ee;
    --text-secondary: #a6a6b3;
    --text-muted: #6c6c78;

    --accent-strong: #ff9268;
    --accent-soft: rgba(255, 122, 71, 0.12);

    --code-comment: #74747f;
    --code-keyword: #ff7a9e;
    --code-string: #9ece6a;
    --code-number: #e5c07b;
    --code-function: #61afef;
    --code-class: #c792ea;
    --code-tag: #56c9d6;

    --scrollbar-thumb: #2c2c33;
    --scrollbar-thumb-hover: #38383f;

    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

/* ── Design tokens (Dark — explicit choice) ── */
:root[data-theme="dark"] {
  --bg: #0b0b0d;
  --bg-nav: rgba(11, 11, 13, 0.82);
  --surface: #16161a;
  --surface-hover: #1c1c21;
  --border: #232329;
  --border-soft: #1a1a1f;

  --text: #e9e9ee;
  --text-secondary: #a6a6b3;
  --text-muted: #6c6c78;

  --accent-strong: #ff9268;
  --accent-soft: rgba(255, 122, 71, 0.12);

  --code-comment: #74747f;
  --code-keyword: #ff7a9e;
  --code-string: #9ece6a;
  --code-number: #e5c07b;
  --code-function: #61afef;
  --code-class: #c792ea;
  --code-tag: #56c9d6;

  --scrollbar-thumb: #2c2c33;
  --scrollbar-thumb-hover: #38383f;

  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

:root[data-theme="light"] { color-scheme: light; }

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: light dark; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }

::selection { background: var(--accent-soft); color: var(--accent-strong); }

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

/* Scrollbars */
* { scrollbar-color: var(--scrollbar-thumb) transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ── Top Nav ── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 56px;
  background: var(--bg-nav);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.site-logo:hover { color: var(--text); text-decoration: none; }

.site-logo-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #0b0b0d;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.02em;
  transition: transform 0.15s;
}
.site-logo:hover .site-logo-badge { transform: scale(1.06); }

.site-logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.site-logo-name {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.site-logo-tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.topnav-links {
  display: flex;
  align-items: center;
  gap: 24px;
}

.topnav-links a {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
.topnav-links a:hover { color: var(--text); text-decoration: none; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent-border); background: var(--surface-hover); }
.theme-toggle svg { display: block; }

/* ── Layout ── */
.layout {
  display: flex;
  min-height: calc(100vh - 56px);
  max-width: 1180px;
  margin: 0 auto;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-soft);
  padding: 24px 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}

.sidebar-section {
  padding: 0 12px;
  margin-bottom: 6px;
}

.sidebar-group-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 14px 8px 5px;
}
.sidebar-group-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 9.5px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

.sidebar-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 14px;
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 1px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.sidebar-item.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 500; }
.sidebar-item.active::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
}
.sidebar-item-dot {
  flex-shrink: 0;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
}
.sidebar-item.active .sidebar-item-dot { background: var(--accent-strong); }

/* ── Main ── */
.main {
  flex: 1;
  padding: 40px 60px 80px;
  min-width: 0;
  max-width: 780px;
}

/* ── Breadcrumb ── */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 22px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); text-decoration: none; }

/* ── Page title ── */
.page-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
.page-date { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }

.post-header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.post-header-tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Divider ── */
.divider { height: 1px; background: var(--border-soft); margin: 28px 0; }

/* ── Article Body ── */
.article-body { color: var(--text-secondary); }

.article-body p { margin-bottom: 18px; }
.article-body strong { color: var(--text); font-weight: 600; }

.article-body h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 40px 0 14px;
  letter-spacing: -0.01em;
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
}
.article-body h1:first-child { border-top: none; margin-top: 0; }

.article-body h2 {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  margin: 36px 0 12px;
  letter-spacing: -0.01em;
}

.article-body h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 24px 0 8px;
}

.article-body ul,
.article-body ol {
  padding-left: 22px;
  margin-bottom: 18px;
}

.article-body li {
  margin-bottom: 5px;
  color: var(--text-secondary);
}

.article-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 24px 0;
  padding: 12px 20px;
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--text-secondary);
}
.article-body blockquote p { margin: 0; }

/* ── Code ── */
.article-body code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  background: var(--surface);
  padding: 2px 5px;
  border-radius: 3px;
  color: var(--accent-strong);
}

.article-body pre,
.highlight {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  margin: 16px 0 22px;
}

.article-body pre code,
.highlight pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 12.5px;
  border-radius: 0;
  font-family: 'JetBrains Mono', monospace;
}

/* Rouge syntax highlighting */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cp { color: var(--code-comment); font-style: italic; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt, .highlight .kc { color: var(--code-keyword); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sc,
.highlight .sd, .highlight .se, .highlight .sh, .highlight .si, .highlight .sx, .highlight .ss { color: var(--code-string); }
.highlight .m, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .mo, .highlight .il { color: var(--code-number); }
.highlight .nf, .highlight .fm { color: var(--code-function); }
.highlight .nc, .highlight .nn, .highlight .bp { color: var(--code-class); }
.highlight .nt { color: var(--code-tag); }
.highlight .na, .highlight .nb, .highlight .no { color: var(--accent-strong); }
.highlight .ow, .highlight .o { color: var(--code-tag); }
.highlight .p { color: var(--text-secondary); }
.highlight .err { color: #ff6b6b; }
.highlight .gh, .highlight .gu { color: var(--text-muted); }

/* ── Images ── */
.article-body img,
.article-body .doc-diagram {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 24px 0;
  display: block;
}

/* ── Math ── */
.article-body .math-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 20px 0 26px;
  overflow-x: auto;
  text-align: center;
}
.article-body .math-block .katex-display {
  margin: 0;
}
.article-body .katex {
  font-size: 1.1em;
  color: var(--text);
}
.article-body .math-caption {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Tables ── */
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0 26px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.article-body th,
.article-body td {
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
}
.article-body th {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}
.article-body td { color: var(--text-secondary); }
.article-body tr:last-child td { border-bottom: none; }
.article-body tr:hover td { background: var(--surface-hover); }

/* ── HR ── */
.article-body hr {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 36px 0;
}

/* ── Tags ── */
.tag {
  font-size: 11px;
  background: var(--surface);
  color: var(--text-secondary);
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 500;
  border: 1px solid var(--border);
}

.post-tag {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 2px 8px;
  border-radius: 4px;
}

.post-date-sm { font-size: 12px; color: var(--text-muted); }

/* ── Article cover cards (real photo per subject) ── */
.post-cover-card {
  position: relative;
  display: flex;
  align-items: flex-end;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.post-cover-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11, 11, 13, 0) 25%, rgba(11, 11, 13, 0.92) 100%);
}

.post-cover-info { position: relative; z-index: 1; padding: 16px 20px; min-width: 0; }
.post-cover-eyebrow {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 4px;
}
.post-cover-title {
  display: block;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  margin-bottom: 8px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.post-cover-duration {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 3px 9px;
  border-radius: 4px;
}

.post-cover-card.size-list { flex: 0 0 300px; min-height: 150px; }

.post-cover-card.size-hero { width: 100%; min-height: 260px; margin-bottom: 24px; }
.post-cover-card.size-hero .post-cover-title {
  font-size: 32px;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin-bottom: 12px;
}
.post-cover-card.size-hero .post-cover-info { padding: 22px 32px; }
.post-cover-card.size-hero .post-cover-duration { font-size: 13px; padding: 5px 12px; }

/* Compact badge used in tight list rows (e.g. "À lire ensuite") */
.cover-badge {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cover-badge-icon { font-size: 18px; }

/* Fallback palette + icon for articles without a generated cover photo yet */
.post-cover-icon-fallback {
  position: absolute;
  right: 18px;
  bottom: 14px;
  z-index: 1;
  font-size: 34px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
}
.cover-0 { background: radial-gradient(120% 150% at 18% 25%, #ff2f92 0%, #7a0f52 42%, #150410 100%); }
.cover-1 { background: radial-gradient(120% 150% at 18% 25%, #4a5cff 0%, #22268a 42%, #06071c 100%); }
.cover-2 { background: radial-gradient(120% 150% at 18% 25%, #ff5252 0%, #8a1f1f 42%, #170707 100%); }
.cover-3 { background: radial-gradient(120% 150% at 18% 25%, #e6ac4f 0%, #6e4a1c 42%, #140d05 100%); }
.cover-4 { background: radial-gradient(120% 150% at 18% 25%, #22c9a0 0%, #115c4d 42%, #04120e 100%); }

@media (max-width: 768px) {
  .post-item { flex-direction: column; align-items: stretch; }
  .post-cover-card.size-list { flex: 0 0 auto; width: 100%; min-height: 150px; }
  .post-cover-card.size-hero { min-height: 200px; }
  .post-cover-card.size-hero .post-cover-info { padding: 18px 20px; }
}

/* ── Post list (index) ── */
.post-list { display: flex; flex-direction: column; }

.post-item {
  display: flex;
  align-items: stretch;
  gap: 20px;
  padding: 20px;
  margin: 0 -20px;
  border-radius: var(--radius);
  border-bottom: 1px solid var(--border-soft);
  color: inherit;
  transition: background 0.15s;
}
.post-item:hover { text-decoration: none; background: var(--surface); }
.post-item:hover .post-item-title { color: var(--accent); }
.post-item-body { min-width: 0; flex: 1; display: flex; flex-direction: column; justify-content: center; }

.post-item-upcoming { cursor: default; }
.post-item-upcoming:hover { background: none; }
.post-item-upcoming:hover .post-item-title { color: var(--text); }
.post-item-upcoming .post-cover-card { filter: saturate(0.7) brightness(0.85); }

.post-item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 5px;
}

.post-item-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
  transition: color 0.15s;
}

.post-item-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* ── Feedback ── */
.feedback {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
}
.feedback p { font-size: 14px; color: var(--text-secondary); margin: 0; }
.feedback-btns { display: flex; gap: 8px; }
.feedback-btns button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.feedback-btns button:hover { border-color: var(--accent-border); background: var(--accent-soft); }

/* ── Related ── */
.related h3 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 10px; }

.related-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 14px;
  color: var(--text-secondary);
}
.related-item:hover { text-decoration: none; }
.related-item:hover .related-item-title { color: var(--accent); }
.related-item-body { flex: 1; min-width: 0; }
.related-item-title { display: block; color: var(--text); font-weight: 600; margin-bottom: 2px; }
.related-item-date { font-size: 12px; color: var(--text-muted); }
.related-arrow { color: var(--text-muted); flex-shrink: 0; }

/* ── Hero image (index) ── */
.hero-image {
  display: block;
  width: 100%;
  max-height: 340px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin: 0 0 28px;
}

@media (max-width: 768px) {
  .hero-image { max-height: 220px; }
}

/* ── Index prose ── */
.main > p,
.main > ul,
.main > ol,
.main > blockquote {
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.main > blockquote {
  border-left: 3px solid var(--accent);
  padding: 12px 20px;
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--text-secondary);
}
.main > h2 {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  margin: 36px 0 14px;
}
.main > strong { color: var(--text); font-weight: 600; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: 24px 20px 60px; }
  .topnav { padding: 0 16px; }
  .page-title { font-size: 22px; }
}
