:root {
  --paper: #f7f2e8;
  --paper-2: #efe8da;
  --card: #fffdf8;
  --ink: #29251f;
  --ink-2: #6a6257;
  --ink-3: #9c9487;
  --line: #e3dac9;
  --line-2: #d4c9b4;
  --gold: #9c6f27;
  --gold-2: #c79a4b;
  --gold-soft: #f4d8a0;
  --night: #070b16;
  --danger: #a3412c;
  --ok: #56724a;
  --serif: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --top: 58px;
  --side: 300px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--gold); }

button.primary, button.ghost, button.plain, button.danger {
  border: 1px solid transparent; border-radius: 8px; padding: 7px 14px; background: none;
  transition: background .2s, border-color .2s, color .2s, opacity .2s;
}
button.primary { background: var(--ink); color: var(--paper); }
button.primary:hover { background: #000; }
button.primary:disabled { opacity: .35; cursor: default; }
button.ghost { border-color: var(--line-2); }
button.ghost:hover { background: var(--paper-2); }
button.plain { padding: 5px 8px; color: var(--ink-2); }
button.plain:hover { color: var(--ink); background: var(--paper-2); }
button.danger { color: var(--danger); border-color: rgba(163, 65, 44, .3); }
button.danger:hover { background: rgba(163, 65, 44, .07); }
button.icon { padding: 6px 10px; line-height: 1; font-size: 16px; }
button:disabled { cursor: default; }

/* ---------- connexion ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 120%, #1a2238 0%, var(--night) 60%);
}
.login-box { width: min(320px, 86vw); text-align: center; display: grid; gap: 14px; }
.login-title { font: italic 500 46px/1 var(--serif); color: var(--gold-soft); }
.login-sub { font: 11px var(--sans); letter-spacing: .4em; color: rgba(248, 240, 218, .45); margin: -4px 0 18px; text-transform: uppercase; }
.login-box input {
  background: rgba(248, 240, 218, .06); border: 1px solid rgba(248, 240, 218, .18); border-radius: 8px;
  padding: 11px 14px; color: #f8f0da; text-align: center; outline: none;
}
.login-box input:focus { border-color: rgba(244, 216, 160, .6); }
.login-box button.primary { background: var(--gold-soft); color: var(--night); padding: 10px; }
.login-err { min-height: 20px; color: #e9a58f; font-size: 13px; }

/* ---------- structure ---------- */
.app { display: grid; grid-template-columns: var(--side) 1fr; grid-template-rows: var(--top) 1fr; height: 100vh; }
.top {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 18px 0 22px;
  border-bottom: 1px solid var(--line); background: var(--paper); z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.brand b { font: italic 500 24px var(--serif); }
.brand span { font-size: 10.5px; letter-spacing: .32em; text-transform: uppercase; color: var(--ink-3); }
.status { flex: 1; font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.dirty { color: var(--gold); }
.status.dirty::before { content: '● '; }
.actions { display: flex; gap: 8px; align-items: center; }
.more { position: relative; }
.pop {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(40, 30, 10, .12);
  display: grid;
}
.pop a, .pop button { display: block; text-align: left; padding: 8px 12px; border-radius: 6px; border: 0; background: none; color: var(--ink); text-decoration: none; }
.pop a:hover, .pop button:hover { background: var(--paper-2); }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.only-narrow { display: none; }

/* ---------- sommaire ---------- */
.side { overflow-y: auto; border-right: 1px solid var(--line); padding: 18px 12px 60px; background: var(--paper); }
.side-h { font-size: 10.5px; letter-spacing: .28em; text-transform: uppercase; color: var(--ink-3); margin: 18px 10px 8px; }
.side-h:first-child { margin-top: 4px; }
.s-row {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 7px; cursor: pointer;
  user-select: none; position: relative;
}
.s-row:hover { background: var(--paper-2); }
.s-row.on { background: var(--ink); color: var(--paper); }
.s-row.on .s-num, .s-row.on .s-meta { color: rgba(247, 242, 232, .6); }
.s-row .s-ttl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-rec .s-ttl { font: italic 500 18.5px/1.25 var(--serif); }
.s-twisty { width: 18px; height: 18px; border: 0; background: none; padding: 0; color: var(--ink-3); font-size: 10px; transition: transform .2s; flex: none; }
.s-twisty.open { transform: rotate(90deg); }
.s-row.on .s-twisty { color: rgba(247, 242, 232, .7); }
.s-meta { font-size: 11.5px; color: var(--ink-3); flex: none; }
.s-texts { margin: 2px 0 8px 18px; padding-left: 8px; border-left: 1px solid var(--line); }
.s-text { padding: 4px 8px; }
.s-text .s-ttl { font: 16.5px/1.3 var(--serif); }
.s-num { font: 10px var(--sans); letter-spacing: .08em; color: var(--ink-3); width: 26px; flex: none; }
.s-star { font-size: 10px; color: var(--gold-2); flex: none; }
.s-row.on .s-star { color: var(--gold-soft); }
.s-add { display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--ink-3); padding: 6px 8px; border-radius: 7px; font-size: 13px; }
.s-add:hover { color: var(--ink); background: var(--paper-2); }
.s-row.drop-before::before, .s-row.drop-after::after {
  content: ''; position: absolute; left: 6px; right: 6px; height: 2px; background: var(--gold-2); border-radius: 2px;
}
.s-row.drop-before::before { top: -1px; }
.s-row.drop-after::after { bottom: -1px; }
.s-row.drop-into { box-shadow: inset 0 0 0 2px var(--gold-2); }
.s-row.dragging { opacity: .4; }

/* ---------- éditeur ---------- */
.main { overflow-y: auto; scroll-behavior: smooth; }
.ed { max-width: 760px; margin: 0 auto; padding: 34px 40px 140px; }
.crumb { font-size: 12px; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 18px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumb a { color: var(--ink-3); text-decoration: none; cursor: pointer; }
.crumb a:hover { color: var(--ink); }
.title-in, .sub-in {
  width: 100%; border: 0; background: none; outline: none; padding: 2px 0; border-bottom: 1px dashed transparent;
}
.title-in { font: italic 500 42px/1.15 var(--serif); }
.sub-in { font: 21px/1.3 var(--serif); color: var(--ink-2); margin-top: 4px; }
.title-in:hover, .sub-in:hover { border-bottom-color: var(--line-2); }
.title-in:focus, .sub-in:focus { border-bottom-color: var(--gold-2); }
.title-in::placeholder, .sub-in::placeholder { color: var(--ink-3); opacity: .6; }

.block { margin-top: 38px; }
.block-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.block-h h3 { margin: 0; font-size: 11px; letter-spacing: .26em; text-transform: uppercase; font-weight: 600; color: var(--ink-2); }
.note { font-size: 12.5px; color: var(--ink-3); margin: 0 0 10px; max-width: 60ch; }
.area {
  display: block; width: 100%; resize: none; overflow: hidden; outline: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px;
  transition: border-color .2s, box-shadow .2s;
}
.area:focus { border-color: var(--gold-2); box-shadow: 0 0 0 3px rgba(199, 154, 75, .12); }
.area.poem { font: italic 22px/1.6 var(--serif); min-height: 120px; }
.area.prose { font: 19.5px/1.65 var(--serif); min-height: 160px; }
.area.sea { font: italic 19px/1.5 var(--serif); min-height: 70px; }
.area.body { font: 19.5px/1.65 var(--serif); min-height: 120px; }
.area::placeholder { color: var(--ink-3); opacity: .7; }

.field { display: grid; gap: 6px; margin-top: 20px; }
.field > span:first-child { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.field input[type=text], .field input[type=date], .field select, .in {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); outline: none;
}
.field input:focus, .field select:focus, .in:focus { border-color: var(--gold-2); }
.f-note { font-size: 12px; color: var(--ink-3); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; margin-top: 18px; }
.switch input { appearance: none; width: 36px; height: 21px; border-radius: 21px; background: var(--line-2); position: relative; cursor: pointer; transition: background .2s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { transform: translateX(15px); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; }
.callout { display: flex; gap: 14px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; margin-top: 26px; }
.callout .ico { font-size: 18px; color: var(--gold-2); line-height: 1.2; }
.callout p { margin: 0; color: var(--ink-2); }
.callout .act { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

.tlist { display: grid; gap: 8px; }
.trow {
  display: grid; grid-template-columns: 34px 1fr auto auto; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 10px 16px; cursor: pointer;
  transition: border-color .2s, transform .2s;
}
.trow:hover { border-color: var(--line-2); }
.trow .num { font-size: 11px; color: var(--ink-3); letter-spacing: .08em; }
.trow .t { font: italic 500 20px/1.25 var(--serif); }
.trow .t small { display: block; font: 14px var(--serif); font-style: normal; color: var(--ink-3); }
.trow .info { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.trow .info.has { color: var(--gold); }
.mv { display: flex; gap: 2px; }
.mv button { border: 0; background: none; color: var(--ink-3); padding: 4px 6px; border-radius: 5px; }
.mv button:hover:not(:disabled) { background: var(--paper-2); color: var(--ink); }
.mv button:disabled { opacity: .25; }
.add-row { margin-top: 10px; }

.foot { margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.foot .grow { flex: 1; }
.foot select { padding: 7px 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--card); }

.empty { text-align: center; padding: 120px 20px; color: var(--ink-3); font: italic 22px var(--serif); }

/* ---------- constellation ---------- */
.sky {
  position: relative; width: 100%; border-radius: 14px; overflow: hidden; touch-action: none; outline: none;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(244, 216, 160, .10), transparent 55%),
    linear-gradient(#070b16 0%, #0c1426 62%, #121b30 84.8%, #0a0f1c 85%, #05080f 100%);
  cursor: crosshair; user-select: none;
}
.sky-dots { position: absolute; inset: 0; pointer-events: none; }
.sky-dots i { position: absolute; width: 1.5px; height: 1.5px; border-radius: 50%; background: #f8f0da; }
.sky-horizon { position: absolute; left: 0; right: 0; height: 1px; background: linear-gradient(90deg, transparent, rgba(244, 216, 160, .45), transparent); pointer-events: none; }
.sky-limit { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed rgba(248, 240, 218, .12); pointer-events: none; }
.sky-limit span { position: absolute; top: 8px; left: 6px; font-size: 10px; letter-spacing: .1em; color: rgba(248, 240, 218, .28); white-space: nowrap; }
.sky-limit.r span { left: auto; right: 6px; }
.sky-out { position: absolute; top: 0; bottom: 0; background: rgba(0, 0, 0, .28); pointer-events: none; }
.sky svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.sky path { fill: none; stroke: rgba(244, 216, 160, .4); stroke-width: 1; }
.w {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap; cursor: grab;
  font-family: var(--serif); font-style: italic; color: rgba(248, 240, 218, .78);
  padding: .3em .45em; border-radius: 6px; transition: color .2s, background .2s, text-shadow .2s;
}
.w:hover { color: #fff8e6; background: rgba(248, 240, 218, .06); }
.w.on { color: #f4d8a0; background: rgba(244, 216, 160, .1); box-shadow: 0 0 0 1px rgba(244, 216, 160, .5); text-shadow: 0 0 10px rgba(244, 216, 160, .5); }
.w.guide::before { content: '✦'; position: absolute; left: 50%; top: -.55em; transform: translateX(-50%); font-size: .5em; font-style: normal; color: #f4d8a0; }
.w.empty { min-width: 3em; min-height: 1.6em; border: 1px dashed rgba(244, 216, 160, .5); }
.w.dragging { cursor: grabbing; }
.w .ord { position: absolute; right: -.3em; bottom: -.35em; font: 9px var(--sans); font-style: normal; color: rgba(248, 240, 218, .35); }
.rf { position: absolute; transform: translate(-50%, -50%) scaleY(-1); white-space: nowrap; pointer-events: none; font-family: var(--serif); font-style: italic; color: rgba(248, 240, 218, .14); filter: blur(.4px); }
.sky-empty { position: absolute; left: 0; right: 0; top: 38%; text-align: center; font: italic 19px var(--serif); color: rgba(248, 240, 218, .45); pointer-events: none; }

.ctools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; min-height: 40px; }
.ctools .in { width: 230px; font: italic 18px var(--serif); padding: 6px 12px; }
.ctools .count { font-size: 12px; color: var(--ink-3); margin-left: auto; }
.chip-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line-2); border-radius: 20px; cursor: pointer; user-select: none; font-size: 13px; background: none; }
.chip-toggle.on { background: var(--gold-soft); border-color: var(--gold-2); }
.suggest { margin-top: 16px; }
.suggest .lbl { font-size: 12px; color: var(--ink-3); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 3px 11px; font: italic 16px var(--serif); color: var(--ink-2); }
.chip:hover { border-color: var(--gold-2); color: var(--ink); }

/* ---------- pages / journal ---------- */
.entry { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px 18px; margin-top: 12px; }
.entry-h { display: flex; gap: 10px; align-items: center; }
.entry-h input[type=date] { width: auto; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.entry-h .grow { flex: 1; }
.entry .e-title { width: 100%; border: 0; outline: none; background: none; font: italic 500 24px var(--serif); margin: 10px 0 6px; }
.entry .area { border-color: transparent; background: var(--paper); }

/* ---------- toast & dialogue ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; font-size: 13.5px;
  display: flex; gap: 14px; align-items: center; transition: opacity .25s, transform .25s; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: none; color: var(--gold-soft); font-weight: 600; padding: 0; }
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(520px, 92vw); max-height: 86vh; background: var(--card); color: var(--ink); box-shadow: 0 30px 80px rgba(20, 14, 4, .3); }
.dlg::backdrop { background: rgba(30, 24, 14, .35); backdrop-filter: blur(2px); }
.dlg-in { padding: 24px 26px 20px; }
.dlg h2 { margin: 0 0 10px; font: italic 500 28px var(--serif); }
.dlg p { margin: 0 0 10px; color: var(--ink-2); }
.dlg-act { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dlg.wide { width: min(680px, 94vw); }
.vlist { max-height: 56vh; overflow-y: auto; margin: 0 -8px; }
.vrow { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.vrow:last-child { border-bottom: 0; }
.vrow b { font-weight: 500; }
.vrow small { display: block; color: var(--ink-3); font-size: 12px; }
.vrow .cur { font-size: 12px; color: var(--ok); }
.help h3 { font: italic 500 21px var(--serif); margin: 18px 0 4px; }
.help p, .help li { color: var(--ink-2); }
.help ul { padding-left: 18px; margin: 4px 0; }

/* ---------- écrans étroits ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .only-narrow { display: inline-block; }
  .side { position: fixed; top: var(--top); bottom: 0; left: 0; width: min(320px, 86vw); z-index: 30; transform: translateX(-100%); transition: transform .25s; box-shadow: 10px 0 30px rgba(0, 0, 0, .08); }
  body.side-open .side { transform: none; }
  .ed { padding: 24px 18px 120px; }
  .title-in { font-size: 34px; }
  .brand span, .status { display: none; }
  .top { gap: 10px; padding: 0 12px; }
}
