:root {
  --paper: #E6E7E3;
  --card: #EFF0EC;
  --ink: #161715;
  --mute: #6B6E68;
  --line: #C4C6C0;
  --accent: #CEFF1A;
  --on-accent: #161715;
  --f: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141513; --card: #1C1D1B; --ink: #E7E8E3; --mute: #8E918A; --line: #2F312D;
  }
}
:root[data-theme="dark"] { --paper: #141513; --card: #1C1D1B; --ink: #E7E8E3; --mute: #8E918A; --line: #2F312D; }

*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--paper); color: var(--ink);
  font-family: var(--f); font-size: 16px; line-height: 1.5;
  font-variation-settings: "wdth" 100;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
a { color: inherit; }

.wrap { max-width: 1320px; margin: 0 auto; padding: 0 clamp(20px, 4vw, 56px); }

/* En-tête */
.top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 26px 0 22px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.brand-mark {
  font-weight: 800; font-stretch: 68%; font-variation-settings: "wdth" 68;
  font-size: 1.35rem; letter-spacing: -0.01em;
}
.brand-name { color: var(--mute); font-size: .95rem; }
.top-link { color: var(--mute); font-size: .95rem; text-decoration: none; }
.top-link:hover { color: var(--ink); }

/* Grille principale */
.grid {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 390px);
  gap: clamp(32px, 5vw, 88px); padding: clamp(36px, 6vw, 72px) 0 96px;
}
.left { min-width: 0; }

/* Phrase */
.phrase {
  margin: 0; max-width: 24ch;
  font-size: clamp(1.9rem, 4.3vw, 3.7rem); line-height: 1.08; letter-spacing: -0.018em;
  font-weight: 300; font-variation-settings: "wdth" 88; color: var(--mute);
  text-wrap: pretty;
}
.phrase .lead { color: var(--ink); }
.tok {
  display: inline; cursor: pointer; -webkit-box-decoration-break: clone; box-decoration-break: clone; padding: 0; margin: 0; border: 0; background: none;
  font: inherit; font-weight: 750; font-variation-settings: "wdth" 72; color: var(--ink);
  letter-spacing: -0.01em; line-height: inherit;
  text-decoration: underline; text-decoration-thickness: .06em; text-underline-offset: .14em;
  text-decoration-color: var(--line); border-radius: 2px;
  transition: background-color .2s var(--ease), text-decoration-color .2s var(--ease);
}
.tok:hover { background: var(--accent); color: var(--on-accent); text-decoration-color: transparent; }
.tok.soft { color: var(--mute); }
.tok.blank { color: var(--line); text-decoration: none; letter-spacing: .02em; }
.tok.active { text-decoration-color: var(--ink); text-decoration-thickness: .08em; }
.tok.blank.active { color: var(--ink); }

/* Question */
.q { margin-top: clamp(40px, 6vw, 72px); border-top: 1px solid var(--line); padding-top: 22px; }
.q-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.q-step { font-size: .85rem; color: var(--mute); font-variant-numeric: tabular-nums; }
.q-back { border: 0; background: none; padding: 0; color: var(--mute); font-size: .9rem; text-decoration: underline; text-underline-offset: 3px; }
.q-back:hover { color: var(--ink); }
.q-title { margin: 0 0 22px; font-size: clamp(1.25rem, 2vw, 1.55rem); font-weight: 600; font-variation-settings: "wdth" 96; letter-spacing: -0.01em; line-height: 1.2; }
.q-hint { margin: -12px 0 22px; color: var(--mute); max-width: 60ch; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left;
  min-height: 96px; padding: 16px 16px 18px; border: 1px solid var(--line); border-radius: 3px;
  background: var(--card);
  transition: border-color .18s var(--ease), background-color .18s var(--ease), color .18s var(--ease), transform .18s var(--ease);
}
.card.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.card-l { font-weight: 650; line-height: 1.25; font-variation-settings: "wdth" 94; }
.card-d { font-size: .86rem; line-height: 1.35; color: var(--mute); }
.card.on .card-d { color: inherit; opacity: .7; }

