/* Tabletop Management – styles. Dark by default, light theme via prefers-color-scheme or the Settings toggle. */

:root {
  --bg: #121018;
  --bg-2: #1a1722;
  --surface: #211d2b;
  --surface-2: #2a2536;
  --border: #3a3349;
  --text: #ece6f5;
  --muted: #a69cb8;
  --accent: #e0a23a;
  --primary: #8b5cf6;
  --primary-text: #ffffff;
  --ok: #3fb27f;
  --warn: #e0a23a;
  --danger: #e2574c;
  --secret: #b48cf2;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --map-bg: #14121a;
  --map-floor: #d9cba3;
  --map-room-grid: rgba(0,0,0,0.14);
  --map-floor-dim: #4e4840;
  --map-corridor: #bfae86;
  --map-corridor-dim: #403b33;
  --map-wall: #2a2433;
  --map-text: #1b1622;
  --map-text-dim: #a69cb8;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: Georgia, "Times New Roman", serif;
  --font-brand: Georgia, "Times New Roman", serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f0e6;
    --bg-2: #ede5d6;
    --surface: #fffdf8;
    --surface-2: #f3ecdf;
    --border: #ddd0bb;
    --text: #2a2233;
    --muted: #6f6479;
    --accent: #b8741a;
    --primary: #6d3fd6;
    --ok: #23865b;
    --warn: #b8741a;
    --danger: #c23d33;
    --secret: #7a4fc9;
    --shadow: 0 4px 18px rgba(60, 40, 20, 0.12);
    --map-bg: #3a3245;
    --map-floor-dim: #6e665c;
    --map-corridor-dim: #5e574c;
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg: #f5f0e6;
  --bg-2: #ede5d6;
  --surface: #fffdf8;
  --surface-2: #f3ecdf;
  --border: #ddd0bb;
  --text: #2a2233;
  --muted: #6f6479;
  --accent: #b8741a;
  --primary: #6d3fd6;
  --ok: #23865b;
  --warn: #b8741a;
  --danger: #c23d33;
  --secret: #7a4fc9;
  --shadow: 0 4px 18px rgba(60, 40, 20, 0.12);
  --map-bg: #3a3245;
  --map-floor-dim: #6e665c;
  --map-corridor-dim: #5e574c;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-body);
  min-height: 100vh;
}

h1, h2, h3, h4 { font-family: var(--font-head); margin: 0 0 0.4em; line-height: 1.25; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; margin-top: 0.6em; }
p { margin: 0.4em 0 0.6em; }
code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; font-size: 0.9em; }
small, .small { font-size: 0.82rem; }
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- Controls ---- */

