/* RTFM — Read The Funny Manual
   Sobre, façon markdown, couleurs EPFL (rouge, gris).
   Thème clair par défaut, thème sombre via la case « dark mode ». */

:root {
  --red: #D8343A;          /* rouge EPFL adouci */
  --red-hover: #B51F1F;    /* groseille EPFL */
  --bg: #FFFFFF;
  --surface: #FAFAFA;
  --ink: #212121;          /* gris EPFL très foncé */
  --muted: #6B6B6B;
  --line: #E2E2E2;
  --comment: #8F8F8F;
  --green: #1E7B3A;
  --green-bg: #E9F5EC;
  --blue: #1F5FAD;
  --blue-bg: #E8F0FA;
  --amber: #A15C00;
  --amber-bg: #FFF4E0;
  --tip-bg: #212121;
  --tip-ink: #FFFFFF;
  --font: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --red: #EF5D60;
  --red-hover: #FF8A8C;
  --bg: #161616;
  --surface: #1D1D1D;
  --ink: #E8E8E8;
  --muted: #A0A0A0;
  --line: #333333;
  --comment: #7A7A7A;
  --green: #5CCB7E;
  --green-bg: #15291C;
  --blue: #6FA8EE;
  --blue-bg: #14223A;
  --amber: #F2B24C;
  --amber-bg: #2E2312;
  --tip-bg: #E8E8E8;
  --tip-ink: #161616;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  border-top: 5px solid var(--red);
  transition: background .2s, color .2s;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 48px 32px 32px;
}

a { color: inherit; text-decoration: none; }
a:focus-visible, .pill:focus-visible, .theme-toggle input:focus-visible + .box {
  outline: 2px solid var(--red); outline-offset: 3px;
}

.md { color: var(--red); font-weight: 400; }

/* ---------- Masthead ---------- */
.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.subtitle { margin: 0; color: var(--muted); font-size: 0.9rem; font-variant-ligatures: none; }
.subtitle .md { color: var(--comment); }

/* Machine à écrire */
.type-caret {
  display: none;
  width: 0.55em;
  height: 1.1em;
  margin-left: 1px;
  vertical-align: -0.2em;
  background: var(--red);
  animation: blink 0.9s steps(1) infinite;
}
.subtitle.typing .type-caret { display: inline-block; }
.subtitle.typing .close-comment { opacity: 0; }
.subtitle.typed-done .close-comment { animation: fadein .3s ease-out; }
@keyframes fadein { from { opacity: 0; } }

h1 {
  margin: 4px 0 0;
  font-size: clamp(2rem, 9.5vw, 5.5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}
.cursor { color: var(--red); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }

.tagline { margin: 14px 0 0; color: var(--muted); font-size: 0.95rem; }

/* Case « dark mode » façon markdown [ ] / [x] */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}
.theme-toggle:hover { color: var(--ink); }
.theme-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.theme-toggle .box::before { content: "[ ]"; color: var(--comment); }
.theme-toggle input:checked + .box::before { content: "[x]"; color: var(--red); }

/* ---------- Navigation : simples liens texte ---------- */
.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin-top: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.nav a {
  color: var(--muted);
  border-bottom: 1px solid transparent;
  transition: color .15s, border-color .15s;
}
.nav a:hover { color: var(--ink); border-bottom-color: var(--comment); }
.nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom: 2px solid var(--red);
}
.nav .sep { color: var(--line); }
.nav a[aria-current="page"] {
  padding: 0 8px;
  background: var(--red);
  color: #FFFFFF;
  border-bottom: none;
  border-radius: 2px;
}
.nav .ext { font-size: 0.8em; color: var(--comment); }


/* ---------- Grille des sections ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin-top: 40px;
}

.card {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
}

h2 { margin: 0 0 16px; font-size: 1.3rem; font-weight: 800; }

.links { list-style: none; margin: 0; padding: 0; }
.links li { padding: 8px 0; }
.links li + li { border-top: 1px dashed var(--line); }

.links a {
  font-weight: 600;
  font-size: 1.02rem;
  transition: color .15s;
}
.links a:hover { color: var(--red-hover); }
.arrow { color: var(--red); margin-right: 6px; display: inline-block; transition: transform .15s; }
.links a:hover .arrow { transform: translateX(3px); }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin: 2px 0 0 28px;
}
.comment { color: var(--comment); font-size: 0.82rem; font-style: italic; }
.folder { color: var(--comment); font-weight: 400; }
.desc {
  margin: 6px 0 0 28px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.55;
}

/* Choix de la source : [ ] / [x] façon markdown */
.source {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 16px 0 0;
  padding: 12px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}
