/*
 * gagnezdutemps — reading.css
 * Reading experience : largeur, TOC sticky, TL;DR, FAQ, footnotes, code, anchors.
 * Mobile-first. Compatible Safari 15.4+.
 */

/* ---------------------------------------------------------------------------
 * 1. Largeur de lecture
 * ------------------------------------------------------------------------- */
.gdt-reading-width {
  max-width: 65ch;
  margin-inline: auto;
}

.gdt-reading-width > * {
  max-width: 65ch;
}

/* Images alignwide depassent la largeur de lecture */
.gdt-reading-width > .alignwide,
.gdt-reading-width > .wp-block-image.alignwide,
.gdt-reading-width > figure.alignwide {
  max-width: min(100%, 880px);
  margin-inline: auto;
}

.gdt-reading-width > .alignfull {
  max-width: none;
  margin-inline: calc(50% - 50vw);
}

/* ---------------------------------------------------------------------------
 * 2. Typographie de lecture
 * ------------------------------------------------------------------------- */
.gdt-reading-width p,
.gdt-reading-width li {
  font-family: var(--wp--preset--font-family--inter);
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.0625rem);
  line-height: 1.7;
  color: var(--wp--preset--color--ink);
  hyphens: auto;
  -webkit-hyphens: auto;
}

.gdt-reading-width p {
  margin-block: 0 var(--wp--preset--spacing--lg);
}

.gdt-reading-width p + p {
  margin-top: var(--wp--preset--spacing--lg);
}

.gdt-reading-width h2 {
  font-family: var(--wp--preset--font-family--fraunces);
  font-size: clamp(1.5rem, 1.25rem + 1.25vw, 2.25rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: var(--wp--preset--color--ink);
  margin-block: var(--wp--preset--spacing--3xl) var(--wp--preset--spacing--lg);
}

.gdt-reading-width h3 {
  font-family: var(--wp--preset--font-family--fraunces);
  font-size: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--wp--preset--color--ink);
  margin-block: var(--wp--preset--spacing--2xl) var(--wp--preset--spacing--md);
}

.gdt-reading-width h4 {
  font-family: var(--wp--preset--font-family--fraunces);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.35;
  margin-block: var(--wp--preset--spacing--xl) var(--wp--preset--spacing--md);
}

/* ---------------------------------------------------------------------------
 * 3. TOC sticky discrete
 * ------------------------------------------------------------------------- */
.gdt-toc-sticky {
  position: sticky;
  top: 24px;
  scroll-margin-top: 24px;
  font-family: var(--wp--preset--font-family--inter);
  font-size: 0.875rem;
  line-height: 1.5;
}

.gdt-toc-sticky__title {
  font-family: var(--wp--preset--font-family--inter);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--wp--preset--color--muted);
  margin: 0 0 var(--wp--preset--spacing--md);
}

.gdt-toc-sticky ol,
.gdt-toc-sticky ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--wp--preset--spacing--sm);
  border-left: 1px solid var(--wp--preset--color--line);
}

.gdt-toc-sticky li {
  margin: 0;
}

.gdt-toc-sticky li ol,
.gdt-toc-sticky li ul {
  margin-top: var(--wp--preset--spacing--sm);
  margin-left: var(--wp--preset--spacing--lg);
  border-left: none;
}

.gdt-toc-sticky a {
  display: block;
  padding: 2px var(--wp--preset--spacing--md);
  color: var(--wp--preset--color--muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color 0.15s ease, border-color 0.15s ease, font-weight 0.15s ease;
}

.gdt-toc-sticky a:hover {
  color: var(--wp--preset--color--ink);
  border-left-color: var(--wp--preset--color--line);
}

.gdt-toc-active,
.gdt-toc-sticky a.is-active,
.gdt-toc-sticky .gdt-toc-active a {
  font-weight: 600;
  color: var(--wp--preset--color--amber);
  border-left-color: var(--wp--preset--color--amber);
}

/* ---------------------------------------------------------------------------
 * 4. TL;DR — "L'essentiel en 30 secondes"
 * ------------------------------------------------------------------------- */
.gdt-tldr {
  background: var(--wp--preset--color--surface);
  padding: var(--wp--preset--spacing--xl);
  border-left: 4px solid var(--wp--preset--color--amber);
  margin-block: var(--wp--preset--spacing--xl) var(--wp--preset--spacing--xl);
  font-family: var(--wp--preset--font-family--inter);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--wp--preset--color--ink);
}

.gdt-tldr__title {
  font-family: var(--wp--preset--font-family--fraunces);
  font-style: italic;
  font-weight: 600;
  font-size: 1.0625rem;
  letter-spacing: -0.005em;
  color: var(--wp--preset--color--ink);
  margin: 0 0 var(--wp--preset--spacing--md);
}

