:root {
  --ink: #f4efe3;
  --muted: #b9b3a6;
  --gold: #e8c35a;
  --panel: rgba(14, 16, 28, 0.88);
  --panel-solid: #12141f;
  --line: rgba(232, 195, 90, 0.35);
  --danger: #e05a4f;
  --ok: #6fc28b;
  --soul: #9d7cf0;
  --stamina: #e8a64a;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0d0f1a; color: var(--ink); font-family: var(--sans); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }

/* ---------- Scène ---------- */
#stage { position: fixed; inset: 0; display: flex; flex-direction: column; }
.bg { position: absolute; inset: 0; z-index: 0; transition: background 1.2s ease; background: radial-gradient(ellipse at 50% 20%, #3b4a6b, #12141f 70%); }
.bg::after { content: ''; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(0,0,0,.25), transparent 30%, transparent 55%, rgba(0,0,0,.65)); }
.bg.terrain { background: linear-gradient(180deg, #7fb2e5 0%, #c9e1f2 38%, #8aa86b 39%, #5c7a45 100%); }
.bg.bibliotheque { background: radial-gradient(ellipse at 50% 30%, #7a5a36, #2a1c10 75%); }
.bg.cafeteria { background: radial-gradient(ellipse at 50% 25%, #c99a5b, #4a3220 80%); }
.bg.chambre { background: radial-gradient(ellipse at 40% 30%, #5d4a6e, #1d1726 80%); }
.bg.foret { background: linear-gradient(180deg, #2f4a33, #142218 80%); }
.bg.marche { background: linear-gradient(180deg, #e7b977 0%, #b6784a 55%, #5a3a24 100%); }
.bg.tour { background: radial-gradient(ellipse at 50% 15%, #6a5bc4, #1b1640 80%); }
.bg.infirmerie { background: radial-gradient(ellipse at 50% 30%, #d8ece6, #6d8f87 85%); }
.bg.souterrain { background: radial-gradient(ellipse at 50% 40%, #3e2a4a, #08060c 75%); }
.bg.classe { background: radial-gradient(ellipse at 50% 25%, #a58a64, #3a2d1f 80%); }
.bg.nuit::before { content: ''; position: absolute; inset: 0; background: rgba(10, 14, 40, .55); z-index: 0; }

#hud { position: relative; z-index: 3; padding: max(10px, env(safe-area-inset-top)) 12px 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; background: linear-gradient(rgba(8,9,16,.85), transparent); }
.header-line { font-family: var(--serif); font-size: 1.05rem; font-weight: 700; color: var(--gold); text-shadow: 0 1px 3px #000; flex: 1 1 260px; }
#hud nav { display: flex; gap: 6px; }
#hud nav button { background: rgba(255,255,255,.08); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; display: flex; gap: 6px; align-items: center; }
#hud nav button:hover { background: rgba(232,195,90,.18); }
#hud nav button:disabled { opacity: .35; cursor: default; }
.demo { width: 100%; font-size: .8rem; color: #ffd28a; }

#sprites { position: relative; z-index: 1; flex: 1; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; min-height: 0; }
.sprite { height: min(62vh, 640px); max-width: 92vw; display: flex; align-items: flex-end; justify-content: center; transition: opacity .3s, transform .3s; }
.sprite img { max-height: 100%; max-width: 100%; object-fit: contain; filter: drop-shadow(0 10px 25px rgba(0,0,0,.6)); border-radius: 14px; }
.sprite.dim { opacity: .45; transform: scale(.97); }
.silhouette { width: min(46vw, 260px); aspect-ratio: 3 / 4; border-radius: 120px 120px 18px 18px; display: grid; place-items: center; font-family: var(--serif); font-size: 4.5rem; font-weight: 700; color: rgba(255,255,255,.85); border: 2px solid rgba(255,255,255,.25); box-shadow: 0 10px 30px rgba(0,0,0,.5); margin-bottom: 20px; }

#dialog { position: relative; z-index: 2; margin: 0 auto 8px; width: min(980px, calc(100% - 24px)); min-height: 150px; max-height: 42vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px 26px; cursor: pointer; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.speaker { position: sticky; top: -18px; display: inline-block; margin: -30px 0 10px -4px; padding: 4px 14px; border-radius: 10px; background: #2a2d40; font-family: var(--serif); font-size: 1.15rem; font-weight: 700; border: 1px solid var(--line); }
.text { font-size: 1.04rem; line-height: 1.6; white-space: pre-wrap; }
.text strong { color: #fff; }
.text em { color: #d8d2c4; }
.text pre { white-space: pre-wrap; font-size: .85rem; background: rgba(0,0,0,.35); padding: 10px; border-radius: 8px; }
.next { position: absolute; right: 16px; bottom: 6px; color: var(--gold); animation: bob 1s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }

#controls { position: relative; z-index: 2; width: min(980px, calc(100% - 24px)); margin: 0 auto max(10px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
#notes:empty { display: none; }
#notes { font-size: .88rem; background: rgba(20, 40, 28, .8); border: 1px solid rgba(111,194,139,.4); border-radius: 10px; padding: 8px 12px; }
#notes div { margin: 2px 0; }
#choices { display: flex; flex-wrap: wrap; gap: 8px; }
#choices button { flex: 1 1 200px; text-align: left; background: rgba(30, 33, 52, .92); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
#choices button:hover { background: rgba(232,195,90,.2); }
#action-form { display: flex; gap: 8px; }
#action { flex: 1; resize: none; background: rgba(10,11,20,.92); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; max-height: 30vh; }
#send, .combat-call button, #aftermath, #login button { background: linear-gradient(#f0cf6e, #c99b2e); color: #1a1405; font-weight: 700; border: 0; border-radius: 12px; padding: 10px 18px; }
#send:disabled { opacity: .5; }
.combat-call { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: rgba(70, 18, 18, .9); border: 1px solid rgba(224,90,79,.6); border-radius: 12px; padding: 10px 14px; }
.combat-call p { margin: 2px 0 0; font-size: .9rem; }

.thinking { position: fixed; z-index: 5; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-solid); border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: blink 1.2s infinite; }
.dot:nth-child(2) { animation-delay: .2s; } .dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }
.toast { position: fixed; z-index: 30; top: 70px; left: 50%; transform: translateX(-50%); max-width: 90vw; background: #3a1414; border: 1px solid var(--danger); border-radius: 12px; padding: 10px 16px; }

/* ---------- Panneaux ---------- */
.panel { position: fixed; z-index: 10; top: 0; right: 0; bottom: 0; width: min(440px, 100%); background: var(--panel-solid); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -10px 0 40px rgba(0,0,0,.5); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-family: var(--serif); color: var(--gold); }
.panel-head button { background: none; border: 0; font-size: 1.3rem; }
.panel-body { overflow-y: auto; padding: 14px 16px 40px; }
.panel-body h3 { font-family: var(--serif); color: var(--gold); margin: 18px 0 8px; font-size: 1.2rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .92rem; }
.stat { margin: 8px 0; }
.stat-top { display: flex; justify-content: space-between; font-size: .92rem; }
.bar { height: 7px; background: rgba(255,255,255,.1); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--gold); border-radius: 99px; transition: width .4s; }
.bar.hp > i { background: var(--ok); } .bar.st > i { background: var(--stamina); } .bar.soul > i { background: var(--soul); } .bar.exp > i { background: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .85rem; padding: 4px 9px; border-radius: 99px; background: rgba(255,255,255,.08); border: 1px solid var(--line); }
.rel { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.rel .avatar { width: 42px; height: 42px; border-radius: 50%; flex: none; background-size: cover; background-position: top center; display: grid; place-items: center; font-weight: 700; }
.rel .info { flex: 1; min-width: 0; }
.rel .status { font-size: .82rem; color: var(--muted); }
.event { padding: 10px 12px; border: 1px solid rgba(255,255,255,.1); border-radius: 10px; margin-bottom: 8px; }
.event.done { opacity: .55; } .event.missed { border-color: rgba(224,90,79,.5); }
.event .when { color: var(--gold); font-size: .85rem; }
.entry { padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.06); font-size: .92rem; line-height: 1.5; white-space: pre-wrap; }
.entry.player { color: #cfe3ff; }
.entry .who { font-weight: 700; color: var(--gold); display: block; margin-bottom: 2px; }

/* ---------- Combat ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(5, 5, 10, .9); display: grid; place-items: center; overflow-y: auto; }
#login .card { width: min(380px, 92vw); background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
#login h1 { font-family: var(--serif); color: var(--gold); margin: 0; }
#login input { background: #0b0c14; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; }
#combat { background: radial-gradient(ellipse at 50% 30%, rgba(90, 20, 20, .92), rgba(5, 5, 10, .97) 70%); align-items: start; }
.combat-wrap { width: min(900px, 100%); padding: 16px 12px 40px; display: flex; flex-direction: column; gap: 12px; }
.combat-top { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--serif); font-size: 1.2rem; color: var(--gold); }
.fighters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.fighter { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 10px; text-align: left; }
.fighter.enemy { border-color: rgba(224,90,79,.45); }
.fighter.target { outline: 2px solid var(--gold); }
.fighter.ko { opacity: .35; }
.fighter .tier { font-size: .78rem; color: var(--muted); }
.allies .fighter { padding: 6px 10px; font-size: .88rem; }
.player-box { background: rgba(232,195,90,.08); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.actions button { text-align: left; background: rgba(30, 33, 52, .95); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.actions button:disabled { opacity: .35; cursor: not-allowed; }
.actions button small { display: block; color: var(--muted); font-size: .76rem; margin-top: 3px; }
.actions .cost { font-size: .75rem; color: var(--stamina); }
.combat-log { background: rgba(0,0,0,.4); border-radius: 12px; padding: 10px 12px; max-height: 32vh; overflow-y: auto; font-size: .88rem; line-height: 1.5; }
.combat-log .turn { color: var(--gold); margin-top: 6px; }
#combat-end { text-align: center; }

@media (max-width: 640px) {
  #hud nav button span { display: none; }
  .header-line { font-size: .92rem; }
  #dialog { min-height: 130px; padding: 16px 14px 24px; }
  .text { font-size: .98rem; }
  .sprite { height: 44vh; }
}

/* ---------- Connexion API ---------- */
.demo.live { color: var(--muted); }
.small { font-size: .8rem; }
.ok { color: var(--ok); }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; flex: 1 1 140px; min-width: 0; }
.field > span { font-size: .85rem; color: var(--muted); }
.panel-body input, .panel-body select { width: 100%; box-sizing: border-box; background: #0b0c14; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; }
.panel-body .row { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.panel-body .row > input { flex: 1 1 160px; }
.panel-body button:not(.chip) { background: rgba(255,255,255,.08); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.panel-body button.primary { background: var(--gold); color: #1a1406; border-color: var(--gold); font-weight: 600; }
.panel-body button:disabled { opacity: .5; cursor: wait; }
.conn { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 12px; margin-bottom: 8px; border: 1px solid rgba(255,255,255,.1); border-radius: 12px; }
.conn.active { border-color: var(--gold); background: rgba(232,195,90,.08); }
.conn .info { min-width: 0; overflow-wrap: anywhere; }
.conn-btns { display: flex; gap: 6px; flex-shrink: 0; }
.conn-form { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.conn-form h3 { margin-top: 0 !important; }

/* ---------- Chronique ---------- */
.chapter { white-space: pre-wrap; line-height: 1.5; }
.thread.résolu, .thread.échoué, .thread.abandonné { opacity: .7; }
.attitude { font-style: italic; }
.panel-body details { margin-top: 14px; }
.panel-body summary { cursor: pointer; color: var(--gold); font-family: var(--serif); font-size: 1.1rem; margin-bottom: 8px; }

/* ---------- Combat : profils des adversaires ---------- */
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge { font-size: .7rem; padding: 1px 6px; border-radius: 99px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); }
.badge.warn { border-color: var(--stamina); color: var(--stamina); }
.badge.danger { border-color: var(--danger); color: #ff9b92; }
.fighter.revealed { box-shadow: 0 0 0 1px var(--danger), 0 0 14px rgba(224,90,79,.35); }
.combat-log .key { color: var(--gold); font-weight: 600; }

/* ---------- Sauvegardes ---------- */
.slot .badge { margin-left: 6px; vertical-align: middle; }
.conn-btns.col { flex-direction: column; align-items: stretch; }
.conn-btns .chip { text-align: center; text-decoration: none; color: inherit; cursor: pointer; }
.button-link { display: inline-block; text-decoration: none; border-radius: 10px; padding: 8px 12px; border: 1px solid var(--line); color: inherit; }
.button-link.primary { background: var(--gold); color: #1a1406; border-color: var(--gold); font-weight: 600; }
.panel-body button.danger { border-color: var(--danger); color: #ff9b92; }

/* ---------- Lorebook ---------- */
.panel-body textarea { width: 100%; box-sizing: border-box; background: #0b0c14; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; resize: vertical; }
.lore-entry .stat-top { align-items: center; }
.linkish { background: none; border: 0; padding: 0; text-align: left; font-weight: 700; color: var(--gold); }
.lore-entry .chips { margin: 4px 0; }
.proposal { flex-direction: column; align-items: stretch; border-color: var(--stamina); }
.check { display: flex; gap: 8px; align-items: center; font-size: .85rem; margin: 6px 0 10px; }
.check input { width: auto; }

/* ---------- Choix de l'aventure ---------- */
#adventures { z-index: 40; background: radial-gradient(ellipse at top, #1d2036, #0a0b14 70%); overflow-y: auto; align-items: flex-start; }
.picker { width: min(900px, 100%); margin: 0 auto; padding: 32px 16px 60px; box-sizing: border-box; }
.picker h1 { font-family: var(--serif); color: var(--gold); text-align: center; font-size: 2rem; margin: 0 0 24px; }
.adventure-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.adventure-card { display: flex; flex-direction: column; text-align: left; padding: 0; overflow: hidden; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; transition: transform .15s, box-shadow .15s; }
.adventure-card:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.adventure-card.current { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.adventure-cover { height: 170px; background-size: cover; background-position: center 20%; display: grid; place-items: center; font-family: var(--serif); font-size: 4rem; color: rgba(255,255,255,.85); }
.adventure-info { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.adventure-info strong { font-family: var(--serif); font-size: 1.35rem; color: var(--gold); }
.adventure-info p { margin: 0; font-size: .9rem; line-height: 1.4; }
.adventure-info .chip { align-self: flex-start; margin-top: 4px; }

/* Portraits */
.rel .conn-btns { flex-wrap: wrap; margin-top: 6px; }
.rel .avatar.pending { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check > span { color: inherit; }
.field.check > input { width: auto; flex: none; }
.img-test { max-width: 160px; border-radius: 10px; margin: 6px 0; }