.source label { color: var(--muted); cursor: pointer; user-select: none; }
.source label:hover { color: var(--ink); }
.source input { position: absolute; opacity: 0; pointer-events: none; }
.source .radio::before { content: "[ ]"; color: var(--comment); }
.source input:checked + .radio::before { content: "[x]"; color: var(--red); }
.source label:has(input:checked) { color: var(--ink); font-weight: 600; }
.source input:focus-visible + .radio { outline: 2px solid var(--red); outline-offset: 2px; }

.quick {
  list-style: none;
  margin: 16px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}
.quick a { color: var(--muted); }
.quick a:hover { color: var(--ink); }
.tick { color: var(--comment); }
.quick a:hover .tick { color: var(--red); }

/* ---------- Pastilles d'accès ---------- */
.pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  padding: 0 6px;
  vertical-align: 2px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.58rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.6;
  white-space: nowrap;
  cursor: help;
}
.pill::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.pill.public { color: var(--green); background: var(--green-bg); }
.pill.ask    { color: var(--blue);  background: var(--blue-bg); }
.pill.warn   { color: var(--amber); background: var(--amber-bg); }
.pill.warn::before { display: none; }
.links a.todo { color: var(--muted); cursor: default; }
.links a.todo:hover { color: var(--muted); }
.links a.todo:hover .arrow { transform: none; }

/* Explication visible seulement au survol */
.pill::after {
  content: attr(data-tip);
  position: absolute;
  left: -4px;
  bottom: calc(100% + 8px);
  transform: translateY(4px);
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--tip-bg);
  color: var(--tip-ink);
  font-size: 0.75rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.4;
  width: max-content;
  max-width: 240px;
  white-space: normal;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
  z-index: 2;
}
.pill:hover::after, .pill:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Popups ---------- */
.popup {
  width: min(440px, calc(100vw - 32px));
  padding: 32px 28px 28px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--red);
  border-radius: 4px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.popup[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.popup::backdrop { background: rgba(20, 20, 20, .45); backdrop-filter: blur(2px); }
.popup h2 { margin: 12px 0 8px; font-size: 1.2rem; }
.popup-text { margin: 0; color: var(--muted); font-size: 0.92rem; }
.popup-comment { margin: 12px 0 0; color: var(--comment); font-size: 0.8rem; font-style: italic; }

.close {
  position: absolute;
  top: 10px; right: 12px;
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--comment);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.close:hover { color: var(--red); }

.pixel-icon { display: block; margin: 0 auto; image-rendering: pixelated; }

.hammer {
  transform-box: view-box;
  transform-origin: 22px 14px;
  animation: swing .9s cubic-bezier(.5, 0, .9, .4) infinite;
}
@keyframes swing {
  0%   { transform: rotate(40deg); }
  55%  { transform: rotate(0deg); }
  65%  { transform: rotate(6deg); }
  100% { transform: rotate(40deg); }
}
.sparks { opacity: 0; animation: sparks .9s steps(1) infinite; }
@keyframes sparks { 0% { opacity: 0; } 55% { opacity: 1; } 75% { opacity: 0; } }

.envelope { animation: bob 1.6s steps(2) infinite; }
@keyframes bob { 50% { transform: translateY(-1px); } }
.blip { animation: blink 1s steps(1) infinite; }

@media (prefers-reduced-motion: reduce) {
  .hammer, .sparks, .envelope, .blip { animation: none; }
  .sparks { opacity: 1; }
}

.mail-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}
.mail {
  font-weight: 600;
  border-bottom: 1px solid transparent;
}
.mail:hover { color: var(--red-hover); border-bottom-color: currentColor; }
.copy {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.copy:hover { color: var(--ink); border-color: var(--comment); }

/* ---------- Footer ---------- */
.foot {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 56px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .page { padding: 32px 16px 24px; }
  .masthead { flex-direction: column-reverse; gap: 12px; }
  .theme-toggle { align-self: flex-end; margin-top: 0; }
  .grid { grid-template-columns: 1fr; gap: 16px; margin-top: 28px; }
  .nav .sep { display: none; }
  .nav { gap: 8px 16px; }
  .card { padding: 20px 16px; }
}
