/* Interface en police système ; chaque texte apporte ses variables --t-* (couleurs, police). */
:root {
  --paper: #f3f4f2; --surface: #ffffff; --ink: #1d2220; --muted: #646d69; --rule: #dde1de;
  --accent: #2a5a48; --accent-ink: #ffffff;
  --draft-bg: #e6e9e7; --draft-fg: #4d5551; --link-bg: #f8ebcd; --link-fg: #7a5200; --public-bg: #d8ece1; --public-fg: #1f5a40;
  --danger: #a33a2a;
  --f-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --f-code: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121614; --surface: #1a1f1d; --ink: #e4e8e5; --muted: #9aa49f; --rule: #2d3532;
    --accent: #84c2a8; --accent-ink: #0f1513;
    --draft-bg: #2a302e; --draft-fg: #b9c1bd; --link-bg: #3b3020; --link-fg: #f0c674; --public-bg: #1f3a2f; --public-fg: #9fd8bd;
    --danger: #f08a78; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--f-ui); font-size: 15px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- lecture ---------- */
.reader-page { background: var(--t-bg); color: var(--t-ink); }
.reader { padding: clamp(40px, 9vw, 96px) max(20px, env(safe-area-inset-left)) 48px; min-height: 100vh; }
.sheet { max-width: 34rem; margin: 0 auto; }
.text { font-family: var(--t-font); }
.text header { margin-bottom: 2rem; }
.text-title { font-weight: 600; font-size: calc(clamp(1.7rem, 6vw, 2.4rem) * var(--t-scale)); line-height: 1.15; margin: 0 0 .5rem; text-wrap: balance; }
.text-date { font-family: var(--f-ui); font-size: 12px; letter-spacing: .06em; color: color-mix(in srgb, var(--t-ink) 60%, var(--t-bg)); }
.text-rule { display: block; width: 2.5rem; height: 2px; background: var(--t-accent); margin-top: 1.2rem; }
.text-body { font-size: calc(clamp(1.05rem, 3.6vw, 1.15rem) * var(--t-scale)); line-height: 1.75; overflow-wrap: break-word; }
.text-body > :first-child { margin-top: 0; }
.text-body p { margin: 0 0 1.4em; }
.text-body strong { font-weight: 700; }
.text-body a { color: var(--t-accent); }
.text-body h1, .text-body h2, .text-body h3 { font-weight: 600; line-height: 1.25; margin: 1.6em 0 .6em; }
.text-body blockquote { margin: 0 0 1.4em; padding-left: 1rem; border-left: 2px solid var(--t-accent); font-style: italic; }
.text-body ul, .text-body ol { padding-left: 1.2em; margin: 0 0 1.4em; }
.text-body pre { overflow-x: auto; font-size: .85em; }
.text-body hr { border: 0; margin: 2em 0; text-align: center; }
.text-body hr::after { content: "⁂"; color: var(--t-accent); }
.layout-left { text-align: left; }
.layout-right { text-align: right; }
.layout-right .text-rule { margin-left: auto; }
.layout-right .text-body blockquote { border-left: 0; border-right: 2px solid var(--t-accent); padding: 0 1rem 0 0; }
.layout-center { text-align: center; }
.layout-center .text-rule { margin-inline: auto; }
.layout-center .text-body blockquote { border-left: 0; padding: 0; }
.layout-center .text-body ul, .layout-right .text-body ul { list-style-position: inside; padding: 0; }
.layout-justify .text-body { text-align: justify; hyphens: auto; }
.reader-foot { max-width: 34rem; margin: 3.5rem auto 0; font-size: 12px; color: color-mix(in srgb, var(--t-ink) 50%, var(--t-bg)); }
.reader-foot a { text-decoration: none; border-bottom: 1px solid currentColor; }
.back { display: inline-flex; gap: 6px; align-items: center; font-family: var(--f-ui); font-size: 13px; text-decoration: none; padding: 6px 0; opacity: .7; }
.back:hover { opacity: 1; }
.reader > .back { max-width: 34rem; margin: -16px auto 28px; display: flex; }
.admin-banner { font-family: var(--f-ui); font-size: 13px; text-align: center; padding: 8px 16px; background: var(--ink); color: var(--paper); }

/* ---------- 404 ---------- */
.gone { max-width: 30rem; margin: 0 auto; padding: 18vh 20px; text-align: center; }
.gone h1 { margin: 0 0 .5rem; }
.gone p { color: var(--muted); }

/* ---------- accueil ---------- */
.hub-page { background: var(--surface); }
.hub { max-width: 52rem; margin: 0 auto; padding: clamp(40px, 10vw, 96px) 20px 64px; }
.hub-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: clamp(24px, 6vw, 40px); }
.hub-head h1 { margin: 0; font-size: clamp(2rem, 8vw, 2.6rem); font-weight: 700; letter-spacing: -.02em; }
.view-toggle { display: flex; gap: 2px; padding: 3px; background: var(--paper); border-radius: 9px; }
.view-toggle button { border: 0; background: transparent; border-radius: 7px; width: 38px; height: 34px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.view-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.hub-list, .hub-grid { list-style: none; margin: 0; padding: 0; }
.hub[data-mode="list"] .hub-grid, .hub[data-mode="grid"] .hub-list { display: none; }
.hub-list { border-top: 1px solid var(--rule); }
.hub-list a { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 16px 2px; border-bottom: 1px solid var(--rule); text-decoration: none; }
.h-swatch { width: 16px; height: 16px; border-radius: 50%; background: linear-gradient(135deg, var(--t-bg) 50%, var(--t-accent) 50%); box-shadow: 0 0 0 1px var(--rule); }
.h-title { font-family: var(--t-font); font-size: calc(1.2rem * var(--t-scale)); font-weight: 600; line-height: 1.25; min-width: 0; overflow-wrap: break-word; }
.hub-list a:hover .h-title { color: var(--accent); }
.h-date { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 14px; }
.hub-grid > li { display: flex; min-width: 0; }
.block { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; height: 15rem; overflow: hidden; padding: 22px 20px 18px; border-radius: 12px; text-decoration: none; background: var(--t-bg); color: var(--t-ink); font-family: var(--t-font); border: 1px solid color-mix(in srgb, var(--t-ink) 12%, var(--t-bg)); transition: transform .15s; }
.block > * { min-width: 0; padding-inline: 2px; }
.block:hover { transform: translateY(-2px); }
.b-title { flex: none; font-weight: 600; font-size: calc(1.25rem * var(--t-scale)); line-height: 1.2; text-wrap: balance; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.b-excerpt { font-size: calc(.95rem * var(--t-scale)); line-height: 1.6; opacity: .85; flex: 1; min-height: 0; overflow: hidden; -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }
.b-foot { flex: none; margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-family: var(--f-ui); font-size: 12px; opacity: .7; }
.b-foot i { width: 18px; height: 2px; background: var(--t-accent); }
.hub-empty { color: var(--muted); padding: 1.5rem 0; }

/* ---------- connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; display: grid; gap: 14px; padding: 32px 24px; background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; }
.login-card h1 { margin: 0; font-size: 1.6rem; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.login-card .error { color: var(--danger); }
.gbtn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; border: 1px solid var(--rule); background: var(--surface); border-radius: 10px; padding: 11px 16px; font-weight: 500; min-height: 44px; text-decoration: none; }
.gbtn:hover { border-color: var(--muted); }
.dev-login { display: flex; gap: 8px; }
.dev-login input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); }

/* ---------- admin ---------- */
.admin-bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px 16px; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; border-bottom: 1px solid var(--rule); background: var(--surface); }
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.admin-nav { display: flex; gap: 2px; }
.admin-nav a { padding: 8px 10px; border-radius: 8px; color: var(--muted); font-size: 14px; white-space: nowrap; text-decoration: none; }
.admin-nav a[aria-current="page"] { color: var(--ink); background: var(--paper); }
.logout { margin: 0 0 0 auto; }
@media (max-width: 480px) { .brand { display: none; } .admin-bar { gap: 8px; padding-inline: 12px; } .admin-nav a { padding: 8px; } }
.admin-main { max-width: 1320px; margin: 0 auto; padding: 20px 16px 96px; }
.row-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.row-head h2 { font-size: 1.4rem; margin: 0; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { border: 1px solid var(--rule); background: var(--surface); padding: 5px 11px; border-radius: 999px; font-size: 13px; color: var(--muted); text-decoration: none; }
.chip[aria-current="page"] { border-color: var(--ink); color: var(--ink); }
.chip span { font-variant-numeric: tabular-nums; margin-left: 4px; opacity: .7; }
.btn { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--rule); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; white-space: nowrap; min-height: 38px; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; min-height: 32px; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }
.push { margin-left: auto; }
.items { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--rule); }
.item:last-child { border-bottom: 0; }
.item-main { display: grid; gap: 4px; min-width: 0; text-decoration: none; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-main:hover .item-title { color: var(--accent); }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 13px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.draft { background: var(--draft-bg); color: var(--draft-fg); }
.pill.link { background: var(--link-bg); color: var(--link-fg); }
.pill.public { background: var(--public-bg); color: var(--public-fg); }
.empty-row { padding: 24px 14px; color: var(--muted); }

/* ---------- éditeur ---------- */
.saved { font-size: 13px; color: var(--public-fg); background: var(--public-bg); padding: 2px 10px; border-radius: 999px; }
.dirty { font-size: 12.5px; color: var(--link-fg); }
.errors { border: 1px solid var(--danger); color: var(--danger); border-radius: 10px; padding: 8px 14px; margin-bottom: 16px; }
.errors p { margin: 4px 0; }
.editor { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.pane-tabs { display: none; }
@media (max-width: 859px) {
  .pane-tabs:not([hidden]) { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; position: sticky; top: calc(58px + env(safe-area-inset-top, 0px)); z-index: 5; margin-bottom: 14px; }
  .pane-tabs button { border: 0; background: transparent; border-radius: 7px; padding: 9px 4px; cursor: pointer; color: var(--muted); font-size: 14px; }
  .pane-tabs button[aria-selected="true"] { background: var(--paper); color: var(--ink); font-weight: 600; }
  .editor[data-pane="write"] > :not([data-pane="write"]),
  .editor[data-pane="preview"] > :not([data-pane="preview"]),
  .editor[data-pane="settings"] > :not([data-pane="settings"]) { display: none; }
  .save-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--surface); border-top: 1px solid var(--rule); padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .save-bar .btn.primary { flex: 1; }
}
@media (min-width: 860px) { .editor { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .settings { grid-column: 1 / -1; } }
@media (min-width: 1240px) { .editor { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr) 300px; } .settings { grid-column: auto; } }
.pane-label { font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; }
.write { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.title-input { font-size: 1.4rem; font-weight: 600; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); padding: 8px 12px; width: 100%; }
textarea.md { font-family: var(--f-code); font-size: 14px; line-height: 1.7; min-height: 60vh; resize: vertical; padding: 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); width: 100%; tab-size: 4; }
@media (min-width: 860px) { textarea.md { min-height: 30rem; } }
.md-help { margin: 0; font-size: 12.5px; color: var(--muted); }
.md-help code { font-family: var(--f-code); font-size: 12px; background: var(--surface); border: 1px solid var(--rule); padding: 0 5px; border-radius: 4px; color: var(--ink); }
.preview-col { min-width: 0; }
.preview { background: var(--t-bg); color: var(--t-ink); border-radius: 10px; border: 1px solid var(--rule); min-height: 50vh; padding: 36px 20px 32px; }
@media (min-width: 860px) { .preview { max-height: 44rem; overflow: auto; padding: 44px 28px 36px; } }
.settings { display: grid; gap: 12px; align-content: start; min-width: 0; }
@media (min-width: 860px) and (max-width: 1239px) { .settings { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px 14px; margin: 0; display: grid; gap: 10px; min-width: 0; }
.card legend { float: left; width: 100%; padding: 0; margin-bottom: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.card legend + * { clear: both; }
.opt input, .font-opt input, .theme-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--paper); border-radius: 9px; padding: 3px; gap: 3px; }
.seg.four { grid-template-columns: repeat(4, 1fr); }
.opt > span { border-radius: 7px; padding: 8px 4px; cursor: pointer; font-size: 13px; color: var(--muted); display: grid; place-items: center; gap: 3px; min-height: 40px; text-align: center; }
.opt small { font-size: 11px; }
.opt input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.opt input:focus-visible + span, .font-opt input:focus-visible + span, .theme-opt input:focus-visible ~ span { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.share-url { display: flex; gap: 6px; }
.share-url input { flex: 1; min-width: 0; font-family: var(--f-code); font-size: 12px; padding: 6px 8px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); }
.share-off input { opacity: .45; text-decoration: line-through; }
.fonts { display: grid; gap: 6px; }
.font-opt > span { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; border: 1px solid var(--rule); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.font-opt small { font-size: 12px; color: var(--muted); }
.font-opt input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.themes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.theme-opt { position: relative; border: 1px solid var(--rule); border-radius: 8px; cursor: pointer; overflow: hidden; background: var(--sw-bg); color: var(--sw-ink); }
.theme-opt span { display: block; padding: 8px 8px 2px; font-size: 13px; font-weight: 600; }
.theme-opt i { display: block; height: 4px; background: var(--sw-accent); margin-top: 6px; }
.theme-opt:has(input:checked) { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.colors label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.colors input { width: 100%; height: 34px; border: 1px solid var(--rule); border-radius: 6px; padding: 2px; background: var(--paper); cursor: pointer; }
.colors input:disabled { opacity: .5; cursor: not-allowed; }
.field { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.field input { font-size: 15px; color: var(--ink); padding: 7px 9px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); }
.field .prefix { display: flex; align-items: center; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); overflow: hidden; }
.field .prefix span { font-family: var(--f-code); font-size: 12px; padding-left: 9px; color: var(--muted); white-space: nowrap; }
.field .prefix input { border: 0; padding-left: 2px; font-family: var(--f-code); font-size: 13px; flex: 1; min-width: 0; }
.save-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 16px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
