/* Clé des maths — interface mobile d'abord, impression des fiches. */
:root {
  --ink: #1b2a4a;
  --ink-soft: #46557a;
  --paper: #f6f4ee;
  --card: #ffffff;
  --line: #e2ddd0;
  --accent: #f5b82e;
  --accent-ink: #5c3d00;
  --ok: #1f7a4d;
  --ok-bg: #e3f4ea;
  --warn: #8a5300;
  --warn-bg: #fff1d6;
  --bad: #a3262a;
  --bad-bg: #fde8e8;
  --chip: #eef1f8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(27, 42, 74, 0.08), 0 4px 14px rgba(27, 42, 74, 0.06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--ink); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; margin-top: 1.4em; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.7em; }
ul { margin: 0 0 0.7em; padding-left: 1.3em; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.88rem; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.nav a { color: #fff; text-decoration: none; font-size: 0.88rem; padding: 6px 8px; border-radius: 999px; white-space: nowrap; }
@media (max-width: 480px) { .brand span { display: none; } .nav { gap: 0; } }
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, 0.14); }

.page { max-width: 760px; margin: 0 auto; padding: 18px 16px 80px; outline: none; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin: 0 0 14px; overflow-wrap: anywhere;
}
.hero { text-align: center; padding: 22px 16px; }
.hero p { color: var(--ink-soft); }

button, .button {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; text-decoration: none;
  background: var(--chip); color: var(--ink);
}
button.primary, .button.primary { background: var(--accent); color: #2b1d00; }
button.dark { background: var(--ink); color: #fff; }
button.ok { background: var(--ok-bg); color: var(--ok); }
button.bad { background: var(--bad-bg); color: var(--bad); }
button.link { background: none; min-height: 0; padding: 0; text-decoration: underline; font-weight: 500; }
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.big { width: 100%; min-height: 58px; font-size: 1.1rem; margin-top: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 0 0 auto; }
.stack > * + * { margin-top: 10px; }

label { display: block; font-weight: 600; margin: 10px 0 4px; }
input[type="text"], input[type="password"], input[type="search"], input:not([type]), textarea {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
textarea { min-height: 110px; resize: vertical; }
.hint { font-size: 0.85rem; color: var(--ink-soft); margin-top: 4px; }
.error { color: var(--bad); font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.badge {
  display: inline-block; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 2px 9px; border-radius: 999px; background: var(--chip); color: var(--ink-soft);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.level { background: var(--ink); color: #fff; }

.list { list-style: none; padding: 0; margin: 0; }
.list li a {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none;
}
.list li:last-child a { border-bottom: 0; }

.photo { width: 100%; max-height: 360px; object-fit: contain; border-radius: 10px; background: #eee; }
.preview { width: 100%; max-height: 320px; object-fit: contain; border-radius: 10px; margin-top: 10px; }

.spinner {
  width: 34px; height: 34px; border-radius: 50%; margin: 6px auto 10px;
  border: 4px solid var(--chip); border-top-color: var(--accent); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.step { position: relative; padding-left: 52px; }
.step-num {
  position: absolute; left: 14px; top: 16px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--ink); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 0.95rem;
}
.calc { background: #f8f7f3; border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 12px; margin: 8px 0; overflow-x: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  min-height: 34px; padding: 4px 12px; border-radius: 999px; font-size: 0.88rem; font-weight: 600;
  background: var(--chip); color: var(--ink);
}
.chip[aria-expanded="true"] { background: var(--ink); color: #fff; }
.answer { border: 2px solid var(--accent); background: #fffaf0; }

.fund { border-left: 5px solid var(--ink); }
.fund summary { cursor: pointer; list-style: none; }
.fund summary::-webkit-details-marker { display: none; }
.fund-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.fund-title { font-weight: 700; }
.retain { background: #fff8e6; border: 1px dashed var(--accent); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.retain-label { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-ink); }
.examples { margin: 6px 0 10px; }
.example { background: #f8f7f3; border-radius: 8px; padding: 8px 10px; margin: 6px 0; overflow-x: auto; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.notice { padding: 10px 12px; border-radius: 10px; margin: 8px 0; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.math-block { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.katex { font-size: 1.08em; }

.toast {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 20;
}
.qr { display: block; width: 220px; height: 220px; margin: 10px auto; background: #fff; border-radius: 8px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }

/* Fiches à apprendre (Bristol) */
.fiches { display: grid; grid-template-columns: 1fr; gap: 14px; }
.fiche {
  background: #fff; border: 1px solid #c9c2ae; border-radius: 6px; padding: 14px 16px;
  background-image: repeating-linear-gradient(to bottom, transparent 0 27px, #dfe9f5 27px 28px);
  background-position: 0 44px; break-inside: avoid; page-break-inside: avoid;
}
.fiche-top { display: flex; justify-content: space-between; gap: 8px; font-size: 0.8rem; color: var(--ink-soft); border-bottom: 2px solid #d9534f; padding-bottom: 6px; margin-bottom: 8px; }
.fiche h3 { margin: 4px 0 6px; }

@media (min-width: 720px) {
  .fiches { grid-template-columns: 1fr 1fr; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 10.5pt; }
  .no-print, .topbar, .toast, .nav { display: none !important; }
  .page { max-width: none; padding: 0; }
  .fiches { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; }
  .fiche { min-height: 128mm; box-shadow: none; }
  .fiche .actions { display: none; }
  .print-title { display: block !important; }
}
.print-title { display: none; }