.cards.visual { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.card.visual { align-items: center; text-align: center; justify-content: flex-end; min-height: 128px; padding: 14px 10px 14px; }
.card.visual svg { display: block; margin-bottom: 8px; color: inherit; }
.card.visual .card-l { font-size: .9rem; font-weight: 600; }
.card.visual .card-d { font-size: .78rem; }
.scale-note { margin: 14px 0 0; font-size: .82rem; color: var(--mute); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 11px 15px; border: 1px solid var(--line); border-radius: 3px; background: var(--card);
  font-variant-numeric: tabular-nums; font-size: .95rem;
  transition: border-color .18s var(--ease), background-color .18s var(--ease), color .18s var(--ease);
}
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.over { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.over label { color: var(--mute); font-size: .92rem; }

.num {
  width: 12ch; padding: 11px 14px; border: 1px solid var(--ink); border-radius: 3px;
  background: var(--card); color: var(--ink); font: inherit; font-variant-numeric: tabular-nums;
}
.stepper { display: flex; align-items: center; gap: 0; }
.stepper button {
  width: 52px; height: 56px; border: 1px solid var(--line); background: var(--card); font-size: 1.4rem; line-height: 1;
}
.stepper button:hover { border-color: var(--ink); }
.stepper button:first-child { border-radius: 3px 0 0 3px; }
.stepper button:last-child { border-radius: 0 3px 3px 0; }
.stepper input {
  width: 96px; height: 56px; border: 1px solid var(--line); border-left: 0; border-right: 0; text-align: center;
  background: var(--card); color: var(--ink);
  font: inherit; font-size: 1.6rem; font-weight: 750; font-variation-settings: "wdth" 72; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.count-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.count-unit { color: var(--mute); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border: 1px solid var(--ink); border-radius: 3px; background: var(--ink); color: var(--paper);
  font-weight: 600; font-size: .95rem;
}
.btn:hover { opacity: .88; }
.btn.ghost { background: transparent; color: inherit; border-color: currentColor; }
.btn[disabled] { opacity: .35; cursor: not-allowed; }

.opts { display: grid; gap: 8px; }
.opt {
  display: flex; align-items: flex-start; gap: 14px; text-align: left;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 3px; background: var(--card);
}
.opt-box {
  flex: none; width: 20px; height: 20px; margin-top: 1px; border: 1.5px solid var(--ink); border-radius: 2px;
  display: grid; place-items: center;
}
.opt.on .opt-box { background: var(--ink); }
.opt.on .opt-box::after { content: ""; width: 9px; height: 5px; border: solid var(--paper); border-width: 0 0 2px 2px; transform: rotate(-45deg) translate(1px, -1px); }
.opt-l { font-weight: 600; }
.opt-d { display: block; font-size: .86rem; color: var(--mute); }
.done-msg { color: var(--mute); max-width: 56ch; margin: 0 0 24px; }

/* Survol : même logique que la phrase, fond chartreuse */
.card, .chip, .opt { transition: border-color .18s var(--ease), background-color .18s var(--ease), color .18s var(--ease), transform .18s var(--ease); }
.card:hover, .chip:hover, .opt:hover {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
  transform: translateY(-2px);
}
.card:hover .card-d, .opt:hover .opt-d { color: var(--on-accent); opacity: .7; }
.opt:hover .opt-box { border-color: var(--on-accent); }
.card.on:hover, .chip.on:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.card.on:hover .card-d { color: inherit; }

/* Plusieurs lignes */
.phrases { display: flex; flex-direction: column; }
.pm {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 28px; align-items: baseline; gap: 14px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.pm:first-child { border-top: 1px solid var(--line); }
.pm-txt {
  border: 0; background: none; padding: 0; text-align: left; color: var(--mute);
  font-size: clamp(1rem, 1.35vw, 1.18rem); line-height: 1.4; font-variation-settings: "wdth" 90;
  transition: color .18s var(--ease);
}
.pm-txt:hover { color: var(--ink); }
.pm-amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pm-del {
  width: 28px; height: 28px; border: 0; border-radius: 2px; background: none; color: var(--mute);
  font-size: 1.25rem; line-height: 1; opacity: 0; transition: opacity .18s var(--ease), background-color .18s var(--ease);
}
.pm:hover .pm-del, .pm-del:focus-visible { opacity: 1; }
.pm-del:hover { background: var(--accent); color: var(--on-accent); }
@media (hover: none) { .pm-del { opacity: 1; } }
.pm + .phrase { margin-top: 32px; }
.phrase + .pm { margin-top: 32px; }
.add-line {
  align-self: flex-start; margin: 26px 0 0 -4px; padding: 2px 6px; border: 0; border-radius: 2px; background: none;
  color: var(--mute); font-size: clamp(1.15rem, 2vw, 1.6rem); font-weight: 700; font-variation-settings: "wdth" 76;
  letter-spacing: -0.01em; transition: background-color .18s var(--ease), color .18s var(--ease);
}
.add-line:hover { background: var(--accent); color: var(--on-accent); }
.done-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.line-h { display: flex; justify-content: space-between; gap: 12px; color: var(--ink); }
.line-link { border: 0; background: none; padding: 0; color: var(--mute); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.blk.is-cur .line-link { color: var(--ink); text-decoration: none; }
.blk.is-cur .line-link::before { content: "● "; color: var(--ink); }
.blk-p { margin: 0; font-size: .92rem; }

/* Panneau résultat */
.right { position: relative; }
.sticky { position: sticky; top: calc(24px + env(safe-area-inset-top, 0px)); }
.panel {
  background: var(--accent); color: var(--on-accent); border-radius: 3px;
  padding: 24px 24px 22px;
}
.panel-k { font-size: .88rem; display: flex; justify-content: space-between; gap: 12px; }
.amount {
  margin: 14px 0 4px; min-height: 1em;
  font-size: clamp(3.2rem, 5.6vw, 5.4rem); line-height: .92; letter-spacing: -0.035em;
  font-weight: 800; font-variation-settings: "wdth" 64; font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.amount.small { font-size: clamp(2.4rem, 4vw, 3.4rem); }
.amount .u { font-size: .34em; font-weight: 700; letter-spacing: 0; margin-left: .18em; font-variation-settings: "wdth" 80; }
.panel-sub { margin: 10px 0 0; font-size: .95rem; line-height: 1.4; max-width: 34ch; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.panel .btn { background: var(--on-accent); color: var(--accent); border-color: var(--on-accent); }
.panel .btn.ghost { background: transparent; color: var(--on-accent); }
.panel .btn[disabled] { background: transparent; color: var(--on-accent); border-color: currentColor; opacity: .3; }

.details { margin-top: 26px; }
.blk + .blk { margin-top: 24px; }
.blk-h { margin: 0 0 10px; font-size: .88rem; font-weight: 600; color: var(--mute); }
.trace { list-style: none; margin: 0; padding: 0; }
.trace li {
  display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--line);
  font-size: .92rem; line-height: 1.35;
}
.trace li span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.trace li.total { border-bottom: 0; font-weight: 700; }
.notes { margin: 0; padding: 0 0 0 1.1em; font-size: .92rem; line-height: 1.45; }
.notes li + li { margin-top: 6px; }
details.blk summary { cursor: pointer; font-size: .88rem; font-weight: 600; color: var(--mute); list-style: none; }
details.blk summary::-webkit-details-marker { display: none; }
details.blk summary::before { content: "+"; display: inline-block; width: 1.1em; }
details.blk[open] summary::before { content: "−"; }
details.blk .notes { margin-top: 10px; color: var(--mute); }

/* Pied */
.foot { border-top: 1px solid var(--line); padding: 28px 0 48px; color: var(--mute); font-size: .88rem; line-height: 1.55; }
.foot p { max-width: 72ch; margin: 0 0 10px; }

/* Barre mobile */
.mbar { display: none; }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); padding-bottom: 40px; }
  .sticky { position: static; }
  .phrase { max-width: none; }
  .mbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    padding: 12px clamp(20px, 4vw, 56px) calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--accent); color: var(--on-accent);
    transform: translateY(0); transition: transform .3s var(--ease);
  }
  .mbar.hide { transform: translateY(110%); }
  .mbar-amount { font-weight: 800; font-size: 1.6rem; font-variation-settings: "wdth" 64; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
  .mbar a { font-size: .92rem; font-weight: 600; }
  body { padding-bottom: 76px; }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
  .cards.visual { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card { min-height: 0; }
  .brand-name { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
