/* Reste Net — thème « papier crayon » (clair) et « ardoise craie » (sombre).
   Polices : Caveat (titres, chiffres) et Patrick Hand (texte), licence SIL OFL, fichiers dans fonts/. */
@font-face { font-family: 'Caveat'; font-style: normal; font-weight: 400 700; font-display: swap; src: url(fonts/caveat.woff2) format('woff2'); }
@font-face { font-family: 'Patrick Hand'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/patrick-hand.woff2) format('woff2'); }

:root {
  --paper: #f4eee1; --card: #fbf7ee; --ink: #2b2b30; --pencil: #5f5c57; --line: #9a958b; --line-soft: #cfc8b8;
  --accent: #2f5f8f; --accent-ink: #fbf7ee; --accent-soft: #dfe9f2;
  --marker: #ffe76a; --marker-soft: #fff3b0; --best: #fff6c4; --best-line: #d1b000;
  --red: #c0392b; --danger: #b42318; --warn: #8a5a00;
  --note: #fff2a0; --note-ink: #2b2b30;
  --shadow: 4px 4px 0 rgba(43, 43, 48, .12); --btn-shadow: 3px 3px 0 var(--ink);
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.25  0 0 0 0 0.22  0 0 0 0 0.18  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --wobble: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wobble-2: 15px 225px 15px 255px / 255px 15px 225px 15px;
  --wobble-pill: 120px 20px 110px 20px / 20px 110px 20px 120px;
  --font-hand: 'Patrick Hand', 'Segoe Print', 'Bradley Hand', 'Chalkboard', cursive;
  --font-title: 'Caveat', 'Segoe Script', 'Bradley Hand', cursive;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #243331; --card: #2c3d3b; --ink: #f1ede1; --pencil: #cfc9b8; --line: #8e9b97; --line-soft: #4a5c59;
    --accent: #9fd6c9; --accent-ink: #1c2a28; --accent-soft: #35504b;
    --marker: #e8d26a; --marker-soft: #5a5530; --best: #44502c; --best-line: #c9b24a;
    --red: #ff8f7a; --danger: #ff8f7a; --warn: #e6c36a;
    --shadow: none; --btn-shadow: 3px 3px 0 rgba(241, 237, 225, .35);
    --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 0.9  0 0 0 .10 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  }
}
:root[data-theme="dark"] {
  --paper: #243331; --card: #2c3d3b; --ink: #f1ede1; --pencil: #cfc9b8; --line: #8e9b97; --line-soft: #4a5c59;
  --accent: #9fd6c9; --accent-ink: #1c2a28; --accent-soft: #35504b;
  --marker: #e8d26a; --marker-soft: #5a5530; --best: #44502c; --best-line: #c9b24a;
  --red: #ff8f7a; --danger: #ff8f7a; --warn: #e6c36a;
  --shadow: none; --btn-shadow: 3px 3px 0 rgba(241, 237, 225, .35);
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 0.9  0 0 0 .10 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light dark; }
body { margin: 0; font-family: var(--font-hand); font-size: 1.08rem; background: var(--paper); background-image: var(--grain); color: var(--ink); line-height: 1.4; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
h1 { font-family: var(--font-title); font-weight: 700; font-size: 2.1rem; line-height: 1; margin: 0; text-decoration: underline wavy var(--marker); text-decoration-thickness: 3px; text-underline-offset: 5px; }
h2 { font-family: var(--font-title); font-weight: 700; font-size: 1.65rem; line-height: 1.1; margin: 0 0 .9rem; display: flex; align-items: center; gap: .6rem; }
h3 { font-family: var(--font-title); font-weight: 700; font-size: 1.35rem; margin: 1.3rem 0 .5rem; color: var(--pencil); }
h4 { font-family: var(--font-title); font-weight: 700; font-size: 1.25rem; margin: 0 0 .4rem; }
.num { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border: 2px solid var(--ink); border-radius: 48% 52% 50% 50% / 52% 48% 52% 48%; font-size: 1.05rem; transform: rotate(-6deg); }
.tagline { margin: .5rem 0 0; color: var(--pencil); font-size: 1rem; }
.hint { color: var(--pencil); font-size: .95rem; margin: .6rem 0 0; }
.warn { color: var(--warn); }
.spacer { flex: 1; }

.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem; padding: 16px 16px 10px; max-width: 1040px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: .8rem; }
.brand img { border: 2px solid var(--ink); border-radius: var(--wobble-2); transform: rotate(-3deg); background: var(--card); }
.top-actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.badge { font-size: .9rem; padding: .15rem .7rem; border: 2px solid var(--line); border-radius: var(--wobble-pill); color: var(--pencil); transform: rotate(-1.5deg); }
.badge-full { background: var(--marker); color: var(--note-ink); border-color: var(--ink); }

