/* =========================================================================================
   Lecture rapide — feuille de style
   ========================================================================================= */

:root {
    --bg: #f6f4ef;
    --surface: #ffffff;
    --surface-2: #efece4;
    --line: #e2ddd2;
    --fg: #1b1a18;
    --muted: #6d6a63;
    --accent: #d8392b;
    --accent-fg: #ffffff;
    --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 6px 24px rgb(0 0 0 / .06);
    --radius: 14px;
    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-read: var(--font-ui);
    --font-scale: 1;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="sepia"]) {
        --bg: #121212; --surface: #1b1b1b; --surface-2: #232323; --line: #2c2c2c;
        --fg: #ececea; --muted: #8e8c87; --accent: #ff5b4d; --accent-fg: #160403;
        --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 30px rgb(0 0 0 / .35);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #121212; --surface: #1b1b1b; --surface-2: #232323; --line: #2c2c2c;
    --fg: #ececea; --muted: #8e8c87; --accent: #ff5b4d; --accent-fg: #160403;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 30px rgb(0 0 0 / .35);
    color-scheme: dark;
}
:root[data-theme="sepia"] {
    --bg: #f2e8d2; --surface: #f9f2e1; --surface-2: #eadfc5; --line: #dccfb1;
    --fg: #3a2e21; --muted: #7b6b56; --accent: #b6402b; --accent-fg: #fff8ee;
    color-scheme: light;
}
:root[data-font="serif"] { --font-read: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif; }
:root[data-font="mono"] { --font-read: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--bg);
    color: var(--fg);
    font: 16px/1.5 var(--font-ui);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg { width: 22px; height: 22px; flex: none; }

