:root {
  --bg: #0b0906; --panel: rgba(20, 15, 10, 0.88); --line: #5a4526; --gold: #d4a64a; --gold2: #f0cf7e;
  --text: #eadcc0; --muted: #a8977a; --red: #d0503c; --blue: #5ad8ff; --green: #6fcf7a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 15px/1.35 "Alegreya Sans", system-ui, sans-serif; }
#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; touch-action: none; }
/* a view drawn by the host's PC: the video lies over this computer's (undrawn) scene; clicks go through to it */
#streamView { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; display: none; background: #000; }
#streamView.on { display: block; }
/* the host's hidden tab that draws a player's view: nothing but the view */
body.render > *:not(#viewport) { display: none !important; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h2, h3, .brand { font-family: "Cinzel", Georgia, serif; letter-spacing: .04em; }
h3 { margin: 16px 0 8px; font-size: 13px; color: var(--gold); text-transform: uppercase; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
h3:first-child { margin-top: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5), inset 0 0 0 1px rgba(212,166,74,.08); backdrop-filter: blur(6px); }

#topbar { position: fixed; top: 0; left: 0; right: 0; height: 46px; display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: linear-gradient(#140f0aee, #140f0a99); border-bottom: 1px solid var(--line); z-index: 10; }
.brand { color: var(--gold); font-weight: 700; font-size: 17px; white-space: nowrap; }
#mapTitle { font-family: "Cinzel", serif; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; }
.badge.live { background: #3a1410; color: #ff8a70; border-color: #8a3020; animation: pulse 2s infinite; }
.badge.prep { background: #1a1630; color: #b8a8ff; border-color: #4a3a8a; }
@keyframes pulse { 50% { box-shadow: 0 0 10px #ff5a3a88; } }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.mini { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex: none; }
#quality { width: auto; }
#fps { white-space: nowrap; flex: none; }
#topbar > button, #topbar > .badge { flex: none; }
#mapTitle { min-width: 80px; flex: 0 1 auto; }

button, .btn, select, input { font: inherit; color: var(--text); }
button, .btn { background: #2a2016; border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; cursor: pointer; transition: .12s; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--gold); background: #362a1c; }
button.primary { background: linear-gradient(#a07a2c, #7a5a1c); border-color: var(--gold); color: #fff6e0; font-weight: 700; }
button.danger { border-color: #8a3020; color: #ffb0a0; }
button.on { border-color: var(--gold); background: #4a3a1c; color: var(--gold2); box-shadow: inset 0 0 0 1px var(--gold); }
.mini-btn { padding: 3px 8px; font-size: 13px; }
select, input { background: #120d08; border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; width: 100%; }
input[type=range] { padding: 0; accent-color: var(--gold); }
input[type=checkbox] { width: auto; accent-color: var(--gold); }
input[type=color] { padding: 0; height: 30px; }
label { display: block; font-size: 12px; color: var(--muted); }
label > input, label > select, label > .row { margin-top: 3px; }
.row { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.row > * { flex: 1; }
.row > .mini-btn { flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.span2 { grid-column: span 2; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin-top: 6px; }

#tools { position: fixed; top: 58px; left: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 9; max-height: calc(100vh - 70px); overflow-y: auto; scrollbar-width: none; }
#tools button { width: 58px; height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 20px; padding: 2px; background: var(--panel); }
#tools button span { font-size: 10px; margin-top: 2px; color: var(--muted); }
#tools button.on span { color: var(--gold2); }
#tools .sep { height: 1px; background: var(--line); margin: 2px 6px; }

#toolopts { position: fixed; top: 58px; left: 80px; width: 250px; max-height: calc(100vh - 80px); overflow-y: auto; overflow-x: hidden; padding: 12px; z-index: 9; }
#toolopts:empty { display: none; }
.palette { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.palette button { padding: 5px 3px; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.palette .sw { width: 100%; height: 22px; border-radius: 4px; border: 1px solid #0006; }
.proplist { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.proplist button { font-size: 12px; text-align: left; padding: 5px 7px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.proplist .lit::after { content: " ✦"; color: #ffb050; }
.seg { display: flex; gap: 3px; }
.seg button { flex: 1; padding: 4px; font-size: 12px; }

#sidebar { position: fixed; top: 58px; right: 12px; bottom: 12px; width: 290px; padding: 14px; z-index: 9; transition: transform .2s; }
#sidebar .side-inner { height: 100%; overflow: auto; padding-right: 4px; }
#sidebar.collapsed { transform: translateX(calc(100% + 12px)); }
.collapse { position: absolute; left: -34px; top: 8px; width: 28px; height: 36px; padding: 0; background: var(--panel); }
#sidebar.collapsed .collapse { left: -46px; }
#sidebar.collapsed .collapse::before { content: ""; }

#mapList { display: flex; flex-direction: column; gap: 5px; }
.mapitem { border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; background: #1a130c; cursor: pointer; }
.mapitem:hover { border-color: #8a6a36; }
.mapitem.viewing { border-color: var(--gold); background: #2a1f12; }
.mapitem .t { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.mapitem .t .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mapitem .sub { font-size: 11px; color: var(--muted); }
.mapitem .acts { display: flex; gap: 4px; margin-top: 5px; }
.mapitem .acts button { padding: 2px 7px; font-size: 12px; }

textarea { font: inherit; color: var(--text); background: #120d08; border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; width: 100%; resize: vertical; }
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--gold); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chips button { font-size: 11px; padding: 2px 8px; border-radius: 99px; color: var(--muted); }
.status { margin-top: 8px; padding: 8px 10px; border-radius: 8px; font-size: 13px; background: #1a130c; border: 1px solid var(--line); }
.status.working { border-color: #8a6a36; color: var(--gold2); }
.status.working::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; border: 2px solid var(--gold); border-top-color: transparent; animation: spin .8s linear infinite; vertical-align: -1px; }
.status.error { border-color: #8a3020; color: #ffb0a0; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-setup { margin-top: 8px; }
.ai-setup .on { color: var(--green); }
.ai-setup a { color: var(--gold2); }
.readaloud { font-style: italic; border-left: 3px solid var(--gold); padding: 4px 0 4px 10px; margin-bottom: 6px; font-size: 14px; }
details summary { cursor: pointer; color: var(--gold); font-family: "Cinzel", serif; font-size: 13px; text-transform: uppercase; margin: 16px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
#banner { position: fixed; top: 56px; left: 50%; transform: translateX(-50%); z-index: 8; padding: 6px 14px; border-radius: 8px; background: #1a1630e8; border: 1px solid #4a3a8a; color: #d8ccff; display: flex; gap: 10px; align-items: center; white-space: nowrap; max-width: calc(100vw - 24px); }
#banner > span { min-width: 0; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
#popup { position: fixed; z-index: 20; padding: 12px; min-width: 210px; max-width: 280px; }
#popup h4 { margin: 0 0 4px; font-family: "Cinzel", serif; color: var(--gold2); }
#popup .col { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
#toasts { position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 30; pointer-events: none; }
.toast { background: var(--panel); border: 1px solid var(--gold); padding: 8px 16px; border-radius: 8px; font-family: "Cinzel", serif; animation: tin .3s; }
@keyframes tin { from { opacity: 0; transform: translateY(10px); } }
#hint { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); font-size: 12px; text-align: center; z-index: 5; pointer-events: none; text-shadow: 0 1px 3px #000; white-space: nowrap; }

.modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 40; }
.card { padding: 20px; width: min(360px, calc(100vw - 32px)); }
.card h2 { margin: 0 0 12px; color: var(--gold); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; padding: 0; border: 2px solid #0008; }
.swatches button.on { border-color: #fff; box-shadow: 0 0 0 2px var(--gold); }

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 50; font-family: "Cinzel", serif; color: var(--gold); font-size: 20px; transition: opacity .5s; }
#loading.gone { opacity: 0; pointer-events: none; }

body:not(.dm) .dm-only { display: none !important; }
/* world, region and city maps */
body:not(.atlas) .atlas-only { display: none !important; }
#crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 0 1 auto; overflow: hidden; font-size: 12px; color: var(--muted); white-space: nowrap; }
#crumbs:empty { display: none; }
#crumbs button, #crumbs span.c { background: none; border: 0; padding: 2px 4px; color: var(--muted); font: inherit; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#crumbs button { cursor: pointer; border-radius: 5px; }
#crumbs button:hover { color: var(--gold2); background: rgba(212,166,74,0.12); }
#crumbs .sepr { opacity: 0.5; }
.mapitem.child { margin-left: 14px; border-left-width: 3px; }
.mapitem.child2 { margin-left: 28px; border-left-width: 3px; }
.mapitem.child3 { margin-left: 42px; border-left-width: 3px; }
#popup .place-kind { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
#popup .place-desc { font-size: 12.5px; line-height: 1.4; margin: 6px 0 2px; color: #e9dcc0; font-style: italic; }
#popup .row2 { display: flex; gap: 5px; }
#popup .row2 > * { flex: 1; }
#genScale { flex: 0 0 auto; width: auto; }
@media (max-width: 760px) { #crumbs { display: none; } }
#measure { position: fixed; z-index: 25; pointer-events: none; padding: 3px 9px; border-radius: 6px; background: #140f0ae8; border: 1px solid var(--gold); color: var(--gold2); font-weight: 700; font-size: 14px; }
/* TV / clean mode: nothing on screen but the map (toasts still show) */
body.clean #topbar, body.clean #tools, body.clean #toolopts, body.clean #sidebar, body.clean #banner, body.clean #hint { display: none !important; }

/* short laptop screens: slimmer tool buttons so Undo stays on screen */
@media (max-height: 640px) {
  #tools { gap: 4px; }
  #tools button { height: 42px; font-size: 16px; }
}
@media (max-width: 760px) {
  .brand, #fps, .mini { display: none; }
  #sidebar { width: calc(100vw - 90px); }
  #toolopts { left: 76px; width: calc(100vw - 92px); max-height: 45vh; }
  #hint { white-space: normal; width: calc(100vw - 32px); }
}

/* ---------------------------------------------------------------- dice tray */
#dice { position: fixed; left: 12px; bottom: 34px; width: 300px; padding: 10px; z-index: 8; display: flex; flex-direction: column; gap: 6px; }
body.dm #dice { left: 80px; }
.dice-head { display: flex; justify-content: space-between; align-items: center; font-family: "Cinzel", serif; color: var(--gold); font-size: 13px; }
#diceLog { max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; font-size: 13px; scrollbar-width: thin; }
#diceLog:empty::before { content: "Rolls show here for everyone."; color: var(--muted); font-size: 12px; }
.roll { padding: 3px 6px; border-radius: 6px; background: #1a130c; border: 1px solid transparent; cursor: pointer; line-height: 1.3; }
.roll:hover { border-color: var(--line); }
.roll .who { font-weight: 700; }
.roll .lbl { color: var(--gold2); }
.roll .expr { color: var(--muted); font-size: 12px; }
.roll .dice { color: var(--muted); font-size: 12px; }
.roll .dice s { opacity: .55; }
.roll .tot { font-weight: 700; font-size: 15px; color: #fff6e0; }
.roll.crit .tot { color: #7dff9a; text-shadow: 0 0 8px #3aff6a; }
.roll.fumble .tot { color: #ff7a6a; }
.roll.priv { background: #1a1630; }
.dice-btns { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dice-btns button { padding: 5px 0; font-size: 12px; font-weight: 700; }
.dice-input { margin-top: 0; }
.dice-input input { min-width: 0; }
.dice-opts { display: flex; flex-wrap: wrap; gap: 0 12px; }
.dice-opts .check { margin-top: 0; font-size: 12px; }
#diceErr { color: #ffb0a0; }
.fab { position: fixed; left: 12px; bottom: 34px; width: 48px; height: 48px; border-radius: 50%; font-size: 22px; padding: 0; z-index: 8; background: var(--panel); }
body.dm .fab { left: 80px; }
body.dice-open #toolopts { max-height: calc(100vh - 380px); }

/* big result in the middle of the screen when someone rolls */
#rollFlash { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 28; pointer-events: none; text-align: center; padding: 14px 26px; border-radius: 14px;
  background: radial-gradient(#1c1510f2, #120d08e8); border: 1px solid var(--gold); box-shadow: 0 10px 40px #000a; animation: flash-in .25s ease-out; }
#rollFlash .n { font-family: "Cinzel", serif; font-size: 54px; font-weight: 700; color: #fff6e0; line-height: 1; }
#rollFlash .w { font-size: 14px; color: var(--muted); margin-top: 4px; }
#rollFlash.crit { border-color: #6dff9a; box-shadow: 0 0 40px #3aff6a66; }
#rollFlash.crit .n { color: #9dffb0; }
#rollFlash.fumble { border-color: #d0503c; }
#rollFlash.fumble .n { color: #ff8a7a; }
#rollFlash.out { animation: flash-out .4s ease-in forwards; }
@keyframes flash-in { from { opacity: 0; transform: translate(-50%, -50%) scale(.85); } }
@keyframes flash-out { to { opacity: 0; transform: translate(-50%, -60%); } }

/* ---------------------------------------------------------------- initiative */
#combat { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); z-index: 8; display: flex; align-items: stretch; gap: 8px; max-width: calc(100vw - 420px); padding: 6px 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px #0008; }
body:not(.dm) #combat { max-width: calc(100vw - 24px); }
.cb-head { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; flex: none; padding-right: 6px; border-right: 1px solid var(--line); }
.cb-round { font-family: "Cinzel", serif; color: var(--gold); font-size: 12px; white-space: nowrap; }
.cb-acts { display: flex; gap: 3px; }
.cb-acts button { padding: 2px 7px; font-size: 12px; }
.cb-list { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; }
.cb-card { flex: none; width: 74px; padding: 5px 4px 4px; border-radius: 8px; background: #1a130c; border: 1px solid var(--line); text-align: center; cursor: pointer; position: relative; }
.cb-card .pip { width: 26px; height: 26px; border-radius: 50%; margin: 0 auto 3px; border: 2px solid #0008; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; color: #0009; }
.cb-card .nm { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-card .in { font-size: 13px; font-weight: 700; color: var(--gold2); }
.cb-card .hp { font-size: 10px; color: var(--muted); }
.cb-card.cur { border-color: #6dffb0; background: #10261a; box-shadow: 0 0 12px #3aff8a55; }
.cb-card.mine .nm { color: #ffe28a; }
.cb-card.hid { opacity: .5; border-style: dashed; }
.cb-card.down { filter: grayscale(.8); }
.cb-roll { flex: none; display: flex; flex-direction: column; gap: 3px; justify-content: center; }
.cb-roll input { width: 64px; padding: 3px 5px; }
body.in-combat #banner { top: 162px; }
#turnFlash { position: fixed; left: 50%; top: 30%; transform: translateX(-50%); z-index: 27; pointer-events: none; font-family: "Cinzel", serif; font-size: 34px; color: #fff6e0;
  text-shadow: 0 2px 12px #000, 0 0 24px #3aff8a88; white-space: nowrap; animation: turn-in 1.8s ease-out forwards; }
#turnFlash.mine { color: #9dffb0; font-size: 42px; }
@keyframes turn-in { 0% { opacity: 0; transform: translate(-50%, 10px); } 15% { opacity: 1; transform: translate(-50%, 0); } 75% { opacity: 1; } 100% { opacity: 0; } }

/* ---------------------------------------------------------------- token sheet popup */
.hp-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.hp-row input { text-align: center; }
.dmg-row { display: flex; gap: 4px; margin-top: 6px; }
.dmg-row input { width: 64px; flex: none; text-align: center; }
.dmg-row button { flex: 1; padding: 4px; }
.conds { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; margin-top: 6px; }
.conds button { padding: 3px 0; font-size: 16px; line-height: 1.1; }
.conds button.on { background: #3a2a10; }
#popup { max-height: calc(100vh - 70px); overflow-y: auto; }
#popup.sheet { max-width: 300px; }

/* ---------------------------------------------------------------- measuring */
#measureBar { position: fixed; bottom: 34px; left: 50%; transform: translateX(-50%); z-index: 9; padding: 6px 8px; display: flex; gap: 10px; align-items: center; }
#measureBar .seg button { padding: 4px 9px; }
#measureBar .check { margin: 0; }

/* ---------------------------------------------------------------- misc */
#offline { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); z-index: 45; padding: 8px 16px; border-radius: 8px; background: #3a1410f0; border: 1px solid #8a3020; color: #ffd0c0; font-weight: 700; }
.card.wide { width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; }
#imgPreview { width: 100%; height: auto; max-height: 42vh; object-fit: contain; background: #000; border-radius: 6px; border: 1px solid var(--line); margin-bottom: 8px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
body:not(.dm) .help-cols { grid-template-columns: 1fr; }
.help ul { margin: 0; padding-left: 18px; font-size: 14px; }
.help li { margin: 4px 0; }
.help code { background: #120d08; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 13px; }
body.clean #dice, body.clean #diceFab, body.clean #measureBar { display: none !important; }

@media (max-width: 1100px) { #topbar .lbl, #role { display: none; } #combatBtn .lbl, #measureBtn .lbl, #topbar #partyLbl { display: inline; } }
@media (max-width: 900px) { #combatBtn .lbl, #measureBtn .lbl { display: none; } #partyBtn:not(.pulse) #partyLbl { display: none !important; } }

/* drop-down menus under the top bar */
.menu { position: fixed; z-index: 35; padding: 6px; min-width: 230px; display: flex; flex-direction: column; gap: 2px; }
#viewMenu > button { display: flex; align-items: center; gap: 10px; text-align: left; background: transparent; border-color: transparent; padding: 7px 10px; }
#viewMenu > button:hover { background: #362a1c; border-color: var(--line); }
#viewMenu > button.on { box-shadow: none; background: #3a2e18; }
#viewMenu > button[role=menuitemcheckbox]::after { content: ""; width: 14px; text-align: center; color: var(--gold2); }
#viewMenu > button.on[role=menuitemcheckbox]::after { content: "✓"; }
#viewMenu .ic { width: 20px; text-align: center; }
kbd { margin-left: auto; font: 11px/1 ui-monospace, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; }
.menu-q { padding: 6px 10px 4px; border-top: 1px solid var(--line); margin-top: 4px; }
/* weather & effects sliders */
#weatherBox { margin: 6px 0; }
#weatherBox summary { cursor: pointer; padding: 4px 0; }
.fx-rows { display: grid; gap: 2px; margin-top: 4px; }
.fx-row { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 6px; font-size: 13px; }
.fx-row input { width: 100%; }
#timeRow input { width: 100%; }
/* monster search (token tool and a token's sheet) */
.mon-search { position: relative; }
.mon-search input { width: 100%; }
.mon-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; margin-top: 2px; max-height: 260px; overflow-y: auto; background: #1d150d; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.mon-opt { padding: 5px 8px; cursor: pointer; font-size: 13px; line-height: 1.25; }
.mon-opt.on, .mon-opt:hover { background: #3a2a16; }
.mon-none { padding: 6px 8px; }
.mon-pick { display: flex; align-items: center; gap: 6px; justify-content: space-between; font-size: 12px; color: var(--gold2); margin: 2px 0 6px; }
/* a monster's stat block */
.stat-panel { position: fixed; z-index: 25; top: 56px; left: 92px; width: min(360px, calc(100vw - 110px)); max-height: calc(100vh - 80px); display: flex; flex-direction: column; padding: 10px 12px; }
/* beside the tool panel and the dice tray, so the rolls it makes stay in view */
@media (min-width: 1100px) { .stat-panel { left: 392px; } }
#popup a { color: var(--gold2); }
.stat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.stat-head h4 { margin: 0; font-family: "Cinzel", serif; color: var(--gold2); }
.stat-body { overflow-y: auto; margin-top: 6px; padding-right: 4px; font-size: 13px; line-height: 1.4; }
.stat-body h5 { margin: 10px 0 4px; font-family: "Cinzel", serif; color: var(--gold); border-bottom: 1px solid var(--line); font-size: 13px; }
.st-sub { font-style: italic; color: var(--muted); margin-bottom: 4px; }
.st-line { margin: 2px 0; }
.st-abs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; margin: 6px 0; }
.st-ab { padding: 3px 0; font-size: 11.5px; line-height: 1.2; text-align: center; }
.st-roll, .st-dice { padding: 1px 6px; font-size: 12px; border-radius: 5px; }
.st-dice { padding: 0 4px; background: transparent; border: 1px dashed var(--line); color: var(--gold2); }
.st-atk { font-weight: 700; }
.st-act { margin: 6px 0; }
.st-desc { color: #d9ccb0; margin-top: 2px; }
.st-dc { color: var(--gold2); font-weight: 700; font-size: 12px; }
.st-credit { margin-top: 10px; }
/* D&D Beyond (Beyond20) */
.mini-btn.b20 { margin-left: auto; margin-right: 6px; font-family: inherit; font-size: 11px; opacity: .75; }
.mini-btn.b20.on { opacity: 1; color: #7dff9a; border-color: #3a7a4a; }
.b20-steps { padding-left: 18px; margin: 4px 0; display: grid; gap: 6px; }
.b20-line { display: block; margin: 4px 0; padding: 4px 6px; background: #120d08; border-radius: 4px; word-break: break-all; user-select: all; }
.roll .src { font-size: 10.5px; padding: 0 4px; border-radius: 4px; background: #2a1a1a; color: #e8b0a0; border: 1px solid #5a2a2a; }
.roll .src.rep { background: #2a2214; color: #e8d0a0; border-color: #6a5a2a; }
/* the speed readout */
.perf { position: fixed; left: 8px; bottom: 8px; z-index: 40; padding: 4px 8px; border-radius: 6px; background: rgba(10, 8, 16, 0.78); color: #e8e0cc; font: 12px/1.4 ui-monospace, Consolas, monospace; pointer-events: none; max-width: calc(100vw - 16px); }
body.clean .perf { display: none; }
#partyPanel { width: 300px; max-height: calc(100vh - 70px); overflow-y: auto; padding: 10px 12px; gap: 6px; }
#partyPanel h4 { margin: 4px 0 2px; font-family: "Cinzel", serif; color: var(--gold); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
#partyPanel h4 + * { margin-top: 2px; }
#inviteBox { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.who { display: flex; align-items: center; gap: 8px; padding: 4px 2px; }
.who .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .tag { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.who.me .nm { color: var(--gold2); }
#partyMine:empty { display: none; }
#inviteQR { align-self: center; line-height: 0; border-radius: 6px; overflow: hidden; }
#inviteQR svg { display: block; width: 172px; height: 172px; }
.invite-url { display: flex; gap: 6px; align-items: center; }
.invite-url code { flex: 1; font-size: 14px; background: #120d08; border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; user-select: all; overflow-wrap: anywhere; }
.invite-pw { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.invite-pw code { font-size: 14px; letter-spacing: 0.04em; background: #120d08; border: 1px solid var(--line); border-radius: 6px; padding: 3px 7px; user-select: all; }
#pwInput { font-family: ui-monospace, Consolas, monospace; letter-spacing: 0.05em; }
button.linkish { background: none; border: none; padding: 2px 0; color: var(--gold2); text-decoration: underline; text-align: left; white-space: normal; }
#partyBtn.pulse { border-color: var(--gold); color: var(--gold2); animation: invite 1.8s ease-in-out infinite; }
@keyframes invite { 50% { box-shadow: 0 0 12px #f0cf7e88; } }
#partyBtn.open, #viewBtn.open { border-color: var(--gold); background: #362a1c; }

/* player view: the DM sees exactly what the players see; tools are paused */
#previewBar { position: fixed; top: 56px; left: 50%; transform: translateX(-50%); z-index: 9; padding: 6px 8px 6px 14px; border-radius: 8px; background: #102a1ae8; border: 1px solid #2f8a50; color: #c8ffd8; display: flex; gap: 10px; align-items: center; white-space: nowrap; max-width: calc(100vw - 24px); overflow: hidden; }
body.previewing #banner { display: none; }
body.previewing #tools, body.previewing #toolopts { opacity: .35; pointer-events: none; }
body.previewing #previewBtn { border-color: #2f8a50; background: #143a22; color: #c8ffd8; box-shadow: inset 0 0 0 1px #2f8a50; }
body.in-combat #previewBar { top: 162px; }

/* players following the DM's camera */
#followBar { position: fixed; top: 54px; right: 12px; z-index: 9; display: flex; gap: 8px; align-items: center; padding: 5px 6px 5px 12px; border-radius: 99px;
  background: #142038ee; border: 1px solid #3a5a9a; color: #cfe0ff; font-size: 13px; white-space: nowrap; }
body.clean #followBar { display: none; }
#followBtn { text-align: left; white-space: normal; }

/* the read-aloud card the DM puts on everyone's screen */
#narration { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 26; width: min(560px, calc(100vw - 24px)); max-height: 46vh; overflow-y: auto; padding: 14px 18px; border-color: var(--gold);
  background: linear-gradient(#2a2014f2, #1a140cf2); animation: fadein .35s; }
#narration h3 { margin: 0 0 6px; border: none; padding: 0; font-size: 15px; color: var(--gold2); text-transform: none; }
#narration .txt { font-size: 17px; line-height: 1.5; white-space: pre-wrap; font-style: italic; color: #f6ead0; }
#narration .row { justify-content: flex-end; }
#narration .row > * { flex: none; }
body.in-combat #narration { top: 162px; }
/* the DM already knows the words: a smaller copy, below the prep banner, so it never covers a control */
body.dm #narration { top: 100px; max-height: 150px; padding: 10px 14px; width: min(460px, calc(100vw - 440px)); }
body.dm #narration .txt { font-size: 14px; }
body.dm.in-combat #narration { top: 206px; }
@media (max-width: 760px) { body.dm #narration { width: calc(100vw - 90px); left: 80px; transform: none; } }
.toast.long { font-family: "Alegreya Sans", system-ui, sans-serif; font-size: 16px; max-width: min(640px, calc(100vw - 24px)); text-align: center; }

/* who pinged, and an arrow at the screen's edge for pings out of view */
#edgePings { position: fixed; inset: 0; pointer-events: none; z-index: 24; }
.edge-ping { position: absolute; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 99px; background: #140f0ae6; border: 1px solid var(--c); color: var(--c);
  font-size: 12px; font-weight: 700; pointer-events: auto; cursor: pointer; animation: fadein .25s; white-space: nowrap; }
.edge-ping.on { pointer-events: none; cursor: default; }
.edge-ping .ar { display: inline-block; font-size: 14px; }
.edge-ping .ar:empty { display: none; }
@media (max-height: 700px) { #diceLog { max-height: 84px; } .dice-btns button { padding: 3px 0; } #dice { gap: 4px; padding: 8px; } }
@media (max-width: 760px) {
  #dice, body.dm #dice { left: 8px; right: 8px; width: auto; bottom: 8px; }
  #diceLog { max-height: 90px; }
  .fab, body.dm .fab { left: auto; right: 12px; bottom: 12px; }
  #combat, body:not(.dm) #combat { max-width: calc(100vw - 16px); left: 8px; right: 8px; transform: none; }
  body.dm #combat { left: 76px; max-width: calc(100vw - 84px); }
  .help-cols { grid-template-columns: 1fr; }
  #measureBar { flex-wrap: wrap; width: calc(100vw - 16px); justify-content: center; }
  #topbar { gap: 6px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
  #topbar > * { flex: none; }
  #mapTitle { flex: 0 1 auto; min-width: 60px; max-width: 34vw; }
  #role, #prepBadge { display: none; }
}

@keyframes fadein { from { opacity: 0; } }