main { max-width: 1040px; margin: 0 auto; padding: 0 16px 24px; display: grid; gap: 18px; }
.card { position: relative; background: var(--card); border: 2px solid var(--ink); border-radius: var(--wobble); padding: 20px 20px 18px; box-shadow: var(--shadow); }
.card::before { content: ""; position: absolute; inset: -5px; border: 1.5px solid var(--ink); border-radius: var(--wobble-2); opacity: .22; pointer-events: none; transform: rotate(.35deg); }
.card::after { content: ""; position: absolute; top: -11px; left: 50%; width: 92px; height: 22px; margin-left: -46px; background: rgba(255, 231, 106, .55); border: 1px solid rgba(43, 43, 48, .12); transform: rotate(-2deg); pointer-events: none; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2 { margin: 0; }
details.card[open] > summary h2 { margin-bottom: .9rem; }

.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span:first-child { color: var(--pencil); font-size: 1rem; }
.field.inline { flex-direction: row; align-items: center; flex-wrap: wrap; gap: .6rem; }
.field.checks { gap: .5rem; justify-content: center; }
.field.checks label { display: flex; align-items: center; gap: .5rem; }
input[type="number"], input[type="text"] {
  font: inherit; font-size: 1.15rem; color: var(--ink); background: transparent; border: 0; border-bottom: 2px solid var(--ink); border-radius: 0; padding: .35rem .4rem .25rem; width: 100%; min-width: 0;
  background-image: linear-gradient(transparent 85%, var(--line-soft) 85%); background-size: 100% 100%;
}
select { font: inherit; font-size: 1rem; color: var(--ink); background: var(--card); border: 2px solid var(--ink); border-radius: var(--wobble-pill); padding: .4rem .7rem; width: 100%; min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, .chip:focus-within { outline: 3px solid var(--marker); outline-offset: 2px; }
input[type="number"]:focus-visible, input[type="text"]:focus-visible { outline: 0; border-bottom-color: var(--accent); background-image: linear-gradient(transparent 85%, var(--marker-soft) 85%); }
.input-unit { display: flex; align-items: baseline; gap: .5rem; }
.input-unit input { flex: 1; }
.input-unit em { font-style: normal; color: var(--pencil); white-space: nowrap; }
input[type="checkbox"], input[type="radio"] {
  appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; margin: 0; flex: none; border: 2px solid var(--ink); border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; background: var(--card); display: inline-grid; place-items: center; cursor: pointer; vertical-align: -3px;
}
input[type="checkbox"]:checked::after, input[type="radio"]:checked::after { content: "✓"; font-family: var(--font-title); font-weight: 700; font-size: 1.25rem; line-height: 1; color: var(--accent); transform: rotate(-8deg) translateY(-1px); }
input[type="checkbox"]:disabled, input[type="radio"]:disabled { opacity: .45; cursor: not-allowed; }

button, .btn-primary, .btn-ghost { font: inherit; font-size: 1.05rem; cursor: pointer; border: 2px solid var(--ink); border-radius: var(--wobble-pill); padding: .45rem 1rem; background: var(--card); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; box-shadow: var(--btn-shadow); transition: transform .08s, box-shadow .08s; }
button:hover, .btn-primary:hover, .btn-ghost:hover { transform: rotate(-1deg); }
button:active, .btn-primary:active, .btn-ghost:active { transform: translate(2px, 2px); box-shadow: none; }
.btn-primary { background: var(--marker); color: var(--note-ink); font-weight: 700; background-image: repeating-linear-gradient(135deg, rgba(43, 43, 48, .07) 0 2px, transparent 2px 7px); }
.btn-icon { width: 2.6rem; justify-content: center; padding: .4rem; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }

/* Sous-titres au surligneur, séparations légères, aides repliables (relecture de Marius, 03/10) */
.subhead { font-family: var(--font-title); font-weight: 700; font-size: 1.3rem; line-height: 1.1; color: var(--ink); margin: 0 0 .55rem; text-decoration: underline; text-decoration-color: var(--marker); text-decoration-thickness: 5px; text-underline-offset: 2px; text-decoration-skip-ink: none; }
.sep { margin-top: 1.1rem; padding-top: 1rem; border-top: 1.5px dashed var(--line-soft); }
.hint.one { margin: 0 0 .7rem; }
.field.end { gap: .2rem; padding-top: .15rem; }
.field.end .hint.one { margin: 0; }
details.more { margin: .5rem 0 0; }
details.more > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: .35rem; color: var(--accent); font-size: .95rem; text-decoration: underline dotted; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸"; font-family: var(--font-title); color: var(--pencil); text-decoration: none; display: inline-block; }
details.more[open] > summary::before { content: "▾"; }
details.more > .more-body { margin: .3rem 0 0 .3rem; padding-left: .8rem; border-left: 2px dashed var(--line-soft); }
details.more > .more-body > p, details.more > .more-body > .hint { margin: .25rem 0 0; }
details.more > .more-body > ul.list { margin: .2rem 0 0; padding-left: 1.2rem; }
details.more > .more-body > ul.list li { margin: .1rem 0; }

.platforms { border: 0; padding: 0; margin: 0; }
.platforms legend { padding: 0; }
.chips { display: grid; gap: .6rem; }
.chip-group { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.chip-group-label { font-size: .95rem; color: var(--pencil); min-width: 8.8rem; font-style: italic; }
.chip { position: relative; display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .85rem; border: 2px solid var(--line); border-radius: var(--wobble-pill); font-size: 1rem; cursor: pointer; background: transparent; color: var(--ink); }
.chip:hover { border-color: var(--ink); transform: rotate(-1deg); }
.chip.on { background: var(--marker); border-color: var(--ink); color: var(--note-ink); font-weight: 700; background-image: repeating-linear-gradient(135deg, rgba(43, 43, 48, .06) 0 2px, transparent 2px 7px); }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chip small { color: var(--pencil); font-weight: 400; font-size: .85rem; }
.chip.on small { color: var(--note-ink); }
.options-wrap { margin-top: 1.1rem; }
.options-wrap .subhead { font-size: 1.2rem; margin-bottom: .3rem; }
.options { display: grid; gap: .35rem; margin-top: .2rem; }
.option-row { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
.option-row strong { font-family: var(--font-title); font-size: 1.2rem; }
.option-row label { display: inline-flex; align-items: center; gap: .45rem; }

#results { display: grid; gap: .7rem; }
.result { border: 2px solid var(--line); border-radius: var(--wobble); background: transparent; }
.result.best { background: var(--best); border-color: var(--best-line); border-width: 2.5px; }
.result > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: .8rem; align-items: center; padding: .7rem 1rem; }
.result > summary::-webkit-details-marker { display: none; }
.result > summary::after { content: "▸"; color: var(--pencil); grid-column: -1; justify-self: end; font-family: var(--font-title); }
.result[open] > summary::after { content: "▾"; }
.result > summary > span { display: flex; flex-direction: column; }
.result > summary > span.r-name { flex-direction: row; align-items: center; gap: .4rem; font-weight: 700; font-size: 1.1rem; }
.result > summary > span.r-net b, .result > summary > span.r-month b { font-family: var(--font-title); font-size: 1.75rem; line-height: 1; font-weight: 700; }
.result > summary small { color: var(--pencil); font-size: .9rem; }
.star { color: var(--red); font-size: 1.2rem; display: inline-block; transform: rotate(-12deg); }
.r-body { padding: 0 1rem 1rem; display: grid; gap: .6rem; }
.lines { width: 100%; border-collapse: collapse; }
.lines td { padding: .3rem 0; border-top: 1.5px dashed var(--line-soft); }
.lines td:last-child { text-align: right; white-space: nowrap; font-family: var(--font-title); font-size: 1.25rem; }
.lines tr:last-child td { border-top: 2px solid var(--ink); }
.lines.month { margin-top: .5rem; }
.lines.month tr:first-child td { border-top: 2px solid var(--ink); padding-top: .6rem; }
.compare { width: 100%; border-collapse: collapse; margin-top: .8rem; }
.compare th { font-family: var(--font-title); font-size: 1.25rem; font-weight: 700; }
.compare th, .compare td { text-align: left; padding: .45rem .4rem; border-bottom: 1.5px dashed var(--line-soft); }
.compare thead th { border-bottom: 2px solid var(--ink); }
.compare td:nth-child(2), .compare td:nth-child(3), .compare th:nth-child(2), .compare th:nth-child(3) { text-align: right; font-family: var(--font-title); font-size: 1.2rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }
.toolbar input[type="text"] { width: auto; flex: 1 1 160px; }
.scenarios { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .45rem; }
.scenarios li { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .5rem .8rem; border: 2px solid var(--line); border-radius: var(--wobble-pill); }
.scenarios li.hint { border-style: dashed; }
.scenarios small { color: var(--pencil); margin-left: .4rem; }

/* Graphique « part du prix que tu gardes » */
.chart { display: grid; gap: .35rem; margin-bottom: 1rem; }
.chart:empty { display: none; }
.chart-title { margin: 0 0 .2rem; font-family: var(--font-title); font-size: 1.3rem; font-weight: 700; color: var(--pencil); }
.bar-row { display: grid; grid-template-columns: minmax(110px, 160px) 1fr 58px; align-items: center; gap: .6rem; }
.bar-label { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 18px; border: 1.5px solid var(--line); border-radius: var(--wobble-pill); overflow: hidden; background: transparent; }
.bar { display: block; height: 100%; background: transparent; background-image: repeating-linear-gradient(135deg, var(--pencil) 0 1.5px, transparent 1.5px 7px); border-right: 2px solid var(--ink); transition: width .25s; }
.bar.best { background: var(--marker); background-image: repeating-linear-gradient(135deg, rgba(43, 43, 48, .08) 0 2px, transparent 2px 7px); }
.bar-value { font-family: var(--font-title); font-size: 1.2rem; text-align: right; }

/* Tableaux de comparaison : trésorerie, objectif, statuts */
.compare td.small { font-size: .9rem; color: var(--pencil); }
.compare tr.best-row td { background: var(--best); }
.compare tr.current td { font-style: italic; }
.compare td.neg { color: var(--red); }
.compare td b { font-family: var(--font-title); font-size: 1.2rem; }
.compare td small { color: var(--pencil); font-size: .85rem; }
.cash td:nth-child(2), .cash th:nth-child(2) { text-align: left; }
.cash td:nth-child(3), .cash th:nth-child(3) { text-align: left; font-family: var(--font-hand); font-size: 1rem; }

/* Jalons */
.milestones { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.milestones li { border: 1.5px solid var(--line-soft); border-radius: var(--wobble); }
.milestones li.hit { border-color: var(--best-line); background: var(--best); }
.milestones li.hint { padding: .6rem .8rem; border-style: dashed; }
.milestones li > details.jalon > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 2rem 1fr auto; gap: .6rem; align-items: start; padding: .6rem .8rem; }
.milestones li > details.jalon > summary::-webkit-details-marker { display: none; }
.milestones li > details.jalon > summary::after { content: "▸"; color: var(--pencil); font-family: var(--font-title); }
.milestones li > details.jalon[open] > summary::after { content: "▾"; }
.milestones li > details.jalon > small { display: block; padding: 0 .8rem .7rem 3.4rem; }
.milestones .mark { font-family: var(--font-title); font-size: 1.5rem; line-height: 1; text-align: center; }
.milestones li.hit .mark { color: var(--accent); }
.milestones .when { color: var(--pencil); }
.milestones small { color: var(--pencil); font-size: .9rem; }

.share { margin-top: 1rem; padding-top: .9rem; border-top: 1.5px dashed var(--line-soft); }
.share .hint { margin: 0; }
.tmi-help .grid3 { align-items: start; }
footer details.more { margin: .2rem 0 .5rem; }

.locked { min-height: 260px; }
.locked.compact { min-height: 0; }
.locked > *:not(.lock-overlay):not(h2) { filter: blur(2.5px); opacity: .5; pointer-events: none; user-select: none; }
.locked.compact > *:not(.lock-overlay):not(h2) { display: none; }
.locked.compact .lock-overlay { position: static; display: block; padding: .2rem 0 .4rem; background: none; }
.locked.compact .lock-overlay > div { display: inline-block; text-align: left; transform: rotate(-.8deg); }
.locked.compact .lock-overlay strong { display: none; }
.locked.compact .lock-overlay p { margin-top: 0; }
.lock-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 18px; text-align: center; border-radius: var(--wobble); background: color-mix(in srgb, var(--card) 45%, transparent); }
.lock-overlay > div { background: var(--note); color: var(--note-ink); padding: 1rem 1.3rem 1.2rem; max-width: 48ch; transform: rotate(-1.5deg); box-shadow: 4px 5px 0 rgba(43, 43, 48, .15); border-radius: 2px; position: relative; }
.lock-overlay > div::before { content: ""; position: absolute; top: -10px; left: 50%; width: 70px; height: 18px; margin-left: -35px; background: rgba(255, 255, 255, .55); border: 1px solid rgba(43, 43, 48, .12); transform: rotate(2deg); }
.lock-overlay strong { font-family: var(--font-title); font-size: 1.4rem; }
.lock-overlay p { color: #4a4740; font-size: 1rem; margin: .4rem auto .9rem; }
.lock-overlay .btn-primary, .lock-overlay .btn-ghost { background-color: #fff; color: var(--note-ink); border-color: #2b2b30; box-shadow: 3px 3px 0 #2b2b30; }
.lock-overlay .btn-primary { background-color: #ffe76a; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.s-block { border: 1.5px solid var(--line); border-radius: var(--wobble); padding: 14px; display: grid; gap: .45rem; }
.s-field { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: .5rem; font-size: .98rem; }
.s-field > span:first-child { color: var(--pencil); }
.s-field input { padding: .2rem .4rem; font-size: 1.05rem; }

footer { max-width: 1040px; margin: 0 auto; padding: 0 16px 32px; color: var(--pencil); font-size: .95rem; }
footer p { margin: .5rem 0; }

dialog { border: 2px solid var(--ink); border-radius: var(--wobble); background: var(--card); color: var(--ink); padding: 24px; max-width: 470px; width: calc(100% - 32px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(43, 43, 48, .5); }
dialog h2 { margin-bottom: .4rem; }
dialog form { display: grid; gap: .8rem; }

@media (max-width: 640px) {
  body { font-size: 1.04rem; }
  h1 { font-size: 1.9rem; }
  .card { padding: 18px 16px 16px; }
  .result > summary { grid-template-columns: 1fr; gap: .4rem; }
  .result > summary > span.r-name { grid-column: 1 / -1; }
  .result > summary > span.r-net, .result > summary > span.r-month { flex-direction: row; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
  .result > summary::after { display: none; }
  .chip-group-label { min-width: 100%; }
  .milestones li > details.jalon > small { padding-left: .8rem; }
  .s-field { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  button, .btn-primary, .btn-ghost, .chip { transition: none; }
  button:hover, .btn-primary:hover, .btn-ghost:hover, .chip:hover { transform: none; }
}
@media print {
  .top-actions, .lock-overlay, #toolsCard, #settingsCard, footer a, .platforms, #inverseCard label, .card::after, .card::before { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #777; border-radius: 6px; break-inside: avoid; }
  .result { break-inside: avoid; }
}
