:root {
  --bg: #0e0f12; --panel: #16181d; --panel2: #1d2027; --line: #2a2e37; --text: #e7e9ee; --muted: #8b92a1;
  --accent: #35d07f; --accent-dim: #1f7a4b; --danger: #ff6b6b; --warn: #f5b84b; --gold: #e8c468;
  --radius: 12px; --safe-top: env(safe-area-inset-top); --safe-bottom: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.15rem; } h4 { font-size: .95rem; }
.muted { color: var(--muted); font-size: .9rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: .6rem .9rem; min-height: 44px; }
button.primary { background: var(--accent); color: #07140d; border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); border-color: #5a2b2b; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; min-height: 44px; }
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent-dim); }
label { display: block; font-size: .8rem; color: var(--muted); margin: .8rem 0 .25rem; text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; gap: .6rem; align-items: center; } .row > * { flex: 1; } .row.tight > * { flex: none; }
.stack > * + * { margin-top: .8rem; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .5rem; padding: calc(.5rem + var(--safe-top)) .8rem .5rem; background: rgba(14,15,18,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); margin-right: auto; }
.top nav { display: flex; gap: .2rem; }
.top nav a { color: var(--muted); padding: .45rem .6rem; border-radius: 8px; font-size: .92rem; }
.top nav a.active { color: var(--text); background: var(--panel2); }
.page { max-width: 720px; margin: 0 auto; padding: 1rem .9rem calc(2rem + var(--safe-bottom)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; }
.list > a, .list > .item { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; margin-bottom: .6rem; color: var(--text); }
.list .sub { color: var(--muted); font-size: .88rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.tag, .cond { display: inline-block; background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: .1rem .55rem; margin: .15rem .2rem .15rem 0; font-size: .82rem; }
.cond { border-color: #6a4a1e; color: var(--warn); }
.error { color: var(--danger); font-size: .9rem; margin-top: .6rem; }
.note { color: var(--muted); font-size: .85rem; margin-top: .4rem; }
.skill-row { display: grid; grid-template-columns: 1fr 1fr 72px 44px; gap: .4rem; margin-bottom: .4rem; }
.attrs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.attrs .a { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .4rem; text-align: center; }
.attrs .a span { display: block; font-size: .75rem; color: var(--muted); }
.attrs .a input { text-align: center; padding: .3rem; min-height: 38px; }
.checks label { display: flex; align-items: center; gap: .6rem; text-transform: none; font-size: 1rem; color: var(--text); margin: .3rem 0; letter-spacing: 0; }
.checks input { width: auto; min-height: 0; }

/* Kampagne */
.campaign { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.chead { display: flex; align-items: center; gap: .4rem; padding: calc(.4rem + var(--safe-top)) .6rem .4rem; border-bottom: 1px solid var(--line); }
.chead .ctitle { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chead button { min-height: 38px; padding: .3rem .7rem; }
.statebar { padding: .5rem .8rem; border-bottom: 1px solid var(--line); background: var(--panel); font-size: .9rem; }
.statebar .where { color: var(--gold); margin-bottom: .35rem; }
.actors { display: flex; gap: .7rem; flex-wrap: wrap; }
.actor { flex: 1 1 130px; min-width: 120px; }
.actor-name { display: flex; justify-content: space-between; font-size: .85rem; }
.hp-text { color: var(--muted); }
.hp { height: 7px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-top: 2px; }
.hp-fill { height: 100%; transition: width .4s; } .hp-fill.high { background: var(--accent); } .hp-fill.mid { background: var(--warn); } .hp-fill.low { background: var(--danger); }
.conds { margin-top: .2rem; }
.messages { flex: 1; overflow-y: auto; padding: .8rem .8rem 1rem; -webkit-overflow-scrolling: touch; }
.msg { margin: 0 0 .9rem; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: #1c3a2c; border: 1px solid #25553d; border-radius: 14px 14px 4px 14px; max-width: 88%; padding: .5rem .8rem; }
.msg.gm .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: .6rem .85rem; }
.msg p { margin: 0 0 .6rem; } .msg p:last-child { margin-bottom: 0; }
.seg-text + .seg-text, .seg-text + .dice, .dice + .seg-text, .chip + .seg-text { margin-top: .5rem; }
.meta { color: var(--muted); font-size: .72rem; margin: .2rem .3rem; }
.chip { font-size: .85rem; color: var(--muted); background: var(--panel2); border-left: 3px solid var(--accent-dim); border-radius: 6px; padding: .3rem .6rem; margin: .45rem 0; }
.chip.refused { border-left-color: var(--danger); }
.chip.pending { border-left-color: var(--warn); }
.dice { border: 1px solid var(--line); border-radius: 12px; padding: .5rem .7rem; margin: .55rem 0; background: var(--panel2); }
.dice-head { font-size: .8rem; color: var(--muted); display: flex; justify-content: space-between; gap: .5rem; }
.dice-main { display: flex; align-items: center; gap: .5rem; margin: .3rem 0; font-size: 1.05rem; }
.die { display: inline-grid; place-items: center; min-width: 2.2rem; height: 2.2rem; padding: 0 .3rem; border-radius: 8px; background: #0b0c0f; border: 1px solid var(--line); font-weight: 700; }
.die.dropped { opacity: .4; text-decoration: line-through; }
.calc { color: var(--muted); } .total { font-weight: 700; margin-left: auto; font-size: 1.2rem; }
.dice-verdict { font-weight: 700; font-size: .9rem; }
.dice.ok { border-color: var(--accent-dim); } .dice.ok .dice-verdict { color: var(--accent); }
.dice.fail { border-color: #6a2b2b; } .dice.fail .dice-verdict { color: var(--danger); }
.dice.crit-ok { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; } .dice.crit-ok .dice-verdict { color: var(--gold); }
.dice.crit-fail { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger) inset; } .dice.crit-fail .dice-verdict { color: var(--danger); }
.live .bubble::after { content: '▍'; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
#banner { padding: 0 .8rem; }
.banner { background: #2a1d1d; border: 1px solid #5a2b2b; border-radius: 10px; padding: .6rem .8rem; margin-bottom: .5rem; font-size: .92rem; }
.banner .row { margin-top: .5rem; }
.composer { display: flex; gap: .5rem; padding: .6rem .8rem calc(.6rem + var(--safe-bottom)); border-top: 1px solid var(--line); background: var(--bg); align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 40vh; resize: none; flex: 1; }
.composer button { flex: none; }
.setup { text-align: center; padding: 1rem; }
.setup .row { margin-top: .8rem; flex-wrap: wrap; }

/* Sheets (modals) */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); border: 1px solid var(--line); border-radius: 16px 16px 0 0; width: 100%; max-width: 760px; max-height: 88dvh; overflow-y: auto; padding: 1rem .9rem calc(1rem + var(--safe-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.sheet pre { white-space: pre-wrap; word-break: break-word; font-size: .8rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6rem; max-height: 60dvh; overflow: auto; }
.inv { margin-bottom: .8rem; }
#toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%); z-index: 30; background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: .5rem 1rem; display: none; max-width: 90vw; }
#toast.show { display: block; } #toast.bad { border-color: var(--danger); color: var(--danger); }
@media (min-width: 760px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 16px; } }

/* [hidden] must win over display:flex, otherwise the input line stays visible before the game starts */
[hidden] { display: none !important; }

/* Beats: the story as short cards, one at a time */
.beats .beat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .85rem; margin: 0 0 .5rem; animation: beat-in .25s ease-out; overflow-wrap: anywhere; }
.beats .beat.narration { line-height: 1.55; }
.beats .beat.dialogue { border-left: 4px solid var(--c, var(--accent)); background: var(--panel2); }
.beats .beat.dialogue .speaker { color: var(--c, var(--accent)); font-size: .78rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; margin-bottom: .15rem; }
.beats .beat.dialogue .line { font-size: 1.02rem; }
.beats .beat.tool { padding: .35rem .5rem; background: transparent; border: none; }
.beats .beat.tool .dice { margin: 0; }
.beats .beat.tool .chip { margin: 0; }
.msg.gm .bubble { all: unset; }
.typing { color: var(--muted); font-size: .85rem; padding: .2rem .4rem; animation: blink 1.2s ease-in-out infinite; }
@keyframes beat-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.dock { border-top: 1px solid var(--line); background: var(--bg); }
.dock .composer { border-top: none; }
.nextbar { display: flex; gap: .5rem; align-items: center; padding: .6rem .8rem calc(.6rem + var(--safe-bottom)); }
.nextbar .big { flex: 1; min-height: 52px; font-size: 1.05rem; }
.live .bubble::after { content: none; }

/* Reading view: one beat at a time, like a visual novel */
.stage { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; padding: .8rem; -webkit-overflow-scrolling: touch; }
.stage > * { margin-top: auto; margin-bottom: auto; }
.stage .stage-note { text-align: center; color: var(--muted); font-size: .9rem; animation: blink 1.2s ease-in-out infinite; }
.vn { padding: .4rem .8rem calc(.7rem + var(--safe-bottom)); }
.vn-box { border: 1px solid var(--line); border-radius: 24px; padding: .9rem .9rem 1rem; background: rgba(0, 0, 0, .45); }
.vn-chip { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; padding: .32rem .85rem; border-radius: 999px; background: var(--panel2); margin-bottom: .65rem; }
.vn-chip.speaker { color: var(--c); box-shadow: inset 0 0 0 1px var(--c); background: transparent; }
.vn-text { border: 1px solid var(--line); border-radius: 18px; padding: 1rem 1.1rem; font-size: 1.2rem; line-height: 1.7; min-height: 8.5rem; max-height: 38dvh; overflow-y: auto; overflow-wrap: anywhere; -webkit-overflow-scrolling: touch; }
.vn-text .muted { font-size: 1rem; }
.vn-text .dice, .vn-text .chip { margin: 0; }
.vn-bar { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .7rem; }
.vn-bar button { min-height: 48px; min-width: 52px; border-radius: 16px; }
.vn-bar #next { min-width: 110px; font-size: 1.05rem; }
.vn-bar button.on { background: var(--accent-dim); border-color: var(--accent); }
.vn .composer { padding: .7rem 0 0; border-top: none; background: transparent; }
.log .beat { margin: 0 0 .5rem; }
