/* =========================================================
   BordTech : thème inspiré des éditeurs de code
   Sombre par défaut, couleurs de catégories = coloration syntaxique
   ========================================================= */

:root {
  --bg: #0e1420;
  --panel: #131b2a;
  --ink: #d7dee9;
  --muted: #7c89a0;
  --line: #1f2a3c;
  --hover: #162033;
  --accent: #5cc8ff;
  --ok: #a3e36b;
  --warn: #ffb86b;
  --err: #ff757f;

  --c-eco-conception: #5fd38d;
  --c-jeux-video: #f78fb3;
  --c-stacks: #f6d365;
  --c-ia: #c792ea;
  --c-web: #82aaff;
  --c-securite: #ff757f;
  --c-open-source: #a3e36b;
  --c-cloud: #4fd6c8;
  --c-materiel: #ffb86b;

  --mono:
    "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --max: 54rem;
  --statusbar: 1.75rem;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b2333;
  --muted: #5e6a7e;
  --line: #dde2ea;
  --hover: #eceff4;
  --accent: #0b6ac9;
  --ok: #287a36;
  --warn: #a35700;
  --err: #c82e3b;

  --c-eco-conception: #167a4c;
  --c-jeux-video: #b63d73;
  --c-stacks: #836800;
  --c-ia: #8b3fd1;
  --c-web: #2f5bd3;
  --c-securite: #c82e3b;
  --c-open-source: #287a36;
  --c-cloud: #0d7871;
  --c-materiel: #a35700;
  color-scheme: light;
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding-bottom: calc(var(--statusbar) + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

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

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  padding: 0.5rem 1rem;
  font-family: var(--mono);
  background: var(--accent);
  color: var(--bg);
  z-index: 10;
}
.skip:focus {
  top: 1rem;
}

/* ---------- En-tête ---------- */
.topbar {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
}

.logo {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
}
.logo-prompt {
  color: var(--accent);
  margin-right: 0.45rem;
}

.tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Recherche façon palette de commandes */
.search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: min(18rem, 52vw);
  padding: 0.35rem 0.5rem 0.35rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.875rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.search-prefix {
  color: var(--accent);
}
.search input {
  flex: 1;
  min-width: 0;
  padding: 0;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: none;
}
.search input::placeholder {
  color: var(--muted);
}
.search kbd {
  padding: 0 0.4rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
}
.search:focus-within kbd {
  visibility: hidden;
}

.theme-btn {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
.theme-btn:hover {
  color: var(--ink);
}

/* ---------- Intro : le terminal ---------- */
main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
}

.intro {
  padding: 3.5rem 0 2.25rem;
  /* Grille de points discrète, comme un papier millimétré */
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: -11px -11px;
}

.prompt {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--ink);
}
.p-path {
  color: var(--accent);
}
.p-dollar {
  color: var(--muted);
}

