/* Carnet d'aventurier — socle visuel de l'app (thème parchemin + mode sombre).
   Les vues ajoutent leurs styles dans sheet.css / turn.css / journal.css / advisor.css,
   en préfixant leurs sélecteurs par  .view[data-view="<vue>"]  ou une classe propre (.sh-, .tn-, .jr-, .ad-). */
:root {
  --bg: #f4ecdc;
  --surface: #fffaf0;
  --surface-2: #efe4cf;
  --ink: #2a1f17;
  --muted: #7a6a58;
  --line: #dccbb0;
  --brand: #8e2c22;          /* rouge dragon */
  --brand-ink: #fff8ee;
  --gold: #b8892b;
  --good: #2f8a4f; --good-soft: #dff1e3;
  --bad: #c0392b;  --bad-soft: #f8e0dc;
  --warn: #c98a10; --warn-soft: #fbefd2;
  --info: #2f5f8a; --info-soft: #dfeaf5;
  --radius: 14px;
  --shadow: 0 1px 0 rgba(42, 31, 23, .08), 0 6px 18px rgba(42, 31, 23, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-title: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f; --surface: #221c16; --surface-2: #2d251d; --ink: #f1e6d3; --muted: #a8977f; --line: #3b3127;
    --brand: #d0574a; --brand-ink: #1a0f0c; --gold: #d9ab4a;
    --good: #5cc283; --good-soft: #1d3326; --bad: #ef6b5c; --bad-soft: #3a1d19;
    --warn: #e9b44c; --warn-soft: #3a2f17; --info: #79a9d8; --info-soft: #1a2a3a;
    --shadow: 0 1px 0 rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

body { font-size: 16px; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
h1, h2, h3 { font-family: var(--font-title); }
.btn { min-height: 44px; padding: 0 16px; font-size: 1rem; font-weight: 700; border-radius: 12px; border: 1px solid var(--line); box-shadow: none; }
.btn.primary { border-color: transparent; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: .9rem; }
.btn.danger, .danger { color: var(--bad); }
.btn.good { background: var(--good); color: #fff; border-color: transparent; }
.btn.bad { background: var(--bad); color: #fff; border-color: transparent; }
.icon-btn { min-width: 40px; min-height: 40px; border: 0; background: transparent; border-radius: 10px; font-size: 1.1rem; }
.icon-btn:hover { background: var(--surface-2); }
.card { border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 14px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { flex: 1; min-width: 140px; }
.grid { display: grid; gap: 12px; }
.stack > * + * { margin-top: 12px; }
.wrap { max-width: 1100px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; min-height: 42px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 600; }
label.field > span { text-transform: uppercase; letter-spacing: .04em; font-size: .72rem; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); }
input[type="number"] { -moz-appearance: textfield; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: .85rem; font-weight: 600; }
.chip.on, .chip.brand { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
button.chip { cursor: pointer; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 0 8px; }
.section-title h2, .section-title h3 { margin: 0; }
.empty { color: var(--muted); font-style: italic; padding: 8px 0; }

/* Barre du haut */
.appbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--line); }
.appbar .back { color: var(--muted); text-decoration: none; font-size: 1.3rem; font-weight: 700; padding: 4px 8px; }
.char-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: transparent; border: 0; text-align: left; padding: 4px; border-radius: 10px; }
.char-btn:hover { background: var(--surface-2); }
#char-portrait { font-size: 1.9rem; line-height: 1; }
.char-meta { min-width: 0; display: grid; }
.char-meta b { font-family: var(--font-title); font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-meta small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.saved[data-ok="false"] { color: var(--bad); }

/* Onglets : en bas sur téléphone, en haut sur grand écran */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { display: grid; justify-items: center; gap: 1px; padding: 8px 0 10px; border: 0; background: transparent; color: var(--muted); font-size: .78rem; font-weight: 700; }
.tabs button span { font-size: 1.35rem; }
.tabs button[aria-selected="true"] { color: var(--brand); }
.tabs button:disabled { opacity: .4; }
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabs { position: sticky; top: 61px; bottom: auto; grid-template-columns: repeat(5, max-content); justify-content: center; gap: 6px; border-top: 0; border-bottom: 1px solid var(--line); background: var(--bg); padding: 4px; }
  .tabs button { grid-auto-flow: column; gap: 6px; padding: 8px 16px; font-size: .95rem; border-radius: 10px; }
  .tabs button span { font-size: 1.1rem; }
  .tabs button[aria-selected="true"] { background: var(--surface); box-shadow: var(--shadow); }
}
.view { min-height: 60vh; }

/* Accueil */
.welcome { margin-top: 24px; text-align: center; max-width: 520px; }
.welcome .big { font-size: 4rem; }

/* Modale */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(20, 12, 6, .45); display: grid; place-items: end center; }
@media (min-width: 600px) { .modal-back { place-items: center; } }
.modal { width: min(560px, 100%); max-height: 88dvh; overflow: auto; border-radius: 18px 18px 0 0; padding: 0; }
@media (min-width: 600px) { .modal { border-radius: 18px; } }
.modal header { position: sticky; top: 0; background: var(--surface); display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 1.2rem; }
.modal-body { padding: 14px; display: grid; gap: 12px; }

.pick-list { display: grid; gap: 6px; }
.pick { display: flex; gap: 12px; align-items: center; text-align: left; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.pick.on { border-color: var(--brand); }
.pick span { display: grid; }
.pick small { color: var(--muted); }
.pick-face { font-size: 1.8rem; }

/* Toasts (résultats de dés, erreurs) */
.toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); display: grid; gap: 6px; width: min(440px, calc(100% - 24px)); pointer-events: none; }
@media (min-width: 900px) { .toasts { bottom: 20px; } }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; font-size: .95rem; }
.toast.good { background: var(--good); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
.roll-total { font-size: 1.5rem; font-weight: 900; margin: 0 6px; }
.roll-toast small { opacity: .8; }

/* Texte riche (réponses IA, journal) */
.prose { line-height: 1.55; overflow-wrap: anywhere; }
.prose p { margin: .4em 0; }
.prose ul, .prose ol { margin: .4em 0; padding-left: 1.3em; }
.prose h3, .prose h4, .prose h5, .prose h6 { margin: .8em 0 .3em; font-size: 1.05rem; }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }

