/* Layout : feuille de frappe à gauche (texte, contrôles, résultats), colonne de bord à droite (direct, moyennes, scores, options). */
:root {
  --paper: #EEF0EA;
  --sheet: #FBFBF7;
  --ink: #1A2130;
  --muted: #646C7C;
  --faint: #A3A9B4;
  --line: #D6D9CF;
  --accent: #2446A6;
  --accent-soft: #DDE4F6;
  --accent-ink: #FFFFFF;
  --ok: #1C7A58;
  --bad: #C42F28;
  --bad-bg: #F6D3CF;
  --e-case: #7245C4;
  --e-accent: #B0367A;
  --e-order: #B26A00;
  --e-double: #16799F;
  --e-other: #66707F;
  --fast: #188A68;
  --slow: #D06A14;
  --shadow: 0 1px 0 rgba(26,33,48,.06), 0 8px 24px -12px rgba(26,33,48,.18);
  /* Polices système uniquement : pas de Google Fonts (aucune requête tierce, CSP stricte) */
  --f-type: "Courier New", "Liberation Mono", "Nimbus Mono PS", ui-monospace, monospace;
  --f-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12151B; --sheet: #1A1E26; --ink: #E6E8EE; --muted: #9AA2B1; --faint: #5E6574; --line: #2B313C;
    --accent: #8EA6FF; --accent-soft: #26304D; --accent-ink: #0E1320; --ok: #5CC69E; --bad: #FF6A60; --bad-bg: #4B1F1D;
    --e-case: #B59CFF; --e-accent: #F07DB8; --e-order: #F0A43E; --e-double: #5AB7E0; --e-other: #A8AFBC; --fast: #4CC79D; --slow: #F09A48;
    --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 28px -14px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12151B; --sheet: #1A1E26; --ink: #E6E8EE; --muted: #9AA2B1; --faint: #5E6574; --line: #2B313C;
  --accent: #8EA6FF; --accent-soft: #26304D; --accent-ink: #0E1320; --ok: #5CC69E; --bad: #FF6A60; --bad-bg: #4B1F1D;
  --e-case: #B59CFF; --e-accent: #F07DB8; --e-order: #F0A43E; --e-double: #5AB7E0; --e-other: #A8AFBC; --fast: #4CC79D; --slow: #F09A48;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 28px -14px rgba(0,0,0,.7);
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* hidden doit l'emporter sur les display:flex/grid des composants */
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--f-ui); font-size: 15px; line-height: 1.5; }
.app { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd { font-family: var(--f-type); font-size: .78em; padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--sheet); color: var(--muted); }

/* Header */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; margin-bottom: 20px; }
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.logo { font-family: var(--f-type); font-weight: 700; font-size: 1.75rem; letter-spacing: -.01em; }
.logo .caret { display: inline-block; width: .55em; height: .12em; background: var(--accent); margin-left: .08em; vertical-align: baseline; animation: blink 1.1s steps(1) infinite; }
.tag { color: var(--muted); font-size: .9rem; }
.top-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--sheet); border-radius: 8px; padding: 7px 12px; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--sheet); }
.seg button { border: 0; background: transparent; padding: 6px 11px; font-size: .88rem; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 700; }
.sound[aria-pressed="true"] { background: var(--accent-soft); }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.filters label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.filters .f { display: flex; gap: 8px; align-items: center; }
select { background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.count { color: var(--muted); font-size: .85rem; }

/* Sheet */
.sheet { position: relative; background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 18px 22px 16px; }
.sheet::before { content: ""; position: absolute; left: 12px; top: 14px; bottom: 14px; width: 2px; border-left: 1px dashed var(--line); }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.genre { font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); font-weight: 700; }
.hint { font-size: .86rem; color: var(--muted); }
.text-wrap { position: relative; }
.text { font-family: var(--f-type); font-size: 1.32rem; line-height: 1.95; overflow-wrap: anywhere; min-height: 4em; }
.sheet { cursor: text; }
.ch { border-radius: 2px; transition: color .08s; }
.ch.ok { color: var(--faint); }
.ch.bad { background: var(--bad-bg); color: var(--bad); box-shadow: inset 0 -2px 0 var(--bad); }
.ch.cur { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); animation: curpulse 1.1s ease-in-out infinite; }
#ta { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; resize: none; border: 0; font-size: 16px; cursor: text; z-index: 2; }
.src { margin-top: 10px; color: var(--muted); font-size: .9rem; font-style: italic; text-align: right; }
.pause { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: color-mix(in oklab, var(--sheet) 70%, transparent); border-radius: 10px; font-weight: 700; color: var(--accent); pointer-events: none; z-index: 3; }
.sheet.running:not(:focus-within) .pause { display: flex; }
.progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 12px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.controls .spacer { flex: 1; }
.timer-note { font-size: .86rem; color: var(--muted); }

