:root {
  --bg: #14110f; --panel: #1e1915; --panel-2: #29221c; --line: #3d332a; --text: #f1e9dc; --muted: #a8998a;
  --accent: #d9a441; --accent-2: #b5452d; --good: #5fbf77; --bad: #e0675a; --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { display: flex; flex-direction: column; font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #1a1208; border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.small, .small button { padding: 3px 7px; font-size: 12px; }
/* Unavailable actions (no slot left, action already used) look it, instead of looking clickable. */
button:disabled { opacity: .4; cursor: not-allowed; filter: grayscale(.7); }
button:disabled:hover { border-color: var(--line); }
button.primary:disabled:hover { border-color: var(--accent); }
input, select, textarea { background: #120f0c; border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; min-width: 0; }
textarea { width: 100%; min-height: 80px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
label input, label select, label textarea { color: var(--text); font-size: 14px; }
h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 650; }
h3 { font-size: 15px; color: var(--accent); }
h4 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 14px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.spacer { flex: 1; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.dot.on { background: var(--good); }

#topbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; letter-spacing: .04em; color: var(--accent); }
.toggle { flex-direction: row; align-items: center; color: var(--text); font-size: 13px; }

main { flex: 1; display: flex; min-height: 0; }
#stage { flex: 1; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#stage canvas { position: absolute; inset: 0; display: block; width: 100% !important; height: 100% !important; touch-action: none; }
#toasts, #turnBanner { z-index: 1; }
#panel { width: 380px; flex-shrink: 0; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
#tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); flex-shrink: 0; }
#tabs button { border: 0; border-radius: 0; background: none; padding: 10px 10px; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; }
#tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tab { display: none; padding: 12px; overflow-y: auto; flex: 1; min-height: 0; }
.tab.active { display: flex; flex-direction: column; gap: 10px; }

#toasts { position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; max-width: min(360px, 80%); }
.toast { background: rgba(20, 17, 15, .88); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; animation: toastIn .25s ease-out; }
.toast.crit { border-color: var(--good); } .toast.fumble { border-color: var(--bad); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }
#turnBanner { position: absolute; top: 10px; right: 10px; background: rgba(20,17,15,.88); border: 1px solid var(--accent); border-radius: 8px; padding: 6px 12px; font-weight: 600; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.overlay[hidden] { display: none; }
.join-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(1000px, 100%); max-height: 100%; overflow: auto; padding: 16px; }

.list-item { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.list-item.active { border-color: var(--accent); }
.swatch { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; border: 1px solid #0006; }
.log-entry { padding: 6px 8px; border-radius: 6px; background: var(--panel-2); }
.log-entry.system { background: none; color: var(--muted); font-size: 12px; padding: 2px 8px; }
.log-entry .total { font-size: 18px; font-weight: 700; color: var(--accent); }
.log-entry.crit .total { color: var(--good); } .log-entry.fumble .total { color: var(--bad); }
.log-entry del { opacity: .5; }
.log-entry.private { border: 1px dashed var(--muted); }
#logList { display: flex; flex-direction: column; gap: 6px; flex: 1; overflow-y: auto; }

.dice-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.dice-btns button { padding: 10px 0; font-weight: 700; }
.chip { display: inline-flex; gap: 4px; align-items: center; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; }
.chip button { padding: 0 4px; border: 0; background: none; }

/* Character sheet */
.sheet-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; position: sticky; top: -16px; background: var(--panel); padding: 4px 0 10px; z-index: 2; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.sheet-head input.name { font-size: 20px; font-weight: 700; flex: 1; min-width: 160px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--accent); color: #1a1208; }
.sheet-cols { display: grid; grid-template-columns: 230px 1fr 1fr; gap: 12px; }
.abil { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.abil .box { text-align: center; padding: 6px 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: pointer; }
.abil .box .m { font-size: 20px; font-weight: 700; }
.abil .box .s { font-size: 11px; color: var(--muted); }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 2px; background: var(--panel-2); }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .k { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.rollable { cursor: pointer; }
.rollable:hover { border-color: var(--accent); }
.skill { display: flex; justify-content: space-between; padding: 3px 6px; border-radius: 5px; cursor: pointer; }
.skill:hover { background: var(--panel-2); }
.skill .p { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--muted); display: inline-block; margin-right: 6px; }
.skill .p.on { background: var(--accent); border-color: var(--accent); }
.skill .p.ex { background: var(--good); border-color: var(--good); }
.hp { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.hp .big { font-size: 26px; font-weight: 800; }
.pips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.pip { width: 16px; height: 16px; border-radius: 4px; border: 1px solid var(--accent); cursor: pointer; padding: 0; }
.pip.used { background: transparent; opacity: .4; }
.pip:not(.used) { background: var(--accent); }
.feature { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.feature .lv { color: var(--muted); font-size: 11px; margin-right: 6px; }
.weapon { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; padding: 4px 0; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 10px; }
.check-grid label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.map-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.map-table td { padding: 4px; border-bottom: 1px solid var(--line); }
.map-table select { width: 100%; }

/* Compendium */
.compendium-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #17130f; display: flex; flex-direction: column; gap: 6px; }
.compendium-card p { margin: 0; line-height: 1.45; }
.compendium-card h4 { margin: 6px 0 0; }
.kv { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.mon-abil { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; text-align: center; }
.mon-abil .box { border: 1px solid var(--line); border-radius: 6px; padding: 4px 0; }
.mon-abil .s { font-size: 10px; color: var(--muted); }
.rollable-text { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.rollable-text:hover { color: var(--accent); }
.spell-row { border-bottom: 1px dashed var(--line); padding: 4px 0; display: flex; flex-direction: column; gap: 6px; }
.spell-row.unprepared .spell-name { opacity: .55; }
.spell-name { cursor: pointer; }
.tag { display: inline-block; font-size: 10px; border: 1px solid var(--muted); border-radius: 4px; padding: 0 3px; margin-left: 5px; color: var(--muted); }
summary { cursor: pointer; color: var(--muted); }
.chip.rating.good { border-color: var(--good); color: var(--good); }
.chip.rating.warn { border-color: var(--accent); color: var(--accent); }
.chip.rating.bad { border-color: var(--bad); color: var(--bad); }
select:disabled, input:disabled { opacity: .5; }
.statblock { white-space: pre-wrap; border-left: 2px solid var(--accent); padding: 6px 10px; margin-top: 6px; color: var(--text); }

@media (max-width: 900px) {
  .sheet-cols { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  main { flex-direction: column; }
  #panel { width: 100%; height: 46vh; border-left: 0; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  #panel.collapsed { height: 42px; }
  #topbar { flex-wrap: wrap; gap: 8px; }
  .brand { display: none; }
  .modal-box { padding: 12px; }
  .overlay { padding: 0; }
  .modal-box { border-radius: 0; height: 100%; }
}
@media print {
  body { overflow: visible; background: #fff; color: #000; }
  #topbar, main, #join { display: none !important; }
  #modal { position: static; background: none; padding: 0; }
  .modal-box { border: 0; max-height: none; background: #fff; color: #000; }
  .no-print { display: none !important; }
}

/* Board toolbar */
#toolbar { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 4px; z-index: 2; background: rgba(20,17,15,.85); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
#toolbar button { border: 0; background: none; padding: 6px 9px; font-size: 13px; white-space: nowrap; }
#toolbar button.on { background: var(--accent); color: #1a1208; }
#toolPanel { position: absolute; left: 10px; top: 10px; z-index: 2; width: min(330px, calc(100% - 20px)); background: rgba(20,17,15,.94); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
#toolPanel select, #toolPanel input { padding: 4px 6px; }
#toolHint { position: absolute; left: 10px; bottom: 54px; z-index: 2; background: rgba(20,17,15,.9); border: 1px solid var(--accent); border-radius: 8px; padding: 5px 10px; font-size: 12px; max-width: min(420px, calc(100% - 20px)); pointer-events: none; }


/* Battle maps */
.map-preview-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 8px; background: #000; }
.map-preview { display: block; max-width: 100%; height: auto; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.map-thumb { border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: var(--panel-2); display: flex; flex-direction: column; gap: 4px; }
.map-thumb img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 4px; cursor: pointer; }

.class-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--panel-2); }

/* Sound */
.icon-btn { padding: 4px 8px; font-size: 16px; line-height: 1; }
#soundPanel { position: fixed; z-index: 40; width: min(320px, calc(100vw - 16px)); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-height: calc(100vh - 70px); overflow-y: auto; }
.vol { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.vol span { width: 72px; font-size: 12px; color: var(--muted); }
.vol input { flex: 1; }
.mood-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mood-grid button.on { background: var(--accent); color: #1a1208; }

/* Turn panel */
#tabs button.attention { color: var(--accent); font-weight: 700; }
#tabs button.attention::after { content: ' ●'; color: var(--good); }
.turn-order { display: flex; flex-wrap: wrap; gap: 4px; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.chip.ok { border-color: var(--good); color: var(--good); }
.chip.used { opacity: .45; text-decoration: line-through; }
.movebar { height: 8px; background: #120f0c; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.movebar div { height: 100%; background: linear-gradient(90deg, #3f9a62, #5fd38a); transition: width .3s; }
.action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; }
.action-grid button { padding: 6px 4px; font-size: 12px; }
.weapon-row { display: flex; gap: 6px; align-items: center; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.end-turn { padding: 12px; font-size: 15px; }

/* Appearance editor */
.appearance { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.look-stage { width: 220px; display: flex; flex-direction: column; gap: 6px; }
.look-preview { width: 220px; height: 260px; border-radius: 10px; background: radial-gradient(circle at 50% 40%, #3a3028, #14110f); border: 1px solid var(--line); }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.swatch-btn { width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 2px solid transparent; }
.swatch-btn.on { border-color: var(--accent); box-shadow: 0 0 0 2px #000 inset; }
.swatches input[type=color] { width: 30px; height: 26px; padding: 0 2px; }
.reaction-prompt { position: fixed; z-index: 60; left: 50%; top: 70px; transform: translateX(-50%); background: var(--panel); border: 2px solid var(--accent); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.6); max-width: calc(100vw - 24px); animation: toastIn .2s ease-out; }

.zone-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.zone-grid button { text-align: left; font-size: 12px; display: flex; align-items: center; gap: 4px; }
.zone-grid button.on, .seg button.on { background: var(--accent); color: #1a1208; }

/* Inventory, feats, level-up */
.inv-row { border-bottom: 1px solid var(--line, #333); padding: 6px 0; }
.inv-row:last-of-type { border-bottom: none; }
.inv-row .row { gap: 6px; flex-wrap: wrap; }
.coins { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.coins input { width: 100%; }
.seg.wrap { flex-wrap: wrap; }
.levelup .card { padding: 10px; }
.levelup details summary { cursor: pointer; font-weight: 600; }
.bad { color: var(--bad); }
details.small summary { cursor: pointer; }

/* Tutorial */
#helpBtn { font-weight: 700; width: 32px; }
.tut-spot { position: fixed; z-index: 900; border-radius: 10px; pointer-events: none; transition: all .25s ease;
  box-shadow: 0 0 0 3px var(--accent), 0 0 0 9999px rgba(0,0,0,.5); }
.tut-card { position: fixed; z-index: 901; width: min(360px, calc(100vw - 16px)); background: var(--panel); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 8px; transition: left .25s ease, top .25s ease; }
.tut-card p { line-height: 1.45; }
.tut-dots { display: flex; gap: 5px; }
.tut-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.tut-dots span.past { background: var(--muted); }
.tut-dots span.on { background: var(--accent); }
.tut-menu { position: fixed; z-index: 902; top: 56px; right: 12px; width: min(340px, calc(100vw - 24px)); max-height: calc(100vh - 80px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.tut-chapter { display: flex; align-items: center; gap: 10px; text-align: left; }
.tut-chapter .ico { font-size: 18px; }
.tut-chapter.done { opacity: .75; }
.tut-guide { margin-top: 8px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,.08); }
.tut-offer { position: fixed; z-index: 903; left: 16px; bottom: 16px; max-width: 300px; background: var(--panel); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
/* Account bar on the start screen, and the "My characters" screen. */
.acct-bar { gap: 6px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.chars-home { width: min(560px, 100%); max-height: 85vh; overflow: auto; }