/* ───── Bulle « 💬 Session » (sessionchat.js), visible sur toutes les vues ───── */
.sc-fab { position: fixed; z-index: 40; right: 14px; bottom: calc(74px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 6px; padding: 10px 16px; border: 0; border-radius: 999px; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: .95rem; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.sc-fab span { font-size: 1.25rem; }
.sc-fab[aria-expanded="true"] { opacity: 0; pointer-events: none; }
.sc-panel { position: fixed; z-index: 41; right: 10px; left: 10px; bottom: calc(70px + env(safe-area-inset-bottom)); max-height: min(72vh, 620px); display: flex; flex-direction: column; padding: 0; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.sc-panel[hidden] { display: none; }
.sc-head { display: flex; gap: 6px; align-items: center; padding: 8px 8px 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.sc-pick { flex: 1; min-width: 0; font-weight: 700; }
.sc-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.sc-hint { color: var(--muted); font-size: .92rem; margin: 4px; }
.sc-msg { max-width: 88%; padding: 8px 11px; border-radius: 14px; font-size: .95rem; line-height: 1.4; overflow-wrap: anywhere; }
.sc-msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 4px; }
.sc-msg.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.sc-msg p { margin: 0; }
.sc-dots { color: var(--muted); font-style: italic; }
.sc-dots span { animation: sc-blink 1s infinite; }
@keyframes sc-blink { 50% { opacity: .2; } }
.sc-preview { border-top: 1px dashed var(--line); padding-top: 8px; font-size: .92rem; }
.sc-preview h3, .sc-preview h4 { margin: .6em 0 .2em; font-size: 1rem; }
.sc-form { border-top: 1px solid var(--line); padding: 8px; display: grid; gap: 6px; background: var(--surface); }
.sc-form textarea { width: 100%; resize: vertical; min-height: 3.2em; max-height: 30vh; font-size: 1rem; }
.sc-row { display: flex; justify-content: space-between; gap: 8px; }
@media (min-width: 900px) {
  .sc-fab { bottom: 20px; right: 20px; }
  .sc-panel { left: auto; right: 20px; bottom: 20px; width: 400px; }
}
body[data-view="advisor"] .sc-fab { bottom: calc(136px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { body[data-view="advisor"] .sc-fab { bottom: 96px; } }

/* ── Site partagé (dnd.baurens.fr) ── */
.appbar .camp-btn { font-size: 1.4rem; padding: 2px 6px; }
.sc-msg.other { align-self: flex-start; background: var(--info-soft); border-bottom-left-radius: 4px; }
.sc-who { display: block; font-size: .78rem; color: var(--info); margin-bottom: 2px; }
.sc-time { display: block; font-size: .7rem; opacity: .65; margin-top: 2px; text-align: right; }
.jr-contribs { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line); display: grid; gap: 8px; justify-items: start; }
.jr-notes-table { width: 100%; }
.jr-notes-table summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.jr-notes-table ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 8px; }
.jr-notes-table li { padding: 8px 10px; border-radius: 10px; background: var(--surface-2, var(--bg)); font-size: .92rem; }
.jr-notes-table small { color: var(--muted); }

/* Compagnie */
.cp { display: grid; gap: 14px; padding-bottom: 90px; }
.cp-head { display: flex; align-items: center; gap: 12px; }
.cp-head .em { font-size: 2.2rem; line-height: 1; }
.cp-head h1 { margin: 0; font-family: var(--font-title); font-size: 1.5rem; }
.cp-head p { margin: 2px 0 0; }
.cp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.cp-card { display: grid; gap: 8px; padding: 14px; text-align: left; font: inherit; color: var(--ink); cursor: pointer; border: 1px solid var(--line); }
.cp-card.me { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold), var(--shadow); }
.cp-card-top { display: flex; gap: 10px; align-items: center; }
.cp-face { font-size: 2rem; line-height: 1; }
.cp-card-top b { font-size: 1.1rem; display: block; }
.cp-card-top small { color: var(--muted); }
.cp-bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.cp-bar i { display: block; height: 100%; background: var(--good); }
.cp-bar.warn i { background: var(--warn); } .cp-bar.bad i { background: var(--bad); }
.cp-stats { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .9rem; }
.cp-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.cp-chips .chip { font-size: .78rem; min-height: 26px; padding: 2px 8px; }
.cp-empty { color: var(--muted); font-size: .9rem; }
.cp-members li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.cp-members li .main { flex: 1; min-width: 160px; }
.cp-members ul { list-style: none; margin: 0; padding: 0; }
.cp-temp { font-family: ui-monospace, monospace; font-size: 1.2rem; padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); user-select: all; }
.cp-detail .cp-abs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; text-align: center; }
.cp-detail .cp-abs div { padding: 6px 2px; border: 1px solid var(--line); border-radius: 10px; }
.cp-detail .cp-abs small { display: block; font-size: .7rem; color: var(--muted); }
.cp-detail h3 { margin: 14px 0 6px; font-size: 1rem; }
.cp-detail ul { margin: 0; padding-left: 1.1rem; }
@media (max-width: 420px) { .cp-detail .cp-abs { grid-template-columns: repeat(3, 1fr); } }
.cp-head { flex-wrap: wrap; }
@media (max-width: 520px) { .cp-head h1 { font-size: 1.25rem; } }
