/*
 * Surcouche La Tourbillonnante au-dessus de screen.css (thème Ghost « Source »
 * porté par zola-sveltia-source, cf. templates/LICENSE-theme-WTFPL).
 * Règles : cf. AGENTS.md § CSS. Les règles reprises de Publii (config/custom-css.css)
 * sont marquées « Publii : ».
 */
@layer tokens, base, components, utilities;

@layer tokens {
  :root {
    /* Couleurs du thème Publii (theme.config.json) */
    --color-primary: #dd2c00;
    --color-text: #343434;
    --color-headings: #343434;
    --color-link: #1e00dd;
    --color-link-hover: #343434;
    --ghost-accent-color: var(--color-primary);
    --background-color: #fff;

    /* Polices système, comme sous Publii */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
    --gh-font-heading: var(--font-sans);
    --gh-font-body: var(--font-sans);

    --entry-width: 68ch;
    --radius: 0.4rem;
  }
}

@layer base {
  body { color: var(--color-text); }
  .gh-content a { color: var(--color-link); text-decoration: underline; }
  .gh-content a:hover { color: var(--color-link-hover); }
  :focus-visible { outline: 3px solid var(--color-primary); outline-offset: 2px; }

  /* Publii : blockquote */
  .gh-content blockquote { padding-right: 0; font-size: inherit; font-style: italic; }
}

@layer components {
  .skip-link {
    position: absolute; left: 1rem; top: -100%;
    padding: 0.8rem 1.6rem; background: var(--color-primary); color: #fff; z-index: 1000;
  }
  .skip-link:focus { top: 1rem; }

  /* Sous-menus en <details> */
  .nav-sous-menu details { position: relative; }
  .nav-sous-menu summary { cursor: pointer; list-style: none; }
  .nav-sous-menu summary::after { content: " ▾"; }
  .nav-sous-menu details ul {
    position: absolute; z-index: 100; min-width: 24rem; padding: 0.8rem 1.6rem;
    list-style: none; background: var(--background-color);
    border: 1px solid var(--color-border); border-radius: var(--radius);
  }
  @media (max-width: 767px) {
    .nav-sous-menu details ul { position: static; border: 0; padding-left: 1.6rem; }
  }

  /* Publii : bandeau d'information */
  .bandeau { background: color-mix(in srgb, var(--color-primary) 10%, white); padding-block: 1.6rem; text-align: center; }
  .bandeau-titre { font-weight: 700; font-size: clamp(1.8rem, 1.6rem + 1vw, 2.6rem); }

  .post-tags, .share, .term-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.8rem 1.6rem; }
  .post-footer { margin-block: 4rem; display: grid; gap: 2.4rem; }
  .post-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 2.4rem; }
  .post-nav span { display: block; font-size: 1.3rem; color: var(--color-secondary-text); }
  .post-nav-next { text-align: right; grid-column: 2; }

  .newsletter { max-width: 48rem; margin-block-end: 4rem; }
  .newsletter input { width: 100%; padding: 0.6rem; }

  /* Publii : notes de bas de page */
  .footnote-definition, .footnotes { font-style: italic; font-size: 80%; }
}

