/* Torchlit: a warm, dark tavern UI. Plain CSS, system fonts only. */

/* ---------- 1. Tokens ---------- */
:root {
  --bg: #16130f;
  --bg-2: #1e1a15;
  --panel: #231e18;
  --panel-2: #2b251e;
  --line: #3a3229;
  --text: #efe6d6;
  --muted: #a79a86;
  --accent: #f2a33a;
  --accent-ink: #1b1309;
  --danger: #d9534f;
  --ok: #4caf6a;
  --gm: #9b6ad6;
  --radius: 8px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .55);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font);
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.2; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: .95rem; margin-top: 1em; }
p { margin: 0 0 .7em; }
a { color: var(--accent); }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
::selection { background: rgba(242, 163, 58, .35); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, kbd { font-family: var(--mono); font-size: .9em; }
code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
code.secret { display: inline-block; font-size: 1.2rem; padding: 8px 12px; color: var(--accent); user-select: all; letter-spacing: .04em; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0; padding: 8px 12px 12px; min-width: 0; }
legend { padding: 0 6px; color: var(--muted); font-size: .85rem; }
.boot { min-height: 100dvh; display: grid; place-items: center; color: var(--muted); font: italic 1.1rem var(--serif); padding: 16px; text-align: center; }
body.in-game { overflow: hidden; height: 100dvh; }
html:has(body.in-game) { overflow: hidden; }

/* ---------- 3. Utilities ---------- */
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
.pad { padding: 10px 14px; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.ico { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ico svg { display: block; }

/* ---------- 4. Forms & buttons ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=email], input:not([type]), select, textarea {
  width: 100%; min-width: 0;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px;
}
textarea { resize: vertical; min-height: 2.6em; }
input::placeholder, textarea::placeholder { color: #75695a; }
input:hover, select:hover, textarea:hover { border-color: #51463a; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(242, 163, 58, .28); }
input:disabled, select:disabled, textarea:disabled { opacity: 1; color: var(--muted); background: transparent; border-color: transparent; cursor: default; -webkit-text-fill-color: var(--muted); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex: none; }
input[type=range] { width: 100%; accent-color: var(--accent); padding: 0; }
input[type=color] { width: 34px; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); cursor: pointer; flex: none; }
input[type=file] { max-width: 100%; }
select { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
option { background: var(--panel); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: .85rem; color: var(--muted); }
.field > small { color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.mini { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.mini input[type=range] { width: 90px; }
.mini input[type=number], .mini input[type=text] { width: 70px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 14px; font-weight: 500; line-height: 1.2;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: #352d24; border-color: #51463a; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #ffb44f; border-color: #ffb44f; }
.btn-danger { background: transparent; color: #ff8a85; border-color: rgba(217, 83, 79, .6); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); border-color: transparent; }
.btn-sm { padding: 4px 9px; font-size: .85rem; }
.btn-block { display: flex; width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 34px; height: 34px; padding: 0;
  background: transparent; border: 0; border-radius: 6px;
  color: var(--muted); text-decoration: none; cursor: pointer;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }
.linklike:hover { color: #ffc274; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: .85rem; cursor: pointer; text-transform: capitalize; }
.chip:hover { border-color: #51463a; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.tag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.tag-ok { color: var(--ok); border-color: rgba(76, 175, 106, .5); background: rgba(76, 175, 106, .12); }
.tag-bad { color: #ff8a85; border-color: rgba(217, 83, 79, .5); background: rgba(217, 83, 79, .12); }
.tag-gm { color: #c9a6f2; border-color: rgba(155, 106, 214, .55); background: rgba(155, 106, 214, .15); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card > * { margin: 0; }
.card .btn { align-self: flex-start; }
.form-error { color: #ff8a85; margin: 0; min-height: 0; }
.form-error:empty { display: none; }
.notice { background: rgba(242, 163, 58, .1); border: 1px solid rgba(242, 163, 58, .4); border-radius: var(--radius); padding: 8px 12px; font-size: .9rem; }

/* ---------- 5. Site pages ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; }
.site-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); margin-bottom: 24px; flex-wrap: wrap; }
.site-head nav { display: flex; gap: 4px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font: 600 1.4rem var(--serif); }
.brand img { width: 28px; height: 28px; }
.dash { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 32px; align-items: start; }
.dash-side { display: flex; flex-direction: column; gap: 16px; }
.camp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.camp-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; transition: border-color .15s, transform .15s; }
.camp-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.camp-link { display: block; padding: 14px 16px 6px; color: inherit; text-decoration: none; flex: 1; }
.camp-link h3 { font-size: 1.15rem; }
.camp-link p { margin: 0 0 4px; }
.camp-actions { display: flex; gap: 8px; justify-content: space-between; padding: 10px 16px 14px; }
.empty { grid-column: 1 / -1; border: 1px dashed var(--line); border-radius: var(--radius); padding: 32px 16px; text-align: center; }
.empty p:first-child { font: 1.2rem var(--serif); }

.auth-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(ellipse at 50% 0%, rgba(242, 163, 58, .12), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.auth-card > p { margin: 0; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand img { width: 40px; height: 40px; }
.auth-brand h1 { margin: 0; font-size: 2rem; }
.auth-card .linklike { align-self: center; }

.admin { padding-bottom: 24px; }
.admin section { margin-bottom: 28px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat-v { font: 600 1.6rem var(--serif); color: var(--accent); }
.stat-k { font-size: .8rem; color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: var(--bg-2); color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(255, 255, 255, .02); }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ---------- 6. Toasts ---------- */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; padding: 9px 14px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; transition: opacity .3s, transform .3s; }
.toast-info { border-left-color: var(--accent); }
.toast-error { border-left-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- 7. Modals ---------- */
.modal-back { position: fixed; inset: 0; z-index: 1000; background: rgba(8, 6, 4, .7); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(2px); }
form.modal { width: 100%; max-width: 440px; max-height: 90dvh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
form.modal.modal-wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-body > p:last-child { margin-bottom: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--bg-2); }

/* ---------- 8. Game shell ---------- */
.game { display: grid; grid-template-rows: 48px 1fr; width: 100%; height: 100dvh; background: var(--bg); position: relative; }
.game-head { display: flex; align-items: center; gap: 8px; padding: 0 8px; background: var(--bg-2); border-bottom: 1px solid var(--line); min-width: 0; }
.head-main { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.camp-title { font: 600 1.05rem var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; flex: none; }
.page-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { font-size: .78rem; white-space: nowrap; }
.conn-online { display: none; }
.conn-connecting, .conn-offline { padding: 2px 10px; border-radius: 999px; border: 1px solid rgba(242, 163, 58, .5); background: rgba(242, 163, 58, .12); color: var(--accent); }
.conn-offline { border-color: rgba(217, 83, 79, .6); background: rgba(217, 83, 79, .15); color: #ff8a85; }
.side-toggle { display: none; }

.page-tabs { display: flex; align-items: center; gap: 4px; overflow-x: auto; min-width: 0; flex: 1; scrollbar-width: thin; padding: 4px 0; }
.page-tab { display: inline-flex; align-items: center; flex: none; border: 1px solid transparent; border-radius: 6px; }
.page-tab:hover { background: var(--panel-2); }
.page-tab.active { background: var(--panel-2); border-color: var(--line); box-shadow: inset 0 -2px 0 var(--accent); }
.page-tab-name { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 5px 10px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.page-tab.active .page-tab-name { color: var(--text); }
.players-here { display: inline-flex; color: var(--accent); }
.page-tab-gear, .page-add { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: none; border: 0; border-radius: 6px; color: var(--muted); cursor: pointer; flex: none; }
.page-tab-gear:hover, .page-add:hover { background: var(--line); color: var(--text); }

.game-body { display: grid; grid-template-columns: 52px minmax(0, 1fr) 340px; min-height: 0; min-width: 0; }

/* Toolbar */
.toolbar { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; background: var(--bg-2); border-right: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.tool { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; background: transparent; border: 1px solid transparent; border-radius: 8px; color: var(--muted); cursor: pointer; flex: none; }
.tool:hover { background: var(--panel-2); color: var(--text); }
.tool.active { background: var(--accent); color: var(--accent-ink); }
.tool-sep { width: 28px; height: 1px; background: var(--line); margin: 6px 0; flex: none; }
.layer-pick { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100%; padding: 0 4px; }
.layer-label { font-size: .6rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.layer { width: 100%; padding: 4px 0; font-size: .64rem; line-height: 1.1; background: transparent; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); cursor: pointer; }
.layer:hover { color: var(--text); border-color: #51463a; }
.layer.active { color: var(--text); background: var(--panel-2); font-weight: 600; }
.layer-map.active { border-color: #5aa0c9; box-shadow: inset 0 -2px 0 #5aa0c9; }
.layer-objects.active { border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.layer-gm.active { border-color: var(--gm); box-shadow: inset 0 -2px 0 var(--gm); color: #d3b5f5; }

/* Board */
.board-wrap { position: relative; overflow: hidden; min-width: 0; min-height: 0; background: #0e0c09; }
canvas.board { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.tool-opts { position: absolute; top: 10px; left: 10px; right: 10px; width: fit-content; max-width: calc(100% - 20px); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 10px; background: rgba(35, 30, 24, .94); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.tool-opts:empty { display: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: var(--bg); border: 0; border-right: 1px solid var(--line); padding: 4px 10px; font-size: .85rem; color: var(--muted); cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.swatches { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .25); padding: 0; cursor: pointer; }
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.page-note { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: rgba(155, 106, 214, .9); color: #fff; border-radius: 999px; font-size: .85rem; box-shadow: var(--shadow); white-space: nowrap; max-width: calc(100% - 20px); }
.page-note:empty { display: none; }
.page-note .btn-primary { background: #fff; color: #3a2060; border-color: #fff; }
.sel-bar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; background: rgba(35, 30, 24, .95); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); white-space: nowrap; max-width: calc(100% - 20px); }
.zoom-ctl { position: absolute; bottom: 14px; left: 10px; display: flex; flex-direction: column; gap: 2px; padding: 3px; background: rgba(35, 30, 24, .92); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- 9. Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); border-left: 1px solid var(--line); }
.side-tabs { display: flex; flex: none; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.side-tab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 4px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font-size: .85rem; cursor: pointer; }
.side-tab:hover { color: var(--text); background: var(--panel-2); }
.side-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.side-chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.side-body { flex: 1; min-height: 0; overflow-y: auto; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 6px; }
.panel-head h3 { margin: 0; }

/* Chat */
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.chat-empty { text-align: center; margin-top: 16px; }
.quick-dice { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-top: 1px solid var(--line); color: var(--muted); flex: none; flex-wrap: wrap; }
.die-btn { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px; font: .78rem var(--mono); color: var(--text); cursor: pointer; }
.die-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-form { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 10px; border-top: 1px solid var(--line); background: var(--bg-2); flex: none; }
.chat-form textarea { resize: none; }
.chat-row { display: flex; gap: 6px; }
.chat-as { flex: 1; min-width: 0; }

.msg { line-height: 1.4; }
.msg-who { font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.msg-avatar { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.msg-meta { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 2px; }
.msg-meta .msg-who { font-size: .85rem; }
.msg-whisper { background: rgba(155, 106, 214, .12); border-left: 3px solid var(--gm); border-radius: 0 6px 6px 0; padding: 6px 10px; }
.msg-whisper .msg-meta { font-style: italic; color: #c9a6f2; }
.msg-emote { font-style: italic; color: #d8c9ae; overflow-wrap: anywhere; }
.msg-desc { text-align: center; font: italic 1rem/1.5 var(--serif); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; color: #e3d5b8; }
.msg-roll { padding: 0; }
.roll-card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.roll-label { font-weight: 600; margin-bottom: 4px; }
.roll-main { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.roll-detail { min-width: 0; flex: 1; }
.roll-formula { font: .78rem var(--mono); color: var(--muted); overflow-wrap: anywhere; }
.roll-break { font-size: .9rem; overflow-wrap: anywhere; }
.roll-dice { white-space: normal; }
.roll-op { color: var(--muted); margin: 0 3px; }
.die { font-family: var(--mono); }
.die.dropped { text-decoration: line-through; opacity: .45; }
.die.crit { color: var(--ok); font-weight: 700; }
.die.fumble { color: #ff6b66; font-weight: 700; }
.die.exploded { color: var(--accent); text-decoration: underline dotted; }
.roll-total { flex: none; min-width: 52px; text-align: center; font: 700 1.7rem/1 var(--serif); padding: 10px 8px; background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); }
.roll-total.crit { border-color: var(--ok); color: var(--ok); }
.roll-total.fumble { border-color: var(--danger); color: #ff6b66; }

/* Journal / party / art */
.journal-list, .member-list { list-style: none; margin: 0; padding: 0; }
.journal-list li { border-bottom: 1px solid var(--line); }
.journal-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 14px; background: none; border: 0; text-align: left; cursor: pointer; }
.journal-item:hover { background: var(--panel-2); }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; background: var(--bg); }
.avatar-blank { display: inline-flex; align-items: center; justify-content: center; font: 600 1rem var(--serif); color: var(--accent); border: 1px solid var(--line); }
.journal-name { display: flex; flex-direction: column; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.journal-name small { font-weight: 400; }
.member-list li { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #5b5246; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.swatch-dot { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.member-list .tag { margin-left: 0; }
.member-actions { display: flex; gap: 4px; width: 100%; justify-content: flex-end; }
.art-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; padding: 10px 14px; }
.art-grid > p { grid-column: 1 / -1; margin: 0; }
.art-item { margin: 0; padding: 0; display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: grab; color: inherit; }
.art-item:hover { border-color: var(--accent); }
.art-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--bg-2); }
.art-item figcaption { padding: 5px 6px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.art-name { font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-actions { display: flex; flex-wrap: wrap; gap: 3px; }
.art-actions .btn-sm { padding: 2px 6px; font-size: .72rem; }
.art-pick { padding: 0; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.art-pick .art-item { cursor: pointer; }

/* Context menu */
.ctx-menu { position: fixed; z-index: 900; min-width: 180px; max-height: calc(100dvh - 16px); overflow-y: auto; padding: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.ctx-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 5px; padding: 6px 10px; cursor: pointer; }
.ctx-menu button:hover, .ctx-menu button:focus-visible { background: var(--accent); color: var(--accent-ink); outline: none; }
.ctx-menu button.danger { color: #ff8a85; }
.ctx-menu button.danger:hover { background: var(--danger); color: #fff; }

/* ---------- 10. Floating windows ---------- */
.window { position: fixed; display: flex; flex-direction: column; max-height: calc(100dvh - 24px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.win-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 4px 4px 14px; background: var(--bg-2); border-bottom: 1px solid var(--line); cursor: move; user-select: none; touch-action: none; flex: none; }
.win-title { font: 600 .95rem var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win-head .icon-btn { cursor: pointer; }
.win-body { flex: 1; min-height: 0; overflow: auto; padding: 12px 14px; }

/* Character sheet */
.sheet { display: flex; flex-direction: column; gap: 14px; }
.sheet h4 { margin: 0; color: var(--muted); font: 600 .78rem var(--font); text-transform: uppercase; letter-spacing: .06em; }
.sheet-head { display: flex; gap: 14px; align-items: flex-start; }
.sheet-avatar { width: 84px; height: 84px; flex: none; padding: 0; overflow: hidden; background: var(--bg); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); font-size: .8rem; cursor: pointer; display: grid; place-items: center; }
.sheet-avatar:disabled { cursor: default; border-style: solid; }
.sheet-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet-ident { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.sheet-name { font: 600 1.4rem var(--serif); padding: 4px 8px; }
.stat-row-sheet { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-box { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1 1 70px; max-width: 100px; padding: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); }
.stat-box > span { font-size: .65rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.stat-box input { text-align: center; font-size: 1.1rem; font-weight: 600; padding: 3px 2px; background: transparent; border-color: transparent; }
.stat-box input:focus-visible { background: var(--bg-2); }
.stat-box .btn { width: 100%; }
.abil-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.abil { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.abil-name { font-size: .7rem; font-weight: 700; letter-spacing: .1em; color: var(--muted); }
.abil-mod { width: 100%; background: transparent; border: 0; color: var(--accent); font: 700 1.5rem var(--serif); cursor: pointer; border-radius: 6px; padding: 2px 0; }
.abil-mod:hover:not(:disabled) { background: var(--panel-2); }
.abil-mod:disabled { cursor: default; }
.abil-score { width: 52px; text-align: center; padding: 2px; }
.save-line { display: flex; align-items: center; gap: 4px; flex-direction: column; font-size: .75rem; }
.save-btn { font-size: .72rem; padding: 2px 6px; }
.attacks { display: flex; flex-direction: column; gap: 6px; }
.attack-row { display: grid; grid-template-columns: minmax(0, 1fr) 54px 84px auto auto auto; gap: 6px; align-items: center; }
.attack-row .narrow, .attack-row .mid { width: 100%; }
.sheet-texts { display: flex; flex-direction: column; gap: 10px; }
.sheet-gm { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: rgba(155, 106, 214, .1); border: 1px solid rgba(155, 106, 214, .45); border-radius: var(--radius); }
.sheet-gm h4 { color: #c9a6f2; }
.sheet-gm .btn-danger { align-self: flex-start; }

/* Initiative */
.init { display: flex; flex-direction: column; gap: 10px; }
.init-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.init-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.init-list li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
.init-list li.current { border-color: var(--accent); background: rgba(242, 163, 58, .14); box-shadow: inset 3px 0 0 var(--accent); }
.init-list li.hidden-entry { border-style: dashed; opacity: .6; }
.init-name { flex: 1; min-width: 0; background: none; border: 0; padding: 2px 4px; text-align: left; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.init-name:hover { color: var(--accent); }
.init-val { width: 54px; flex: none; text-align: center; font-weight: 700; }
input.init-val { padding: 3px 4px; }
.init-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* Token editor */
.token-editor { display: flex; flex-direction: column; gap: 14px; }
.tok-top { display: flex; gap: 14px; align-items: flex-start; }
.tok-preview { width: 96px; height: 96px; flex: none; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--line); overflow: hidden; display: grid; place-items: center; }
.tok-preview img { width: 100%; height: 100%; object-fit: contain; }
.tok-preview span { width: 80px; height: 80px; border-radius: 50%; display: grid; place-items: center; font: 700 2rem var(--serif); color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); text-transform: uppercase; border: 2px solid rgba(255, 255, 255, .3); }
.cond-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Help */
.help h3 { margin-top: 1em; }
.help h3:first-child { margin-top: 0; }
.help-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.help-table td { padding: 4px 8px 4px 0; vertical-align: top; border-bottom: 1px solid var(--line); }
.help-table td:first-child { width: 40%; }

/* ---------- 11. Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: #4a4034 transparent; }

/* ---------- 12. Responsive ---------- */
@media (max-width: 800px) {
  input[type=text], input[type=password], input[type=number], input[type=search], input:not([type]), select, textarea { font-size: 16px; }
  .dash { grid-template-columns: 1fr; gap: 24px; }
  .dash-side { order: -1; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .table { font-size: .85rem; }

  .game-body { grid-template-columns: 48px minmax(0, 1fr); }
  .toolbar { padding: 6px 0; }
  .tool { width: 36px; height: 36px; }
  .camp-title { max-width: 28vw; font-size: .95rem; }
  .side-toggle { display: inline-flex; }
  .sidebar { position: fixed; top: 48px; right: 0; bottom: 0; width: min(360px, 92vw); z-index: 40; transform: translateX(100%); transition: transform .2s ease; box-shadow: -8px 0 30px rgba(0, 0, 0, .5); }
  .game.side-open .sidebar { transform: none; }
  .tool-opts { right: auto; }
  .abil-grid { grid-template-columns: repeat(3, 1fr); }
  .attack-row { grid-template-columns: minmax(0, 1fr) 54px 74px; }
  .attack-row .btn, .attack-row .icon-btn { justify-self: start; }
  .sheet-head { flex-wrap: wrap; }
  .tok-top { flex-direction: column; }
}
@media (max-width: 480px) {
  .auth-card { padding: 22px 18px; }
  .modal-actions .btn { flex: 1; }
}

/* ---------- 13. Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
