/* Cahier — styles */
:root {
  --bg: #f3f5f9; --surface: #ffffff; --surface-2: #eef2f8; --text: #1d2433; --muted: #66708a; --border: #dde3ee;
  --accent: #2f6fb3; --accent-2: #5c95d6; --accent-text: #ffffff; --danger: #c2415b; --desk: #e4e8ef;
  --shadow: 0 8px 24px rgba(30, 50, 90, 0.12); --radius: 14px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161d; --surface: #1b212b; --surface-2: #232b37; --text: #e8edf6; --muted: #98a3b8; --border: #2e3846;
    --accent: #5c95d6; --accent-2: #8bb5e8; --accent-text: #0d1520; --desk: #0d1117; --shadow: 0 8px 24px rgba(0, 0, 0, 0.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161d; --surface: #1b212b; --surface-2: #232b37; --text: #e8edf6; --muted: #98a3b8; --border: #2e3846;
  --accent: #5c95d6; --accent-2: #8bb5e8; --accent-text: #0d1520; --desk: #0d1117; --shadow: 0 8px 24px rgba(0, 0, 0, 0.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: .85em; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger, .danger { color: var(--danger); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  display: inline-grid; place-items: center; cursor: pointer; font-size: 17px; text-decoration: none; flex: none;
}
.icon-btn:hover { border-color: var(--accent-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.small { width: 30px; height: 30px; font-size: 15px; }
.chip { padding: 5px 11px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13.5px; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ---------- bibliothèque ---------- */
.library { max-width: 1200px; margin: 0 auto; padding: 16px 16px 40px; padding-top: max(16px, env(safe-area-inset-top)); }
.lib-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { border-radius: 9px; }
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: .01em; }
.brand p { margin: 0; color: var(--muted); font-size: .9rem; }
.lib-top-actions { display: flex; gap: 6px; }
.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 12px; }
.lib-filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.lib-filters input[type=search] { width: 100%; padding: 10px 14px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 18px; }
.card { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cover {
  position: relative; aspect-ratio: 3 / 4; border: 0; border-radius: 6px 12px 12px 6px; cursor: pointer; overflow: hidden; padding: 0;
  background: linear-gradient(135deg, color-mix(in srgb, var(--cover) 85%, #fff), var(--cover)); box-shadow: var(--shadow);
  transition: transform .15s;
}
.cover:hover { transform: translateY(-3px); }
.cover .spine { position: absolute; left: 0; top: 0; bottom: 0; width: 12px; background: rgba(0,0,0,.18); }
.cover .peek { position: absolute; right: 10px; top: 10px; width: 46%; aspect-ratio: 210 / 297; background: #fff; border-radius: 3px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.2); transform: rotate(3deg); }
.cover .peek img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .label { position: absolute; left: 20px; right: 10px; bottom: 12px; text-align: left; color: #fff; display: flex; flex-direction: column; gap: 3px; text-shadow: 0 1px 3px rgba(0,0,0,.35); }
.cover .label strong { font-size: 15px; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cover .label em { font-style: normal; font-size: 12px; align-self: flex-start; background: rgba(255,255,255,.25); padding: 1px 8px; border-radius: 99px; }
.meta { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: 12.5px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); max-width: 460px; margin: 40px auto; }
.empty .big { font-size: 48px; margin: 0; }
.storage { color: var(--muted); font-size: 12.5px; margin-top: 30px; text-align: center; }

/* ---------- éditeur ---------- */
.editor { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--desk); }
.ed-top {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.ed-title { width: 170px; min-width: 70px; flex: 0 1 170px; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 6px 8px; font-weight: 600; text-overflow: ellipsis; }
.ed-title:hover, .ed-title:focus { border-color: var(--border); background: var(--surface-2); outline: none; }
.tools { display: flex; gap: 2px; flex: 1; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tools > :first-child { margin-left: auto; }
.tools > :last-child { margin-right: auto; }
.tools::-webkit-scrollbar { display: none; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 1px; border: 0; background: transparent; cursor: pointer;
  padding: 4px 7px; border-radius: 10px; font-size: 19px; line-height: 1.1; flex: none;
}
.tool span { font-size: 10.5px; color: var(--muted); }
.tool:hover { background: var(--surface-2); }
.tool.active { background: color-mix(in srgb, var(--accent) 18%, transparent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.tool.active span { color: var(--accent); font-weight: 600; }
.ed-actions { display: flex; gap: 4px; }
.ed-options {
  display: flex; align-items: center; gap: 14px; padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; min-height: 46px; scrollbar-width: thin;
}
.opt-group { display: flex; align-items: center; gap: 5px; flex: none; }
.opt-group.stamps { flex-wrap: nowrap; }
.hint { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); background: var(--c); box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; flex: none; position: relative; overflow: hidden; }
.swatch.active { box-shadow: 0 0 0 2.5px var(--accent); }
.swatch.custom { background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); display: inline-block; }
.swatch.custom input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.size { width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; display: grid; place-items: center; }
.size.active { border-color: var(--accent); background: var(--surface-2); }
.sz-dot { display: block; border-radius: 50%; background: currentColor; }
.sz-txt { font-size: 12px; font-weight: 600; }
.stamp-btn { border: 2px solid var(--c); color: var(--c); background: #fff; border-radius: 8px; padding: 2px 8px; font-weight: 800; font-size: 13px; cursor: pointer; white-space: nowrap; flex: none; }
.stamp-btn.plain { border-color: transparent; font-size: 18px; padding: 0 6px; }
.stamp-btn.active { box-shadow: 0 0 0 2.5px var(--accent); }

.ed-body { flex: 1; display: flex; min-height: 0; position: relative; }
.thumbs { width: 108px; flex: none; overflow-y: auto; padding: 10px 10px 30px; display: flex; flex-direction: column; gap: 10px; background: var(--surface); border-right: 1px solid var(--border); }
.thumb { position: relative; border: 0; padding: 0; background: transparent; cursor: pointer; }
.thumb img { width: 100%; display: block; background: #fff; border-radius: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.18); outline: 2px solid transparent; outline-offset: 2px; }
.thumb.active img { outline-color: var(--accent); }
.thumb .num { position: absolute; bottom: 3px; right: 4px; font-size: 11px; background: rgba(0,0,0,.55); color: #fff; padding: 0 5px; border-radius: 6px; }
.viewport { flex: 1; overflow: auto; position: relative; touch-action: none; overscroll-behavior: contain; -webkit-user-select: none; user-select: none; }
.viewport.grab, .viewport.panning { cursor: grab; }
.stage { min-width: 100%; min-height: 100%; width: max-content; padding: 16px; display: flex; align-items: flex-start; justify-content: center; }
.sheet { position: relative; flex: none; background: #fff; box-shadow: 0 4px 22px rgba(0,0,0,.18); }
.sheet canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.sheet[data-tool="pen"], .sheet[data-tool="hl"], .sheet[data-tool="shape"] { cursor: crosshair; }
.sheet[data-tool="text"] { cursor: text; }
.sheet[data-tool="eraser"] { cursor: cell; }
.sheet[data-tool="stamp"] { cursor: copy; }
.sheet[data-tool="hand"] { cursor: grab; }
.text-edit {
  position: absolute; z-index: 3; min-width: 60px; border: 1.5px dashed var(--accent); background: rgba(255,255,255,.85); outline: none;
  padding: 0; margin: 0; resize: none; overflow: hidden; line-height: 1.25; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; white-space: pre; color-scheme: light;
}
.sel-bar { position: absolute; z-index: 4; display: flex; gap: 2px; padding: 4px; background: #222a36; border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.sel-bar button { border: 0; background: transparent; color: #fff; font-size: 16px; width: 36px; height: 34px; border-radius: 7px; cursor: pointer; }
.sel-bar button:hover { background: rgba(255,255,255,.14); }

.ed-bottom { display: flex; align-items: center; gap: 6px; padding: 6px 10px; padding-bottom: max(6px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
.page-ind, .zoom-ind { border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 7px 12px; cursor: pointer; font-variant-numeric: tabular-nums; min-width: 72px; }
.icon-btn.add { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }

/* ---------- présentation ---------- */
body.presenting .ed-top, body.presenting .ed-options, body.presenting .ed-bottom, body.presenting .thumbs { display: none; }
body.presenting .editor { background: #111; }
.present-bar {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 4px;
  background: rgba(25, 30, 40, .9); color: #fff; padding: 6px 10px; border-radius: 16px; box-shadow: 0 6px 24px rgba(0,0,0,.4); backdrop-filter: blur(6px); max-width: calc(100vw - 20px); overflow-x: auto;
}
.present-bar button { border: 0; background: transparent; color: #fff; font-size: 19px; min-width: 38px; height: 38px; border-radius: 10px; cursor: pointer; flex: none; }
.present-bar .tool { padding: 0; display: grid; place-items: center; }
.present-bar .tool.active { background: rgba(255,255,255,.18); box-shadow: none; }
.present-bar button:hover { background: rgba(255,255,255,.12); }
.present-bar #present-ind { font-variant-numeric: tabular-nums; padding: 0 4px; font-size: 14px; }
.present-bar .swatches { display: flex; gap: 4px; padding: 0 6px; }
.present-bar .swatch { min-width: 0; width: 24px; height: 24px; border-color: #191e28; background: var(--c); }
.present-bar .swatch.active { box-shadow: 0 0 0 2.5px #fff; }

/* ---------- menus, dialogues, toasts ---------- */
.popover { position: fixed; z-index: 30; min-width: 250px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; }
.popover button, .popover .check { text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.popover button:hover, .popover .check:hover { background: var(--surface-2); }
.popover hr { border: 0; border-top: 1px solid var(--border); margin: 4px 6px; width: auto; }
.dialog { border: 0; border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(440px, calc(100vw - 24px)); }
.dialog.wide { width: min(780px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(10, 15, 25, .45); }
.dialog form { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.dialog h2 { margin: 0 0 4px; font-size: 1.25rem; }
.dialog h3 { margin: 4px 0; font-size: 1rem; }
.dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--muted); }
.dialog input:not([type=radio]):not([type=checkbox]), .dialog select { padding: 9px 11px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 15px; }
.dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 6px 0 0; padding: 0; }
.dialog ul { padding-left: 18px; margin: 4px 0; }
.dialog li { margin: 4px 0; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.new-only { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; align-items: start; }
.new-only canvas { grid-row: span 3; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.18); background: #fff; }
.colors { border: 0; padding: 0; margin: 0; }
.colors legend { font-size: 13.5px; color: var(--muted); margin-bottom: 6px; padding: 0; }
#cover-colors { display: flex; flex-wrap: wrap; gap: 8px; }
.cover-dot { flex-direction: row !important; cursor: pointer; }
.cover-dot input { position: absolute; opacity: 0; pointer-events: none; }
.cover-dot span { width: 28px; height: 28px; border-radius: 8px; background: var(--c); display: block; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.cover-dot input:checked + span { box-shadow: 0 0 0 2.5px var(--accent); }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-grid .btn { justify-content: center; }
.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 50;
  background: #222a36; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); transition: .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.busy { position: fixed; inset: 0; z-index: 60; background: rgba(10, 15, 25, .45); display: grid; place-items: center; color: #fff; text-align: center; }
.spinner { width: 42px; height: 42px; margin: 0 auto 10px; border-radius: 50%; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- petits écrans ---------- */
@media (max-width: 760px) {
  .ed-title { display: none; }
  .ed-top { flex-wrap: wrap; row-gap: 4px; }
  .ed-actions { margin-left: auto; }
  .tools { order: 3; flex-basis: 100%; }
  .tool span { display: none; }
  .tool { font-size: 20px; padding: 6px; }
  .thumbs { position: absolute; z-index: 5; left: 0; top: 0; bottom: 0; box-shadow: var(--shadow); }
  .help-cols { grid-template-columns: 1fr; }
  .lib-actions .spacer { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