/* ------------------------------- Boutons ------------------------------- */
.icon-btn {
    display: inline-grid; place-items: center;
    width: 44px; height: 44px; border-radius: 50%;
    background: transparent; border: 0; color: var(--fg);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn.small svg { width: 18px; height: 18px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--line); font-weight: 600;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row.end { justify-content: flex-end; }

/* ------------------------------- Bibliothèque ------------------------------- */
.library {
    max-width: 760px; margin: 0 auto;
    padding: calc(12px + var(--safe-t)) 16px calc(48px + var(--safe-b));
}
.lib-header { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.install-btn {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 10px;
    border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-fg); font-weight: 650; font-size: .88rem;
}
.install-btn svg { width: 18px; height: 18px; }
.offline-pill { font-size: .75rem; font-weight: 650; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.install-steps { margin: 0; padding: 4px 20px 0 44px; display: grid; gap: 10px; }
.install-note { padding: 12px 20px 20px; }
.inline-ico { width: 18px; height: 18px; vertical-align: -3px; color: var(--accent); }
@media (max-width: 340px) { .install-btn span { display: none; } .install-btn { padding: 0 9px; } }

/* Une fois installée : comportement d'app native */
html.standalone body { overscroll-behavior: none; }
html.standalone .hint { display: none; }
.reader { overscroll-behavior: none; }
.chrome, .controls, .lib-header { -webkit-user-select: none; user-select: none; }

.brand { margin: 0; font-size: 1.35rem; letter-spacing: -.02em; font-weight: 750; }
.brand span { color: var(--accent); margin-left: .28em; font-weight: 750; }

.eyebrow, .section-title {
    margin: 28px 0 12px; font-size: .78rem; font-weight: 700;
    letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.eyebrow { margin-top: 8px; }

.resume-card {
    position: relative; display: grid; width: 100%; text-align: left; gap: 4px;
    padding: 20px 84px 20px 20px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.resume-title { font-size: 1.25rem; font-weight: 700; line-height: 1.25; letter-spacing: -.01em; }
.resume-author { color: var(--muted); }
.resume-card .bar { margin-top: 12px; }
.resume-meta { font-size: .85rem; color: var(--muted); }
.resume-play {
    position: absolute; right: 20px; top: 50%; translate: 0 -50%;
    display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
    background: var(--accent); color: var(--accent-fg);
}

.bar { display: block; height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; }

.add-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .add-grid { grid-template-columns: repeat(4, 1fr); } }
.add-btn {
    display: flex; align-items: center; gap: 12px; min-height: 72px; padding: 14px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    cursor: pointer; text-align: left; transition: border-color .15s, transform .15s;
}
.add-btn:hover { border-color: var(--muted); }
.add-btn:active { transform: scale(.98); }
.add-btn svg { color: var(--accent); width: 26px; height: 26px; }
.add-btn strong { display: block; font-size: .95rem; }
.add-btn small { display: block; color: var(--muted); font-size: .78rem; line-height: 1.3; }
.hint { color: var(--muted); font-size: .85rem; margin: 10px 2px 0; }
@media (hover: none) { .desktop-only { display: none; } }

.book-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.book {
    display: grid; grid-template-columns: 1fr auto; align-items: center;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.book-open {
    display: grid; gap: 3px; padding: 14px 4px 14px 16px; text-align: left;
    background: none; border: 0; min-width: 0;
}
.book-title { font-weight: 650; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-author { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-meta { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: .8rem; color: var(--muted); }
.book-meta .bar { flex: 1; max-width: 160px; }
.book-meta svg { width: 16px; height: 16px; }
.book-actions { padding-right: 6px; }
.book-actions .icon-btn { color: var(--muted); }
.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

.drop-overlay {
    position: fixed; inset: 0; display: none; place-items: center; z-index: 50;
    background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(4px);
}
.drop-overlay div { padding: 32px 40px; border: 2px dashed var(--accent); border-radius: 20px; font-weight: 650; font-size: 1.1rem; }
body.dragging .drop-overlay { display: grid; }

/* ------------------------------- Lecteur ------------------------------- */
.reader {
    position: fixed; inset: 0; overflow: hidden;
    background: var(--bg); user-select: none; -webkit-user-select: none;
    touch-action: manipulation;
}
.stage {
    position: absolute; inset: 0; display: grid; align-items: center;
    cursor: pointer;
}
.word {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline;
    width: 100%; white-space: pre;
    font-family: var(--font-read);
    font-size: calc(clamp(2.1rem, 8.4vw, 4.4rem) * var(--font-scale));
    font-weight: 500; letter-spacing: .01em; line-height: 1.2;
    font-variant-ligatures: none; font-kerning: normal;
    transform: translateY(-4vh);
}
.w-left { text-align: right; }
.w-right { text-align: left; }
.w-pivot { color: var(--accent); }
.word.message { grid-template-columns: 1fr; text-align: center; font-size: calc(1.4rem * var(--font-scale)); color: var(--muted); white-space: normal; padding: 0 24px; }
.word.message .w-left, .word.message .w-right { display: none; }
.word.message .w-pivot { color: var(--muted); }

/* Repère : deux petits traits alignés sur la lettre de fixation (toujours au centre de l'écran) */
.w-pivot { position: relative; }
.w-pivot::before, .w-pivot::after {
    content: ""; position: absolute; left: 50%; width: 2px; height: .28em; translate: -1px 0;
    background: var(--accent); opacity: .5; border-radius: 2px;
}
.w-pivot::before { top: -.42em; }
.w-pivot::after { bottom: -.42em; }
.word.message .w-pivot::before, .word.message .w-pivot::after,
:root[data-guide="off"] .w-pivot::before, :root[data-guide="off"] .w-pivot::after { display: none; }
:root[data-guide="off"] .w-pivot { color: inherit; }

.progress-line { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--surface-2); }
.progress-line div { height: 100%; background: var(--accent); opacity: .7; transform-origin: left; transform: scaleX(0); }
:root[data-progress="off"] .reader.playing .progress-line { display: none; }

/* Commandes : visibles en pause, totalement masquées pendant la lecture */
.chrome { position: absolute; left: 0; right: 0; transition: opacity .25s ease, transform .25s ease; }
.reader.playing .chrome { opacity: 0; pointer-events: none; }
.reader.playing .chrome-top { transform: translateY(-8px); }
.reader.playing .chrome-bottom { transform: translateY(8px); }
.reader.playing { cursor: none; }
.reader.playing .stage { cursor: none; }

.chrome-top {
    top: 0; display: flex; align-items: center; gap: 4px;
    padding: calc(8px + var(--safe-t)) 8px 8px;
}
.book-heading { flex: 1; min-width: 0; text-align: center; }
.book-heading-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-heading-author { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chrome-context {
    top: calc(50% + 9vh); display: flex; justify-content: center; padding: 0 20px;
    pointer-events: none;
}
.context {
    max-width: 640px; margin: 0; max-height: 22vh; overflow: hidden;
    font-family: var(--font-read); font-size: 1.02rem; line-height: 1.6;
    color: var(--muted); text-align: center; pointer-events: auto;
}
.context span { cursor: pointer; border-radius: 4px; padding: 1px 0; }
.context span:hover { color: var(--fg); }
.context span.current { color: var(--fg); background: color-mix(in srgb, var(--accent) 22%, transparent); padding: 1px 3px; }
.context .done { color: var(--fg); font-weight: 600; }

.chrome-bottom { bottom: 0; padding: 0 16px calc(16px + var(--safe-b)); }
.seek-row { max-width: 720px; margin: 0 auto 6px; }
.seek-meta { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; padding: 0 2px; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; }

.controls {
    max-width: 720px; margin: 0 auto;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
}
.speed { display: flex; align-items: center; gap: 2px; justify-self: start; background: var(--surface-2); border-radius: 999px; padding: 4px; }
.speed output { min-width: 4.6em; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; font-size: .92rem; }
.speed output::after { content: " mots/min"; font-weight: 400; color: var(--muted); font-size: .78rem; display: block; line-height: 1; }
.transport { display: flex; align-items: center; gap: 10px; }
.extra { justify-self: end; }
.play-btn {
    display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%;
    background: var(--accent); color: var(--accent-fg); border: 0; box-shadow: var(--shadow);
}
.play-btn svg { width: 28px; height: 28px; }
.play-btn:active { transform: scale(.96); }
@media (max-width: 420px) {
    .controls { grid-template-columns: auto 1fr auto; }
    .transport { justify-content: center; gap: 4px; }
    .speed output { min-width: 3.4em; }
    .speed output::after { content: "mpm"; }
}

/* ------------------------------- Dialogues ------------------------------- */
dialog.sheet {
    width: min(640px, calc(100vw - 24px)); max-height: min(86vh, 900px);
    padding: 0; border: 1px solid var(--line); border-radius: 20px;
    background: var(--surface); color: var(--fg); box-shadow: var(--shadow);
    overflow: auto;
}
dialog.sheet.small { width: min(460px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(0 0 0 / .45); backdrop-filter: blur(2px); }
@media (max-width: 600px) {
    dialog.sheet:not(.small) {
        width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0;
        border-radius: 20px 20px 0 0; padding-bottom: var(--safe-b);
    }
}
.sheet-head {
    position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
    padding: 12px 10px 8px 20px; background: var(--surface);
}
.sheet-head h2, .confirm-title { margin: 0; font-size: 1.15rem; }
.confirm-title { padding: 20px 20px 0; }
dialog.small > .sheet-note { padding: 0 20px; }
dialog.small > .btn-row { padding: 0 20px 20px; }
.sheet-note { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.stack { display: grid; gap: 12px; padding: 4px 20px 20px; }
input[type="text"], input[type="url"], input[type="search"], input[type="email"], input[type="password"], textarea, select {
    width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--bg);
}
textarea { resize: vertical; min-height: 180px; line-height: 1.5; }
select { width: auto; }

.source-tabs { display: flex; gap: 6px; padding: 0 20px 12px; }
.tab { flex: 1; min-height: 40px; border-radius: 999px; border: 1px solid var(--line); background: transparent; font-weight: 600; font-size: .9rem; }
.tab[aria-selected="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.bought { margin: 0 20px 20px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: .88rem; }
.bought summary { cursor: pointer; font-weight: 600; }
.bought p { margin: 10px 0 0; color: var(--muted); line-height: 1.5; }
.bought strong { color: var(--fg); }
.result-meta { color: var(--muted); font-size: .78rem; }
#moodChip { color: var(--accent); }
.search-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; padding: 0 20px; }
@media (max-width: 480px) { .search-row { grid-template-columns: 1fr auto; } .search-row .btn { grid-column: 1 / -1; } }
#dlgGutenberg .sheet-note { padding: 0 20px; }
.row.disabled { opacity: .45; pointer-events: none; }
.result-list { list-style: none; margin: 8px 0 0; padding: 0 8px 16px; }
.result-list li button {
    display: grid; width: 100%; text-align: left; gap: 2px; padding: 12px; border-radius: 12px;
    background: none; border: 0;
}
.result-list li button:hover { background: var(--surface-2); }
.result-title { font-weight: 600; line-height: 1.3; }
.result-author { color: var(--muted); font-size: .88rem; }
.result-list .status { padding: 20px 12px; color: var(--muted); text-align: center; }

.settings { padding: 0 20px 20px; }
fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; padding: 0; }
.row { display: grid; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row > span { display: flex; justify-content: space-between; gap: 12px; font-size: .95rem; }
.row output { color: var(--muted); font-variant-numeric: tabular-nums; }
.row.check { grid-template-columns: auto 1fr; align-items: center; gap: 12px; }
.row.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.row:has(select) { grid-template-columns: 1fr auto; align-items: center; }
#accountOut { display: grid; gap: 12px; padding-top: 6px; }
#accountOut .stack { padding: 0; }
.account-line { margin: 6px 0 12px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 6px 0; font-size: .9rem; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }
kbd { display: inline-block; min-width: 1.8em; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; font: 600 .8rem var(--font-ui); text-align: center; background: var(--bg); }

/* ------------------------------- Chargement / notifications ------------------------------- */
.busy {
    position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
    background: rgb(0 0 0 / .45); backdrop-filter: blur(2px); padding: 16px;
}
.busy-card {
    display: grid; justify-items: center; gap: 14px; width: min(360px, 100%);
    padding: 28px 24px 20px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); text-align: center;
}
.busy-card p { margin: 0; }
.busy-card .bar { width: 100%; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed; left: 50%; top: calc(16px + var(--safe-t)); translate: -50% 0; z-index: 200;
    max-width: min(520px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 14px;
    background: var(--fg); color: var(--bg); box-shadow: var(--shadow); font-size: .92rem;
}
.toast.error { background: var(--accent); color: var(--accent-fg); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation-duration: 0s !important; }
}
