/* ==========================================================================
   Selam Éditions — base styles
   « Le livre » : the site is laid out like a book read on an e-reader.
   Black ink, white paper, a few greys. Mobile first.
   Design tokens, reset, typography, page sheet, running head, table of
   contents (navigation) and colophon (footer).
   Components live in components.css, breakpoints in responsive.css,
   line drawings and their animations in illustrations.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Palette — e-ink: paper, ink and greys only */
  --paper: #ffffff;
  --paper-deep: #f6f6f4;     /* tinted pages, insets */
  --paper-shade: #ececea;    /* cover placeholders, image wells */
  --desk: #e4e4e1;           /* the table the book lies on (wide screens) */
  --ink: #111111;
  --ink-soft: #333333;
  --muted: #5e5e5e;          /* 6.6:1 on white */
  --faint: #8a8a8a;          /* decorative only (folios, ornaments) */
  --rule: #dcdcdc;
  --rule-strong: #b5b5b5;
  --accent: #111111;         /* no colour accent: emphasis is ink */
  --accent-deep: #000000;
  --on-ink: #ffffff;
  --focus: #111111;
  --error: #111111;
  --success: #111111;

  /* Type families — system stacks, no remote fonts (CSP: font-src 'self').
     Iowan Old Style is the default book face of Apple Books. */
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
    "URW Palladio L", P052, Georgia, serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans", Arial, sans-serif;

  /* Fluid type scale — modest, like a book page */
  --step--2: clamp(0.72rem, 0.7rem + 0.08vw, 0.78rem);
  --step--1: clamp(0.82rem, 0.8rem + 0.12vw, 0.9rem);
  --step-0: clamp(1.06rem, 1rem + 0.25vw, 1.16rem);
  --step-1: clamp(1.18rem, 1.1rem + 0.4vw, 1.4rem);
  --step-2: clamp(1.38rem, 1.24rem + 0.7vw, 1.8rem);
  --step-3: clamp(1.62rem, 1.4rem + 1.1vw, 2.3rem);
  --step-4: clamp(1.9rem, 1.55rem + 1.8vw, 3rem);
  --step-5: clamp(2.2rem, 1.7rem + 2.6vw, 3.8rem);

  /* Spacing scale */
  --space-3xs: 0.25rem;
  --space-2xs: 0.5rem;
  --space-xs: 0.75rem;
  --space-s: 1rem;
  --space-m: 1.5rem;
  --space-l: 2rem;
  --space-xl: 3rem;
  --space-2xl: 4.5rem;
  --space-3xl: 6.5rem;
  --space-section: clamp(3.5rem, 2.6rem + 4.5vw, 7rem);

  /* Layout — the page sheet and its text block */
  --sheet: 54rem;            /* width of the page on wide screens */
  --container: 44rem;        /* text block inside the page */
  --container-narrow: 36rem;
  --gutter: clamp(1.25rem, 0.6rem + 3.2vw, 3.5rem);
  --measure: 33em;
  --header-h: 3.5rem;
  --radius: 0;

  /* Lines & motion */
  --hairline: 1px solid var(--rule);
  --hairline-strong: 1px solid var(--rule-strong);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --duration: 200ms;

  color-scheme: light;
}

/* --------------------------------------------------------------------------
   2. Reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + var(--space-m));
  background: var(--paper);
}

/* Smooth scrolling is switched on by main.js only once the page has fully
   loaded: on arrival at an address such as /en/#contact, a smooth scroll
   would aim at a position that moves while the books and drawings load. */
