:root {
  --bg: #14110f; --panel: #1d1916; --panel2: #26211d; --line: #3a322b; --text: #ece4d8; --muted: #9a8f80;
  --accent: #c2410c; --accent2: #f59e0b; --ok: #22c55e; --bad: #ef4444;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; overscroll-behavior: none; }
[hidden] { display: none !important; }
img.logo { width: 1.5em; height: 1.5em; vertical-align: -.35em; border-radius: 22%; }
h1, h2, h4 { margin: 0 0 .5rem; } h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; color: var(--muted); font-weight: 500; }
h4 { margin: 1rem 0 .4rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent2); }
small, .muted { color: var(--muted); } .pad { padding: 1rem; } .pad0 { padding: .25rem 0; font-size: .85rem; }
.err { color: var(--bad); min-height: 1.2em; margin: .25rem 0; }
.code { font-family: ui-monospace, monospace; letter-spacing: .12em; color: var(--accent2); }

/* ---- controls */
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .8rem; min-height: 38px; cursor: pointer; }
button:active { transform: scale(.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger { background: #7f1d1d; border-color: #991b1b; }
button.link { background: none; border: 0; color: var(--accent2); }
button.x { padding: .3rem .55rem; min-height: 32px; background: transparent; color: var(--muted); }
button.on { background: var(--accent); border-color: var(--accent); }
input, select, textarea { background: #100d0b; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; min-height: 38px; width: 100%; }
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--accent); }
input[type=color] { padding: 2px; }
textarea { resize: vertical; }
label { display: block; font-size: .78rem; color: var(--muted); }
label input, label select { margin-top: 2px; color: var(--text); font-size: 1rem; }
label.chk { display: flex; align-items: center; gap: .4rem; margin-top: 1.1rem; }
.row { display: flex; gap: .5rem; align-items: flex-end; margin: .4rem 0; } .row.between { justify-content: space-between; align-items: center; }
.row.wrap { flex-wrap: wrap; } .row.end { justify-content: flex-end; } .grow { flex: 1; min-width: 0; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding: .5rem; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.chip { white-space: nowrap; border-radius: 999px; padding: .3rem .75rem; min-height: 0; }
.chip small { margin-left: .4rem; font-size: .7rem; } .chip.on { background: var(--accent); }
.chip.add { border-style: dashed; background: transparent; }
#charlist { display: block; overflow: visible; padding: .5rem; border-bottom: 1px solid var(--line); }
.charrows { list-style: none; margin: 0 0 .4rem; padding: 0; max-height: 38vh; overflow-y: auto; display: flex; flex-direction: column; gap: .3rem; }
.charrows li { display: flex; gap: .4rem; align-items: stretch; }
.charrows li .who { flex: 1; min-width: 0; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: .5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.charrows li.on .who { background: var(--accent); }
.charrows li > button:not(.who) { flex: none; font-size: .8rem; padding: 0 .6rem; }

/* ---- auth / lobby */
.screen { height: 100dvh; }
.center { display: flex; align-items: center; justify-content: center; padding: 1rem; overflow: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.4rem; width: min(380px, 100%); display: grid; gap: .7rem; }
.card.wide { width: min(560px, 100%); }
.camps { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.camps li { display: flex; gap: .3rem; align-items: center; }
.camp { flex: 1; text-align: left; display: grid; padding: .7rem .9rem; }

/* ---- game layout (mobile: map or one panel, tabs at bottom) */
#game { display: grid; grid-template-rows: 44px 1fr calc(56px + var(--safe-b)); grid-template-columns: 100%; position: relative; }
#top { display: flex; align-items: center; gap: .5rem; padding: 0 .5rem; background: var(--panel); border-bottom: 1px solid var(--line); }
#top b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #top button { min-height: 32px; padding: .2rem .6rem; }
#top #code { margin-left: auto; font-family: ui-monospace, monospace; letter-spacing: .1em; }
#netdot { width: 9px; height: 9px; border-radius: 50%; flex: none; } #netdot.on { background: var(--ok); } #netdot.off { background: var(--bad); }
#top, #tabs, #stage, #panel { grid-column: 1; }
#stage { position: relative; grid-row: 2; overflow: hidden; background: #0b0a09; min-height: 0; }
#map { position: absolute; inset: 0; touch-action: none; display: block; }
#panel { grid-row: 2; position: relative; min-height: 0; background: var(--panel); display: none; overflow: hidden; }
#game:not([data-tab=map]) #panel { display: block; z-index: 5; }
.pane { display: none; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#game[data-tab=sheet] #pane-sheet, #game[data-tab=init] #pane-init, #game[data-tab=dm] #pane-dm { display: block; }
#game[data-tab=book] #pane-book { display: flex; }

/* ---- compendium */
#pane-book { flex-direction: column; overflow: hidden; }
.bookbar { padding: .5rem; display: grid; gap: .4rem; border-bottom: 1px solid var(--line); }
.bookbar .row { margin: 0; } .bookbar .row > * { flex: 1; }
.booklist { list-style: none; margin: 0; padding: .4rem; overflow-y: auto; flex: 1; display: grid; gap: 4px; align-content: start; }
.bk { background: var(--panel2); border-radius: 8px; } .bk.open { box-shadow: inset 3px 0 var(--accent2); }
.bkh { width: 100%; text-align: left; display: grid; background: none; border: 0; padding: .45rem .7rem; }
.bkh small { font-size: .72rem; } .bkb { padding: 0 .7rem .6rem; font-size: .9rem; } .bkb p { margin: .3rem 0; }
.abs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; margin: .3rem 0; }
.abs button { display: grid; padding: .2rem 0; min-height: 0; font-size: .75rem; line-height: 1.2; } .abs small { color: var(--muted); font-size: .6rem; } .abs b { color: var(--accent2); }
.act { display: flex; gap: .3rem; align-items: center; margin: .2rem 0; } .act span { flex: 1; }
.act button, .dchip { min-height: 28px; padding: 0 .5rem; font-size: .8rem; } .dchip { background: #3b2415; border-color: var(--accent2); border-radius: 6px; color: var(--accent2); margin: 0 1px; }
#game[data-tab=chat] #pane-chat { display: flex; }
#pane-init, #pane-dm { padding: .8rem; }
#tabs { grid-row: 3; display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); z-index: 6; }
#tabs button { flex: 1; border: 0; border-radius: 0; background: none; display: grid; font-size: 1.3rem; line-height: 1.1; padding: .3rem 0; position: relative; }
#tabs button span { font-size: .65rem; color: var(--muted); } #tabs button.on { background: var(--panel2); } #tabs button.on span { color: var(--accent2); }
#tabs button.ping::after { content: ""; position: absolute; top: 6px; right: 28%; width: 9px; height: 9px; border-radius: 50%; background: var(--accent2); }

@media (min-width: 900px) {
  #game { grid-template-rows: 44px 52px 1fr; grid-template-columns: 1fr 420px; }
  #top { grid-column: 1 / 3; }
  #stage { grid-column: 1; grid-row: 2 / 4; }
  #tabs { grid-column: 2; grid-row: 2; border-top: 0; border-bottom: 1px solid var(--line); }
  #tabs button { grid-template-columns: auto auto; gap: .4rem; justify-content: center; align-items: center; font-size: 1.1rem; }
  #tabs button[data-tab=map] { display: none; }
  #panel { grid-column: 2; grid-row: 3; display: block !important; border-left: 1px solid var(--line); }
}

/* ---- map overlays */
#tools { position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
#tools button { width: 44px; height: 44px; padding: 0; font-size: 1.15rem; background: rgba(29,25,22,.92); }
#tokcard { position: absolute; left: 8px; right: 8px; bottom: 8px; max-width: 460px; margin: 0 auto; background: rgba(29,25,22,.97);
  border: 1px solid var(--line); border-radius: 12px; padding: .6rem .7rem; z-index: 3; max-height: 55%; overflow-y: auto; display: grid; gap: .45rem; }
.hpbar { position: relative; height: 22px; background: #100d0b; border-radius: 6px; overflow: hidden; }
.hpbar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #166534, #22c55e); }
.hpbar span { position: absolute; inset: 0; text-align: center; font-weight: 600; font-size: .85rem; line-height: 22px; text-shadow: 0 1px 2px #000; }
.hpctl input { width: 80px; text-align: center; }
.conds { display: flex; flex-wrap: wrap; gap: 4px; }
.cond { min-height: 28px; padding: 2px 8px; font-size: .75rem; border-radius: 999px; text-transform: capitalize; }
.cond.on { background: #92400e; border-color: var(--accent2); }
.edit { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }

/* ---- sheet */
fieldset.sheet { border: 0; margin: 0; padding: .6rem; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin: .5rem 0; }
.stat { text-align: center; display: grid; font-size: .75rem; color: var(--muted); } .stat b { font-size: 1.25rem; color: var(--text); }
.hp { display: flex; gap: .3rem; align-items: flex-end; } .hp label { flex: 1; } .hp button { padding: .4rem .5rem; }
.abils { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-top: .6rem; }
.abil { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: .4rem; display: grid; gap: .25rem; text-align: center; }
.abil b { font-size: .75rem; color: var(--muted); } .abil input { text-align: center; padding: .2rem; }
.abil > button { font-size: 1.2rem; font-weight: 700; } .abil .sv { display: flex; align-items: center; gap: .25rem; }
.abil .sv button { flex: 1; font-size: .72rem; padding: .2rem; min-height: 30px; }
.skills { display: grid; grid-template-columns: 1fr 1fr; gap: 2px .5rem; }
.skill { display: flex; align-items: center; min-width: 0; } .skill .pp { padding: 0; width: 28px; min-height: 30px; border: 0; background: none; color: var(--accent2); }
.skill .sk { flex: 1; text-align: left; border: 0; background: none; font-size: .8rem; padding: .2rem; min-height: 30px; display: flex; gap: .3rem; align-items: baseline; }
.skill .sk small { font-size: .62rem; } .skill .sk b { margin-left: auto; }
.atk { display: grid; grid-template-columns: 1.4fr .6fr 1fr auto auto auto; gap: .3rem; margin-bottom: .3rem; align-items: center; }
.slots { display: grid; gap: .3rem; } .slot { display: grid; grid-template-columns: 14px 54px 1fr; gap: .4rem; align-items: center; }
.slot input { padding: .2rem .4rem; min-height: 32px; } .pips { display: flex; gap: 6px; flex-wrap: wrap; }
.pip { width: 24px; height: 24px; min-height: 0; padding: 0; border-radius: 50%; background: var(--accent2); border-color: var(--accent2); } .pip.used { background: transparent; }

/* ---- chat */
#pane-chat { flex-direction: column; overflow: hidden; }
#chatlog { flex: 1; overflow-y: auto; padding: .6rem; display: flex; flex-direction: column; gap: .4rem; }
.msg { background: var(--panel2); border-radius: 10px; padding: .4rem .65rem; max-width: 92%; align-self: flex-start; } .msg.mine { align-self: flex-end; background: #3b2415; }
.msg p { margin: 0; overflow-wrap: anywhere; } .msg b { font-size: .8rem; color: var(--accent2); } .whisper { color: #a78bfa; }
.msg.roll { width: 92%; } .msg .lbl { font-size: .8rem; color: var(--muted); margin-left: .4rem; }
.rl { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; } .rl .ex { font-size: .72rem; color: var(--muted); font-family: ui-monospace, monospace; }
.rl .br { flex: 1; font-size: .9rem; } .rl .tot { font-size: 1.7rem; font-weight: 800; min-width: 2ch; text-align: right; }
.d { display: inline-block; min-width: 1.5em; text-align: center; background: #100d0b; border-radius: 5px; padding: 0 .2em; margin-right: 3px; }
.d.drop { text-decoration: line-through; opacity: .4; } .d.hi { color: var(--ok); } .d.lo { color: var(--bad); }
.msg.crit { box-shadow: 0 0 0 2px var(--ok); } .msg.fumble { box-shadow: 0 0 0 2px var(--bad); }
#dicebar { padding: .4rem .5rem; border-top: 1px solid var(--line); display: grid; gap: .35rem; }
.dice { display: flex; gap: .3rem; } .dice button { flex: 1; padding: .3rem 0; min-height: 36px; } .dice input { width: 64px; text-align: center; flex: none; }
.fline { display: flex; gap: .3rem; } .fline input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; } .fline button { flex: none; }
#savedf { display: flex; flex-wrap: wrap; gap: .3rem; } #savedf:empty { display: none; }
.sf { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--panel2); }
.sf button { border: 0; border-radius: 0; min-height: 30px; padding: .1rem .55rem; background: transparent; font-size: .82rem; font-family: ui-monospace, monospace; }
.sf button.x { padding: .1rem .4rem; }
#dicebar.building .dice button[data-die] { outline: 2px dashed var(--accent2); outline-offset: -3px; }
#chatform { display: flex; gap: .4rem; padding: .4rem .5rem; padding-bottom: .5rem; }

/* ---- initiative / dm */
.initlist { list-style: none; padding: 0; margin: .6rem 0; display: grid; gap: 4px; }
.initlist li { display: flex; align-items: center; gap: .5rem; background: var(--panel2); border-radius: 8px; padding: .35rem .6rem; }
.initlist li.cur { background: #4a2a10; box-shadow: inset 3px 0 var(--accent2); } .initlist .nm { flex: 1; } .initlist .mark { width: 1em; color: var(--accent2); }
.initlist input { width: 64px; padding: .2rem .4rem; min-height: 32px; } .iv { font-size: 1.2rem; }
.actions { display: grid; gap: .4rem; }
.scn { display: flex; gap: .3rem; margin-bottom: .3rem; } .scn > button:first-child { flex: 1; text-align: left; } .scn.view > button:first-child { border-color: var(--accent2); }
.members { display: flex; gap: .3rem; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translate(-50%, 20px); background: #000d; border: 1px solid var(--line);
  padding: .5rem .9rem; border-radius: 999px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- dice animation overlay + roll dialog */
#diceover { position: fixed; inset: 0; z-index: 60; pointer-events: none; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 1rem; }
.dtray { display: grid; justify-items: center; gap: .35rem; padding: .7rem 1rem .6rem; max-width: 94vw; border-radius: 16px;
  background: rgba(20, 17, 15, .82); backdrop-filter: blur(3px); box-shadow: 0 8px 30px #000a; transition: opacity .4s, transform .4s; }
.dtray.out { opacity: 0; transform: translateY(-14px); }
.dwho { font-size: .85rem; color: var(--accent2); font-weight: 600; } .dwho i { color: #a78bfa; font-weight: 400; }
.drow { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem; min-height: 56px; }
.dmore { align-self: center; color: var(--muted); }
.dw { width: 52px; height: 52px; filter: drop-shadow(0 3px 3px #000a); animation: dthrow .65s cubic-bezier(.2, .7, .3, 1) both; }
.df { width: 100%; height: 100%; display: grid; place-items: center; font-weight: 800; font-size: 1.25rem; color: #2a1608;
  background: radial-gradient(circle at 35% 28%, #fde7b0, #f59e0b 60%, #b45309); animation: dspin .65s linear both; }
.df.set { animation: dpop .25s ease-out; } .df.drop { opacity: .5; filter: saturate(.3); }
.dwho em { font-style: normal; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; padding: 1px 6px; border-radius: 999px; margin-left: .3rem; } .dwho em.adv { background: #14532d; color: #bbf7d0; } .dwho em.dis { background: #7f1d1d; color: #fecaca; }
.df.hi { background: radial-gradient(circle at 35% 28%, #bbf7d0, #22c55e 60%, #166534); }
.df.lo { background: radial-gradient(circle at 35% 28%, #fecaca, #ef4444 60%, #7f1d1d); color: #fff; }
.dtot { display: flex; align-items: baseline; gap: .5rem; } .dtot small { font-family: ui-monospace, monospace; }
.dtot b { font-size: 2.2rem; line-height: 1; min-width: 1ch; text-align: center; }
.dtray.done .dtot b { animation: dpop .3s ease-out; }
.dtray.crit { box-shadow: 0 0 0 2px var(--ok), 0 0 30px #22c55e88; } .dtray.fumble { box-shadow: 0 0 0 2px var(--bad), 0 0 30px #ef444488; }
@keyframes dthrow { from { transform: translate(var(--dx), -55vh) rotate(calc(var(--dir) * -240deg)); opacity: 0; } 25% { opacity: 1; } 70% { transform: translate(0, 6px); } to { transform: none; } }
@keyframes dspin { from { transform: rotate(0); } to { transform: rotate(calc(var(--dir, 1) * 720deg)); } }
@keyframes dpop { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .dw, .df, .df.set, .dtray.done .dtot b { animation: none; } }

#rolldlg { position: fixed; inset: 0; z-index: 70; background: #000a; display: flex; align-items: center; justify-content: center; padding: 1rem; }
#rolldlg .card { width: min(360px, 100%); display: grid; gap: .6rem; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; }
#rolldlg h3 { margin: 0; } #rolldlg .row { margin: 0; } #rolldlg .row button { flex: 1; padding: .4rem .2rem; font-size: .85rem; }

/* ---- token portraits */
.portrait-row { align-items: center; }
.portrait { flex: none; width: 52px; height: 52px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; background: var(--panel2); border: 2px solid var(--line); font-size: 1.5rem; }
.portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---- character creator + spell lists */
#creator, #spellpick, #importrep, #featpick, #hbman, #accman, #filesman, #lvlup, #mastpick, #bgpick, #mipick, #fxpick { position: fixed; inset: 0; z-index: 65; background: #000b; display: flex; align-items: stretch; justify-content: center; }
.cwrap { width: min(560px, 100%); display: flex; flex-direction: column; background: var(--panel); min-height: 0; }
.cwrap header { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
.cwrap header b { flex: 1; font-size: 1.05rem; }
.dots { display: flex; gap: 5px; } .dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); } .dots i.on { background: var(--accent2); } .dots i.done { background: var(--accent); }
.cbody { flex: 1; overflow-y: auto; padding: .8rem; display: grid; gap: .6rem; align-content: start; -webkit-overflow-scrolling: touch; }
.cwrap footer { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .6rem .8rem calc(.6rem + var(--safe-b)); border-top: 1px solid var(--line); }
.cwrap footer span { display: flex; gap: .4rem; } .cwrap footer [hidden] { display: none; } .warn { color: var(--accent2); } button:disabled { opacity: .45; cursor: default; }
.methods button { flex: 1; } .abtable { width: 100%; border-collapse: collapse; } .abtable th { text-align: left; font-weight: 500; padding: .2rem .3rem; color: var(--muted); font-size: .8rem; }
.abtable td { padding: .2rem .3rem; text-align: center; } .abtable td select, .abtable td input { min-height: 34px; padding: .2rem .3rem; text-align: center; }
.pb { display: inline-flex; align-items: center; gap: .5rem; } .pb button { min-height: 32px; width: 34px; padding: 0; } .pb b { min-width: 1.5em; }
.skillpick { display: flex; flex-wrap: wrap; gap: .35rem; } .ck { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: .25rem .7rem; }
.ck.on { background: var(--accent); border-color: var(--accent); } .ck.off { opacity: .4; } .ck input { display: none; }
.splist, .spl { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.sprow { background: var(--panel2); border-radius: 8px; padding: .3rem .6rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.sprow label { flex: 1; display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .95rem; min-height: 32px; } .sprow.on { box-shadow: inset 3px 0 var(--accent2); } .sprow.off { opacity: .45; }
.sprow p { width: 100%; margin: 0; }
.rv { margin: 0; } .rvgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: .4rem; }
.rvgrid div { background: var(--panel2); border-radius: 8px; padding: .3rem; text-align: center; display: grid; } .rvgrid b { font-size: 1.25rem; } .rvgrid em { font-style: normal; color: var(--accent2); font-size: .8rem; }
.feat { white-space: pre-wrap; font: .8rem/1.5 ui-monospace, monospace; color: var(--muted); margin: .3rem 0 0; }
.chip.create { background: var(--accent); border-style: solid; border-color: var(--accent); color: #fff; }
.spl li { background: var(--panel2); border-radius: 8px; display: flex; flex-wrap: wrap; align-items: center; padding-right: .3rem; }
.spl .sp { flex: 1; text-align: left; background: transparent; border: 0; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.spdesc { width: 100%; padding: 0 .7rem .5rem; font-size: .9rem; } .spdesc p { margin: .2rem 0; }
.chip.wide { display: block; width: 100%; margin: 0 0 .4rem; padding: .5rem .75rem; border-radius: 10px; text-align: center; }
.sheetacts { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: .4rem; margin: 0 0 .6rem; } .sheetacts .chip { width: 100%; margin: 0; white-space: nowrap; }

/* ---- homebrew manager */
.hbrow { list-style: none; display: flex; gap: .4rem; align-items: stretch; }
.hbrow .who { flex: 1; min-width: 0; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: .5rem; overflow: hidden; }
.hbrow .who small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hbform { display: grid; gap: .55rem; } #hbform textarea { min-height: 3rem; }

/* class resources and chat cards for casts / feature uses */
.res { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.res li { background: var(--panel2, #1f1b16); border: 1px solid var(--line, #3a3228); border-radius: 8px; padding: .5rem; }
.res .rh { display: flex; align-items: center; gap: .5rem; } .res .rh b { flex: 1; } .res .rh button { min-height: 32px; padding: 0 .8rem; }
.res .pips { margin: .4rem 0 .2rem; } .res .rp { display: flex; align-items: center; gap: .4rem; margin: .3rem 0; } .res .rp input { width: 4.5rem; }
.spl .sp + .primary { min-height: 32px; padding: 0 .7rem; margin-left: .3rem; } .castat { align-items: center; gap: .3rem; }
.msg.use { width: 94%; } .ucard { border-left: 3px solid var(--accent2); background: #2a2118; border-radius: 6px; padding: .4rem .6rem; margin-top: .2rem; }
.ucard b { display: block; } .ucard small { display: block; color: var(--muted); white-space: pre-line; margin: .15rem 0; } .ucard p { margin: .3rem 0 0; font-size: .9rem; }

/* level up */
.lvlbar { margin-bottom: .5rem; gap: .4rem; } .lvlmark { color: var(--accent2); font-size: .75rem; margin-left: .3rem; }
.lufeat { margin: .3rem 0; padding-left: 1.1rem; } #lvlup .cbody h4 { margin: .8rem 0 .3rem; }

/* spell area placement bar */
#tplbar { position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .5rem .7rem; background: rgba(29,25,22,.95); border: 1px solid var(--line); border-radius: 10px; }
#tplbar[hidden] { display: none; } #tplbar b { display: block; } #tplbar small { color: var(--muted); } #tplbar span { display: flex; gap: .4rem; flex-shrink: 0; } #tplbar button { min-height: 40px; }

/* background window */
.bglist { display: grid; gap: .4rem; } .bgcard { text-align: left; display: grid; gap: .1rem; padding: .5rem .7rem; min-height: 0; }
.bgcard small { color: var(--muted); } .bgcard.on { border-color: var(--accent2); background: #2a2118; }

.perk { border: 1px solid var(--line); border-radius: 8px; padding: .5rem; margin: .4rem 0; display: grid; gap: .4rem; } .perk details { margin: 0; }

/* battle mode: turn order over the map and the action menu */
#turnbar { position: absolute; top: 8px; left: 60px; right: 8px; z-index: 3; display: flex; align-items: center; gap: .5rem; padding: .35rem .5rem; background: rgba(29,25,22,.95); border: 1px solid var(--line); border-radius: 10px; }
#turnbar[hidden], #actmenu[hidden] { display: none; }
#pausebar { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 4; padding: .4rem .9rem; border-radius: 999px; background: rgba(120,53,15,.95); border: 1px solid var(--accent2); color: #fff; font-weight: 600; white-space: nowrap; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; }
#pausebar[hidden] { display: none; }
#game.paused[data-role=player] #map { pointer-events: none; filter: saturate(.6) brightness(.85); }
#turnbar .rnd { font-size: .75rem; color: var(--muted); white-space: nowrap; }
#turnbar ol { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#turnbar li { flex: none; display: flex; align-items: center; gap: .35rem; padding: .25rem .55rem; border-radius: 999px; background: var(--panel2); font-size: .8rem; white-space: nowrap; cursor: pointer; }
#turnbar li b { font-size: .7rem; color: var(--muted); }
#turnbar li.cur { background: #4a2a10; box-shadow: 0 0 0 2px var(--accent2); }
#turnbar li.hid { opacity: .5; }
#turnbar .eco { display: flex; gap: 3px; } #turnbar .pip { min-height: 28px; width: 28px; padding: 0; font-size: .7rem; border-radius: 50%; background: #1e5a2e; border-color: #2f8f4a; }
#turnbar .pip.used { background: var(--panel2); border-color: var(--line); color: var(--muted); text-decoration: line-through; }
#turnbar .primary { min-height: 34px; padding: 0 .7rem; white-space: nowrap; }
#actmenu { position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 4; max-width: 460px; max-height: 62%; overflow-y: auto; margin: 0 auto; padding: .6rem .7rem; background: rgba(29,25,22,.98); border: 1px solid var(--accent2); border-radius: 12px; display: grid; gap: .5rem; }
#actmenu h5 { margin: 0 0 .25rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#actmenu .aitems { display: flex; flex-wrap: wrap; gap: 6px; }
#actmenu .aitem { display: grid; text-align: left; min-height: 44px; padding: .3rem .7rem; gap: 0; }
#actmenu .aitem small { color: var(--muted); font-size: .7rem; }
#actmenu .aitem.react { border-color: #a855f7; }
/* in battle the token card and the action menu sit side by side */
#stage.acting #tokcard { left: 8px; right: calc(50% + 4px); max-width: none; margin: 0; max-height: 62%; overflow-y: auto; }
#stage.acting #actmenu { left: calc(50% + 4px); right: 8px; max-width: none; margin: 0; }
#turnbar .face { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex: none; display: grid; place-items: center; font-size: .75rem; font-weight: 700; color: #fff; border: 1px solid rgba(0,0,0,.5); margin-left: -.35rem; }
#turnbar li.cur .face { border-color: var(--accent2); }

/* bigger turn order */
#turnbar { padding: .5rem .7rem; gap: .7rem; } #turnbar .rnd { font-size: .9rem; }
#turnbar li { padding: .35rem .8rem .35rem .5rem; font-size: 1rem; gap: .5rem; } #turnbar li b { font-size: .85rem; }
#turnbar .face { width: 42px; height: 42px; font-size: 1.1rem; margin-left: 0; } #turnbar li.cur { transform: scale(1.06); }
#turnbar .pip { min-height: 36px; width: 36px; font-size: .85rem; } #turnbar .primary { min-height: 42px; font-size: 1rem; }
#turnbar .go { min-height: 30px; width: 30px; padding: 0; border-radius: 50%; font-size: .8rem; }
@media (max-width: 700px) {
  #turnbar { flex-wrap: wrap; row-gap: .35rem; padding: .4rem .5rem; }
  #turnbar .rnd { order: 1; flex: 1; } #turnbar .eco { order: 2; } #turnbar .primary { order: 3; } #turnbar ol { order: 4; flex: 1 1 100%; }
  #turnbar .face { width: 34px; height: 34px; } #turnbar li { font-size: .9rem; } #turnbar .pip { min-height: 32px; width: 32px; }
}
.spl li[hidden], .splist li[hidden] { display: none; }
#spq, #hbsearch { width: 100%; margin: .4rem 0; }
.dmgrow { display: flex; gap: 6px; margin-top: .35rem; } .dmgrow button { flex: 1; min-height: 40px; display: grid; gap: 0; } .dmgrow small { font-size: .7rem; color: var(--muted); }
#tokcard .saves { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: .3rem 0; } #tokcard .saves small { width: 100%; color: var(--muted); }
#tokcard .saves button { min-height: 32px; padding: 2px 8px; font-size: .78rem; } #tokcard .saves b { margin-left: 2px; }
/* reordering the turn order */
.grip { cursor: grab; touch-action: none; user-select: none; padding: 0 .35rem; color: var(--muted); font-size: 1.1rem; line-height: 1; }
li.dragging { position: relative; z-index: 6; opacity: .85; box-shadow: 0 6px 18px rgba(0,0,0,.6); }
li.dropat { outline: 2px dashed var(--accent2); outline-offset: 1px; }
.addcombat { display: grid; gap: 6px; margin: .8rem 0; padding: .6rem; background: var(--panel2); border-radius: 10px; }
/* status icons */
.ci { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; vertical-align: middle; flex: none; }
.cond { display: inline-flex; align-items: center; gap: 4px; } .cond .ci { width: 18px; height: 18px; margin-left: -4px; }
#turnbar li .ci { width: 22px; height: 22px; margin-left: -2px; }
.problems { list-style: none; padding: 0; margin: .2rem 0 .8rem; display: grid; gap: 4px; } .problems li { background: var(--panel2); border-radius: 8px; padding: .35rem .6rem; } .problems small { display: block; color: var(--muted); }
.resblock { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem; margin: .5rem 0; display: grid; gap: .4rem; background: rgba(255,255,255,.02); }

/* choices of options (runes, maneuvers...) */
.optpick { display: grid; gap: 6px; } .ck.opt { display: flex; align-items: flex-start; gap: .5rem; padding: .45rem .6rem; border-radius: 10px; } .ck.opt span { display: grid; gap: 2px; } .ck.opt .d { color: var(--muted); font-size: .8rem; white-space: pre-wrap; }
.chip .keybtn { min-height: 0; padding: 0 .2rem; margin-left: .2rem; border: 0; background: transparent; font-size: .8rem; }
.accbox { margin: .6rem 0; padding: .6rem .75rem; border: 1px solid var(--accent); border-radius: 10px; }
.accbox code { user-select: all; font-size: 1rem; }

/* ---- homebrew library: wide on big screens, with the lists in columns */
#hbman .cwrap { width: min(1100px, 100%); }
@media (min-width: 900px) {
  #hbman .splist { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
  #hbman #hbform .row.wrap label, #hbman #hbform .perk .row.wrap label { min-width: 0; }
}
#hbman .hbrow > button:not(.who):not(.x) { white-space: nowrap; }

/* ---- the DM's player accounts window */
#accman .cwrap, #filesman .cwrap { width: min(820px, 100%); }
#filesman .meter { height: 8px; border-radius: 99px; background: var(--panel2); margin-top: .35rem; overflow: hidden; } #filesman .meter i { display: block; height: 100%; background: var(--accent); }
#filesman .files { display: grid; grid-template-columns: 1fr; gap: .5rem; }
.fileitem { display: flex; align-items: center; gap: .6rem; padding: .4rem; border: 1px solid var(--line); border-radius: 10px; list-style: none; }
.fileitem img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--panel2); flex: none; }
.fileitem .who { flex: 1; min-width: 0; display: grid; } .fileitem small { color: var(--muted); }
.fileitem.pend { opacity: .6; } .fileitem.pend img { filter: grayscale(1); }
@media (min-width: 700px) { #filesman .files { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); } }
.acctable { width: 100%; border-collapse: collapse; margin: .4rem 0; } .acctable th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 500; padding: .2rem .3rem; }
.acctable td { padding: .25rem .3rem; border-top: 1px solid var(--line); } .acctable code { font-size: 1rem; user-select: all; }
@media (min-width: 700px) { #accman .splist { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); } }