.intro h1 {
  margin: 0.6rem 0 0;
  min-height: 1.05em;
  font-family: var(--mono);
  font-size: clamp(2.1rem, 8vw, 4.5rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.cursor {
  display: inline-block;
  width: 0.55em;
  height: 0.85em;
  margin-left: 0.08em;
  vertical-align: -0.04em;
  background: var(--accent);
}

@media (prefers-reduced-motion: no-preference) {
  .cursor {
    animation: blink 1.1s steps(1) 5;
  }
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

.summary {
  margin: 1rem 0 0;
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--muted);
}
.summary::before {
  margin-right: 0.5rem;
}
.summary[data-state="loading"]::before {
  content: "[..]";
  color: var(--muted);
}
.summary[data-state="ok"]::before {
  content: "[ok]";
  color: var(--ok);
}
.summary[data-state="error"]::before {
  content: "[erreur]";
  color: var(--err);
}

/* ---------- Filtres ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.3rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
.chip::before {
  content: "#";
  content: "#" / "";
  color: var(--cat);
  font-weight: 700;
}
.chip[data-cat="tout"]::before {
  content: "*";
  content: "*" / "";
}
.chip .count {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chip:hover {
  border-color: var(--cat);
}
.chip[aria-pressed="true"] {
  background: color-mix(in srgb, var(--cat) 16%, transparent);
  border-color: var(--cat);
}

/* ---------- Fil d'articles ---------- */
.day {
  margin-top: 2.25rem;
}

.day h2 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin: 0 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
}
.day h2 .comment {
  color: var(--muted);
  opacity: 0.7;
  margin-right: 0.4rem;
}
.day-count {
  font-weight: 400;
  font-size: 0.8rem;
}

.items {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Chaque article = une "ligne" d'éditeur : numéro dans la gouttière + contenu */
.item {
  position: relative;
  display: grid;
  grid-template-columns: 3.25rem 1fr;
  border-top: 1px solid var(--line);
}
.item:last-child {
  border-bottom: 1px solid var(--line);
}

.ln {
  padding: 1.1rem 0.9rem 0 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.body {
  min-width: 0;
  padding: 1rem 0.75rem 1.1rem 1rem;
  border-left: 2px solid var(--line);
}

.item:hover {
  background: var(--hover);
}
.item:hover .ln {
  color: var(--ink);
  opacity: 1;
}
.item:hover .body {
  border-left-color: var(--cat);
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}
.item-meta .tag {
  color: var(--cat);
  font-weight: 500;
}
.item-meta .src {
  color: var(--ink);
}

.item h3 {
  max-width: 62ch;
  margin: 0.35rem 0 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.35;
}
.item h3 a {
  color: inherit;
  text-decoration: none;
}
/* Toute la ligne est cliquable */
.item h3 a::after {
  content: "";
  position: absolute;
  inset: 0;
}
.item:hover h3 a {
  text-decoration: underline;
  text-decoration-color: var(--cat);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}
.item h3 a:focus-visible {
  outline: none;
}
.item:has(a:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.excerpt {
  max-width: 65ch;
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- États ---------- */
.state {
  padding: 3rem 0;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--muted);
}
.state p {
  margin: 0 0 1rem;
}

.btn {
  padding: 0.45rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--bg);
  background: var(--accent);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

/* ---------- Page article ---------- */
.article {
  max-width: 44rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}
.article .back {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
}
.article .back:hover {
  text-decoration: underline;
}
.article h1 {
  margin: 1.25rem 0 0.5rem;
  font-family: var(--mono);
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.article .byline {
  margin: 0 0 1.5rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}
.article .byline .tag {
  color: var(--c-eco-conception);
}
.article .lead {
  font-size: 1.1rem;
  font-weight: 600;
}
.article h2 {
  margin: 2.5rem 0 0.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 1.3rem;
  line-height: 1.3;
}
.article h2::before {
  content: "## ";
  color: var(--accent);
}
.article p,
.article li {
  max-width: 68ch;
}
.article li {
  margin-bottom: 0.5rem;
}
.article table {
  width: 100%;
  margin: 1rem 0;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.article th,
.article td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  vertical-align: top;
  border: 1px solid var(--line);
}
.article th {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--muted);
  background: var(--panel);
}
.article pre {
  overflow-x: auto;
  padding: 0.9rem 1rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.article .note {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--muted);
}
.article a {
  color: var(--accent);
}
.article code,
.article kbd {
  padding: 0.1rem 0.35rem;
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
}
.article pre code {
  padding: 0;
  background: none;
  border: 0;
}

/* ---------- Barre d'état ---------- */
.statusbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: calc(var(--statusbar) + env(safe-area-inset-bottom, 0px));
  padding: 0 1rem env(safe-area-inset-bottom, 0px);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.sb-item {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.sb-spacer {
  flex: 1;
}
.dot {
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.45rem;
  border-radius: 50%;
  background: var(--muted);
}
#sb-conn[data-state="demo"] .dot {
  background: var(--warn);
}
#sb-conn[data-state="live"] .dot {
  background: var(--ok);
}
#sb-conn[data-state="error"] .dot {
  background: var(--err);
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .topbar {
    flex-wrap: wrap;
  }
  .tools {
    flex: 1;
  }
  .search {
    flex: 1;
    width: auto;
  }
  .search kbd {
    display: none;
  }
  .intro {
    padding-top: 2.5rem;
  }
  .item {
    grid-template-columns: 2.25rem 1fr;
  }
  .ln {
    padding-right: 0.6rem;
  }
  .sb-optional {
    display: none;
  }
}

/* ---------- Accessibilité ---------- */
/* La cible du lien d évitement ne doit pas afficher de contour au focus programmatique */
#contenu:focus {
  outline: none;
}

/* Zones défilantes (code, tableaux) atteignables au clavier */
.article pre:focus-visible,
.scroll:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.scroll {
  overflow-x: auto;
}

/* Mode contraste élevé de Windows : les états ne reposent plus sur la couleur seule */
@media (forced-colors: active) {
  .chip[aria-pressed="true"] {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
  .cursor {
    background: CanvasText;
  }
  .item:hover .body {
    border-left-color: Highlight;
  }
}

/* Réduction des animations demandée par l utilisateur */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Pied de page ---------- */
.footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
}
.footer a {
  display: inline-block;
  padding: 0.25rem 0;
  color: var(--ink);
  text-underline-offset: 3px;
}
.footer a:hover {
  color: var(--accent);
}
.footer p {
  margin: 0.75rem 0 0;
}

/* ---------- Page 404 ---------- */
.not-found .btn {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  text-decoration: none;
}
.not-found .btn:hover {
  filter: brightness(1.1);
}
.not-found .prompt {
  margin-bottom: 0.25rem;
}

/* ---------- Don ---------- */
.footer .donate {
  margin: 0 0 1rem;
}
.footer a.btn {
  margin-left: 0.5rem;
  padding: 0.45rem 0.9rem;
  color: var(--bg);
  text-decoration: none;
}
.footer a.btn:hover {
  color: var(--bg);
  filter: brightness(1.1);
}

/* ---------- Archives ---------- */
.archive-link {
  margin: 2rem 0 0;
  font-family: var(--mono);
  font-size: 0.9rem;
}
.archive-link a {
  color: var(--accent);
  text-underline-offset: 3px;
}
.archive-note {
  margin: 0 0 1.5rem;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  background: var(--panel);
  border-left: 3px solid var(--warn);
}

/* ---------- Mise en page des articles ---------- */
/* Colonne alignée sur l'en-tête, texte limité à une largeur confortable */
.article {
  max-width: var(--max);
}
.article > * {
  max-width: 46rem;
}
.article > .items {
  max-width: none;
}
.article h2 {
  scroll-margin-top: 1rem;
}
.article h2::before,
.article .byline .tag {
  color: var(--cat, var(--accent));
}
.article .byline .tag {
  font-weight: 500;
}

.reading-time {
  margin: 0 0 1.25rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}
.byline + .reading-time {
  margin-top: -1rem;
}

.toc {
  margin: 0 0 2rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.toc summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.9rem;
}
.toc ol {
  margin: 0.75rem 0 0;
  padding-left: 1.4rem;
}
.toc li {
  margin-bottom: 0.25rem;
}
.toc a {
  color: var(--ink);
  text-underline-offset: 3px;
}

.related {
  margin-top: 3rem;
}
.related-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.related-list li {
  max-width: none;
  margin: 0;
  padding: 0.9rem 0;
  border-top: 1px solid var(--line);
}
.related-list li:last-child {
  border-bottom: 1px solid var(--line);
}
.related-list a {
  display: block;
  color: var(--ink);
  font-weight: 600;
  text-underline-offset: 4px;
}
.rel-meta {
  display: block;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

/* Bouton « Copier » sur les blocs de code */
.code {
  position: relative;
}
.code pre {
  padding-right: 5.5rem;
}
.code .copy {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
}
.code .copy:hover {
  border-color: var(--accent);
}

/* ---------- Accueil : filtres et haut de page ---------- */
.chip.is-empty {
  color: var(--muted);
  border-style: dashed;
}
.intro {
  padding: 2.25rem 0 1.5rem;
}
.intro h1 {
  font-size: clamp(1.9rem, 6vw, 3.25rem);
}

/* ---------- Impression ---------- */
@media print {
  :root {
    --bg: #fff;
    --panel: #fff;
    --ink: #000;
    --muted: #444;
    --line: #bbb;
    --accent: #000;
  }
  body {
    padding: 0;
    font-size: 11pt;
    color: #000;
    background: #fff;
  }
  .skip,
  .topbar .tools,
  .statusbar,
  .back,
  .toc,
  .related,
  .footer .donate,
  .code .copy,
  .archive-link {
    display: none !important;
  }
  .article,
  .article > * {
    max-width: none;
  }
  .article a {
    color: #000;
  }
  .article a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    word-break: break-all;
  }
  .article h2,
  .article h3 {
    break-after: avoid;
  }
  .article pre,
  .article table,
  .article li {
    break-inside: avoid;
  }
  .article pre {
    white-space: pre-wrap;
    border: 1px solid #bbb;
  }
}

/* ---------- Assistant IA ---------- */
.chat-toggle {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  padding: 0.55rem 1rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--bg);
  background: var(--accent);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}