@media (prefers-reduced-motion: no-preference) {
  html.smooth-scroll {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh; /* the visible height, between the phone's browser bars */
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: var(--step-0);
  line-height: 1.65;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  font-variant-numeric: oldstyle-nums proportional-nums;
  hanging-punctuation: first;
  hyphens: auto;
  -webkit-hyphens: auto;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

main {
  flex: 1 0 auto;
}

/* <main tabindex="-1"> receives focus from the skip link: no frame around
   the whole page */
main:focus {
  outline: none;
}

img,
svg,
picture {
  display: block;
  max-width: 100%;
  height: auto;
}

h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol {
  margin: 0;
}

:where(ul[class], ol[class], .breadcrumb ol) {
  list-style: none;
  padding: 0;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   3. Typography — set like a book
   -------------------------------------------------------------------------- */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: 0;
  text-wrap: balance;
  hyphens: manual;
  -webkit-hyphens: manual;
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p {
  text-wrap: pretty;
}

cite {
  font-style: italic;
}

a {
  color: inherit;
  text-decoration-color: var(--rule-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: color var(--duration) var(--ease), text-decoration-color var(--duration) var(--ease);
}

a:hover {
  color: var(--ink);
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

::selection {
  background: var(--ink);
  color: var(--paper);
}

/* Small capitals in grey: chapter numbers, running heads, labels */
.kicker {
  font-family: var(--font-serif);
  font-size: var(--step--1);
  font-weight: 400;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.16em;
  text-transform: lowercase;
  color: var(--muted);
}

.lead {
  font-size: var(--step-1);
  font-style: italic;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: var(--measure);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: var(--step--1);
  line-height: 1.55;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Typographic ornament between parts: ⁂ */
.ornament {
  display: block;
  margin-block: var(--space-xl);
  color: var(--faint);
  font-size: var(--step-1);
  line-height: 1;
  text-align: center;
  letter-spacing: 0.4em;
}

.ornament::before {
  content: "\2042";
}

/* --------------------------------------------------------------------------
   4. Layout — the page sheet
   On phones the screen is the page. From 48rem the page sits on a grey desk
   with a soft shadow and a spine on its left edge (see responsive.css).
   -------------------------------------------------------------------------- */
.book {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 0 auto;
  width: 100%;
  background: var(--paper);
}

.container {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--gutter));
  margin-inline: auto;
  /* keep clear of the notch when a phone is held sideways */
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}

.container--narrow {
  max-width: calc(var(--container-narrow) + 2 * var(--gutter));
}

.section {
  position: relative;
  padding-block: var(--space-section);
}

.section-head {
  display: grid;
  justify-items: center;
  gap: var(--space-2xs);
  margin-bottom: var(--space-xl);
  text-align: center;
}

.section-head h2 {
  font-size: var(--step-3);
  font-style: italic;
}

/* A short rule under every chapter title */
.section-head h2::after {
  content: "";
  display: block;
  width: 2.5rem;
  height: 1px;
  margin: var(--space-s) auto 0;
  background: var(--ink);
}

.section-head__intro {
  color: var(--muted);
  max-width: 30em;
}

.section-head .section-head__intro {
  margin-inline: auto;
}


/* --------------------------------------------------------------------------
   5. Skip link
   -------------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  top: var(--space-2xs);
  left: var(--space-2xs);
  z-index: 100;
  padding: var(--space-2xs) var(--space-s);
  background: var(--ink);
  color: var(--on-ink);
  font-size: var(--step--1);
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
  color: var(--on-ink);
}

/* --------------------------------------------------------------------------
   6. Running head (header) — like the top line of an e-reader
   -------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--paper);
  border-bottom: var(--hairline);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
  min-height: var(--header-h);
  max-width: calc(var(--sheet));
}

/* Reading progress, drawn as a hairline under the running head (illustrations.js) */
.reading-progress {
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 100%;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  pointer-events: none;
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45em;
  margin-right: auto;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 400;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.3em;
  line-height: 1;
  text-transform: lowercase;
  text-decoration: none;
  white-space: nowrap;
}

.wordmark:hover {
  color: var(--ink);
}

/* Set exactly like the imprint line of the title page: SELAM ÉDITIONS */
.wordmark__name,
.wordmark__imprint {
  color: var(--ink);
}

/* The name written out in running labels (e.g. above a book title) */
.imprint {
  font-family: var(--font-serif);
  font-size: var(--step--1);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.18em;
  text-transform: lowercase;
  color: var(--muted);
}

/* Table of contents — the navigation. Mobile first: a full page that
   slides in when "Sommaire / Menu" is pressed. */
.site-nav {
  display: none;
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--paper);
  border-top: var(--hairline);
}

.site-header.is-open .site-nav {
  display: block;
  animation: toc-in 320ms var(--ease) both;
}

@keyframes toc-in {
  from { opacity: 0; transform: translateY(-0.75rem); }
  to { opacity: 1; transform: none; }
}

.site-nav::before {
  content: "Sommaire";
  display: block;
  padding: var(--space-xl) var(--gutter) var(--space-s);
  font-size: var(--step-3);
  font-style: italic;
  text-align: center;
}

:lang(en) .site-nav::before {
  content: "Contents";
}

.site-nav__list {
  counter-reset: toc;
  display: grid;
  max-width: 30rem;
  margin-inline: auto;
  padding: var(--space-s) var(--gutter) var(--space-2xl);
}

/* The first entry (home) is the title page: it carries no chapter number,
   so the numbers match the "Chapitre I, II…" headings of the homepage. */
.site-nav__item + .site-nav__item {
  counter-increment: toc;
}

/* Title . . . . . . . . . . chapter number (as in a printed contents page) */
.site-nav__link {
  display: flex;
  align-items: baseline;
  gap: var(--space-2xs);
  padding: var(--space-xs) 0;
  font-family: var(--font-serif);
  font-size: var(--step-1);
  text-decoration: none;
}

.site-nav__link::after {
  content: "";
  order: 1;
  flex: 1;
  min-width: 1.5rem;
  border-bottom: 1px dotted var(--rule-strong);
  transform: translateY(-0.3em);
}

.site-nav__link::before {
  content: counter(toc, upper-roman);
  order: 2;
  min-width: 1.75rem;
  color: var(--muted);
  font-size: var(--step--1);
  font-variant-numeric: lining-nums;
  text-align: right;
}

.site-nav__item:first-child .site-nav__link {
  font-style: italic;
}

.site-nav__item:first-child .site-nav__link::before {
  content: "\2042";
}

.site-nav__link[aria-current] {
  font-style: italic;
}

.site-nav__link[aria-current]::before {
  color: var(--ink);
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  min-height: 2.75rem;
  padding: 0 var(--space-2xs);
  margin-right: calc(-1 * var(--space-2xs));
  border: 0;
  background: none;
  font-family: var(--font-serif);
  font-size: var(--step--1);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.14em;
  text-transform: lowercase;
}

.nav-toggle__icon {
  position: relative;
  width: 1.15rem;
  height: 0.7rem;
}

.nav-toggle__icon::before,
.nav-toggle__icon::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: currentColor;
  transition: transform var(--duration) var(--ease), top var(--duration) var(--ease);
}

.nav-toggle__icon::before { top: 0; }
.nav-toggle__icon::after { top: calc(100% - 1px); }

.nav-toggle[aria-expanded="true"] .nav-toggle__icon::before {
  top: calc(50% - 0.5px);
  transform: rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle__icon::after {
  top: calc(50% - 0.5px);
  transform: rotate(-45deg);
}

/* Language switch */
.lang-switch {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  font-family: var(--font-serif);
  font-size: var(--step--1);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.12em;
}

.lang-switch a,
.lang-switch span[aria-current] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: 2.75rem;
  text-decoration: none;
}

.lang-switch span[aria-current] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.45em;
}

.lang-switch a {
  color: var(--muted);
}

.lang-switch a:hover {
  color: var(--ink);
}

.lang-switch__sep {
  color: var(--rule-strong);
}

/* --------------------------------------------------------------------------
   7. Colophon (footer) — the last page of the book
   -------------------------------------------------------------------------- */
.site-footer {
  margin-top: auto;
  background: var(--paper);
  color: var(--muted);
  border-top: var(--hairline);
  font-size: var(--step--1);
  line-height: 1.6;
  text-align: center;
}

.site-footer a {
  color: var(--ink);
  text-decoration-color: var(--rule-strong);
}

.site-footer a:hover {
  text-decoration-color: currentColor;
}

/* Smartphone first: the colophon fits on one screen. The "Explorer" list
   repeats the contents page (Sommaire) and is only shown from 48rem; the
   legal links become a single line separated by dots. */
.site-footer__grid {
  display: grid;
  justify-items: center;
  gap: var(--space-s);
  padding-block: var(--space-m) var(--space-s);
}

.site-footer__grid > nav {
  display: none;
}

.site-footer .wordmark {
  margin: 0;
  font-size: 1.1rem;
}

.site-footer__about p {
  margin: var(--space-2xs) auto 0;
  max-width: 24em;
  font-style: italic;
  line-height: 1.5;
}

.site-footer__heading {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.site-footer__list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 var(--space-s);
}

.site-footer__list a,
.site-footer__list button {
  display: inline-block;
  padding-block: 0.4rem; /* comfortable tap target */
}

/* © + credit on top, then language and "back to top" side by side.
   The bottom padding keeps clear of the iPhone home bar and of the
   Android gesture bar (safe area). */
.site-footer__bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 var(--space-s);
  padding-top: var(--space-s);
  padding-bottom: calc(var(--space-s) + env(safe-area-inset-bottom, 0px));
  border-top: var(--hairline);
}

.site-footer__bottom > p {
  flex-basis: 100%;
}

.site-footer__bottom .lang-switch {
  margin: 0;
  padding: 0;
  border: 0;
}

/* "Achevé d'imprimer" line and design credit */
.colophon-credit {
  font-style: italic;
}

.colophon-credit a {
  font-style: normal;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.1em;
}

.back-to-top {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  min-height: 2.75rem;
  padding: 0 var(--space-xs);
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: var(--step--1);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.14em;
}

.back-to-top svg {
  width: 0.9rem;
  height: 0.9rem;
  transition: transform var(--duration) var(--ease);
}

.back-to-top:hover svg {
  transform: translateY(-2px);
}



/* --------------------------------------------------------------------------
   8. Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
