:root {
  --bg: #EDE5D9;
  --bg-2: #E4DACB;
  --paper: #F4EEE5;
  --ink: #1C1714;
  --ink-2: #4A403A;
  --muted: #7A6E66;
  --line: #CDBFAE;
  --accent: #7C1416;
  --accent-ink: #F4EEE5;
  --ok: #3F5B3A;
  --nav-h: 64px;
  --head-h: 52px;
  --title: 'IM Fell English', Georgia, serif;
  --text: 'EB Garamond', Georgia, serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15110F;
  --bg-2: #201A17;
  --paper: #1D1815;
  --ink: #EDE5D9;
  --ink-2: #CFC4B6;
  --muted: #9C8F84;
  --line: #3A302A;
  --accent: #C0474A;
  --accent-ink: #15110F;
  --ok: #8FB087;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--text);
  font-size: 18px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- structure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--head-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-family: var(--title); font-style: italic; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: none; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink);
}
.icon-btn svg { width: 24px; height: 24px; }
main {
  max-width: 640px; margin: 0 auto;
  padding: 20px 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
.offline-banner {
  position: sticky; top: var(--head-h); z-index: 19;
  background: var(--ink); color: var(--bg);
  font-size: 15px; text-align: center; padding: 6px 12px;
}

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg); border-top: 1px solid var(--line);
}
nav.tabs a {
  flex: 1; min-width: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 13px; line-height: 1.1;
}
nav.tabs a svg { width: 24px; height: 24px; }
nav.tabs a.active { color: var(--accent); }
nav.tabs a.active span { font-weight: 600; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

.menu-sheet {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.35);
  display: flex; align-items: flex-start; justify-content: flex-end;
}
.menu-sheet .panel {
  margin: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  min-width: 250px; padding: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.menu-sheet button, .menu-sheet a.item {
  display: flex; width: 100%; min-height: 48px; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 12px; border: 0; background: none; text-align: left; border-radius: 8px; cursor: pointer;
  text-decoration: none; color: var(--ink); font-size: 18px;
}
.menu-sheet button:active { background: var(--bg-2); }

/* ---------- typographie ---------- */
h1, h2, h3 { font-family: var(--title); font-style: italic; font-weight: 400; line-height: 1.15; margin: 0; }
h1 { font-size: 34px; }
h2 { font-size: 28px; color: var(--accent); }
h3 { font-size: 23px; }
p { margin: 0 0 14px; }
.kicker { font-size: 14px; letter-spacing: .35em; text-transform: uppercase; color: var(--accent); text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 16px; }
.center { text-align: center; }

.sep {
  display: flex; align-items: center; justify-content: center; gap: 14px; margin: 26px auto; color: var(--accent);
}
.sep::before, .sep::after { content: ''; width: 72px; height: 1px; background: var(--accent); }
.sep i { width: 9px; height: 9px; border: 1px solid var(--accent); transform: rotate(45deg); }
.sep.solo::before, .sep.solo::after { display: none; }

.page-title { text-align: center; margin: 8px 0 4px; }
.page-title h1 { font-size: 36px; }

/* ---------- livret ---------- */
.lore-page {
  min-height: calc(100vh - var(--head-h) - var(--nav-h));
  padding: 28px 4px 36px;
  border-bottom: 1px solid var(--line);
}
.lore-page:last-child { border-bottom: 0; }
.lore-cover { text-align: center; padding-top: 12px; }
.lore-cover .dates { font-family: var(--title); font-style: italic; color: var(--accent); letter-spacing: .45em; font-size: 18px; }
.lore-cover h1 { font-size: 48px; margin: 18px 0 18px; line-height: 1.05; }
.tagline { font-family: var(--title); font-style: italic; font-size: 22px; line-height: 1.35; margin: 0; }
.lore-page h2 { margin: 30px 0 12px; }
.lore-page .big-title { font-family: var(--title); font-size: 64px; text-align: center; margin: 14px 0 0; font-style: normal; }
.lore-page .lineage-title { font-family: var(--title); font-style: italic; font-size: 40px; margin: 22px 0 14px; color: var(--ink); }
.lore-page .lore-i { font-style: italic; }
.lore-page .lore-r { font-style: italic; color: var(--accent); }
.lore-page .folio { text-align: center; font-family: var(--title); font-style: italic; color: var(--accent); margin-top: 24px; }
.lore-toc { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0 0; }
.lore-toc a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--line);
  border-radius: 22px; text-decoration: none; color: var(--ink); font-size: 16px;
}