.chat-toggle:hover {
  filter: brightness(1.1);
}
.chat-panel {
  position: fixed;
  right: 1rem;
  bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
  z-index: 21;
  display: flex;
  flex-direction: column;
  width: min(24rem, calc(100vw - 2rem));
  max-height: min(34rem, calc(100vh - 6rem));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.35);
}
.chat-panel[hidden] {
  display: none;
}
/* La barre d'état de l'accueil est fixée en bas : on se place au-dessus */
body:has(.statusbar) .chat-toggle {
  bottom: calc(var(--statusbar) + 1rem + env(safe-area-inset-bottom, 0px));
}
body:has(.statusbar) .chat-panel {
  bottom: calc(var(--statusbar) + 4rem + env(safe-area-inset-bottom, 0px));
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.chat-head h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.95rem;
}
.chat-close {
  padding: 0.2rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
}
.chat-log {
  flex: 1;
  min-height: 8rem;
  padding: 0.9rem;
  overflow-y: auto;
}
.chat-msg {
  margin: 0 0 0.7rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.chat-user {
  margin-left: 1.5rem;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}
.chat-assistant {
  margin-right: 1.5rem;
}
.chat-pending {
  color: var(--muted);
}
.chat-msg a {
  color: var(--accent);
  text-underline-offset: 3px;
}
.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--line);
}
.chat-form textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.chat-form textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.chat-form .btn[disabled] {
  opacity: 0.6;
  cursor: wait;
}
.chat-note {
  margin: 0;
  padding: 0 0.9rem 0.7rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.chat-note a {
  color: var(--ink);
}
@media (max-width: 560px) {
  .chat-panel {
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
  }
}
@media print {
  .chat-toggle,
  .chat-panel {
    display: none !important;
  }
}