.gdt-tldr__title::before {
  content: "L'essentiel en 30 secondes";
}

.gdt-tldr ul {
  margin: 0;
  padding-left: var(--wp--preset--spacing--xl);
  display: flex;
  flex-direction: column;
  gap: var(--wp--preset--spacing--sm);
}

.gdt-tldr ul li::marker {
  color: var(--wp--preset--color--amber);
}

.gdt-tldr p:last-child,
.gdt-tldr ul:last-child {
  margin-bottom: 0;
}

/* ---------------------------------------------------------------------------
 * 5. Barre de progression de lecture
 * ------------------------------------------------------------------------- */
.gdt-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--wp--preset--color--amber);
  transform: scaleX(0);
  transform-origin: left center;
  z-index: 100;
  pointer-events: none;
  will-change: transform;
}

/* ---------------------------------------------------------------------------
 * 6. FAQ details/summary
 * ------------------------------------------------------------------------- */
.gdt-faq {
  margin-block: var(--wp--preset--spacing--2xl);
}

.gdt-faq__title {
  font-family: var(--wp--preset--font-family--fraunces);
  font-size: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--wp--preset--color--ink);
  margin: 0 0 var(--wp--preset--spacing--lg);
}

.gdt-faq details {
  border-bottom: 1px solid var(--wp--preset--color--line);
}

.gdt-faq details:first-of-type {
  border-top: 1px solid var(--wp--preset--color--line);
}

.gdt-faq summary {
  cursor: pointer;
  padding: var(--wp--preset--spacing--md) 0;
  font-family: var(--wp--preset--font-family--inter);
  font-weight: 500;
  font-size: 1.0625rem;
  line-height: 1.4;
  color: var(--wp--preset--color--ink);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--wp--preset--spacing--md);
  transition: color 0.15s ease;
}

.gdt-faq summary::-webkit-details-marker {
  display: none;
}

.gdt-faq summary::after {
  content: "+";
  font-family: var(--wp--preset--font-family--fraunces);
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--wp--preset--color--amber);
  flex-shrink: 0;
  transition: transform 0.2s ease;
  line-height: 1;
}

.gdt-faq details[open] summary::after {
  transform: rotate(45deg);
}

.gdt-faq summary:hover {
  color: var(--wp--preset--color--amber);
}

.gdt-faq details[open] > *:not(summary) {
  padding-bottom: var(--wp--preset--spacing--lg);
  font-family: var(--wp--preset--font-family--inter);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--wp--preset--color--muted);
}

/* ---------------------------------------------------------------------------
 * 7. Footnotes inline
 * ------------------------------------------------------------------------- */
.gdt-fn,
sup.footnote-ref,
sup a[href^="#fn"] {
  font-family: var(--wp--preset--font-family--inter);
  font-size: 0.7em;
  font-weight: 600;
  vertical-align: super;
  line-height: 1;
  margin-inline: 0.1em;
  padding: 0.1em 0.35em;
  background: var(--wp--preset--color--surface);
  color: var(--wp--preset--color--amber);
  text-decoration: none;
  border-radius: 4px;
  transition: background 0.15s ease;
  position: relative;
}

.gdt-fn:hover,
sup.footnote-ref:hover,
sup a[href^="#fn"]:hover {
  background: var(--wp--preset--color--amber);
  color: var(--wp--preset--color--ink);
}

.gdt-fn[data-tooltip]:hover::after,
.gdt-fn[data-tooltip]:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--wp--preset--color--ink);
  color: var(--wp--preset--color--paper);
  padding: var(--wp--preset--spacing--sm) var(--wp--preset--spacing--md);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  z-index: 50;
  pointer-events: none;
  vertical-align: baseline;
}

.gdt-footnotes {
  margin-top: var(--wp--preset--spacing--3xl);
  padding-top: var(--wp--preset--spacing--xl);
  border-top: 1px solid var(--wp--preset--color--line);
  font-family: var(--wp--preset--font-family--inter);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--wp--preset--color--muted);
}

.gdt-footnotes ol {
  padding-left: var(--wp--preset--spacing--xl);
  display: flex;
  flex-direction: column;
  gap: var(--wp--preset--spacing--md);
}

/* ---------------------------------------------------------------------------
 * 8. Heading anchors
 * ------------------------------------------------------------------------- */
:target {
  scroll-margin-top: 80px;
}

h2:target,
h3:target,
h4:target {
  background: color-mix(in srgb, var(--wp--preset--color--amber) 12%, transparent);
  padding-inline: var(--wp--preset--spacing--md);
  margin-inline: calc(var(--wp--preset--spacing--md) * -1);
  border-radius: 2px;
  animation: gdt-target-fade 2.5s ease-out 1s forwards;
}

