:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #1f2430;
  --muted: #5d6475;
  --accent: #1e3c78;
  --line: #d9d4c7;
  --c1: #2f6fdb;
  --c2: #e07a1f;
  --good: #1f9d55;
  --bad: #d23c3c;
  --card: #ffffff;
  --card-edge: #1e3c78;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181f; --panel: #1f232c; --ink: #e8e9ee; --muted: #a2a8b8;
    --accent: #8fb0ff; --line: #363b48; --card-edge: #8fb0ff;
  }
}
:root[data-theme="dark"] {
  --bg: #15181f; --panel: #1f232c; --ink: #e8e9ee; --muted: #a2a8b8;
  --accent: #8fb0ff; --line: #363b48; --card-edge: #8fb0ff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
h1 { margin: 0; font-size: 1.25rem; color: var(--accent); }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { border: 0; background: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; }
nav button.active { background: var(--accent); color: var(--panel); }
main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 24px; }
footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 12px 16px 24px; }
footer a { color: var(--accent); }

button, select, input {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--panel); border-color: var(--accent); }
input[type=number] { width: 4.5em; }

.tab { display: none; }
.tab.active { display: block; }
.tab-title { text-align: center; font-size: 1.3rem; margin: 10px 0 6px; }
.intro { margin: 4px 0 12px; max-width: 70ch; }
.intro.wide { max-width: none; }
.controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 8px 0; }
.controls.center { justify-content: center; }
.controls label { display: flex; align-items: center; gap: 6px; }
.controls[hidden], button[hidden] { display: none; }
#plan-by-num input { width: 4.5em; }
#plan-by-num input.bad { outline: 2px solid #d33; }
.eq { color: var(--muted); min-width: 8em; }
.status { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--muted); min-height: 1.5em; font-variant-numeric: tabular-nums; }
button.quiet { background: none; color: var(--muted); font-size: 0.9rem; }
button.big { font-size: 1.2rem; padding: 10px 24px; }

/* ---------- Fin de partie ---------- */
.end { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  max-width: 34rem; margin: 24px auto; padding: 24px 16px 28px; }
.end-title { font-size: 1.4rem; color: var(--accent); font-weight: 600; }
.end-score { font-size: clamp(3rem, 16vw, 5.5rem); font-weight: 700; line-height: 1.1; margin: 12px 0 4px;
  font-variant-numeric: tabular-nums; color: var(--ink); }
.end-detail { color: var(--muted); }
.end-record { min-height: 1.5em; margin: 10px 0 18px; font-weight: 600; color: var(--good); }
.msg { text-align: center; min-height: 1.5em; margin: 6px 0; }

/* ---------- Cartes ---------- */
.board { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 8px 0; }
.card-box { width: min(46vw, 70vh, 480px); aspect-ratio: 1; }
@media (orientation: portrait) {
  .card-box { width: min(88vw, 34vh, 480px); }
}
.board.small .card-box { width: min(42vw, 220px); }
svg.card { width: 100%; height: 100%; display: block; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.card-bg { fill: var(--card); stroke: var(--card-edge); stroke-width: 0.025; }
.card-box.c1 .card-bg { stroke: var(--c1); stroke-width: 0.05; }
.card-box.c2 .card-bg { stroke: var(--c2); stroke-width: 0.05; }
.item .halo { fill: none; }
.item { pointer-events: none; }
svg.card.clickable { cursor: pointer; }
.item.found .halo { fill: none; stroke: var(--good); stroke-width: 0.03; }
.item.wrong { animation: wrong 0.4s; }
@keyframes wrong {
  0%, 100% { opacity: 1; }
  30% { opacity: 0.25; }
}
.item.wrong .halo { fill: rgba(210, 60, 60, 0.18); }

/* ---------- Explications ---------- */
.explain { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 14px; margin: 10px auto; max-width: 70ch; }
.explain .eq { font-family: "Cambria Math", Georgia, serif; font-style: italic; white-space: nowrap; }
.explain .answer { display: flex; align-items: center; gap: 8px; }
.explain .answer img { width: 40px; height: 40px; object-fit: contain; }
.explain-title { margin: 16px 0 4px; font-size: 1rem; }
.cardinfo p { margin: 10px 0 4px; }
.calc { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; flex-direction: column; align-items: center; min-width: 54px; padding: 4px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 0.85rem; line-height: 1.2; }
.chip img { width: 34px; height: 34px; object-fit: contain; }
.chip small { color: var(--muted); white-space: nowrap; }
.chip.coord b { font-size: 1.3rem; font-weight: 600; white-space: nowrap; padding: 4px 2px 2px; }
.chip.coord small { font-size: 0.75rem; }
.chip.common { border-color: var(--good); border-width: 2px; background: color-mix(in srgb, var(--good) 14%, var(--panel)); }
.rules { margin: 10px 0; }
.rules summary { cursor: pointer; color: var(--accent); }
.rules ul { padding-left: 1.2em; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.note { color: var(--muted); font-size: 0.9rem; }

/* ---------- Plan projectif ---------- */
.plan-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 760px) {
  .plan-layout { grid-template-columns: 1fr; }
  h1 { font-size: 1.05rem; }
  header { padding: 6px 16px; }
  .controls { margin: 4px 0; gap: 6px 10px; }
}
.grid-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
svg.grid { width: 100%; height: auto; display: block; }
.caption { margin: 4px 8px; color: var(--muted); font-size: 0.85rem; }
.affine-bg { fill: none; stroke: var(--line); stroke-width: 0.03; }
.grid .dot { fill: var(--muted); opacity: 0.6; }
.infinity-bg { fill: none; stroke: var(--muted); stroke-width: 0.03; stroke-dasharray: 0.12 0.08; }
.gridline { stroke: var(--line); stroke-width: 0.02; }
.part-title { fill: var(--ink); text-anchor: middle; font-weight: 600; }
.axis { font-size: 0.3px; fill: var(--muted); text-anchor: middle; }
.axis-name { font-size: 0.3px; fill: var(--muted); text-anchor: middle; font-style: italic; }
.inf-label { font-size: 0.24px; fill: var(--muted); text-anchor: middle; }
.label { font-size: 0.32px; fill: var(--ink); text-anchor: middle; dominant-baseline: middle; }
.label.tiny { font-size: 0.26px; }
.mark.c1 { fill: color-mix(in srgb, var(--c1) 30%, transparent); stroke: var(--c1); stroke-width: 0.04; }
.mark.c2 { fill: color-mix(in srgb, var(--c2) 30%, transparent); stroke: var(--c2); stroke-width: 0.04; }
.mark.both { fill: color-mix(in srgb, var(--good) 35%, transparent); stroke: var(--good); stroke-width: 0.08; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.swatch.c1 { background: var(--c1); }
.swatch.c2 { background: var(--c2); }
#plan select { max-width: 52vw; }

/* ---------- Tables ---------- */
.tables { display: flex; flex-wrap: wrap; gap: 8px 32px; }
.tables h3 { font-size: 1rem; margin: 8px 0; }
.tables > div { max-width: 100%; overflow-x: auto; }
table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { width: 2em; height: 1.8em; text-align: center; border: 1px solid var(--line); }
th { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
td.one { background: color-mix(in srgb, var(--good) 30%, var(--panel)); font-weight: 600; }
table.small th, table.small td { min-width: 2em; }
tr.noinv td { background: color-mix(in srgb, var(--muted) 25%, var(--panel)); }
