/* ---------- tokens ---------- */
:root {
  --fs: 20px;
  --ls: 0em;
  --lh: 1.7;

  --bg: #f7f7f4;
  --ink: #16222e;
  --muted: #4a5866;
  --surface: #ffffff;
  --edge: #74828f;       /* control borders, >= 3:1 on surface and backgrounds */
  --line: #d3dae0;       /* decorative dividers */
  --accent: #0f6b6e;
  --accent-press: #0a5457;
  --on-accent: #ffffff;
  --tint: #d9eceb;
  --tint-edge: #8cc4c2;
  --grid: #c3ced8;
  --focus: #9a4a00;

  --r-card: 1.25rem;
  --r-ctl: 0.85rem;
  --shadow: 0 1px 2px rgba(22, 34, 46, 0.06), 0 6px 18px rgba(22, 34, 46, 0.05);
}
:root[data-bg="creme"] { --bg: #f4ecd8; --grid: #d1c7a8; }
:root[data-bg="gris"]  { --bg: #e6e9ec; --grid: #b9c3cd; }
:root[data-bg="bleu"]  { --bg: #e0ecf5; --grid: #b2c5d6; }

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { font-size: var(--fs); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Verdana, sans-serif;
  letter-spacing: var(--ls);
  line-height: var(--lh);
  text-align: left;
  overflow-wrap: break-word;
}
#app {
  width: 100%;
  max-width: 38rem;
  margin: 0 auto;
  padding-inline: 1rem;
  padding-block: 1rem 3rem;
  outline: none;
}
h1, h2 { line-height: 1.25; margin: 0; font-weight: 700; }
h1 { font-size: 2.3rem; }
h2 { font-size: 1.5rem; outline: none; margin: 0.25rem 0 0.75rem; }
p { margin: 0.5rem 0; max-width: 58ch; }
.hint { color: var(--muted); font-size: 0.9rem; }

.screen.fade { animation: fade 0.2s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .screen.fade { animation: none; } }

.notice {
  background: #fdf1cf; color: #3d2f00; border-bottom: 2px solid #b8860b;
  padding: 0.75rem 1rem; text-align: left;
}

/* ---------- buttons ---------- */
button {
  font: inherit; font-weight: 600; letter-spacing: inherit; color: var(--ink);
  min-height: max(48px, 3rem); min-width: 48px;
  padding: 0.45rem 1.25rem;
  border: 2px solid var(--edge); border-radius: var(--r-ctl);
  background: var(--surface); cursor: pointer;
  touch-action: manipulation;
  overflow-wrap: break-word;
}
button:hover:not(:disabled) { background: var(--tint); border-color: var(--accent); }
button:active:not(:disabled) { background: var(--tint-edge); }
button:focus-visible, .select:focus-visible, .word:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.tile:disabled { opacity: 0.65; }

button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover:not(:disabled), button.primary:active:not(:disabled) { background: var(--accent-press); border-color: var(--accent-press); }
button.big { font-size: 1.1rem; min-height: 3.5rem; }

button.ghost { background: transparent; border-color: var(--edge); color: var(--ink); font-weight: 500; }
button.link {
  background: none; border-color: transparent; color: var(--accent-press);
  padding-inline: 0.5rem; font-weight: 600;
}
button.link:hover:not(:disabled) { background: transparent; border-color: transparent; text-decoration: underline; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin: 1.25rem 0 0.25rem; }
.row > button { flex: 0 1 auto; }
.icon { width: 1.15em; height: 1.15em; vertical-align: -0.2em; margin-right: 0.35em; flex: none; }

/* ---------- home ---------- */
.screen.home, .screen.pause {
  max-width: 28rem; margin-inline: auto;
  min-height: calc(100dvh - 4rem);
  display: flex; flex-direction: column; justify-content: center;
  padding-block: 1rem;
}
.brand { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.5rem; }
.logo { width: 4.25rem; height: 4.25rem; color: var(--accent); flex: none; }
.logo svg { width: 100%; height: 100%; display: block; }
.home .lead { font-size: 1.1rem; color: var(--muted); margin: 0.25rem 0 1.5rem; }
.home .cta { margin: 0; }
.home .cta button { width: 100%; max-width: 22rem; }
.home .secondary { margin-top: 1.5rem; gap: 0.5rem; }

/* ---------- problem screens ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; }
.topbar button.link { margin-left: -0.5rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem 1.5rem;
}

.phase { margin: 0 0 0.5rem; }
.phase-text { color: var(--muted); font-size: 0.85rem; margin: 0.4rem 0 0; }
.progress { display: flex; gap: 0.3rem; }
.progress span { flex: 1 1 0; max-width: 2.5rem; height: 0.35rem; border-radius: 99px; background: var(--line); }
.progress span.done { background: var(--tint-edge); }
.progress span.current { background: var(--accent); }

.qbox {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 0.5rem); z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 0.75rem;
  background: var(--tint); border: 1px solid var(--tint-edge); border-left: 6px solid var(--accent);
  border-radius: var(--r-ctl);
  padding: 0.6rem 0.75rem 0.6rem 1rem; margin: 0.5rem 0 1rem;
  box-shadow: var(--shadow);
  max-height: 45dvh; overflow-y: auto;
}
.qbox p { margin: 0; font-weight: 600; font-size: 0.95rem; line-height: 1.5; flex: 1 1 11rem; }
.qbox button { background: var(--surface); padding-inline: 0.9rem; }
.qbox.large { padding: 1.25rem 1.25rem 1rem 1.25rem; font-size: 1.3rem; }

/* statement */
.chunk {
  margin: 0.4rem 0; padding: 0.55rem 0.9rem;
  border-left: 4px solid transparent; border-radius: 0.6rem;
  max-width: 58ch;
}
.chunk.active { background: var(--tint); border-left-color: var(--accent); }
.word { all: unset; display: inline; cursor: pointer; padding: 0.25em 0.04em; border-radius: 0.25em; }
.word:hover { background: rgba(15, 107, 110, 0.12); }
.word.num { padding-inline: 0.2em; background: var(--tint); border-bottom: 2px dashed var(--accent); }
.word.num-b { font-weight: 700; }
.word.mark-relevant { padding-inline: 0.2em; background: var(--accent); color: var(--on-accent); font-weight: 700; border-bottom: 2px solid var(--accent); }
.word.mark-relevant::after { content: " ✓"; }
.word.mark-irrelevant { padding-inline: 0.2em; background: #e1e5e9; color: var(--muted); text-decoration: line-through; border-bottom: 2px solid transparent; }

/* choices */
.stack { display: flex; flex-direction: column; gap: 0.7rem; margin: 1rem 0; }
.stack > button { text-align: left; }
.choice, .tile { min-width: 0; display: flex; align-items: center; gap: 0.85rem; font-weight: 500; line-height: 1.4; padding-block: 0.7rem; }
.choice::before, .tile::before {
  content: ""; flex: none; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--edge); background: var(--surface);
}
.tile.has-badge::before { display: none; }
button[aria-pressed="true"] { background: var(--tint); border-color: var(--accent); font-weight: 600; }
button[aria-pressed="true"].choice::before, button[aria-pressed="true"].tile::before {
  border-color: var(--accent); background: var(--accent) radial-gradient(circle, var(--on-accent) 0 28%, transparent 32%);
}
.choice .txt, .tile .txt { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; font-size: 16px; letter-spacing: 0;
  background: var(--accent); color: var(--on-accent); font-weight: 700; flex: none;
}

/* calcul */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.4rem 0 0.75rem; }
.chip {
  background: var(--tint); border: 1px solid var(--tint-edge); border-radius: 99px;
  padding: 0.05rem 0.9rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.grid-canvas {
  display: block; width: 100%; height: 16rem; touch-action: none; margin-top: 1rem;
  background-color: var(--surface);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 1.6rem 1.6rem;
  border: 2px solid var(--edge); border-radius: var(--r-ctl);
}
.answer-display {
  display: flex; align-items: center; min-height: 4rem; margin: 1.25rem 0 0.75rem; padding: 0.4rem 1rem;
  background: var(--surface); border: 2px solid var(--accent); border-radius: var(--r-ctl);
  font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.keypad button { min-height: 3.6rem; font-size: 1.5rem; padding: 0; font-variant-numeric: tabular-nums; }

/* reveal */
.answer-line { font-size: 1.6rem; font-weight: 700; line-height: 1.3; margin: 0.5rem 0 0.75rem; color: var(--accent-press); }

/* ---------- settings ---------- */
fieldset, .setting {
  background: var(--surface); border: 1px solid var(--line); border-radius: 1rem;
  padding: 0.75rem 1.1rem 1rem; margin: 0.9rem 0; min-width: 0;
}
legend { font-weight: 700; padding: 0 0.4rem; margin-left: -0.4rem; }
.setting label { display: block; font-weight: 700; margin-bottom: 0.25rem; }
fieldset .row, .setting .row { margin: 0.5rem 0 0.25rem; gap: 0.5rem; }
fieldset .row button { padding-inline: 1rem; }
.select {
  font: inherit; letter-spacing: inherit; color: var(--ink); background: var(--surface);
  min-height: max(48px, 3rem); padding: 0.4rem 0.75rem; max-width: 100%; flex: 1 1 14rem;
  border: 2px solid var(--edge); border-radius: var(--r-ctl);
}

/* ---------- parents ---------- */
.stat { font-size: 1.15rem; font-weight: 700; }
.table-wrap {
  overflow-x: auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 1rem; padding: 0.25rem 1rem 0.5rem; margin: 0.9rem 0;
}
table { border-collapse: collapse; width: 100%; }
caption { text-align: left; font-weight: 700; padding: 0.75rem 0 0.25rem; }
th, td { padding: 0.45rem 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-weight: 500; padding-right: 1rem; }
td { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child th, tr:last-child td { border-bottom: none; }

@media (max-width: 30rem) {
  .choice, .tile { gap: 10px; padding-inline: 12px; }
  .card { padding: 1rem 1rem 1.25rem; }
  fieldset, .setting { padding-inline: 0.9rem; }
  h1 { font-size: 2rem; }
}