/* ---------- formulaires ---------- */
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 18px 16px; margin: 0 0 16px;
}
.field { margin: 0 0 26px; }
.field > label, .field > .label { display: block; font-weight: 600; font-size: 19px; margin-bottom: 2px; }
.help { color: var(--ink-2); font-size: 17px; margin: 0 0 8px; line-height: 1.4; }
.vis { display: inline-block; font-size: 13px; font-weight: 500; letter-spacing: .04em; padding: 1px 8px; border-radius: 10px; margin-left: 6px; vertical-align: 2px; border: 1px solid var(--line); color: var(--muted); }
.vis.pub { color: var(--accent); border-color: var(--accent); }
input[type="text"], input[type="number"], input[type="date"], input[type="time"], textarea, select {
  width: 100%; min-height: 48px; padding: 10px 12px; font-size: 18px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .85; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.choices { display: grid; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; text-align: left; width: 100%;
}
.choice .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.choice.sel { border-color: var(--accent); background: var(--paper); }
.choice.sel .dot { border-color: var(--accent); background: radial-gradient(var(--accent) 45%, transparent 50%); }
.choice[disabled] { opacity: .5; cursor: not-allowed; }
.choice .meta { margin-left: auto; font-size: 15px; color: var(--muted); text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid var(--line); background: var(--bg); cursor: pointer;
}
.chip.sel { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 22px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); font-size: 18px; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn svg { width: 20px; height: 20px; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 16px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }

.save-state { font-size: 14px; color: var(--muted); min-height: 20px; text-align: right; }
.notice { border-left: 3px solid var(--accent); padding: 10px 14px; background: var(--paper); margin: 0 0 18px; border-radius: 0 8px 8px 0; }
.notice.ok { border-left-color: var(--ok); }
.error-text { color: var(--accent); font-size: 16px; margin-top: 6px; }
.field.missing input, .field.missing textarea, .field.missing .choices { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.step-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.step-head h2 { font-size: 26px; }

.portrait-box { display: flex; gap: 14px; align-items: center; }
.portrait-box img, .portrait-ph { width: 96px; height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2); flex: none; }

/* ---------- connexion ---------- */
.login { max-width: 420px; margin: 0 auto; padding: 40px 20px; text-align: center; min-height: 100vh; }
.login h1 { font-size: 46px; line-height: 1.05; margin: 18px 0; }
.login input { text-align: center; letter-spacing: .08em; text-transform: uppercase; font-size: 22px; min-height: 56px; }

/* ---------- personnages ---------- */
.char-list { display: grid; gap: 10px; }
.char-item {
  display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--paper); text-decoration: none; color: var(--ink); min-height: 64px;
}
.char-item img, .char-item .ph { width: 48px; height: 60px; border-radius: 6px; object-fit: cover; background: var(--bg-2); flex: none; border: 1px solid var(--line); }
.char-item .name { font-family: var(--title); font-style: italic; font-size: 22px; line-height: 1.15; }
.char-item .sub { font-size: 15px; color: var(--muted); }
.char-sheet .portrait { width: 100%; max-height: 420px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 16px; }
.char-sheet dt { font-size: 15px; color: var(--accent); letter-spacing: .05em; margin-top: 14px; }
.char-sheet dd { margin: 2px 0 0; white-space: pre-wrap; }
.waiting { text-align: center; padding: 60px 8px; }
.waiting p { font-family: var(--title); font-style: italic; font-size: 26px; line-height: 1.3; }

/* ---------- liens ---------- */
.link-card h3 { font-size: 22px; color: var(--accent); }
.link-card .who { font-size: 16px; color: var(--muted); margin: 2px 0 10px; }
.link-card .who a { color: var(--ink); }
.entry { border-top: 1px solid var(--line); padding: 10px 0; }
.entry .by { font-size: 14px; color: var(--muted); }
.entry .body { white-space: pre-wrap; }
.tag {
  display: inline-block; font-size: 13px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); vertical-align: 3px;
}
.tag.red { color: var(--accent); border-color: var(--accent); }

/* ---------- cartes ---------- */
.secret-card { position: relative; border: 1px solid var(--accent); background: var(--paper); border-radius: 12px; padding: 18px 16px; margin-bottom: 14px; }
.secret-card h3 { font-size: 23px; }
.secret-card .body { white-space: pre-wrap; margin-top: 10px; }
.secret-card.sealed { text-align: center; }
.seal {
  width: 64px; height: 64px; margin: 4px auto 10px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--title); font-style: italic; font-size: 24px;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.15), 0 2px 0 rgba(0,0,0,.15);
}
.new-flag { position: absolute; top: 10px; right: 12px; font-size: 13px; color: var(--accent); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }

/* ---------- carnet ---------- */
.fab {
  position: fixed; z-index: 25; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  min-height: 54px; padding: 0 22px; border-radius: 27px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 18px; font-weight: 500;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
}
.note { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.note .when { font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.note .text { white-space: pre-wrap; margin: 6px 0 0; }
.note textarea { min-height: 140px; background: var(--bg); }
.note .thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.note .thumbs .th { position: relative; }
.note .thumbs img { width: 88px; height: 88px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.note .thumbs .rm { position: absolute; top: -8px; right: -8px; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); cursor: pointer; font-size: 18px; line-height: 1; }
.note .pending { font-size: 13px; color: var(--accent); }
.filter-bar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; }
.filter-bar .chip { flex: none; }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.9); display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; }

/* ---------- admin ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .n { font-family: var(--title); font-size: 34px; line-height: 1; }
.stat .l { font-size: 15px; color: var(--muted); }
.stat.alert { border-color: var(--accent); }
.stat.alert .n { color: var(--accent); }
.list-item {
  display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
  margin-bottom: 10px; text-decoration: none; color: var(--ink);
}
.list-item .t { font-weight: 600; }
.list-item .s { font-size: 15px; color: var(--muted); }
.code-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 22px; letter-spacing: .06em; padding: 10px 12px; border: 1px dashed var(--accent); border-radius: 8px; text-align: center; background: var(--bg); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 56px; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch { position: relative; width: 56px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--paper); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(24px); }
.member-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--bg); }
.sub-tabs { display: flex; gap: 8px; margin: 0 0 16px; overflow-x: auto; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 84px + env(safe-area-inset-bottom)); z-index: 70;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 22px; font-size: 16px; max-width: calc(100% - 32px); text-align: center;
}
details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
