:root {
  --ink: #e9e1cf; --dim: #a59c88; --faint: #6f675a;
  --bg: #14110e; --panel: #1d1914; --panel2: #25201a; --line: #3a3228;
  --gold: #d6a648; --gold2: #f0c66e; --ember: #e0703a; --eerie: #7fe0a0; --blood: #c0453a;
  --parch: #efe2c4; --parch-ink: #2c2218; --parch-line: #c9b48a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#gate { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 30%, #2a2219, #0d0b09); }
.gate-card { text-align: center; padding: 40px 56px; border: 1px solid var(--line); background: var(--panel); border-radius: 14px; }
.gate-card h1 { font-family: var(--serif); color: var(--gold); margin-top: 0; }

#app { height: 100%; display: flex; flex-direction: column; }
header { height: 46px; display: flex; align-items: center; gap: 18px; padding: 0 14px; border-bottom: 1px solid var(--line);
  background: linear-gradient(#211c16, #1a1612); }
.brand { font-family: var(--serif); font-size: 18px; color: var(--gold2); letter-spacing: .3px; white-space: nowrap; }
.sigil { color: var(--gold); }
nav { display: flex; gap: 6px; flex: 1; }
.tab { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; color: var(--dim); }
.tab[aria-pressed="true"] { color: var(--ink); border-color: var(--gold); background: #2b2318; }
.seat { color: var(--dim); white-space: nowrap; }
.seat b { color: var(--ink); }
#seatRole { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; padding: 2px 7px; border-radius: 4px; background: #33291c; color: var(--gold); }

#layout { flex: 1; min-height: 0; display: flex; }
.drawer { width: 340px; flex: none; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.drawer-head, .col-head { padding: 9px 12px; font-family: var(--serif); color: var(--gold2); font-size: 15px; border-bottom: 1px solid var(--line); background: var(--panel2); }
.col-head.sub { border-top: 1px solid var(--line); }
.private { font-family: var(--sans); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--faint); margin-left: 6px; }
#advTitle { color: var(--dim); font-size: 13px; margin-left: 6px; }

#stage { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#sceneWrap { position: relative; flex: 58 1 0; min-height: 120px; background: #000; }
#scene { width: 100%; height: 100%; display: block; }
#caption { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); max-width: min(760px, 86%); text-align: center;
  font-family: var(--serif); font-size: 17px; font-style: italic; color: #f7efdc; text-shadow: 0 1px 3px #000, 0 0 18px #000;
  padding: 8px 18px; background: linear-gradient(90deg, transparent, rgba(0,0,0,.45) 15%, rgba(0,0,0,.45) 85%, transparent); transition: opacity .6s; }
#caption:empty { opacity: 0; }
#sceneTag { position: absolute; top: 10px; left: 12px; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: rgba(255,240,210,.7);
  text-shadow: 0 1px 2px #000; }
#splitter { height: 7px; cursor: row-resize; background: var(--panel2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#splitter:hover { background: #3a2f22; }
#boardWrap { position: relative; flex: 42 1 0; min-height: 100px; background: #0f0d0b; }
#board { width: 100%; height: 100%; display: block; }
#boardHint { position: absolute; right: 10px; bottom: 8px; font-size: 11px; color: var(--faint); pointer-events: none; }

#chatCol { width: 340px; flex: none; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); min-height: 0; }
#dmCol { width: 440px; flex: none; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); min-height: 0; }
.log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
#dmCol .adventure { flex: 1.4; }
#dmCol #assistant { flex: 1; }
.msg { line-height: 1.4; }
.msg .who { font-weight: 600; margin-right: 6px; }
.msg.dm .who, .msg.agent .who { color: var(--gold2); }
.msg.system { color: var(--dim); font-style: italic; font-size: 13px; }
.msg.narration { font-family: var(--serif); font-size: 15px; font-style: italic; color: #f3e6c8; border-left: 2px solid var(--gold); padding-left: 10px; }
.msg.secret { opacity: .75; } .msg.secret::before { content: "secret · "; color: var(--faint); font-size: 11px; }
.roll { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; display: flex; align-items: center; gap: 10px; }
.roll .total { font-family: var(--serif); font-size: 22px; color: var(--gold2); min-width: 34px; text-align: center; }
.roll .total.crit { color: var(--eerie); } .roll .total.fumble { color: var(--blood); }
.roll .detail { font-size: 12px; color: var(--dim); }
.roll .label { color: var(--ink); font-weight: 600; }
#dice { display: flex; flex-wrap: wrap; gap: 5px; padding: 8px 10px; border-top: 1px solid var(--line); align-items: center; }
#dice button { background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; font-weight: 600; color: var(--dim); }
#dice button:hover { color: var(--ink); border-color: var(--gold); }
#dice .d20 { color: var(--gold2); }
.secret { font-size: 12px; color: var(--faint); margin-left: auto; }
.composer { display: flex; gap: 6px; padding: 8px 10px 10px; border-top: 1px solid var(--line); }
.composer input { flex: 1; min-width: 0; background: #120f0c; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--ink); font: inherit; }
.composer input:focus { outline: none; border-color: var(--gold); }
.composer button { background: #3a2c18; border: 1px solid var(--gold); border-radius: 8px; padding: 0 14px; color: var(--gold2); }
.asst { padding: 8px 10px; border-radius: 8px; background: var(--panel2); white-space: pre-wrap; }
.asst.dm { background: #2c2418; align-self: flex-end; max-width: 85%; }
.asst .who { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--faint); display: block; margin-bottom: 2px; }

/* Adventure text */
.adventure { overflow-y: auto; padding: 14px 18px 30px; font-family: var(--serif); font-size: 15px; line-height: 1.55; color: #e8dcc2; min-height: 0; }
.adventure h1 { font-size: 22px; color: var(--gold2); margin: 4px 0 10px; }
.adventure h2 { font-size: 18px; color: var(--gold); border-bottom: 1px solid var(--line); padding-bottom: 3px; margin: 22px 0 8px; }
.adventure h3 { font-size: 16px; color: var(--gold2); margin: 16px 0 6px; }
.adventure blockquote { margin: 10px 0; padding: 8px 14px; background: #2a2216; border-left: 3px solid var(--gold); font-style: italic; color: #f3e6c8; border-radius: 0 6px 6px 0; }
.adventure strong { color: #fff3d6; }
.adventure .focus { outline: 2px solid var(--gold); outline-offset: 4px; border-radius: 3px; animation: glow 2.5s ease-out; }
.adventure mark { background: rgba(214,166,72,.28); color: inherit; padding: 0 2px; border-radius: 2px; }
@keyframes glow { from { box-shadow: 0 0 0 8px rgba(214,166,72,.35); } to { box-shadow: 0 0 0 0 rgba(214,166,72,0); } }
#focusNote { margin: 8px 12px 0; padding: 7px 10px; font-size: 13px; border-radius: 7px; background: #2e2617; border: 1px solid #574523; color: var(--gold2); }

/* Character sheets */
.sheet-tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.sheet-tabs button { border: 1px solid var(--line); background: var(--panel2); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--dim); }
.sheet-tabs button.on { color: var(--ink); border-color: var(--gold); }
.sheet-tabs .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 10px; min-height: 0; }
.sheet { background: var(--parch); color: var(--parch-ink); border-radius: 10px; padding: 14px 14px 16px; font-family: var(--serif);
  box-shadow: inset 0 0 40px rgba(120,80,30,.25), 0 2px 10px rgba(0,0,0,.4); }
.sheet h2 { margin: 0; font-size: 21px; line-height: 1.1; }
.sheet .sub { font-size: 13px; color: #6b5639; font-style: italic; margin: 2px 0 10px; }
.vitals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.vital { border: 1.5px solid var(--parch-line); border-radius: 8px; text-align: center; padding: 4px 2px; background: rgba(255,255,255,.35); }
.vital b { display: block; font-size: 20px; } .vital span { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #6b5639; font-family: var(--sans); }
.hpbar { height: 6px; border-radius: 3px; background: #d9c8a4; margin: 4px 6px 0; overflow: hidden; } .hpbar i { display: block; height: 100%; background: #5d8f4c; }
.hpbar i.low { background: var(--blood); }
.hpctl { display: flex; justify-content: center; gap: 4px; margin-top: 3px; } .hpctl button { border: 1px solid var(--parch-line); background: #f6ecd5; color: var(--parch-ink); border-radius: 4px; padding: 0 7px; font-size: 12px; }
.abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-bottom: 10px; }
.ab { border: 1.5px solid var(--parch-line); border-radius: 10px 10px 14px 14px; text-align: center; padding: 3px 0 4px; background: rgba(255,255,255,.35); }
.ab span { font-size: 9px; font-family: var(--sans); letter-spacing: 1px; color: #6b5639; display: block; }
.ab b { font-size: 18px; display: block; line-height: 1.1; } .ab i { font-style: normal; font-size: 11px; color: #6b5639; }
.ab.save { border-color: #a37b2c; }
.sheet h4 { margin: 10px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: #7a5a24; font-family: var(--sans); border-bottom: 1px solid var(--parch-line); }
.sheet ul { margin: 0; padding-left: 18px; font-size: 14px; } .sheet li { margin: 1px 0; }
.atk { display: flex; justify-content: space-between; font-size: 14px; border-bottom: 1px dotted var(--parch-line); padding: 2px 0; }
.atk button { border: none; background: none; color: #7a3b17; text-decoration: underline dotted; padding: 0; font-family: var(--serif); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; } .chip { font-size: 12px; padding: 1px 7px; border-radius: 999px; background: #e3d2ab; }
.notes { font-size: 13px; font-style: italic; color: #4a3a26; }

::-webkit-scrollbar { width: 9px; } ::-webkit-scrollbar-thumb { background: #3a3228; border-radius: 5px; } ::-webkit-scrollbar-track { background: transparent; }
@media (max-width: 1100px) { #dmCol { width: 360px; } #chatCol { width: 290px; } .drawer { width: 300px; } }