@keyframes gdt-target-fade {
  to {
    background: transparent;
  }
}

.gdt-heading-anchor {
  display: inline-block;
  margin-left: var(--wp--preset--spacing--sm);
  color: var(--wp--preset--color--muted);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

h2:hover .gdt-heading-anchor,
h3:hover .gdt-heading-anchor,
h4:hover .gdt-heading-anchor,
.gdt-heading-anchor:focus-visible {
  opacity: 1;
}

.gdt-heading-anchor:hover {
  color: var(--wp--preset--color--amber);
}

/* ---------------------------------------------------------------------------
 * 9. Code blocks et inline
 * ------------------------------------------------------------------------- */
.wp-block-code,
pre,
pre code {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background: var(--wp--preset--color--surface);
  color: var(--wp--preset--color--ink);
  padding: var(--wp--preset--spacing--lg);
  border-radius: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  tab-size: 2;
  margin-block: var(--wp--preset--spacing--xl);
}

.wp-block-code code {
  background: transparent;
  padding: 0;
}

p code,
li code,
:not(pre) > code {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875em;
  background: var(--wp--preset--color--surface);
  color: var(--wp--preset--color--ink);
  padding: var(--wp--preset--spacing--xs) 0.4em;
  border-radius: 4px;
  border: 1px solid var(--wp--preset--color--line);
}

/* Scrollbar discrete pour les blocs code */
.wp-block-code::-webkit-scrollbar,
pre::-webkit-scrollbar {
  height: 6px;
}

.wp-block-code::-webkit-scrollbar-thumb,
pre::-webkit-scrollbar-thumb {
  background: var(--wp--preset--color--line);
  border-radius: 999px;
}

/* ---------------------------------------------------------------------------
 * 10. Images dans contenu
 * ------------------------------------------------------------------------- */
.gdt-reading-width .wp-block-image,
.gdt-reading-width figure.wp-block-image {
  margin-block: var(--wp--preset--spacing--xl);
}

.gdt-reading-width .wp-block-image.alignwide,
.gdt-reading-width figure.alignwide {
  margin-block: var(--wp--preset--spacing--2xl);
}

.gdt-reading-width .wp-block-image figcaption,
.gdt-reading-width figcaption {
  font-family: var(--wp--preset--font-family--inter);
  font-style: italic;
  font-size: 0.875rem;
  color: var(--wp--preset--color--muted);
  text-align: left;
  margin-top: var(--wp--preset--spacing--md);
  line-height: 1.5;
  max-width: 65ch;
}

/* ---------------------------------------------------------------------------
 * 11. Listes editoriales
 * ------------------------------------------------------------------------- */
.gdt-reading-width ul,
.gdt-reading-width ol {
  padding-left: var(--wp--preset--spacing--xl);
  margin-block: var(--wp--preset--spacing--lg);
  display: flex;
  flex-direction: column;
  gap: var(--wp--preset--spacing--sm);
}

.gdt-reading-width li::marker {
  color: var(--wp--preset--color--amber);
}

.gdt-reading-width li > ul,
.gdt-reading-width li > ol {
  margin-top: var(--wp--preset--spacing--sm);
}

/* ---------------------------------------------------------------------------
 * 12. Hr separateur editorial
 * ------------------------------------------------------------------------- */
.gdt-reading-width hr,
.gdt-reading-width .wp-block-separator {
  border: none;
  height: 1px;
  background: var(--wp--preset--color--line);
  margin-block: var(--wp--preset--spacing--3xl);
  max-width: 120px;
  margin-inline: auto;
}

.gdt-reading-width .wp-block-separator.is-style-dots {
  background: transparent;
  height: auto;
  text-align: center;
  font-family: var(--wp--preset--font-family--fraunces);
  letter-spacing: 0.5em;
  color: var(--wp--preset--color--muted);
}

.gdt-reading-width .wp-block-separator.is-style-dots::before {
  content: "···";
}

/* ---------------------------------------------------------------------------
 * 13. Tables
 * ------------------------------------------------------------------------- */
.gdt-reading-width .wp-block-table,
.gdt-reading-width table {
  font-family: var(--wp--preset--font-family--inter);
  font-size: 0.9375rem;
  line-height: 1.5;
  border-collapse: collapse;
  width: 100%;
  margin-block: var(--wp--preset--spacing--xl);
}

.gdt-reading-width th,
.gdt-reading-width td {
  padding: var(--wp--preset--spacing--md) var(--wp--preset--spacing--lg);
  text-align: left;
  border-bottom: 1px solid var(--wp--preset--color--line);
}

.gdt-reading-width th {
  font-weight: 600;
  color: var(--wp--preset--color--ink);
  border-bottom: 2px solid var(--wp--preset--color--ink);
}