/* Results */
.results { background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 20px 22px; display: flex; flex-direction: column; gap: 18px; }
.res-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; font-weight: 700; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 620px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-left: 3px solid var(--line); }
.kpi.lead { border-left-color: var(--accent); }
.kpi .lbl { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.kpi .val { font-family: var(--f-type); font-weight: 700; font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: .5em; font-weight: 400; color: var(--muted); margin-left: 4px; }
.kpi .sub { font-size: .82rem; color: var(--muted); }
.kpi .sub.pen { color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; }
.chip i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chip b { font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
.rtext { font-family: var(--f-type); font-size: 1.12rem; line-height: 2; overflow-wrap: anywhere; }
.rtext span.e { border-radius: 2px; padding: 1px 0; }
.e-case { background: color-mix(in oklab, var(--e-case) 26%, transparent); box-shadow: inset 0 -2px 0 var(--e-case); }
.e-accent { background: color-mix(in oklab, var(--e-accent) 26%, transparent); box-shadow: inset 0 -2px 0 var(--e-accent); }
.e-order { background: color-mix(in oklab, var(--e-order) 26%, transparent); box-shadow: inset 0 -2px 0 var(--e-order); }
.e-double { background: color-mix(in oklab, var(--e-double) 26%, transparent); box-shadow: inset 0 -2px 0 var(--e-double); }
.e-other { background: color-mix(in oklab, var(--e-other) 30%, transparent); box-shadow: inset 0 -2px 0 var(--e-other); }
.e-unc { background: var(--bad); color: var(--sheet); }
.rw { border-radius: 3px; padding: 1px 1px; }
.r-vs { background: color-mix(in oklab, var(--slow) 55%, transparent); }
.r-s { background: color-mix(in oklab, var(--slow) 25%, transparent); }
.r-f { background: color-mix(in oklab, var(--fast) 25%, transparent); }
.r-vf { background: color-mix(in oklab, var(--fast) 55%, transparent); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
/* Pastilles de couleur (chips et légende) */
.sw-case { background: var(--e-case); } .sw-accent { background: var(--e-accent); } .sw-order { background: var(--e-order); }
.sw-double { background: var(--e-double); } .sw-other { background: var(--e-other); } .sw-unc { background: var(--bad); }
.r-avg { border: 1px solid var(--line); }
.chart-box { position: relative; }
#chart { width: 100%; height: auto; display: block; overflow: visible; }
#chart text { fill: var(--muted); font-family: var(--f-ui); font-size: 11px; }
.tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--ink); color: var(--sheet); font-size: .8rem; padding: 3px 8px; border-radius: 5px; white-space: nowrap; pointer-events: none; }
.res-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
@media (max-width: 560px) { .res-grid { grid-template-columns: minmax(0, 1fr); } }
.res-grid ol, .res-grid ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.res-grid li { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; border-bottom: 1px dotted var(--line); padding-bottom: 3px; }
.res-grid li code { font-family: var(--f-type); font-size: 1rem; }
.res-grid li span { color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: .88rem; font-style: italic; }
.rate { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding-top: 14px; border-top: 1px solid var(--line); }
.stars { display: inline-flex; gap: 2px; }
.stars button { border: 0; background: transparent; font-size: 1.35rem; line-height: 1; padding: 2px; color: var(--faint); }
.stars button.on { color: var(--e-order); }
.rate-msg { font-size: .85rem; color: var(--muted); }
.res-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Rules */
.rules { background: transparent; border-top: 1px solid var(--line); padding-top: 12px; }
.rules summary { cursor: pointer; font-weight: 700; }
.rules p, .rules li { color: var(--muted); max-width: 68ch; }
.rules ul { padding-left: 18px; }

/* Side */
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card { background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.card h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin-bottom: 10px; }
.live dl { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.live dt { font-size: .74rem; color: var(--muted); }
.live dd { margin: 0; font-family: var(--f-type); font-weight: 700; font-size: 1.45rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.live dd small { font-size: .55em; font-weight: 400; color: var(--muted); margin-left: 2px; }
.avg { display: flex; justify-content: space-between; gap: 10px; }
.avg div { display: flex; flex-direction: column; }
.avg b { font-family: var(--f-type); font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.avg span { font-size: .78rem; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list li { display: grid; grid-template-columns: 52px minmax(0,1fr) auto; gap: 8px; align-items: center; font-size: .85rem; font-variant-numeric: tabular-nums; }
.list .w { font-family: var(--f-type); font-weight: 700; font-size: 1rem; }
.list .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.list .bar span { display: block; height: 100%; background: var(--accent); }
.list .meta { color: var(--muted); font-size: .78rem; }
.list li.empty { display: block; }
ol.list li.empty::before { content: none; counter-increment: none; }
ol.list { counter-reset: r; }
ol.list li { grid-template-columns: 18px 52px minmax(0,1fr); }
ol.list li::before { counter-increment: r; content: counter(r); color: var(--muted); font-size: .78rem; }
.opt { display: flex; flex-direction: column; gap: 10px; }
.opt label { display: flex; gap: 8px; align-items: flex-start; font-size: .88rem; cursor: pointer; }
.opt label input { margin-top: 3px; accent-color: var(--accent); }
.opt small { display: block; color: var(--muted); font-size: .78rem; }
.opt .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .85rem; }
.linkbtn { border: 0; background: transparent; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; font-size: .85rem; }
.linkbtn.danger { color: var(--bad); }

@keyframes blink { 50% { opacity: 0; } }
@keyframes curpulse { 50% { box-shadow: inset 2px 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