input, select, textarea {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
input[type="checkbox"] { width: auto; accent-color: var(--primary); }
input.tiny { width: 90px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; color: var(--muted); }
label small { color: var(--muted); opacity: 0.8; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.inline { flex-direction: row; align-items: center; gap: 8px; white-space: nowrap; }
label.inline select { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
  transition: transform 0.05s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }
.icon-btn:hover { color: var(--text); }
.link-btn { background: none; border: none; padding: 0; color: var(--primary); cursor: pointer; font: inherit; display: inline; }

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.secret { color: var(--secret); border-color: color-mix(in srgb, var(--secret) 40%, transparent); }
.badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 0.75rem; font-weight: 700; }
.badge.warn { background: var(--warn); color: #1b1622; }

/* ---- Layout ---- */

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.four { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid .full { grid-column: 1 / -1; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-family: var(--font-brand); font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand .campaign-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand.big { font-size: 1.6rem; margin-bottom: 4px; }
.logo { color: var(--primary); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.whoami { font-weight: 600; white-space: nowrap; }
.whoami small { color: var(--muted); font-weight: 400; }
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 57px); }
.sidebar {
  position: sticky; top: 57px; align-self: start;
  display: flex; flex-direction: column; gap: 2px; padding: 12px 8px;
  height: calc(100vh - 57px); overflow-y: auto;
  border-right: 1px solid var(--border);
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border-radius: 8px; border: none; background: none;
  color: var(--muted); font: inherit; text-align: left; cursor: pointer;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-icon { width: 1.4em; text-align: center; }

.view { padding: 24px; max-width: 1200px; width: 100%; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.page-head h2 { margin-bottom: 2px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.group-title { margin-top: 8px; }

.empty { color: var(--muted); padding: 14px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; }
.banner { padding: 10px 14px; border-radius: 10px; background: color-mix(in srgb, var(--primary) 15%, var(--surface)); border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.banner.warn { background: color-mix(in srgb, var(--warn) 15%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.secret-note { background: color-mix(in srgb, var(--secret) 12%, var(--surface)); border-left: 3px solid var(--secret); padding: 8px 10px; border-radius: 6px; margin: 8px 0; font-size: 0.92rem; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.list.compact { gap: 6px; }
.party-line { display: grid; grid-template-columns: 1fr 140px; gap: 10px; align-items: center; }
.meta { display: flex; gap: 14px; color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; flex-wrap: wrap; }

details { margin-top: 6px; }
summary { cursor: pointer; color: var(--muted); font-weight: 600; }

/* ---- HP bars & stats ---- */

.hpbar { position: relative; height: 20px; background: var(--bg-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); min-width: 90px; }
.hpfill { height: 100%; transition: width 0.3s; }
.hpfill.good { background: var(--ok); }
.hpfill.mid { background: var(--warn); }
.hpfill.bad { background: var(--danger); }
.hpbar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.78rem; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); }

.stats { display: grid; grid-template-columns: 70px 70px 1fr; gap: 8px; margin: 8px 0; }
.stat { background: var(--bg-2); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.stat span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat strong { font-size: 1.2rem; }
.char.mine { border-color: color-mix(in srgb, var(--primary) 55%, var(--border)); }
.hp-quick { margin-bottom: 6px; }

.quest.status-completed { opacity: 0.75; }
.quest.status-failed { opacity: 0.6; }
.npc.attitude-hostile { border-left: 3px solid var(--danger); }
.npc.attitude-friendly { border-left: 3px solid var(--ok); }
.npc.attitude-wary { border-left: 3px solid var(--warn); }
.pill.att { text-transform: capitalize; }

/* ---- Messages ---- */

.chat { display: grid; grid-template-columns: 240px 1fr; gap: 14px; min-height: 420px; }
.chat-channels { display: flex; flex-direction: column; gap: 6px; }
.channel {
  display: grid; grid-template-columns: 1fr auto; align-items: center; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; color: var(--text); font: inherit; cursor: pointer;
}
.channel small { grid-column: 1; color: var(--muted); }
.channel .badge { grid-column: 2; grid-row: 1 / span 2; }
.channel.active { border-color: var(--primary); background: var(--surface-2); }
.chat-main { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; max-height: 60vh; min-height: 300px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); align-self: flex-start; }
.msg.out { align-self: flex-end; background: color-mix(in srgb, var(--primary) 22%, var(--surface)); }
.msg-meta { font-size: 0.78rem; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.msg-meta .link-btn { color: var(--muted); margin-left: 6px; }
.msg-body { white-space: normal; overflow-wrap: anywhere; }
.chat-compose { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); align-items: flex-end; }

/* ---- Tables ---- */

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions select { width: auto; padding: 4px 6px; }

/* ---- Initiative ---- */

.init-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.init-row { display: grid; grid-template-columns: 48px 1fr 160px auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--bg-2); border: 1px solid transparent; }
.init-row.current { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg-2)); }
.init-row.hidden-entry { opacity: 0.7; border-style: dashed; border-color: var(--secret); }
.init-row.down .init-name strong { text-decoration: line-through; color: var(--muted); }
.init-num { font-family: var(--font-head); font-size: 1.4rem; font-weight: 700; text-align: center; color: var(--accent); }
.init-actions { flex-wrap: nowrap; }

/* ---- Dice ---- */

.dice-quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 14px; }
.die {
  aspect-ratio: 1.4; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font: 700 1rem var(--font-head); cursor: pointer;
}
.die:hover { border-color: var(--accent); color: var(--accent); }
.roll { display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: center; }
.roll-total { font: 700 1.4rem var(--font-head); text-align: center; background: var(--bg-2); border-radius: 8px; padding: 4px 0; }
.roll.crit .roll-total { color: var(--ok); outline: 2px solid var(--ok); }
.roll.fumble .roll-total { color: var(--danger); outline: 2px solid var(--danger); }
.rolls { max-height: 520px; overflow-y: auto; }

/* ---- Dungeons ---- */

.chip { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 6px 14px; font: inherit; cursor: pointer; }
.chip.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 25%, var(--surface)); }
.dungeon-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; margin-top: 10px; }
.map-wrap { min-width: 0; }
canvas.map { width: 100%; height: auto; display: block; border-radius: 10px; border: 1px solid var(--border); cursor: pointer; background: var(--map-bg); }
.map-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.room-detail { background: var(--bg-2); border-radius: 10px; padding: 12px; }
.room-info { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }
.room-info li { display: grid; grid-template-columns: 24px 1fr; }
.room-key { list-style: none; padding: 0; margin: 0; max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.room-key li { display: flex; justify-content: space-between; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; }
.room-key li:hover { background: var(--surface-2); }
.room-key li.active { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); }
.room-key li.unrevealed { color: var(--muted); }
.room-key li.unrevealed strong::after { content: " 🔒"; font-size: 0.75em; }
.preview { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 16px; }

/* ---- Tools ---- */

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; font-size: 1.6rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; color: var(--text); cursor: pointer; }
.tool span { font-size: 0.9rem; font-weight: 600; }
.tool:hover { border-color: var(--accent); }
.toolbar input[type="search"] { max-width: 320px; }

