@font-face {
  font-family: "OpenDyslexic";
  src: url("/vendor/opendyslexic-latin-400-normal.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("/vendor/opendyslexic-latin-700-normal.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --bg: #fff7e8;
  --surface: #ffffff;
  --surface-2: #fdf0d8;
  --ink: #1e2a3a;
  --ink-soft: #5b6878;
  --line: #ead9b8;
  --primary: #1f7a8c;
  --primary-ink: #ffffff;
  --accent: #f28c28;
  --accent-ink: #1e2a3a;
  --mark: #ffe08a;
  --ok: #2e9e6b;
  --danger: #c9404b;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(30, 42, 58, .08), 0 8px 24px rgba(30, 42, 58, .08);
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --read-font: "OpenDyslexic", "Comic Sans MS", "Trebuchet MS", sans-serif;
  --read-size: 30px;
  --read-line: 1.9;
  --read-letter: 0.04em;
  --nav-h: 0px;
  color-scheme: light;
}
:root[data-theme="white"] { --bg: #ffffff; --surface: #f6f7f9; --surface-2: #eceff3; --line: #dfe3e9; }
:root[data-theme="blue"]  { --bg: #e6f1fb; --surface: #f6faff; --surface-2: #d5e6f6; --line: #bcd3ea; --mark: #ffe08a; }
:root[data-theme="dark"] {
  --bg: #14202b; --surface: #1d2d3b; --surface-2: #26394a; --ink: #f2ebdd; --ink-soft: #a9b6c3;
  --line: #34495c; --primary: #3fb0c4; --primary-ink: #0d1a23; --accent: #ffa94d; --accent-ink: #14202b;
  --mark: #6b5a1d; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui-font); font-size: 16px; line-height: 1.45;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
[hidden] { display: none !important; }
svg { width: 1.4em; height: 1.4em; flex: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding-top: env(safe-area-inset-top); }

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--primary); color: var(--primary-ink);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 800; font-size: 1.25rem; letter-spacing: .01em; }
.brand img { border-radius: 10px; background: #fff; }
.tabs { display: flex; gap: 6px; margin: 0 auto; }
.tab {
  display: flex; align-items: center; gap: 8px; border: 0; background: transparent; color: inherit; padding: 10px 16px;
  border-radius: 999px; font-weight: 700; opacity: .85; white-space: nowrap;
}
.tab:hover { opacity: 1; background: rgba(255, 255, 255, .14); }
.tab[aria-current="page"] { background: var(--surface); color: var(--ink); opacity: 1; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
:root[data-theme="dark"] .tab[aria-current="page"] { background: var(--surface-2); }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: inherit; }
.icon-btn:hover { background: rgba(255,255,255,.28); }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 16px; gap: 12px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; border: 2px solid transparent; border-radius: 14px;
  padding: 12px 20px; font-weight: 700; background: var(--surface); color: var(--ink); min-height: 48px; line-height: 1.1;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 3px 0 rgba(0,0,0,.18); }
.btn.accent  { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 rgba(0,0,0,.18); }
.btn.ghost   { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger  { color: var(--danger); }
.btn.big { padding: 16px 22px; font-size: 1.1rem; flex: 1 1 14rem; }
.btn.round { border-radius: 999px; padding-inline: 22px; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: .9rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ---------- Écran « Mon texte » ---------- */
#view-text { overflow: auto; }
.text-layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; width: 100%; max-width: 1180px; margin: 0 auto; }
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h1 { margin: 0 0 4px; font-size: 1.5rem; line-height: 1.2; }
.hint { margin: 0 0 16px; color: var(--ink-soft); }
.import-buttons { display: grid; gap: 12px; }
.big-btn {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px; align-items: center; text-align: left;
  padding: 18px 20px; border-radius: var(--radius); background: var(--surface-2); border: 2px dashed var(--line); font-weight: 800; font-size: 1.1rem; cursor: pointer;
  transition: border-color .15s, background .15s, transform .08s;
}
.big-btn svg { grid-row: 1 / span 2; width: 2.2em; height: 2.2em; color: var(--primary); }
.big-btn small { grid-column: 2; font-weight: 500; color: var(--ink-soft); }
.big-btn:hover, .big-btn:focus-visible { border-color: var(--primary); }
.big-btn:active { transform: scale(.99); }
.drop-hint { margin-top: 14px; font-size: .9rem; color: var(--ink-soft); text-align: center; }
body.dragging .card.import { outline: 3px dashed var(--accent); outline-offset: 4px; }
.status { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-weight: 600; }
.status.error { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.status.ok { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); }
.spin { width: 1.2em; height: 1.2em; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.editor-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.editor-head label { font-weight: 800; }
.count { color: var(--ink-soft); font-size: .95rem; }
textarea.reading-text {
  width: 100%; resize: vertical; min-height: 12rem; max-height: 55vh; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg); font-size: min(var(--read-size), 28px);
}
textarea.reading-text:focus { outline: none; border-color: var(--primary); }
.editor-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.go-buttons { display: flex; gap: 12px; flex-wrap: wrap; }
.privacy { margin: 0 auto; max-width: 1180px; font-size: .85rem; color: var(--ink-soft); text-align: center; }

/* ---------- Texte de lecture (police Dys) ---------- */
.reading-text {
  font-family: var(--read-font); font-size: var(--read-size); line-height: var(--read-line); letter-spacing: var(--read-letter);
  word-spacing: .2em; color: var(--ink);
}
:root[data-dys="off"] { --read-font: Verdana, "Segoe UI", system-ui, sans-serif; }
.reading-text .para { margin: 0 0 .8em; }
.reading-text .w { display: inline-block; padding: 0 .07em; border-radius: .25em; }
.reading-text .w.gone { opacity: 0; }
.reading-text .w.active {
  --edge: calc(var(--p, 0) * 112%);
  -webkit-mask-image: linear-gradient(90deg, transparent calc(var(--edge) - 12%), #000 var(--edge));
          mask-image: linear-gradient(90deg, transparent calc(var(--edge) - 12%), #000 var(--edge));
}

/* ---------- Scène de lecture ---------- */
.stage-wrap { position: relative; flex: 1; min-height: 180px; display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.stage { position: relative; flex: 1; min-height: 0; overflow-y: auto; padding: 28px clamp(18px, 5vw, 64px) 40vh; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
.stage:focus-visible { outline-offset: -3px; }
.eraser {
  position: absolute; left: 0; top: 0; width: 6px; border-radius: 999px; background: var(--accent); opacity: 0; pointer-events: none; will-change: transform;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 28%, transparent), 0 0 22px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: opacity .2s;
}
.eraser.on { opacity: 1; }
.progress { height: 6px; background: var(--surface-2); flex: none; }
.progress i { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 0 6px 6px 0; }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(6rem, 22vw, 12rem); font-weight: 900; color: var(--primary);
  background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(3px); z-index: 5;
}
.countdown b { animation: pop .9s ease-out both; }
.countdown .bravo { font-size: clamp(3.5rem, 12vw, 7rem); color: var(--ok); }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 25% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); opacity: .9; } }

/* ---------- Commandes ---------- */
.controls { flex: none; max-height: 46dvh; overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: grid; gap: 12px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.ctl-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toggles { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.rec-toggle { cursor: pointer; }
.rec-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.rec-pill { display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 999px; border: 2px solid var(--line); font-weight: 700; min-height: 48px; transition: background .15s, color .15s, border-color .15s; }
.rec-toggle input:focus-visible + .rec-pill { outline: 3px solid var(--accent); outline-offset: 2px; }
.rec-toggle input:checked + .rec-pill { background: var(--danger); border-color: var(--danger); color: #fff; }
.asst-toggle input:checked + .rec-pill { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.asst-live { color: var(--primary); font-weight: 700; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); }
.reading-text .w.reveal { opacity: 1 !important; background: var(--mark); box-shadow: inset 0 -.18em 0 var(--accent); -webkit-mask-image: none !important; mask-image: none !important; }
.speed { display: grid; grid-template-columns: auto 1fr auto auto; gap: 4px 10px; align-items: center; }
.speed output { font-weight: 800; min-width: 8.5em; text-align: right; }
.speed .est { grid-column: 1 / -1; color: var(--ink-soft); font-size: .9rem; text-align: right; }
.speed-ico { font-size: 1.4rem; }
input[type="range"] { width: 100%; accent-color: var(--primary); height: 32px; }
.rec-live { display: flex; align-items: center; gap: 10px; color: var(--danger); font-weight: 700; }
.rec-live i { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rec-result { display: grid; gap: 10px; padding: 12px; border-radius: 14px; background: var(--surface-2); }
.rec-result strong { font-size: .95rem; }
.rec-result audio { width: 100%; }
.rec-result .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rec-result .note { color: var(--ink-soft); font-size: .9rem; }

/* ---------- Mode 2 ---------- */
.timer-badge { position: absolute; top: 12px; right: 12px; z-index: 4; width: 84px; height: 84px; display: grid; place-items: center; background: var(--surface); border-radius: 50%; box-shadow: var(--shadow); }
.timer-badge svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-badge circle { fill: none; stroke-width: 3.5; }
.timer-badge .trk { stroke: var(--surface-2); }
.timer-badge .bar { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 119.4; stroke-dashoffset: 0; }
.timer-badge b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.timer-badge.done .bar { stroke: var(--ok); }
.timer-badge.done { animation: ring 0.6s ease-out 3; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 var(--accent); } 100% { box-shadow: 0 0 0 28px transparent; } }
.banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4; background: var(--accent); color: var(--accent-ink); padding: 12px 22px; border-radius: 999px; font-weight: 700; box-shadow: var(--shadow); max-width: calc(100% - 130px); text-align: center; }
#view-mode2 .stage { padding-top: 56px; }
#view-mode2.picking .w { cursor: pointer; }
#view-mode2.picking .w:hover { background: var(--mark); }
.w.read { background: var(--mark); }
.w.last { box-shadow: inset 0 -.18em 0 var(--accent); }
.result { display: grid; gap: 6px; padding: 14px 16px; border-radius: 14px; background: var(--surface-2); }
.result-main { display: flex; align-items: baseline; gap: 12px; }
.result-main b { font-size: 3rem; line-height: 1; color: var(--primary); font-variant-numeric: tabular-nums; }
.result-main span { font-size: 1.3rem; font-weight: 700; }
.result-sub { margin: 0; color: var(--ink-soft); }
.errors { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.step { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); font-size: 1.4rem; font-weight: 800; line-height: 1; }
.errors b { min-width: 1.5em; text-align: center; font-size: 1.2rem; }
.wcpm { margin-left: auto; font-weight: 700; }
.history summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.history ol { margin: 8px 0 12px; padding-left: 1.4em; display: grid; gap: 4px; color: var(--ink-soft); max-height: 9em; overflow: auto; }
.history li b { color: var(--ink); }

/* ---------- Réglages ---------- */
dialog { border: 0; border-radius: 22px; padding: 0; width: min(92vw, 460px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(20, 32, 43, .55); }
dialog form { padding: 22px; display: grid; gap: 14px; }
dialog h2 { margin: 0; font-size: 1.3rem; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 600; border: 0; padding: 0; margin: 0; }
.row.col { flex-direction: column; align-items: stretch; gap: 4px; }
.row output { color: var(--ink-soft); font-weight: 500; margin-left: 6px; }
.row input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--primary); }
legend { padding: 0; font-weight: 600; margin-bottom: 6px; }
.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.themes input { position: absolute; opacity: 0; }
.sw { display: block; text-align: center; padding: 10px 4px; border-radius: 12px; background: var(--c); color: #1e2a3a; border: 3px solid var(--line); font-size: .9rem; font-weight: 700; cursor: pointer; }
.sw.dark { color: #f2ebdd; }
.themes input:checked + .sw { border-color: var(--accent); }
.themes input:focus-visible + .sw { outline: 3px solid var(--accent); outline-offset: 2px; }
.settings-preview { padding: 12px 16px; border-radius: 14px; background: var(--bg); border: 2px solid var(--line); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dialog-actions { display: flex; justify-content: flex-end; }

/* ---------- Adaptations tablette / téléphone ---------- */
@media (max-width: 900px) {
  .text-layout { grid-template-columns: 1fr; }
  .tab span { display: none; }
  .tab { padding: 10px 14px; }
  .tab svg { width: 1.6em; height: 1.6em; }
  .brand span { font-size: 1.1rem; }
}
@media (max-width: 640px) {
  .topbar { padding: 6px 12px; gap: 8px; }
  .topbar .icon-btn { margin-left: auto; }
  .tabs { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; margin: 0; justify-content: space-around; gap: 0; background: var(--primary); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(0,0,0,.18); }
  .tabs .tab { flex-direction: column; gap: 2px; font-size: .72rem; padding: 6px 10px; border-radius: 14px; flex: 1; }
  .tabs .tab span { display: block; white-space: normal; text-align: center; line-height: 1.1; }
  .app { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  .view { padding: 10px; }
  .card { padding: 16px; }
  .btn.round span { display: none; }
  .btn.round { padding-inline: 16px; }
  #m1Play span, #m2Start span { display: inline; }
  .stage { padding-inline: 16px; }
  .timer-badge { width: 68px; height: 68px; top: 8px; right: 8px; }
  .timer-badge b { font-size: 1.1rem; }
  .banner { font-size: .9rem; padding: 9px 14px; max-width: calc(100% - 96px); left: 8px; transform: none; border-radius: 16px; text-align: left; }
  .speed { grid-template-columns: auto 1fr auto; }
  .speed output { grid-column: 1 / -1; text-align: center; }
  .speed .est { text-align: center; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { padding-block: 4px; }
  .brand span { display: none; }
  .controls { padding-block: 8px; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .stage { scroll-behavior: auto; }
  .countdown b, .rec-live i, .spin { animation-duration: 2s; }
}
