:root {
  --bg: #0b0d12;
  --bg-soft: #141821;
  --fg: #f3f5f9;
  --muted: #8b94a7;
  --accent: #ff5c5c;
  --accent-soft: #ff8a5c;
  --good: #4cd5a3;
  --line: #232936;
  --radius: 16px;
  --max: 640px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(255, 92, 92, 0.18), transparent 60%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: var(--max);
  padding: 48px 24px 64px;
}

.hero { text-align: center; }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--accent-soft);
  margin: 0 0 14px;
  font-weight: 600;
}

.flag {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--fg);
  letter-spacing: 0.04em;
}

h1 {
  font-size: clamp(1.9rem, 6vw, 2.9rem);
  line-height: 1.1;
  margin: 0 0 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sub {
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto;
}

.sexsel {
  display: flex;
  gap: 5px;
  max-width: 460px;
  margin: 38px auto 0;
  padding: 5px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.sex-opt {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 11px 6px;
  border-radius: 11px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.sex-opt:hover { color: var(--fg); }

.sex-opt.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: #fff;
}

.srcsel { margin-top: 8px; }

.src-note {
  max-width: 460px;
  margin: 8px auto 0;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.4;
  text-align: center;
}

.form {
  display: flex;
  gap: 10px;
  margin: 12px auto 0;
  max-width: 460px;
}

.form input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 1.1rem;
  padding: 16px 18px;
  outline: none;
  transition: border-color 0.15s;
}

.form input:focus { border-color: var(--accent); }

.form button {
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0 26px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

.form button:hover { filter: brightness(1.08); }
.form button:active { transform: scale(0.97); }

.error {
  text-align: center;
  color: var(--accent);
  min-height: 1.2em;
  margin: 12px 0 0;
  font-size: 0.92rem;
}

.result {
  margin-top: 40px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 36px 28px;
  text-align: center;
  animation: rise 0.5s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-lead { color: var(--muted); margin: 0; font-size: 1rem; }

.result-number {
  font-size: clamp(3rem, 14vw, 5.5rem);
  font-weight: 800;
  line-height: 1;
  margin: 8px 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.03em;
}

.result-tail { margin: 0; font-size: 1.1rem; color: var(--fg); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 30px 0 24px;
}

.stat {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-label { font-size: 0.72rem; color: var(--muted); line-height: 1.3; }

.bar {
  display: flex;
  height: 26px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
}

.bar-dead,
.bar-alive {
  height: 100%;
  width: 0;
  transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}

.bar-dead { background: linear-gradient(90deg, var(--accent), var(--accent-soft)); }
.bar-alive { background: linear-gradient(90deg, var(--good), #6ee7c0); }

.legend {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin: 14px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-item span:first-child + span,
.legend span[id] { color: var(--fg); font-weight: 700; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-dead { background: var(--accent); }
.dot-alive { background: var(--good); }

.bar-caption { font-size: 0.8rem; color: var(--muted); margin: 16px 0 0; }

.chart { margin: 30px 0 0; padding: 0; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-caption { font-size: 0.8rem; color: var(--muted); line-height: 1.5; margin: 14px 0 0; }
.chart-caption b { color: var(--fg); }

/* éléments SVG du graphe */
.ch-axis { stroke: var(--line); stroke-width: 1; }
.ch-tick { fill: var(--muted); font-size: 9px; }
.ch-line { fill: none; stroke: var(--fg); stroke-width: 1.6; stroke-linejoin: round; }
.ch-past { fill: var(--accent); opacity: 0.32; }
.ch-future { fill: var(--muted); opacity: 0.14; }
.ch-mark { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 3; }
.ch-dot { fill: var(--accent); }
.ch-label { fill: var(--accent-soft); font-size: 10px; font-weight: 700; }

.explain-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 28px;
  padding: 18px 20px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--fg);
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}

.explain-banner:hover {
  border-color: var(--accent-soft);
  background: #181d28;
}

.explain-banner:active { transform: scale(0.99); }

.explain-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex: none;
}

.explain-text { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.explain-title { font-weight: 700; font-size: 1rem; }
.explain-sub { color: var(--muted); font-size: 0.84rem; line-height: 1.4; }

.explain-arrow {
  font-size: 1.3rem;
  color: var(--accent-soft);
  flex: none;
  transition: transform 0.15s;
}

.explain-banner:hover .explain-arrow { transform: translateX(4px); }

.footer {
  margin-top: 48px;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

.footer a { color: var(--accent-soft); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ───────────────────────── Page « Comprendre le calcul » ───────────────────────── */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 28px;
  transition: color 0.15s;
}
.back-link:hover { color: var(--fg); }

.method h1 {
  font-size: clamp(1.7rem, 5.5vw, 2.5rem);
  text-align: left;
}

.method .lead {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
  margin: 0 0 8px;
}

.step {
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.step:first-of-type { border-top: none; }

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  margin-right: 10px;
  vertical-align: middle;
}

.step h2 {
  display: inline;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.step p {
  color: var(--fg);
  line-height: 1.65;
  font-size: 0.98rem;
  margin: 16px 0;
}

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

.formula {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin: 22px 0;
  font-family: "SF Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 1rem;
  line-height: 1.7;
  overflow-x: auto;
  color: var(--fg);
}

.formula .var { color: var(--accent-soft); font-weight: 600; }
.formula .cmt { color: var(--muted); }

.note {
  background: rgba(255, 92, 92, 0.07);
  border: 1px solid rgba(255, 92, 92, 0.25);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--fg);
  margin: 22px 0;
}

.note strong { color: var(--accent-soft); }

/* Exemple interactif */
.try {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 22px;
  margin: 22px 0;
}

.try-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.try-controls label { font-size: 0.92rem; color: var(--muted); }

.try-controls input {
  width: 120px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--fg);
  font-size: 1.05rem;
  padding: 10px 14px;
  outline: none;
}
.try-controls input:focus { border-color: var(--accent); }

.try-summary {
  margin: 18px 0 8px;
  font-size: 1.02rem;
  line-height: 1.7;
}
.try-summary b { color: var(--accent-soft); }

.method-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0 4px;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.method-table th,
.method-table td {
  text-align: right;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.method-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.method-table td:first-child,
.method-table th:first-child { text-align: left; }

.method-table tbody tr:last-child td { border-bottom: none; }
.method-table .row-final td {
  border-top: 1px solid var(--line);
  font-weight: 700;
  color: var(--fg);
}
.method-table .q-col { color: var(--accent-soft); }

.table-caption { color: var(--muted); font-size: 0.8rem; margin: 8px 0 0; line-height: 1.5; }

@media (max-width: 460px) {
  .form { flex-direction: column; }
  .form button { padding: 14px; }
  .stat-value { font-size: 1.05rem; }
  .method-table { font-size: 0.78rem; }
  .method-table th, .method-table td { padding: 6px 6px; }
}