/* ---- Start screen ---- */

.start { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 50%), radial-gradient(circle at 90% 90%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 45%); }
.start-card { max-width: 640px; width: 100%; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.tagline { color: var(--muted); margin-top: 0; }
.who-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.who { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer; }
.who small { color: var(--muted); }
.who.dm { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.who.active { border-color: var(--primary); outline: 2px solid var(--primary); }
.login-row input { max-width: 200px; }

/* ---- Toasts ---- */

#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--primary); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); transition: opacity 0.5s, transform 0.5s; }
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---- Quest board & NPC roster ---- */

.quick-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.quick-add > input:first-child { flex: 1 1 260px; }
.quick-add input[name="role"] { flex: 0 1 200px; }
.quick-add select { width: auto; }
.quick-add.small { margin-top: 6px; }
.quick-add.small input[name="text"] { flex: 1 1 200px; padding: 6px 8px; }
.toolbar { gap: 10px; }
.toolbar input[type="search"] { flex: 1 1 180px; max-width: 280px; }
.toolbar select { width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips .chip { padding: 4px 12px; font-size: 0.88rem; }

.master-detail { display: grid; grid-template-columns: minmax(240px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.item-list { padding: 6px; display: flex; flex-direction: column; gap: 2px; max-height: 70vh; overflow-y: auto; }
.item-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  padding: 9px 10px; border-radius: 8px; border: 1px solid transparent; background: none;
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.item-row:hover { background: var(--surface-2); }
.item-row.active { background: var(--surface-2); border-color: var(--primary); }
.item-row.status-completed .item-main strong, .item-row.dead .item-main strong { text-decoration: line-through; color: var(--muted); }
.item-main { display: flex; flex-direction: column; min-width: 0; }
.item-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-side { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.group-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 10px 10px 2px; }
.detail { position: sticky; top: 72px; min-width: 0; }
.actions-row { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }

.progress { display: inline-block; width: 54px; height: 6px; border-radius: 3px; background: var(--bg-2); overflow: hidden; vertical-align: middle; margin-right: 4px; border: 1px solid var(--border); }
.progress span { display: block; height: 100%; background: var(--ok); }
h4 .progress { margin-left: 8px; }

.objectives { list-style: none; padding: 0; margin: 4px 0; display: flex; flex-direction: column; gap: 4px; }
.objectives li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--bg-2); }
.objectives li.done .obj-text { text-decoration: line-through; color: var(--muted); }
.objectives li.secret { border: 1px dashed var(--secret); }
.objectives input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.obj-text { flex: 1; }
.obj-actions { display: flex; }
.obj-actions .icon-btn { font-size: 0.9rem; padding: 2px 6px; }
.check-mark { font-size: 1.1rem; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 8px; flex-wrap: wrap; }
.segmented button { background: var(--surface-2); color: var(--muted); border: none; border-right: 1px solid var(--border); padding: 5px 10px; font: inherit; font-size: 0.85rem; cursor: pointer; text-transform: capitalize; }
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--primary); color: var(--primary-text); }
.npc-picks { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.npc-picks legend { color: var(--muted); font-size: 0.88rem; padding: 0 4px; }
.npc.dead { opacity: 0.75; }

/* ---- Dungeon builder ---- */

.builder-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; }
.builder-bar form { flex: 1 1 240px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.builder-bar form .builder-name { flex: 1 1 200px; }
.builder-name { font-family: var(--font-head); font-size: 1.1rem; font-weight: 700; }
.builder-tools { margin: 0; }
.builder-tools button { padding: 8px 14px; font-size: 0.92rem; }
.builder-hint { margin: -6px 0 0; }
canvas.builder-canvas { touch-action: none; cursor: crosshair; }
canvas.builder-canvas.tool-select { cursor: pointer; }
canvas.builder-canvas.tool-erase { cursor: not-allowed; }
.builder-room h3 { margin: 0; }
.builder-room .grid.two { grid-template-columns: 1fr; }
.builder-help ol { padding-left: 18px; margin: 6px 0; }
.prop-palette { border-top: 1px solid var(--border); padding-top: 8px; max-height: 520px; overflow-y: auto; }
.prop-palette h4 { margin: 10px 0 6px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.prop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.prop-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--map-floor); color: var(--map-text); cursor: pointer; font: inherit; font-size: 0.72rem; line-height: 1.15; text-align: center; }
.prop-btn canvas { width: 34px; height: 34px; }
.prop-btn:hover { border-color: var(--accent); }
.prop-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.prop-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.room-info .prop-list li { display: block; padding: 0; border: 0; }
canvas.builder-canvas.tool-prop { cursor: copy; }
.btn[disabled] { opacity: 0.45; cursor: default; }

/* ---- Style picker ---- */

.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.style-card { border-radius: 10px; border: 2px solid var(--border); padding: 0; overflow: hidden; cursor: pointer; text-align: left; font: inherit; background: none; color: inherit; }
.style-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
.style-card .swatch { height: 64px; display: flex; align-items: flex-end; padding: 8px; font-size: 1.3rem; font-weight: 700; }
.style-card .style-name { display: block; padding: 6px 10px; background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 0.9rem; }
.swatch.classic { background: linear-gradient(135deg, #211d2b 50%, #8b5cf6 50%); color: #ece6f5; font-family: Georgia, serif; }
.swatch.fantasy { background: radial-gradient(circle at 30% 30%, #f6ead0, #d9c08e); color: #6b1f12; font-family: "Cinzel", Georgia, serif; }
.swatch.deep { background: radial-gradient(circle at 20% 0%, rgba(232, 134, 47, 0.45), transparent 55%), linear-gradient(160deg, #1d1f23, #0a0b0d); color: #cfe0f2; font-family: "Cinzel", Georgia, serif; text-shadow: 0 0 10px rgba(160, 200, 255, 0.8); letter-spacing: 0.2em; }
.swatch.scifi { background: linear-gradient(135deg, #04070d, #0b2a3a); color: #22e6ff; font-family: "Orbitron", sans-serif; text-shadow: 0 0 8px #22e6ff; }
.swatch.horror { background: radial-gradient(circle at 50% 120%, #5a0b10, #0a0606 70%); color: #d41f2a; font-family: "Creepster", cursive; letter-spacing: 0.05em; }

/* =========================================================================
   Styles. "classic" is the default palette above (with light/dark/auto).
   ========================================================================= */

/* ---- Fantasy: parchment, ink and gold leaf ---- */
html:root[data-style="fantasy"] {
  --bg: #e9dbb8;
  --bg-2: #f3e7c9;
  --surface: #f8eed6;
  --surface-2: #efe0bd;
  --border: #b99a63;
  --text: #2e1d10;
  --muted: #6e5537;
  --accent: #9a6b12;
  --primary: #7a2416;
  --primary-text: #fbefd5;
  --ok: #3f6b2a;
  --warn: #a2641a;
  --danger: #9e2a1c;
  --secret: #5b3a8c;
  --shadow: 0 2px 0 rgba(90, 60, 20, 0.15), 0 6px 18px rgba(70, 45, 15, 0.18);
  --radius: 6px;
  --map-bg: #2b1f14;
  --map-floor: #efdfb5;
  --map-room-grid: rgba(60,30,10,0.16);
  --map-floor-dim: #6f5d43;
  --map-corridor: #d6c193;
  --map-corridor-dim: #5b4a33;
  --map-wall: #120c07;
  --map-text: #5a1a10;
  --map-text-dim: #d6c193;
  --font-body: "Alegreya", Georgia, serif;
  --font-head: "Cinzel", Georgia, serif;
  --font-brand: "Cinzel Decorative", "Cinzel", Georgia, serif;
  color-scheme: light;
}
html:root[data-style="fantasy"] body {
  font-size: 16.5px;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(110, 70, 20, 0.28) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.3  0 0 0 0 0.1  0 0 0 0.09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    var(--bg);
  background-attachment: fixed;
}
html:root[data-style="fantasy"] .topbar { background: #3a2414; color: #f3e2b8; border-bottom: 3px double #b99a63; }
html:root[data-style="fantasy"] .topbar .whoami small, html:root[data-style="fantasy"] .topbar .icon-btn { color: #d8c08e; }
html:root[data-style="fantasy"] .topbar .logo { color: #d9a93a; }
html:root[data-style="fantasy"] .topbar .btn { background: transparent; color: #f3e2b8; border-color: #b99a63; }
html:root[data-style="fantasy"] .sidebar { background: rgba(58, 36, 20, 0.06); border-right: 3px double var(--border); }
html:root[data-style="fantasy"] .nav-item.active { background: var(--primary); color: var(--primary-text); }
html:root[data-style="fantasy"] .card { border: 1px solid var(--border); outline: 1px solid rgba(185, 154, 99, 0.45); outline-offset: -5px; }
html:root[data-style="fantasy"] .page-head h2 { font-size: 1.9rem; letter-spacing: 0.02em; }
html:root[data-style="fantasy"] .page-head h2::before { content: "❦ "; color: var(--accent); }
html:root[data-style="fantasy"] .page-head h2::after { content: " ❦"; color: var(--accent); }
html:root[data-style="fantasy"] .card-head h3 { color: var(--primary); }
html:root[data-style="fantasy"] .btn { border-radius: 4px; font-family: var(--font-head); font-weight: 700; letter-spacing: 0.02em; }
html:root[data-style="fantasy"] .btn.primary { background: linear-gradient(#8e2c1b, #6a1e12); border-color: #d9a93a; box-shadow: inset 0 1px 0 rgba(255, 220, 160, 0.3); }
html:root[data-style="fantasy"] .item-row.active { border-color: var(--accent); }
html:root[data-style="fantasy"] .hpbar span { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
html:root[data-style="fantasy"] .badge { background: var(--primary); }

/* ---- Dwarven Deep: torchlit stone halls, mithril and runes ---- */
html:root[data-style="deep"] {
  --bg: #0b0c0e;
  --bg-2: #141518;
  --surface: #17191c;
  --surface-2: #202327;
  --border: #393d43;
  --text: #ddd7ca;
  --muted: #8f8a80;
  --accent: #e8862f;
  --primary: #a8c3dc;
  --primary-text: #0b0c0e;
  --ok: #7fa36a;
  --warn: #e8862f;
  --danger: #c4483b;
  --secret: #8fb3e6;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --radius: 3px;
  --map-bg: #050506;
  --map-floor: #6a665e;
  --map-room-grid: rgba(0,0,0,0.32);
  --map-floor-dim: #26262a;
  --map-corridor: #4f4c46;
  --map-corridor-dim: #1c1c1f;
  --map-wall: #000000;
  --map-text: #e8f2ff;
  --map-text-dim: #5b5e66;
  --font-body: "Alegreya", Georgia, serif;
  --font-head: "Cinzel", Georgia, serif;
  --font-brand: "Cinzel", Georgia, serif;
  color-scheme: dark;
}
html:root[data-style="deep"] body {
  font-size: 16.5px;
  background:
    radial-gradient(ellipse 60% 45% at 8% 0%, rgba(232, 134, 47, 0.16), transparent 70%),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(232, 134, 47, 0.08), transparent 70%),
    radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.75) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.55' numOctaves='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.6  0 0 0 0 0.6  0 0 0 0 0.62  0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    var(--bg);
  background-attachment: fixed;
}
/* Ithildin: headings glow faintly like moonlit mithril. */
html:root[data-style="deep"] .page-head h2 { font-size: 1.85rem; letter-spacing: 0.12em; text-transform: uppercase; color: #dbe9f7; text-shadow: 0 0 14px rgba(150, 195, 255, 0.45); }
html:root[data-style="deep"] .page-head h2::before { content: "ᛞ "; color: var(--primary); opacity: 0.8; }
html:root[data-style="deep"] .page-head h2::after { content: " ᛞ"; color: var(--primary); opacity: 0.8; }
html:root[data-style="deep"] h3 { color: #e9d9b8; letter-spacing: 0.05em; }
html:root[data-style="deep"] .brand { letter-spacing: 0.14em; text-transform: uppercase; color: #dbe9f7; }
html:root[data-style="deep"] .logo { color: var(--accent); text-shadow: 0 0 10px rgba(232, 134, 47, 0.8); animation: torch 4s ease-in-out infinite; }
@keyframes torch { 0%, 100% { opacity: 1; } 40% { opacity: 0.8; } 55% { opacity: 0.95; } 70% { opacity: 0.75; } }
html:root[data-style="deep"] .topbar {
  background: linear-gradient(#17191c, #0d0e10);
  border-bottom: 1px solid #000;
  box-shadow: 0 1px 0 #3f444b, 0 6px 18px rgba(0, 0, 0, 0.6);
}
html:root[data-style="deep"] .sidebar { background: linear-gradient(90deg, rgba(0, 0, 0, 0.35), transparent); border-right: 1px solid #000; box-shadow: 1px 0 0 #2c2f34; }
html:root[data-style="deep"] .nav-item.active { background: linear-gradient(90deg, rgba(168, 195, 220, 0.16), transparent); color: #e6f0fa; box-shadow: inset 3px 0 0 var(--primary); text-shadow: 0 0 8px rgba(150, 195, 255, 0.5); }
/* Carved stone panels with a silver inlay along the top edge. */
html:root[data-style="deep"] .card {
  background: linear-gradient(180deg, #1c1e22, #141518);
  border: 1px solid #000;
  box-shadow: inset 0 0 0 1px #2e3136, inset 0 2px 0 rgba(168, 195, 220, 0.25), var(--shadow);
}
html:root[data-style="deep"] .btn { border-radius: 2px; font-family: var(--font-head); font-weight: 700; letter-spacing: 0.06em; background: linear-gradient(#2a2d32, #1b1d21); border-color: #000; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 1px 0 #2e3136; }
html:root[data-style="deep"] .btn:hover { border-color: var(--primary); }
html:root[data-style="deep"] .btn.primary { background: linear-gradient(#cfe0f0, #8fa9c2); color: #0b0c0e; border-color: #5c6f82; box-shadow: 0 0 12px rgba(150, 195, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6); }
html:root[data-style="deep"] input, html:root[data-style="deep"] select, html:root[data-style="deep"] textarea { background: #0e0f11; border-color: #000; box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8), 0 1px 0 #2a2d31; }
html:root[data-style="deep"] .chip.active, html:root[data-style="deep"] .item-row.active { border-color: var(--primary); box-shadow: 0 0 8px rgba(150, 195, 255, 0.25); }
html:root[data-style="deep"] .badge { background: var(--accent); color: #0b0c0e; }
html:root[data-style="deep"] .hpfill.good { background: linear-gradient(90deg, #4f6e43, #7fa36a); }
html:root[data-style="deep"] .init-num, html:root[data-style="deep"] .roll-total { color: var(--accent); text-shadow: 0 0 8px rgba(232, 134, 47, 0.5); }
@media (prefers-reduced-motion: reduce) { html:root[data-style="deep"] .logo { animation: none; } }

/* ---- Sci-fi: starship console ---- */
html:root[data-style="scifi"] {
  --bg: #03060c;
  --bg-2: #08121e;
  --surface: rgba(10, 24, 38, 0.86);
  --surface-2: #0e2233;
  --border: #1d4d66;
  --text: #d8f6ff;
  --muted: #6fa3b8;
  --accent: #ffb020;
  --primary: #12c8e8;
  --primary-text: #001018;
  --ok: #3cf0a0;
  --warn: #ffb020;
  --danger: #ff4d6d;
  --secret: #c77dff;
  --shadow: 0 0 0 1px rgba(18, 200, 232, 0.08), 0 0 22px rgba(18, 200, 232, 0.08);
  --radius: 2px;
  --map-bg: #020509;
  --map-floor: #0f5a70;
  --map-room-grid: rgba(18,200,232,0.28);
  --map-floor-dim: #0b2632;
  --map-corridor: #0c4658;
  --map-corridor-dim: #08202a;
  --map-wall: #12c8e8;
  --map-text: #e6fcff;
  --map-text-dim: #3f7d92;
  --font-body: "Exo 2", system-ui, sans-serif;
  --font-head: "Orbitron", "Exo 2", sans-serif;
  --font-brand: "Orbitron", sans-serif;
  color-scheme: dark;
}
html:root[data-style="scifi"] body {
  background:
    linear-gradient(rgba(18, 200, 232, 0.05) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, rgba(18, 200, 232, 0.05) 1px, transparent 1px) 0 0 / 32px 32px,
    radial-gradient(ellipse at top, #0a1f33, var(--bg) 70%);
  background-attachment: fixed;
}
html:root[data-style="scifi"] h2, html:root[data-style="scifi"] h3, html:root[data-style="scifi"] .brand, html:root[data-style="scifi"] .nav-item, html:root[data-style="scifi"] .btn, html:root[data-style="scifi"] .table th { text-transform: uppercase; letter-spacing: 0.08em; }
html:root[data-style="scifi"] h2 { color: var(--primary); text-shadow: 0 0 12px rgba(18, 200, 232, 0.55); font-size: 1.45rem; }
html:root[data-style="scifi"] h3 { font-size: 0.95rem; color: var(--primary); }
html:root[data-style="scifi"] .page-head h2::before { content: "// "; color: var(--accent); }
html:root[data-style="scifi"] .card { clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px)); border-color: var(--border); backdrop-filter: blur(4px); }
html:root[data-style="scifi"] .card::before { content: ""; }
html:root[data-style="scifi"] .btn { border-radius: 0; font-size: 0.8rem; background: transparent; border-color: var(--primary); color: var(--primary); }
html:root[data-style="scifi"] .btn:hover { background: rgba(18, 200, 232, 0.12); box-shadow: 0 0 10px rgba(18, 200, 232, 0.4); }
html:root[data-style="scifi"] .btn.primary { background: var(--primary); color: var(--primary-text); box-shadow: 0 0 14px rgba(18, 200, 232, 0.5); }
html:root[data-style="scifi"] .btn.danger { border-color: var(--danger); color: var(--danger); }
html:root[data-style="scifi"] .nav-item { font-size: 0.82rem; }
html:root[data-style="scifi"] .nav-item.active { background: rgba(18, 200, 232, 0.12); color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
html:root[data-style="scifi"] input, html:root[data-style="scifi"] select, html:root[data-style="scifi"] textarea { border-radius: 0; font-family: "Share Tech Mono", monospace; }
html:root[data-style="scifi"] .topbar { border-bottom-color: var(--primary); box-shadow: 0 0 18px rgba(18, 200, 232, 0.25); }
html:root[data-style="scifi"] .logo { color: var(--accent); text-shadow: 0 0 8px var(--accent); }
html:root[data-style="scifi"] .hpbar, html:root[data-style="scifi"] .progress, html:root[data-style="scifi"] .chip, html:root[data-style="scifi"] .pill { border-radius: 0; }
html:root[data-style="scifi"] .hpfill.good { background: linear-gradient(90deg, #0b8a6a, var(--ok)); box-shadow: 0 0 8px var(--ok); }
html:root[data-style="scifi"] .init-num, html:root[data-style="scifi"] .roll-total { color: var(--accent); text-shadow: 0 0 8px rgba(255, 176, 32, 0.6); font-family: "Share Tech Mono", monospace; }

/* ---- Horror: candlelight and dried blood ---- */
html:root[data-style="horror"] {
  --bg: #0a0707;
  --bg-2: #140d0c;
  --surface: #181010;
  --surface-2: #221615;
  --border: #3d2422;
  --text: #e6dccf;
  --muted: #9c8a7a;
  --accent: #c9a24a;
  --primary: #9b111e;
  --primary-text: #f3e6d8;
  --ok: #6f8f3a;
  --warn: #c9a24a;
  --danger: #d6303b;
  --secret: #8e7cc3;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.7), inset 0 0 40px rgba(80, 0, 0, 0.12);
  --radius: 4px;
  --map-bg: #050303;
  --map-floor: #8a7660;
  --map-room-grid: rgba(0,0,0,0.24);
  --map-floor-dim: #2e2420;
  --map-corridor: #5f4e40;
  --map-corridor-dim: #221a16;
  --map-wall: #000000;
  --map-text: #3a0508;
  --map-text-dim: #7a6656;
  --font-body: "EB Garamond", Georgia, serif;
  --font-head: "Special Elite", "Courier New", monospace;
  --font-brand: "Creepster", "Special Elite", cursive;
  color-scheme: dark;
}
html:root[data-style="horror"] body {
  font-size: 16.5px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(120, 10, 15, 0.22), transparent 60%),
    radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.85) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.4  0 0 0 0 0.35  0 0 0 0.07 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    var(--bg);
  background-attachment: fixed;
}
html:root[data-style="horror"] .brand { font-size: 1.5rem; color: var(--danger); letter-spacing: 0.04em; text-shadow: 0 0 10px rgba(214, 48, 59, 0.4); }
html:root[data-style="horror"] .page-head h2 { font-family: var(--font-brand); font-weight: 400; font-size: 2.3rem; color: var(--danger); letter-spacing: 0.05em; text-shadow: 0 2px 0 #000, 0 0 18px rgba(155, 17, 30, 0.6); }
html:root[data-style="horror"] h3 { color: #d8c3a5; }
html:root[data-style="horror"] .card { border-color: var(--border); background: linear-gradient(180deg, rgba(40, 20, 18, 0.95), rgba(20, 12, 11, 0.95)); }
html:root[data-style="horror"] .btn { border-radius: 2px; font-family: var(--font-head); font-weight: 400; }
html:root[data-style="horror"] .btn.primary { background: linear-gradient(#a3121f, #6b0a13); border-color: #4a0509; box-shadow: 0 0 12px rgba(155, 17, 30, 0.45); }
html:root[data-style="horror"] .nav-item.active { background: rgba(155, 17, 30, 0.25); color: #f3e6d8; box-shadow: inset 3px 0 0 var(--danger); }
html:root[data-style="horror"] .logo { color: var(--danger); animation: flicker 6s infinite; }
html:root[data-style="horror"] .hpfill.good { background: #556b2f; }
html:root[data-style="horror"] .hpfill.bad { background: #8b0000; }
@keyframes flicker { 0%, 92%, 100% { opacity: 1; } 93% { opacity: 0.3; } 95% { opacity: 0.9; } 96% { opacity: 0.2; } }
@media (prefers-reduced-motion: reduce) { html:root[data-style="horror"] .logo { animation: none; } }

/* ---- Responsive ---- */

@media (max-width: 900px) {
  .dungeon-layout { grid-template-columns: 1fr; }
  .master-detail { grid-template-columns: 1fr; }
  .item-list { max-height: 260px; }
  .detail { position: static; }
  .chat { grid-template-columns: 1fr; }
  .chat-channels { flex-direction: row; overflow-x: auto; }
  .channel { min-width: 170px; }
  .init-row { grid-template-columns: 40px 1fr 110px; }
  .init-actions { grid-column: 1 / -1; flex-wrap: wrap; }
}

@media (max-width: 720px) {
  html:root[data-style] body { background-attachment: scroll; }
  .menu-btn { display: block; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    display: none; position: fixed; top: 57px; left: 0; right: 0; height: auto; max-height: calc(100vh - 57px);
    background: var(--bg); z-index: 9; border-bottom: 1px solid var(--border); border-right: none;
  }
  .sidebar.open { display: flex; }
  .view { padding: 16px; }
  .whoami small, .top-right .pill { display: none; }
  .grid.two, .grid.cards { grid-template-columns: 1fr; }
  .party-line { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
  .table th:nth-child(3), .table td:nth-child(3) { display: none; }
  .dice-quick { grid-template-columns: repeat(5, 1fr); }
}
