:root {
  color-scheme: dark;
  --gold: #d7bb86;
  --paper: #f1efeb;
  --muted: #d1cdc5;
  --line: #595650;
  --panel: #242528de;
  --provisional: #d7c1ed;
  font: 14px/1.43 "Segoe UI", system-ui, sans-serif;
  color: var(--paper);
  background: #141517;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; background: linear-gradient(125deg,#2c2c2d,#141517 59%,#101113) fixed; }
#rune-backdrop { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
header, main { position: relative; }
header {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center;
  gap: .75rem; padding: .7rem max(1rem,calc((100vw - 1070px)/2));
  min-height: 52px; background: #1c1d20e6; border-bottom: 1px solid var(--line);
}
header a { font: 23px Georgia, serif; color: var(--paper); text-decoration: none; }
main { max-width: 1102px; margin: auto; padding: 1.5rem 1rem 6rem; }
h1,h2,h3 { font-family: Georgia,serif; line-height: 1.15; margin: 0 0 .7rem; overflow-wrap: anywhere; }
h1,h2 { padding-bottom: .45rem; border-bottom: 1px solid #595650a6; }
h1 { font-size: 26px; }
h2 { font-size: 23px; }
h3 { font-size: 18px; }
p { margin: .5rem 0; }
nav,.actions,#account { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
nav { padding-block: .5rem 1rem; }
button,input,select,textarea { font: inherit; color: inherit; border-radius: 3px; }
button {
  min-height: 32px; padding: .35rem 1rem; cursor: pointer; color: var(--gold);
  border: 1px solid var(--line); background: transparent; font-weight: 600;
}
button:hover,button[aria-pressed=true] { background: #d7bb861c; border-color: var(--gold); }
button.primary { background: var(--gold); color: #141517; border-color: var(--gold); }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,22rem),1fr)); gap: .75rem; }
.panel,article {
  padding: 1rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 3px; margin-bottom: 1rem; min-width: 0;
}
article { margin-bottom: 0; }
label { display: grid; gap: .25rem; margin-bottom: .65rem; min-width: 0; }
label > span,.muted,small { color: var(--muted); font-size: .93em; font-style: italic; }
input,textarea,select {
  width: 100%; min-width: 0; min-height: 42px; padding: .55rem .75rem;
  background: var(--panel); border: 1px solid #b5b0a8;
}
input::placeholder,textarea::placeholder { font-style: italic; color: #dcd7ccbf; }
textarea { min-height: 7rem; resize: vertical; }
.details { min-height: 15rem; font-family: monospace; }
pre { font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
details { margin-block: .6rem; }
details summary { color: var(--gold); cursor: pointer; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 3px; }
details[open] > summary { background: #d7bb861c; margin-bottom: .75rem; }
dl { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.5fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
dt,dd { margin: 0; padding: .45rem .65rem; overflow-wrap: anywhere; }
dt { background: #37342f; }
dd { background: #222326; text-align: right; }
#message:not(:empty) { padding: .65rem .85rem; margin-bottom: 1rem; border: 1px solid var(--line); color: #ffb4a8; overflow-wrap: anywhere; }
.auth { max-width: 32rem; margin: clamp(1rem,9vh,6rem) auto; padding: clamp(1rem,4vw,1.75rem); }
.auth form { margin: 1.25rem 0 .75rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,11rem),1fr)); gap: .5rem .75rem; }
.home-toolbar { margin-bottom: 1rem; }
.home-heading { margin-bottom: 1rem; }
.character-list { display: grid; gap: .4rem; margin-bottom: 1.4rem; }
.character-card { display: flex; align-items: center; gap: .65rem; padding: .7rem .85rem; }
.character-card .identity { flex: 1; min-width: 0; }
.character-card h3 { font: 600 16px/1.3 "Segoe UI",system-ui,sans-serif; margin: 0; }
.character-card p { color: var(--muted); margin: .2rem 0 0; }
.portrait { width: 44px; height: 44px; object-fit: cover; border-radius: 50%; }
.stage-skill { margin-bottom: .45rem; background: linear-gradient(110deg,#d7bb861c,#d7bb8602 78%,#d7bb8610); }
.stage-skill h3 { font: 650 16px/1.25 "Segoe UI",system-ui,sans-serif; }
.stage-cost { color: var(--gold); font-weight: 650; }
.provisional { color: var(--provisional); }
.sheet-fields { margin-bottom: .7rem; }
@media (max-width: 550px) {
  header { position: static; }
  #account { justify-content: flex-end; }
  main { padding-top: 1rem; }
  .character-card { flex-wrap: wrap; }
  .character-card .actions { flex-basis: 100%; }
}
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--gold); }
dt button,dd button { min-height: 26px; padding: .1rem .4rem; }
dd button { margin-inline-start: .55rem; }
.sheet-dialog { border: 1px solid var(--line); border-radius: 3px; color: var(--paper); background: #232427; width: min(36rem,calc(100vw - 2rem)); padding: 1.2rem; }
.sheet-dialog::backdrop { background: #070708ab; }
.sheet-dialog h2 { text-align: center; }
.dialog-actions { display:flex; justify-content:flex-end; gap:.75rem; padding-top:1rem; margin-top:.75rem; border-top:1px solid var(--line); }
.dialog-status { color:#ffb6ad; }
.dialog-status:empty { display:none; }
.password-field { display:flex; gap:.35rem; align-items:center; }
.password-field input { min-width:0; flex:1; }
.photo-editor { display:grid; gap:.65rem; }
.photo-editor > button { justify-self:start; }
.photo-controls { display:flex; gap:.5rem; align-items:center; }
.photo-controls input { min-width:0; flex:1; accent-color:var(--gold); }
.photo-controls button { font-size:1.15rem; min-width:2.25rem; }
.journal-toolbar { justify-content:center; }
.dice-result { padding: .8rem; margin: .7rem 0; text-align: center; }
.dice-result output { display: block; font-size: 2.7rem; font-weight: 700; }
.dice-result.fumble { background: #793635; }
.dice-result.critical { background: #3b603c; }
.item-card { border-color: var(--gold); text-align: center; }
.item-card .actions { justify-content: center; margin-top: .45rem; }
.inventory-grid { grid-template-columns: repeat(auto-fit,minmax(min(100%,12rem),1fr)); margin-bottom: .8rem; }
.sheet-dialog { max-height: calc(100dvh - 2rem); overflow-y: auto; }
.reference-row { display:flex; gap:1rem; justify-content:space-between; align-items:center; margin-bottom:.35rem; }
.reference-row p { color:var(--muted); margin-bottom:0; }
.manual-frame { width:100%; height:62vh; min-height:220px; border:1px solid var(--line); background:white; }
.sheet-dialog:has(.manual-frame) { width:min(74rem,calc(100vw - 2rem)); }
a.button-link { display:inline-flex; align-items:center; min-height:32px; padding:.35rem 1rem; border:1px solid var(--line); border-radius:3px; color:var(--gold); text-decoration:none; font-weight:600; }
.power-row { display:grid; grid-template-columns:minmax(8rem,1fr) minmax(0,2fr) auto; gap:.65rem; align-items:center; padding:.45rem; border:1px solid var(--line); }
.power-slots { display:flex; flex-wrap:wrap; justify-content:flex-end; gap:.35rem .9rem; }
.power-group { display:inline-flex; gap:.22rem; }
.power-total { display:grid; justify-items:end; }
.power-total strong { color:var(--gold); font-size:1.2rem; }
table { width:100%; border-collapse:collapse; margin-block:.35rem .65rem; }
th,td { border:1px solid var(--line); padding:.25rem .45rem; text-align:center; }
th:first-child,td:first-child { text-align:left; }
th:last-child,td:last-child { text-align:right; }
.print-sheet { display:none; }
@page { size:A4; margin:9mm; }
@media print {
  html,body { background:white !important; color:#171717; }
  body > :not(.print-sheet) { display:none !important; }
  .print-sheet { display:block; width:100%; padding:0; margin:0; font:9pt/1.2 "Segoe UI",sans-serif; --line:#aaa; }
  .print-sheet h1 { font-size:17pt; margin-bottom:.2em; }
  .print-sheet h2 { font-size:11pt; margin:.5em 0 .3em; padding:0; }
  .print-sheet p { margin:.25em 0; }
  .print-sheet table { margin:0 0 .3em; }
  .print-sheet th,.print-sheet td { padding:1.1pt 3pt; }
  .print-sheet th { background:#eee; white-space:nowrap; }
  .print-sheet tr { break-inside:avoid; }
  .print-sheet thead { display:table-header-group; }
  .print-sheet td:first-child { white-space:nowrap; }
  .print-sheet .print-columns { display:grid; grid-template-columns:1.15fr 1fr; gap:4mm; }
  .print-sheet .print-next { break-before:page; }
  .print-sheet .print-portrait { width:11mm; height:11mm; border-radius:50%; object-fit:cover; float:left; margin-right:3mm; }
  .print-sheet.print-color { print-color-adjust:exact; -webkit-print-color-adjust:exact; }
  .print-color h2 { color:#743330; }
  .print-color th { background:#e9e0cf; }
}
.sheet-dialog:has(.manual-source) { width:min(72rem,calc(100vw - 2rem)); }
.pdf-viewport { background:#131416; border:1px solid var(--line); max-height:61vh; min-height:12rem; overflow:auto; overscroll-behavior:contain; padding:9px; }
.pdf-page { position:relative; width:max-content; margin-inline:auto; cursor:grab; line-height:0; }
.pdf-page.placing { cursor:crosshair; }
.pdf-page canvas { background:#fff; }
.pdf-guide { position:absolute; pointer-events:none; z-index:1; }
.pdf-guide.horizontal { inset-inline:0; border-top:2px dashed #e12724; }
.pdf-guide.vertical { inset-block:0; border-left:2px dashed #e12724; }
.pdf-controls { margin:.55rem 0; }
.pdf-controls input[type=range] { width:min(15rem,35vw); min-height:0; padding:0; accent-color:var(--gold); }
.manual-source input[type=number] { width:5.5rem; min-height:32px; }
.item-card { position:relative; overflow:hidden; isolation:isolate; }
.object-photo { position:absolute; inset:0; overflow:hidden; pointer-events:none; z-index:-1; opacity:.48; }
.object-photo img { position:absolute; display:block; max-width:none; }
.object-photo.framing { position:relative; width:100%; aspect-ratio:1.7; opacity:1; z-index:auto; pointer-events:auto; cursor:grab; touch-action:none; border:1px solid var(--line); }
.object-photo.framing:active { cursor:grabbing; }
.object-photo.framing::before,.object-photo.framing::after { content:''; position:absolute; z-index:1; pointer-events:none; }
.object-photo.framing::before { top:50%; inset-inline:0; border-top:1px dashed #d7bb86; }
.object-photo.framing::after { left:50%; inset-block:0; border-left:1px dashed #d7bb86; }
.pdf-page.dragging { cursor:grabbing; }
.manual-source pre { white-space:pre-wrap; max-height:22rem; overflow:auto; }
.pdf-excerpt { padding:.65rem .8rem; margin-bottom:.65rem; border-inline-start:2px solid var(--gold); background:#d7bb8610; }
.pdf-excerpt h3 { margin-bottom:.25rem; }
/* Table surfaces and selected section headers match the desktop theme. */
:root {
  --table-heading: #d7bb8633;
  --table-cell: #2425289e;
  --section-active: #d7bb8626;
}
main { max-width:864px; }
.character-list { gap:.3rem; }
.character-card { min-height:64px; padding:.45rem .75rem; }
.character-card .identity p:empty { display:none; }
.home-toolbar { margin-top:.35rem; }
h1,h2 { letter-spacing:0; border-color:#595650; }
details[open] > summary { background:var(--section-active); color:var(--paper); font-weight:650; }
dl { background:transparent; gap:0; grid-template-columns:1.2fr 1fr; }
dt,dd { border-bottom:1px solid var(--line); }
dt { background:var(--table-heading); border-inline-end:1px solid var(--line); font-weight:650; }
dd { background:var(--table-cell); }
dt:nth-last-child(2),dd:last-child { border-bottom:0; }
th { background:var(--table-heading); font-weight:700; }
td { background:var(--table-cell); }
.panel .reference-row { border-radius:0; background:linear-gradient(100deg,#d7bb8613,transparent 82%,#d7bb8609); }
nav { gap:.35rem; }
@media print {
  .print-sheet { max-width:none; }
  .print-sheet td { background:white; }
}

/* Desktop character list and sheet surfaces. */
main:has(.character-list),main:has(.sheet-layout) { max-width:none; }
.character-card { padding:0 .45rem 0 0; gap:0; background:#242528de; min-height:62px; }
.character-open { display:flex; flex:1; align-items:center; gap:1rem; min-height:60px; min-width:0; padding:.5rem 1rem; border:0; text-align:left; color:var(--paper); font-weight:400; }
.character-open .identity { display:grid; gap:.12rem; overflow-wrap:anywhere; }
.character-open strong { font-size:16px; font-weight:500; }
.character-open .identity > span { color:var(--muted); font-size:14px; }
.character-actions { display:flex; flex:0 0 auto; align-items:center; }
.icon-button { display:grid; place-items:center; width:40px; height:40px; padding:8px; border:0; border-radius:50%; color:var(--muted); }
.icon-button svg { width:22px; height:22px; fill:currentColor; }
.icon-button:hover { background:#d7bb861c; color:var(--gold); }
.new-character { position:fixed; bottom:18px; right:20px; z-index:2; }
.new-character button { min-height:50px; padding-inline:1rem; }
.sheet-appbar { display:flex; align-items:center; gap:.7rem; min-height:48px; background:#1c1d20e6; border-bottom:1px solid var(--line); }
.sheet-appbar strong { font:23px Georgia,serif; }
.sheet-layout { max-width:880px; margin-inline:auto; }
.sheet-layout.illustrated { display:grid; grid-template-columns:minmax(0,880px) minmax(190px,320px); gap:24px; max-width:1224px; justify-content:center; }
.sheet-page { min-width:0; }
.sheet-artwork { position:sticky; top:calc(50vh - min(31vh,310px)); align-self:start; margin:12px 0; border:1px solid var(--line); border-radius:3px; overflow:hidden; background:#242528de; }
.sheet-artwork img { display:block; width:100%; max-height:min(62vh,620px); object-fit:contain; }
.sheet-tabs { flex-wrap:nowrap; gap:0; overflow:auto; padding:0; border-bottom:1px solid var(--line); scrollbar-width:thin; }
.sheet-tabs button { flex:none; min-height:48px; padding-inline:1rem; border:0; border-bottom:3px solid transparent; border-radius:0; color:var(--muted); background:transparent; }
.sheet-tabs button[aria-pressed=true] { color:var(--gold); border-bottom-color:var(--gold); }
.sheet-content { padding:24px; }
.sheet-heading { display:flex; align-items:flex-start; gap:12px; margin-bottom:.65rem; }
.sheet-heading-content { flex:1; min-width:0; }
.sheet-portrait { width:64px; height:64px; }
.sheet-heading details { margin:0; }
.sheet-heading details summary { padding:.3rem .65rem; }
.wide-action button { width:100%; }
.desktop-table-wrap { overflow:auto; margin-bottom:1rem; }
.desktop-table { margin:0; font-size:14px; }
.desktop-table th,.desktop-table td { height:36px; padding:.35rem .5rem; }
.desktop-table td button,.desktop-table th button { border:0; padding:0; min-height:20px; }
.desktop-table td:first-child button { color:var(--paper); font-weight:400; text-align:left; }
.desktop-table td:last-child button { color:var(--gold); font-weight:700; }
.desktop-identity { min-width:590px; }
.desktop-identity th,.desktop-identity td { height:58px; }
.desktop-skill,.trait-row { display:flex; justify-content:space-between; align-items:center; gap:.6rem; padding:.42rem .85rem; margin-bottom:2px; }
.desktop-skill { border:1px solid color-mix(in srgb,var(--skill-color) 48%,transparent); background:linear-gradient(90deg,color-mix(in srgb,var(--skill-color) 29%,transparent),color-mix(in srgb,var(--skill-color) 14%,transparent) 48%,transparent 82%,color-mix(in srgb,var(--skill-color) 16%,transparent)); }
.desktop-skill button { border:0; padding:0; min-height:30px; font-size:18px; font-weight:400; text-align:left; }
.desktop-skill button:first-child { color:var(--paper); }
.desktop-skill.trained button { font-weight:700; }
.trait-group { --trait-color:#366eb3; margin-bottom:.5rem; }
.trait-group.flaws { --trait-color:#b44442; }
.trait-group h3 { padding:.55rem .65rem; font:700 17px/1.3 "Segoe UI",sans-serif; margin:0 0 2px; background:color-mix(in srgb,var(--trait-color) 64%,transparent); }
.trait-row { border:1px solid color-mix(in srgb,var(--trait-color) 48%,transparent); background:linear-gradient(90deg,color-mix(in srgb,var(--trait-color) 35%,transparent),transparent 82%,color-mix(in srgb,var(--trait-color) 16%,transparent)); }
.trait-row p { margin:0; font-size:.92em; font-style:italic; color:var(--muted); }
@media(max-width:900px) {
  .sheet-layout.illustrated { display:block; }
  .sheet-artwork { position:static; max-width:18rem; margin-inline:auto; }
}
@media(max-width:550px) {
  .sheet-content { padding:14px 0; }
  .character-card { flex-wrap:nowrap; }
  .icon-button { width:36px; height:36px; }
}
body:has(.sheet-layout)>header { display:none; }
main:has(.sheet-layout) { padding:0 0 4rem; }
.sheet-appbar { position:sticky; top:0; z-index:2; padding-inline:.5rem; }
.sheet-layout { padding-inline:12px; }
.sheet-tabs { position:sticky; top:48px; z-index:1; background:#1c1d20e6; }
.desktop-identity { table-layout:fixed; }
.desktop-identity th,.desktop-identity td { overflow-wrap:anywhere; }
.desktop-identity th { width:14%; }
.desktop-identity td { width:11%; }
/* The signed-in home and campaign share the same page and dialog surfaces. */
body:has(.home-toolbar) > header { padding-inline: 1rem; }
.campaign-list { display:grid; gap:.3rem; margin-bottom:1.4rem; }
.campaign-list:empty { display:none; }
.campaign-card { position:relative; isolation:isolate; min-height:4.5rem; display:flex; align-items:center; justify-content:space-between; }
.campaign-open { border:0; padding:0; font:600 1.15rem Georgia,serif; color:var(--paper); text-align:left; }
.campaign-card .object-photo { opacity:.36; }
.campaign-tabs { flex-wrap:nowrap; overflow-x:auto; gap:.25rem; padding:0; margin:0 0 1rem; border-bottom:1px solid var(--line); }
.campaign-tabs button { border:0; border-bottom:2px solid transparent; border-radius:0; color:var(--muted); white-space:nowrap; padding:.7rem .85rem; }
.campaign-tabs button[aria-selected=true],.campaign-tabs button[aria-current=page] { color:var(--gold); border-bottom-color:var(--gold); }
.campaign-character { display:grid; gap:.25rem; margin-bottom:.4rem; }
.campaign-character > button { justify-self:end; }
.campaign-character > p { color:var(--muted); margin:.1rem 0; }
.inactive-character { opacity:.56; filter:grayscale(.75); }
.sheet-dialog:has(.account-panel) { width:min(70rem,calc(100vw - 2rem)); }
.object-photo.portrait-framing { aspect-ratio:1; max-width:16rem; border-radius:50%; margin-inline:auto; }
.campaign-entry .object-photo,.timeline-card .object-photo { position:relative; aspect-ratio:1.8; z-index:auto; opacity:1; }
.campaign-timeline { max-width:74rem; margin:1rem auto; position:relative; }
.campaign-timeline::before { content:''; position:absolute; top:0; bottom:0; left:50%; border-left:1px solid var(--gold); }
.timeline-row { position:relative; display:grid; grid-template-columns:1fr 3.5rem 1fr; margin:0 0 1rem; align-items:start; }
.timeline-marker { grid-column:2; grid-row:1; justify-self:center; position:relative; isolation:isolate; overflow:hidden; width:2.5rem; height:2.5rem; border:1px solid var(--gold); border-radius:50%; background:var(--panel); }
.timeline-marker .object-photo { z-index:auto; opacity:1; }
.timeline-handle { cursor:grab; touch-action:none; }
.timeline-row.dragging { opacity:.55; }
.timeline-row.drop-target .timeline-card { border-color:var(--gold); }
.timeline-drag-preview { position:fixed; z-index:100; margin:0; pointer-events:none; transform:scale(1.025); box-shadow:0 10px 28px #0009; border-color:var(--gold); }
.timeline-card { grid-column:1; grid-row:1; background:var(--panel); }
.timeline-row:nth-child(even) .timeline-card { grid-column:3; }
.timeline-card time,.chat-text time,.chat-roll time { color:var(--muted); font-size:.85rem; }
.timeline-card p,.campaign-entry p,.chat-text p,.chat-roll p { white-space:pre-wrap; overflow-wrap:anywhere; }
.campaign-chat { display:grid; grid-template-columns:minmax(15rem,1fr) minmax(18rem,1.4fr); gap:1rem; }
.campaign-chat-log { overflow:auto; height:clamp(15rem,49vh,42rem); padding:.5rem; border:1px solid var(--line); border-radius:3px; display:flex; flex-direction:column; gap:.45rem; }
.campaign-chat-log article { padding:.55rem .75rem; }
.campaign-chat-log article time { float:right; margin-left:.5rem; }
.chat-roll { border-left:3px solid var(--gold); }
.chat-character { display:flex; gap:.6rem; align-items:center; margin-bottom:.35rem; padding:.6rem; }
.chat-character button { margin-left:auto; }
.chat-actions { margin-top:1rem; }
.chat-actions progress { accent-color:#a93649; width:100%; max-width:14rem; }
.campaign-chat-room form { display:flex; align-items:end; gap:.5rem; margin-top:.6rem; }
.campaign-chat-room form label { flex:1; margin:0; }
@media (max-width:650px) {
  .campaign-chat { grid-template-columns:1fr; }
  .campaign-timeline::before { left:1.35rem; }
  .timeline-row { grid-template-columns:2.75rem minmax(0,1fr); }
  .timeline-marker { grid-column:1; width:2rem; height:2rem; }
  .timeline-row .timeline-card,.timeline-row:nth-child(even) .timeline-card { grid-column:2; }
}

.campaign-inventory-group { min-height:4rem; margin-block:.75rem; }
.campaign-inventory-group article[draggable=true] { cursor:grab; }
.chat-character button { margin-left:0; }