/* Composants de contenu (templates/components/contenu.html) */
@layer components {
  .gh-content .post__image img { margin-inline: auto; }
  .gh-content figcaption { text-align: center; font-size: 1.4rem; color: var(--color-secondary-text); }
  .galerie {
    display: grid; gap: 0.8rem;
    grid-template-columns: repeat(var(--colonnes, 3), minmax(0, 1fr));
  }
  @media (max-width: 600px) { .galerie { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  .galerie-item { margin: 0; }
  .galerie-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
  .video { position: relative; aspect-ratio: 16 / 9; }
  .video iframe, .cadre iframe { width: 100%; height: 100%; border: 0; }
  .video iframe { position: absolute; inset: 0; }
  /* Publii : cadre agenda masqué sur petit écran */
  @media (max-width: 56.1875em) { .cadre.big-only { display: none; } }
  .gh-content .msg { padding: 1.6rem 2rem; border-left: 4px solid var(--color-primary); background: #f6f6f6; }
  .gh-content .msg--highlight { background: color-mix(in srgb, var(--color-primary) 8%, white); }
  /* Publii : tableaux */
  .gh-content table { border-collapse: collapse; width: 100%; }
  .gh-content td, .gh-content th { padding: 0.6rem; vertical-align: top; }
}

/* En-tête, visionneuse, impression, partage */
@layer components {
  .site-subtitle { font-style: italic; font-size: 1.4rem; color: var(--color-secondary-text); }
  @media (max-width: 767px) { .site-subtitle { display: none; } }

  /* Publii : avertissement des tribunes libres */
  .avertissement-tribune { padding: 1.6rem 2.4rem; background: #fff7e5; text-align: center; margin-block: 2rem; }

  .table-defilante { overflow-x: auto; }

  .visionneuse { max-width: 96vw; max-height: 96vh; padding: 0; border: 0; background: transparent; }
  .visionneuse::backdrop { background: rgb(0 0 0 / 0.85); }
  .visionneuse figure { margin: 0; }
  .visionneuse img { max-width: 92vw; max-height: 84vh; margin: auto; }
  .visionneuse figcaption, .visionneuse-compteur { color: #fff; text-align: center; margin-top: 0.8rem; }
  .visionneuse button {
    position: fixed; background: rgb(0 0 0 / 0.5); color: #fff; border: 0;
    font-size: 3.2rem; line-height: 1; padding: 0.4rem 1.2rem; cursor: pointer; border-radius: var(--radius);
  }
  .visionneuse-prec { left: 1rem; top: 50%; }
  .visionneuse-suiv { right: 1rem; top: 50%; }
  .visionneuse-fermer { right: 1rem; top: 1rem; }

  /* Publii : bouton et menu d'impression (créés par js/impression/print-paged.js) */
  .print-btn { background: none; border: 0; padding: 0.4rem; cursor: pointer; color: var(--color-text); }
  .print-btn > svg { width: 2rem; height: 2rem; fill: currentColor; }
  .print-btn:hover > svg { fill: var(--color-primary); }
  .print-menu { background: #fff; border: 1px solid #ccc; border-radius: 6px; box-shadow: 0 6px 18px rgb(0 0 0 / 0.16); padding: 4px; z-index: 1000; }
  .print-menu__item { display: block; width: 100%; text-align: left; white-space: nowrap; background: none; border: 0; padding: 0.5em 0.9em; font: inherit; color: var(--color-text); cursor: pointer; border-radius: 4px; }
  .print-menu__item:hover, .print-menu__item:focus { background: var(--color-primary); color: #fff; }

  .partage-fediverse { display: grid; gap: 0.6rem; max-width: 48rem; }
  .partage-fediverse-champ { display: flex; gap: 0.6rem; }
  .partage-fediverse-champ input { flex: 1; padding: 0.6rem; }
  .partage-fediverse-champ button { padding: 0.6rem 1.6rem; }
  .partage-fediverse-message:empty { display: none; }
}

/* Publii : impression native (Ctrl+P sans passer par le menu Paged.js) */
@media print {
  img { opacity: 1 !important; }
  .gh-navigation, .gh-footer, .bandeau, .post-footer, .lies, .print-btn, .print-menu,
  .skip-link, .gh-container:has(.lies) { display: none !important; }
  @page { margin: 18mm 16mm; }
  html, body { background: #fff !important; color: #000 !important; font-size: 11pt; }
  figure, figcaption, img, blockquote, table, .video, .cadre { break-inside: avoid; }
  h1, h2, h3, h4 { break-after: avoid; }
  p { orphans: 3; widows: 3; }
  .gh-content a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #555; word-break: break-all; }
  * { print-color-adjust: exact; }
}

/* Le titre de liste est le seul <h1> de la page : le thème le masque, on le garde visible */
@layer components {
  .gh-navigation ~ * .gh-container-title,
  :is(.paged, .tag-template, .author-template) .gh-container .gh-container-title { display: block; }
  .term-header { grid-column: 3 / span 12; }
  @media (min-width: 1200px) { .term-header { margin-bottom: 2.4rem; } }
}

/* Le <summary> d'un sous-menu prend le style des liens du menu */
@layer components {
  .gh-navigation .nav summary { font-weight: inherit; }
  @media (max-width: 767px) {
    #gh-navigation .nav summary { font-size: 1.75rem; font-weight: 600; text-align: center; }
    #gh-navigation .nav-sous-menu details ul { padding: 0.8rem 0 0; text-align: center; }
    #gh-navigation .nav-sous-menu details li { opacity: 1; }
  }
}
