:root {
  --bg: #f4f1ea; --panel: #fffdf8; --ink: #23201b; --muted: #6e675c; --line: #d9d2c4;
  --accent: #b5462b; --accent-ink: #fff; --rock: #3a3631; --floor: #efe6d2; --corr: #e6dcc4;
  --wall: #1e1b17; --door: #8a5a2b; --secret: #7a3fb0; --water: #4f86b8; --stair: #b5462b;
  --frontier: #e3a21a; --grid: rgba(0,0,0,.07); --sel: #2f7dd1; --good: #2e9d5b; --bad: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181614; --panel: #221f1c; --ink: #ece6da; --muted: #a39b8d; --line: #3a3530;
    --accent: #e0694a; --rock: #0f0e0d; --floor: #c9bea6; --corr: #b8ac92; --wall: #050404;
    --door: #a8743d; --secret: #b07ae0; --water: #6aa3d6; --grid: rgba(0,0,0,.12); --stair: #c2412a;
  }
}
:root[data-theme="dark"] {
  --bg: #181614; --panel: #221f1c; --ink: #ece6da; --muted: #a39b8d; --line: #3a3530;
  --accent: #e0694a; --rock: #0f0e0d; --floor: #c9bea6; --corr: #b8ac92; --wall: #050404;
  --door: #a8743d; --secret: #b07ae0; --water: #6aa3d6; --grid: rgba(0,0,0,.12); --stair: #c2412a;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.hot { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.small { padding: 1px 8px; font-size: 12.5px; }
button:disabled { opacity: .45; cursor: default; }
input, select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px; }
label { display: inline-flex; gap: 6px; align-items: center; }
.muted { color: var(--muted); }
.err { color: var(--bad); }
.row { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }

/* lobby */
.lobby { max-width: 760px; margin: 0 auto; padding: 32px 16px; }
.lobby h1 { letter-spacing: .08em; margin: 0 0 4px; font-size: 30px; }
.lobby .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 24px; }
.lobby .card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.lobby .card h2 { margin: 0 0 10px; font-size: 18px; }
.lobby form { display: grid; gap: 10px; }
.lobby form label { display: grid; gap: 3px; }
.lobby ul { padding-left: 18px; }

/* table */
.bar { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.bar h1 { font-size: 16px; margin: 0; }
.bar .code { font-family: ui-monospace, Consolas, monospace; letter-spacing: .12em; font-weight: 700; }
.wrap { display: grid; grid-template-columns: minmax(0, 1fr) 380px; height: calc(100vh - 47px); min-height: 480px; }
.mapPane { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.mapTools { display: flex; gap: 6px; align-items: center; padding: 6px 10px; flex-wrap: wrap; }
#mapScroll { flex: 1; overflow: auto; background: var(--rock); touch-action: none; position: relative; }
#map { display: block; cursor: pointer; }
#mapScroll.panning, #mapScroll.panning #map { cursor: grabbing; }
#mapScroll.placing #map { cursor: copy; }
.empty { color: #d8cfbf; padding: 40px; text-align: center; }
.side { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; padding: 9px 4px; background: transparent; border-bottom: 2px solid transparent; }
.tabs button.on { border-bottom-color: var(--accent); font-weight: 600; }
.tab { display: none; padding: 12px 14px; overflow: auto; flex: 1; min-height: 0; }
.tab.on { display: block; }
.tab h3 { font-size: 12px; margin: 16px 0 6px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.tab h3:first-child { margin-top: 0; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.card h4 { margin: 0 0 4px; font-size: 15px; }
.card p { margin: 3px 0; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.member { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.member .on { color: var(--good); font-size: 12px; }
.member .off { color: var(--muted); font-size: 12px; }
.tok { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.barline { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.barline b { font-variant-numeric: tabular-nums; min-width: 4.5em; display: inline-block; }

/* dice */
.dicebox input[type=text] { width: 9em; }
.quick { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.log { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.entry { border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.entry .who { font-weight: 600; }
.entry .total { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 6px; }
.entry .total.miss { color: var(--bad); }
.entry .total.crit { color: var(--good); }
.entry .note { color: var(--muted); font-style: italic; }
.dd { display: inline-block; min-width: 1.6em; text-align: center; border: 1px solid var(--line); border-radius: 4px; margin: 1px; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.dd.drop { opacity: .4; text-decoration: line-through; }
.dd.prim { border-color: var(--accent); font-weight: 700; }
.dd.boom { border-color: var(--good); color: var(--good); font-weight: 700; }
.priv { font-size: 11px; border: 1px solid var(--secret); color: var(--secret); border-radius: 8px; padding: 0 5px; margin-left: 4px; }
.toast { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 6px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%; }
.toast.show { opacity: .95; }
.tab.sheetTab { padding: 0; overflow: hidden; display: none; }
.tab.sheetTab.on { display: flex; flex-direction: column; }
.tab.sheetTab iframe { flex: 1; width: 100%; border: 0; background: #eef1f4; }
.card.key { border-color: var(--secret); }
.card.key h4 { color: var(--secret); }
.code.big { font-size: 26px; text-align: center; margin: 6px 0; }
.note { color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.entry.note.warn { color: var(--bad); font-style: normal; }
.dd small { font-size: 9px; color: var(--muted); margin-left: 2px; }
#mapScroll.painting #map { cursor: cell; }
.entry.say .text { font-size: 14px; }
.turn { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; }
.turn.cur { background: var(--accent); color: var(--accent-ink); }
.turn .nm { flex: 1; }
.turn button { padding: 0 6px; }
.card.campaign img, .card.fb img { max-width: 100%; border-radius: 6px; display: block; margin: 6px 0; }
.card.campaign .text, .card.fb .text { white-space: pre-wrap; }
.handout img { max-width: 100%; border-radius: 6px; display: block; margin-top: 6px; cursor: zoom-in; }
.handout .text { white-space: pre-wrap; }
.barline input[type=number] { width: 4.2em; padding: 1px 4px; }
textarea { width: 100%; min-height: 120px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px; font: inherit; }
.hint { margin: 6px 12px 8px; color: var(--muted); font-size: 12.5px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal[hidden] { display: none; }
.modal .box { background: var(--panel); color: var(--ink); border-radius: 12px; max-width: 640px; max-height: 90vh; overflow: auto; padding: 18px 22px; border: 1px solid var(--line); }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 14px 0 4px; }
.modal ul { margin: 0; padding-left: 18px; }
.modal li { margin: 4px 0; }
#drawBtn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#mapScroll.drawing #map { cursor: crosshair; }
.filebtn { display: inline-block; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; background: var(--panel); }
.filebtn:hover { border-color: var(--accent); }
.filebtn input { display: none; }
.filebtn.small { padding: 1px 8px; font-size: 12.5px; }
.tabFull { display: none; }
@media (max-width: 860px) {
  .wrap { grid-template-columns: 1fr; height: auto; }
  #mapScroll { height: 62vh; flex: none; }
  .side { border-left: 0; border-top: 1px solid var(--line); min-height: 60vh; }
  .tabFull { display: block; flex: 0 0 auto; border: 0; border-radius: 0; padding: 9px 10px; background: transparent; font-size: 16px; }
  /* Phone: the panel can take the whole screen (building a hero, reading a handout). */
  body.panelFull .mapPane, body.panelFull .hint { display: none; }
  body.panelFull .side { min-height: calc(100vh - 47px); height: calc(100vh - 47px); }
  body.panelFull .tab.sheetTab.on { height: calc(100vh - 90px); }
}
