/* ============ Themes ============ */
:root, [data-theme="parchment"] {
  --bg: #e9dcc0; --bg2: #dfcfad; --panel: #f6ecd6; --panel2: #efe2c4; --ink: #2b2118; --muted: #6f5d48;
  --line: #b9a37d; --line2: #d4c19c; --accent: #8a2c1d; --accent-ink: #fff7ea; --accent2: #3f5d3a;
  --ok: #3f6d35; --bad: #a3261a; --warn: #9a6a12; --input: #fbf4e4; --focus: #8a2c1d55;
  --head: 'Cinzel', Georgia, serif; --body: 'Crimson Pro', Georgia, serif; --base: 17px;
  --radius: 6px; --shadow: 0 1px 0 #fff8 inset, 0 2px 8px #4a361f22; --glow: none;
  --bgimg: radial-gradient(ellipse at 20% 0%, #f3e8cf 0, transparent 60%), radial-gradient(ellipse at 100% 100%, #d8c49b 0, transparent 55%);
  color-scheme: light;
}
[data-theme="light"] {
  --bg: #f4f5f7; --bg2: #eceef2; --panel: #ffffff; --panel2: #f7f8fa; --ink: #1c2230; --muted: #687083;
  --line: #d9dde5; --line2: #e8ebf0; --accent: #4f46e5; --accent-ink: #fff; --accent2: #0f766e;
  --ok: #15803d; --bad: #c2341d; --warn: #b45309; --input: #fff; --focus: #4f46e544;
  --head: 'Inter', system-ui, sans-serif; --body: 'Inter', system-ui, sans-serif; --base: 15px;
  --radius: 10px; --shadow: 0 1px 2px #1c223010, 0 4px 14px #1c22300a; --glow: none; --bgimg: none;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #14161b; --bg2: #1b1e25; --panel: #1f232b; --panel2: #262a33; --ink: #e6e8ee; --muted: #9097a6;
  --line: #343a46; --line2: #2b303a; --accent: #e0a145; --accent-ink: #1b1305; --accent2: #6fb39a;
  --ok: #5fb878; --bad: #ef6b5a; --warn: #e3a447; --input: #171a20; --focus: #e0a14544;
  --head: 'Inter', system-ui, sans-serif; --body: 'Inter', system-ui, sans-serif; --base: 15px;
  --radius: 10px; --shadow: 0 2px 10px #0006; --glow: none; --bgimg: none;
  color-scheme: dark;
}
[data-theme="future"] {
  --bg: #05070f; --bg2: #0a0f1f; --panel: #0b1226cc; --panel2: #0f1a36; --ink: #d9f6ff; --muted: #6f93a8;
  --line: #1e3a5c; --line2: #142847; --accent: #19e3ff; --accent-ink: #001218; --accent2: #ff3ec8;
  --ok: #3dffa8; --bad: #ff4d6d; --warn: #ffc43d; --input: #050b1a; --focus: #19e3ff55;
  --head: 'Orbitron', 'Rajdhani', sans-serif; --body: 'Rajdhani', system-ui, sans-serif; --base: 16.5px;
  --radius: 2px; --shadow: 0 0 0 1px #19e3ff22, 0 0 24px #19e3ff12 inset; --glow: 0 0 10px #19e3ff88;
  --bgimg: linear-gradient(#19e3ff08 1px, transparent 1px), linear-gradient(90deg, #19e3ff08 1px, transparent 1px), radial-gradient(ellipse at 50% -20%, #19e3ff22, transparent 60%), radial-gradient(ellipse at 100% 120%, #ff3ec822, transparent 50%);
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { font-size: var(--base); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); background-image: var(--bgimg); background-size: auto, auto, auto, auto;
  color: var(--ink); font-family: var(--body); line-height: 1.45; }
[data-theme="future"] body { background-size: 32px 32px, 32px 32px, auto, auto; background-attachment: fixed; }
h1, h2, h3, h4, h5 { font-family: var(--head); line-height: 1.2; margin: 0 0 .5rem; font-weight: 700; letter-spacing: .01em; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
h4 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .4rem; }
[data-theme="future"] h1, [data-theme="future"] h2 { color: var(--accent); text-shadow: var(--glow); text-transform: uppercase; letter-spacing: .06em; }
[data-theme="future"] h1 { font-size: 1.6rem; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--panel2); padding: .05em .35em; border-radius: 4px; }
p { margin: .3rem 0 .7rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .bad { color: var(--bad); } .warn { color: var(--warn); }
.neg { color: var(--bad); } .pos { color: var(--ok); }
[hidden] { display: none !important; }

input, textarea, select { font: inherit; color: var(--ink); background: var(--input); border: 1px solid var(--line); border-radius: calc(var(--radius) * .7);
  padding: .4rem .55rem; width: 100%; min-width: 0; }
textarea { resize: vertical; line-height: 1.4; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }
input[type=range] { padding: 0; }
label { display: block; font-size: .9rem; }
label > input, label > select, label > textarea { margin-top: .2rem; }
.lbl { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: block; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

.btn { font: inherit; font-weight: 600; font-size: .92rem; border: 1px solid var(--line); background: var(--panel2); color: var(--ink);
  border-radius: var(--radius); padding: .45rem .85rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
[data-theme="future"] .btn.primary { box-shadow: var(--glow); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); } .btn.danger:hover { border-color: var(--bad); }
.btn.primary.danger, .modal .btn.danger:not(.ghost) { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ok { color: var(--ok); }
.btn.small { padding: .28rem .6rem; font-size: .82rem; } .btn.tiny { padding: .12rem .45rem; font-size: .78rem; }
.btn:disabled { opacity: .5; cursor: default; }
[data-theme="future"] .btn { text-transform: uppercase; letter-spacing: .06em; font-size: .82rem; }

.row { display: flex; gap: .5rem; align-items: center; } .row.wrap { flex-wrap: wrap; } .row.tight { gap: .25rem; }
.row.between { justify-content: space-between; } .row.end { justify-content: flex-end; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .7rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.w3 { width: 3.5rem; } .w5 { width: 5rem; } .w12 { width: 12rem; }

/* ============ Shell ============ */
.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem 1.2rem; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 85%, transparent); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; text-decoration: none; color: var(--ink); font-family: var(--head); font-weight: 700; font-size: 1.1rem; }
[data-theme="future"] .brand { color: var(--accent); text-shadow: var(--glow); text-transform: uppercase; font-size: .95rem; letter-spacing: .1em; }
.mark { font-size: 1.4rem; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { text-decoration: none; color: var(--muted); padding: .35rem .7rem; border-radius: var(--radius); font-weight: 600; }
.nav a:hover { color: var(--ink); background: var(--panel2); }
.nav a.on { color: var(--accent); background: var(--panel2); }
.nav a.me { border: 1px solid var(--line); }
.page { max-width: 1240px; margin: 0 auto; padding: 1.4rem 1.2rem 4rem; }
.page.narrow { max-width: 640px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
[data-theme="future"] .panel { backdrop-filter: blur(8px); position: relative; }
[data-theme="future"] .panel::before { content: ''; position: absolute; top: -1px; left: -1px; width: 14px; height: 14px; border-top: 2px solid var(--accent); border-left: 2px solid var(--accent); }
[data-theme="future"] .panel::after { content: ''; position: absolute; bottom: -1px; right: -1px; width: 14px; height: 14px; border-bottom: 2px solid var(--accent2); border-right: 2px solid var(--accent2); }
.hero { margin: .5rem 0 1.2rem; }
.empty { color: var(--muted); font-style: italic; } .empty-big { text-align: center; padding: 2.5rem; }
.notice { background: var(--panel2); border-left: 3px solid var(--accent); padding: .5rem .8rem; border-radius: 4px; }
.badge { font-size: .75rem; padding: .1rem .45rem; border-radius: 99px; border: 1px solid var(--line); background: var(--panel2); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); } .badge.ai { color: var(--accent2); border-color: var(--accent2); }

.list { list-style: none; padding: 0; margin: 0; }
.li { display: flex; align-items: center; gap: .7rem; padding: .55rem .4rem; border-bottom: 1px solid var(--line2); color: inherit; text-decoration: none; }
a.li:hover { background: var(--panel2); }
.li strong, .li .small { display: block; }
.avatar { width: 2.4rem; height: 2.4rem; border-radius: 50%; object-fit: cover; flex: none; border: 2px solid var(--line); display: inline-grid; place-items: center; background: var(--panel2); font-family: var(--head); font-weight: 700; color: var(--muted); }
.avatar.lg { width: 4.2rem; height: 4.2rem; font-size: 1.5rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.card { display: flex; flex-direction: column; margin: 0; }
.card-main { display: flex; gap: .9rem; color: inherit; text-decoration: none; flex: 1; }
.card-main h3 { margin: .2rem 0; } .card-actions { margin-top: .6rem; }
.tbl { width: 100%; border-collapse: collapse; } .tbl th, .tbl td { text-align: left; padding: .35rem .45rem; border-bottom: 1px solid var(--line2); vertical-align: top; }
.tbl th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tbl td.end { text-align: right; white-space: nowrap; } .tbl tr.private td { opacity: .75; }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin: 0 0 1rem; overflow-x: auto; }
.tab { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 3px solid transparent; padding: .55rem .9rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
[data-theme="future"] .tab { text-transform: uppercase; letter-spacing: .08em; font-size: .85rem; } [data-theme="future"] .tab.on { text-shadow: var(--glow); }
.tabs.small .tab { padding: .4rem .7rem; }

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; max-width: min(380px, calc(100vw - 2rem)); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: .65rem .85rem; border-radius: var(--radius); box-shadow: 0 6px 24px #0003; transition: opacity .4s, transform .4s; }
.toast.bad { border-left-color: var(--bad); } .toast.roll { border-left-color: var(--accent2); font-size: 1.02rem; }
.toast.out { opacity: 0; transform: translateY(8px); }
.modal-bg { position: fixed; inset: 0; background: #0008; display: grid; place-items: center; z-index: 90; padding: 1rem; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; width: min(460px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px #0006; }
.modal.wide { width: min(760px, 100%); } .modal .row.end { margin-top: 1rem; }
.big-code code { font-size: 1.5rem; padding: .3rem .6rem; }

/* auth */
.auth { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 1rem; }
.auth-card { width: min(420px, 100%); text-align: center; padding: 2rem 1.6rem; }
.auth-card form { text-align: left; } .auth-mark { font-size: 3rem; } .auth .tabs { justify-content: center; }

/* account themes */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; }
.theme-pick { font: inherit; color: var(--ink); background: var(--panel2); border: 2px solid var(--line); border-radius: var(--radius); padding: .6rem; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: .2rem; }
.theme-pick.on { border-color: var(--accent); }
.swatch { display: block; height: 78px; border-radius: 6px; background: var(--bg); background-image: var(--bgimg); padding: 10px; margin-bottom: .3rem; border: 1px solid var(--line); }
[data-theme="future"].swatch { background-size: 12px 12px, 12px 12px, auto, auto; }
.sw-panel { display: block; height: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; position: relative; }
.sw-head { font-family: var(--head); color: var(--accent); font-weight: 700; font-size: 14px; display: block; text-shadow: var(--glow); }
.sw-line { display: block; height: 5px; width: 70%; background: var(--line); border-radius: 3px; margin-top: 5px; } .sw-line.short { width: 40%; }
.sw-btn { position: absolute; right: 6px; bottom: 6px; width: 26px; height: 12px; border-radius: var(--radius); background: var(--accent); box-shadow: var(--glow); }

/* switch / segmented / pips / chips */
.switch { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; font-weight: 600; font-size: .9rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { width: 2.3rem; height: 1.3rem; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: calc(1.3rem - 4px); height: calc(1.3rem - 4px); border-radius: 50%; background: var(--panel); transition: transform .2s; }
.switch input:checked + span { background: var(--accent); } .switch input:checked + span::after { transform: translateX(1rem); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { font: inherit; font-size: .82rem; font-weight: 600; background: none; border: 0; padding: .28rem .6rem; color: var(--muted); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); } .seg button.on { background: var(--accent); color: var(--accent-ink); }
.pip { width: .95rem; height: .95rem; border-radius: 50%; border: 2px solid var(--muted); background: transparent; padding: 0; cursor: pointer; flex: none; }
.pip.on { background: var(--accent); border-color: var(--accent); box-shadow: var(--glow); }
.pip.exp { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: .2rem; padding: .1rem .5rem; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); font-size: .82rem; }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0 0 .1rem; }
.chips select { width: auto; font-size: .82rem; padding: .1rem .3rem; }
.chk { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 0 .3rem; }
.x:hover { color: var(--bad); }

/* ============ Character sheet ============ */
.sheet .box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .65rem .75rem; margin-bottom: .75rem; box-shadow: var(--shadow); }
.sheet .box.inline { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.sheet-head { display: grid; grid-template-columns: auto minmax(200px, 1fr) 2fr; gap: 1rem; align-items: center; }
.portrait { width: 92px; height: 92px; border-radius: 50%; border: 3px solid var(--accent); padding: 0; overflow: hidden; background: var(--panel2); cursor: pointer; color: var(--muted); font: inherit; font-size: .8rem; line-height: 1.2; box-shadow: var(--glow); }
.portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.char-name { font-family: var(--head); font-size: 1.6rem; font-weight: 700; border: 0; border-bottom: 2px solid var(--line); border-radius: 0; background: transparent; padding: .2rem 0; }
[data-theme="future"] .char-name { color: var(--accent); text-shadow: var(--glow); text-transform: uppercase; }
.head-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .45rem .7rem; }
.head-grid label span, .story-grid label span { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.head-grid input { padding: .25rem .4rem; }
.sheet-bar { display: flex; justify-content: space-between; gap: .6rem 1rem; flex-wrap: wrap; align-items: center; margin: .2rem 0 .6rem; }
.roll-to { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; } .roll-to select { width: auto; padding: .2rem .4rem; }
.save-status { font-size: .8rem; color: var(--muted); min-width: 5.5rem; text-align: right; } .save-status.bad { color: var(--bad); font-weight: 600; } .save-status.ok { color: var(--ok); }

.core-grid { display: grid; grid-template-columns: minmax(300px, 1.05fr) minmax(320px, 1.25fr) minmax(240px, 1fr); gap: .9rem; align-items: start; }
.col-a { display: grid; grid-template-columns: 108px 1fr; gap: .7rem; align-items: start; }
.col-a > .box:last-child { grid-column: 1 / -1; }
.abils { display: flex; flex-direction: column; gap: .55rem; }
.abil { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .35rem .3rem .45rem; text-align: center; box-shadow: var(--shadow); }
.abil-name { font: inherit; font-family: var(--head); font-size: .6rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; background: none; border: 0; color: var(--ink); cursor: pointer; padding: 0; }
.abil-name:hover { color: var(--accent); }
.abil-mod { font-size: 1.7rem; font-weight: 700; text-align: center; border: 0; background: transparent; padding: 0; font-family: var(--head); }
.abil-score { width: 3.2rem; margin: 0 auto; display: block; text-align: center; border-radius: 99px; padding: .1rem; font-weight: 600; }
.pr { display: flex; align-items: center; gap: .4rem; padding: .08rem 0; }
.mini { width: 2.8rem; text-align: center; padding: .1rem .2rem; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; font-weight: 700; }
.mid { width: 4.5rem; text-align: center; font-weight: 700; font-size: 1.1rem; }
.rl { font: inherit; font-size: .9rem; background: none; border: 0; color: var(--ink); cursor: pointer; padding: 0; text-align: left; }
.rl:hover { color: var(--accent); text-decoration: underline dotted; }
.rl .muted { font-size: .78rem; }
input.overridden { color: var(--accent2); font-style: italic; }
.ovr::placeholder { color: var(--muted); opacity: .6; }
.combat { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-bottom: .75rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .35rem; text-align: center; box-shadow: var(--shadow); }
.stat > span:first-child { font-size: .62rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: block; }
.stat input { text-align: center; font-weight: 700; font-size: 1.15rem; border: 0; background: transparent; padding: .1rem; }
.stat.shield { clip-path: polygon(0 0, 100% 0, 100% 70%, 50% 100%, 0 70%); padding-bottom: .9rem; }
.with-roll { display: inline-flex; align-items: center; gap: .15rem; }
.die-btn { background: none; border: 0; cursor: pointer; font-size: 1rem; padding: 0 .15rem; filter: grayscale(.3); }
.die-btn:hover { filter: none; transform: scale(1.15); }
.hp-top { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: .6rem; text-align: center; }
.hp-top input { text-align: center; font-weight: 700; } .hp-top input.big { font-size: 1.8rem; padding: .2rem; font-family: var(--head); }
.hp-act { margin-top: .5rem; } .hp-act input { width: 5.5rem; }
.hpbar { height: 6px; background: var(--line2); border-radius: 3px; margin-top: .5rem; overflow: hidden; }
.hpbar span { display: block; height: 100%; background: var(--ok); transition: width .3s; box-shadow: var(--glow); }
.row2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: .7rem; }
.hd { width: 100%; border-collapse: collapse; font-size: .85rem; } .hd th { text-align: left; font-weight: 600; } .hd thead th { font-size: .65rem; color: var(--muted); text-transform: uppercase; }
.hd input { padding: .1rem .25rem; width: 3rem; text-align: center; }
.ds .pr { justify-content: space-between; } .ds .lbl { flex: 1; } .ds .btn { margin-top: .3rem; }
.atk { border-bottom: 1px solid var(--line2); padding: .4rem 0; }
.atk-main { display: grid; grid-template-columns: 1.4fr auto 1.6fr; gap: .4rem; align-items: center; }
.atk-more summary { font-size: .78rem; color: var(--muted); cursor: pointer; margin-top: .2rem; }
.atk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .4rem .6rem; margin: .4rem 0; font-size: .82rem; }
.atk-grid .span { grid-column: 1 / -1; } .atk-grid .chk { align-self: end; padding-bottom: .4rem; }
.box.tall textarea { min-height: 28rem; }
.coins { display: flex; gap: .5rem; flex-wrap: wrap; }
.coin b { font-size: 1.05rem; }

/* inventory */
.coin-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem; }
.coin-box { border: 1px solid var(--line); border-radius: var(--radius); padding: .45rem; text-align: center; background: var(--panel2); }
.coin-n { display: block; font-size: 1.45rem; font-family: var(--head); margin: .1rem 0 .3rem; }
.coin-box .row { justify-content: center; } .coin-amt { width: 3.6rem; padding: .15rem .3rem; text-align: center; }
.c-gp .coin-n { color: #b8860b; } .c-pp .coin-n { color: #8aa0b4; } .c-sp .coin-n { color: #8d9399; } .c-cp .coin-n { color: #b06a3b; } .c-ep .coin-n { color: #6f8f71; }
.add-item .row > * { flex: none; } .add-item .grow { flex: 1 1 200px; } .add-item select { width: auto; }
.inv-sum { margin: .2rem 0 .6rem; font-size: .88rem; }
.item { border-bottom: 1px solid var(--line2); padding: .45rem 0; }
.item.zero .item-name, .item.zero .qty-n { opacity: .5; }
.item-main { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.item-name { flex: 1 1 180px; font-weight: 600; border-color: transparent; background: transparent; }
.item-name:hover, .item-name:focus { border-color: var(--line); background: var(--input); }
.qty { display: inline-flex; align-items: center; gap: .3rem; }
.qty-n { min-width: 3.2rem; text-align: center; font-size: 1.25rem; font-family: var(--head); }
.amt { width: 4.2rem; padding: .15rem .35rem; text-align: center; }
.item details summary { cursor: pointer; margin-top: .15rem; }
.tbl.log { font-size: .8rem; margin-top: .3rem; }

/* spells */
.spell-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; align-items: end; }
.spell-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .75rem; align-items: start; }
.spell-grid .box { margin: 0; }
.lv-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; }
.lv-head label { margin-left: auto; display: flex; align-items: center; gap: .3rem; } .lv-head input { width: 3.2rem; text-align: center; padding: .1rem; }
.lv-n { width: 1.8rem; height: 1.8rem; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); border-radius: var(--radius); font-family: var(--head); font-weight: 700; box-shadow: var(--glow); }
.slots { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; margin-bottom: .4rem; }
.spells { list-style: none; padding: 0; margin: 0 0 .3rem; }
.spells li { display: flex; align-items: center; gap: .35rem; padding: .1rem 0; }
.spells input:not([type=checkbox]) { border: 0; border-bottom: 1px solid var(--line2); border-radius: 0; background: transparent; padding: .15rem .2rem; }
.add-spell { font-size: .88rem; padding: .25rem .4rem; border-style: dashed; }

/* story */
.story-grid { grid-template-columns: repeat(6, 1fr); }
.story-cols { display: grid; grid-template-columns: 1fr 1.3fr; gap: .9rem; }
.symbol { width: 100%; aspect-ratio: 1; max-width: 240px; display: grid; place-items: center; border: 2px dashed var(--line); background: var(--panel2); border-radius: var(--radius); cursor: pointer; font: inherit; color: var(--muted); overflow: hidden; padding: 0; }
.symbol img { width: 100%; height: 100%; object-fit: cover; }
.appearance { overflow: hidden; } .portrait-lg { float: left; width: 130px; height: 130px; border-radius: 50%; object-fit: cover; margin: 0 .8rem .4rem 0; border: 3px solid var(--accent); }
.custom { display: flex; gap: .4rem; margin-bottom: .35rem; align-items: center; }

.readonly .sheet-body input, .readonly .sheet-body textarea, .readonly .sheet-body select { background: transparent; }
.crop { width: 300px; height: 300px; margin: .5rem auto; border-radius: 8px; overflow: hidden; background: #000; touch-action: none; }
.crop.round { border-radius: 50%; box-shadow: 0 0 0 3px var(--accent); }
.crop canvas { display: block; cursor: grab; }

/* dice rendering */
.rollv { white-space: nowrap; }
.dice { display: inline-flex; gap: 2px; }
.die { display: inline-grid; place-items: center; min-width: 1.5em; height: 1.5em; padding: 0 .2em; border: 1px solid var(--line); border-radius: 4px; background: var(--panel2); font-size: .9em; }
.die.drop { opacity: .4; text-decoration: line-through; } .die.nat20 { border-color: var(--ok); color: var(--ok); font-weight: 700; } .die.nat1 { border-color: var(--bad); color: var(--bad); }
.total { font-size: 1.2em; color: var(--accent); } .total.crit { color: var(--ok); } .total.fumble { color: var(--bad); }
em.crit { color: var(--ok); font-weight: 700; font-style: normal; } em.fumble { color: var(--bad); font-weight: 700; font-style: normal; }

/* ============ Campaign ============ */
.camp-title h1 { margin-bottom: .1rem; } .camp-desc { color: var(--muted); max-width: 70ch; }
.joincode code { font-size: 1.05rem; letter-spacing: .12em; }
.camp-grid { display: grid; grid-template-columns: 290px 1fr; gap: 1rem; align-items: start; }
.party { position: sticky; top: 4.4rem; }
.pc { border: 1px solid var(--line); border-radius: var(--radius); padding: .55rem; margin-bottom: .55rem; background: var(--panel2); }
.pc.empty { opacity: .75; } .pc.down { border-color: var(--bad); } .pc.low .hpbar span { background: var(--bad); } .pc.mid .hpbar span { background: var(--warn); }
.pc-top { display: flex; align-items: center; gap: .55rem; color: inherit; text-decoration: none; }
.pc-top strong, .pc-top .small { display: block; }
.pc-stats { display: flex; justify-content: space-between; font-size: .88rem; margin-top: .4rem; } .tmp { color: var(--accent2); }
.pc-act { margin-top: .4rem; } .pc-amt { width: 3.8rem; padding: .1rem .3rem; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--line); display: inline-block; flex: none; } .dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.table { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
#log { height: min(62vh, 640px); overflow-y: auto; padding: .8rem 1rem; display: flex; flex-direction: column; gap: .55rem; }
.entry { border-radius: var(--radius); padding: .45rem .65rem; background: var(--panel2); border: 1px solid var(--line2); max-width: 100%; overflow-wrap: anywhere; }
.entry.k-ai { background: color-mix(in srgb, var(--accent2) 10%, var(--panel)); border-color: color-mix(in srgb, var(--accent2) 40%, var(--line)); }
.entry.k-ai .e-body { font-size: 1.04rem; line-height: 1.55; }
.entry.k-system { background: none; border: 0; padding: .1rem; text-align: center; } .sys { color: var(--muted); font-size: .85rem; font-style: italic; }
.entry.private { border-style: dashed; }
.e-head { display: flex; gap: .4rem; align-items: baseline; flex-wrap: wrap; } .e-time { margin-left: auto; }
.roll-label { font-weight: 600; }
.thinking { padding: .3rem 1rem; color: var(--accent2); font-size: .9rem; }
.dots i { animation: blink 1.2s infinite; font-style: normal; } .dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }
.composer { border-top: 1px solid var(--line); padding: .7rem; display: flex; flex-direction: column; gap: .5rem; background: var(--panel); }
.composer select { width: auto; padding: .25rem .4rem; }
.journal { border-bottom: 1px solid var(--line2); padding: .7rem 0; } .j-body { white-space: normal; }
.world-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.world-e { border-bottom: 1px solid var(--line2); padding: .45rem 0; } .world-e.private { opacity: .8; }
.meter { height: 10px; background: var(--line2); border-radius: 5px; overflow: hidden; margin: .4rem 0; }
.meter span { display: block; height: 100%; background: var(--ok); box-shadow: var(--glow); } .meter.warn span { background: var(--warn); } .meter.bad span { background: var(--bad); }
.admin h3 { margin-top: .6rem; }

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  .core-grid { grid-template-columns: 1fr 1fr; } .col-c { grid-column: 1 / -1; } .box.tall textarea { min-height: 14rem; }
}
@media (max-width: 820px) {
  .core-grid, .story-cols, .camp-grid { grid-template-columns: 1fr; }
  .sheet-head { grid-template-columns: auto 1fr; } .head-grid { grid-column: 1 / -1; }
  .party { position: static; } .story-grid { grid-template-columns: repeat(3, 1fr); }
  .coin-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 520px) {
  .page { padding: 1rem .7rem 3rem; } h1 { font-size: 1.5rem; }
  .col-a { grid-template-columns: 92px 1fr; } .combat { grid-template-columns: repeat(2, 1fr); }
  .row2 { grid-template-columns: 1fr; } .atk-main { grid-template-columns: 1fr auto; } .atk-main > :last-child { grid-column: 1 / -1; }
  .top { padding: .5rem .7rem; } .brand span:last-child { font-size: .95rem; }
  .coin-row { grid-template-columns: repeat(2, 1fr); }
}

/* ============ Print sheet ============ */
.print-wrap { padding: 1rem; }
.print-bar { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; max-width: 8.5in; margin: 0 auto 1rem; }
.sheet-print { --p-ink: #1a1a1a; --p-line: #444; --p-soft: #999; color: var(--p-ink); font-family: 'Crimson Pro', Georgia, serif; }
.p-page { width: 8.5in; min-height: 11in; margin: 0 auto 1rem; background: #fff; padding: .4in .4in .3in; box-shadow: 0 4px 20px #0003; display: flex; flex-direction: column; font-size: 10.5px; line-height: 1.3; position: relative; }
.p-page.skip { display: none; }
.p-page footer { margin-top: auto; text-align: center; color: #888; font-size: 8px; padding-top: 4px; }
.p-page h5 { font-family: 'Cinzel', serif; font-size: 8px; letter-spacing: .08em; text-transform: uppercase; margin: 0 0 4px; color: #333; text-align: center; }
.p-head { display: grid; grid-template-columns: 1fr 1.7fr; gap: 12px; margin-bottom: 10px; }
.p-name { border: 2px solid var(--p-line); border-radius: 8px; padding: 6px 10px; display: flex; flex-direction: column; justify-content: flex-end; }
.p-name span, .p-hgrid span { font-size: 7px; text-transform: uppercase; letter-spacing: .06em; color: #555; font-family: 'Cinzel', serif; }
.p-val { border-bottom: 1px solid var(--p-soft); min-height: 15px; font-size: 11px; }
.p-val.big { font-size: 18px; font-family: 'Cinzel', serif; min-height: 24px; }
.p-hgrid { border: 2px solid var(--p-line); border-radius: 8px; padding: 6px 10px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 12px; }
.p-hgrid.three { grid-template-columns: repeat(3, 1fr); text-align: center; } .p-hgrid.three .p-val { font-size: 16px; min-height: 22px; }
.p-cols3 { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 10px; flex: 1; }
.p-cols3.spells { grid-template-columns: repeat(3, 1fr); }
.p-cols2 { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; flex: 1; }
.p-c1 { display: grid; grid-template-columns: 68px 1fr; gap: 6px; align-content: start; } .p-c1 > .p-mini.wide, .p-c1 > .p-box { grid-column: 1 / -1; }
.p-abils { display: flex; flex-direction: column; gap: 6px; }
.p-abil { border: 2px solid var(--p-line); border-radius: 8px; text-align: center; padding: 3px 2px 0; height: 76px; display: flex; flex-direction: column; align-items: center; }
.p-abil span { font-family: 'Cinzel', serif; font-size: 6.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.p-abil b { font-size: 20px; flex: 1; display: grid; place-items: center; }
.p-abil i { font-style: normal; border: 1.5px solid var(--p-line); border-radius: 50%; width: 34px; height: 20px; display: grid; place-items: center; background: #fff; margin-bottom: -8px; font-size: 11px; }
.p-c1b > * { margin-bottom: 6px; }
.p-mini { border: 1.5px solid var(--p-line); border-radius: 6px; padding: 3px 6px; display: flex; gap: 6px; align-items: center; font-size: 8.5px; text-transform: uppercase; font-family: 'Cinzel', serif; }
.p-mini b { border: 1.5px solid var(--p-line); border-radius: 50%; min-width: 24px; height: 20px; display: grid; place-items: center; font-family: 'Crimson Pro', serif; font-size: 11px; }
.p-box { border: 1.5px solid var(--p-line); border-radius: 6px; padding: 5px 7px; margin-bottom: 7px; }
.p-box.grow { flex: 1; }
.p-row { display: flex; align-items: center; gap: 4px; min-height: 14px; }
.p-row u { text-decoration: none; border-bottom: 1px solid var(--p-soft); min-width: 18px; text-align: center; display: inline-block; }
.p-row em { color: #888; font-size: 8px; }
.p-dot { width: 8px; height: 8px; border-radius: 50%; border: 1.2px solid var(--p-line); display: inline-block; flex: none; }
.p-dot.on { background: #222; } .p-dot.exp { box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.6px #222; }
.p-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 7px; }
.p-stat { border: 1.5px solid var(--p-line); border-radius: 6px; text-align: center; padding: 3px; display: flex; flex-direction: column-reverse; }
.p-stat b { font-size: 15px; min-height: 22px; } .p-stat span { font-size: 6.5px; text-transform: uppercase; font-family: 'Cinzel', serif; }
.p-hp { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 6px; text-align: center; }
.p-hp span { font-size: 6.5px; text-transform: uppercase; font-family: 'Cinzel', serif; display: block; }
.p-hp b { display: block; font-size: 15px; min-height: 26px; border-bottom: 1px solid var(--p-soft); } .p-hp b.tall { min-height: 40px; font-size: 22px; }
.p-two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.p-tbl { width: 100%; border-collapse: collapse; } .p-tbl th { font-size: 6.5px; text-transform: uppercase; text-align: left; color: #555; font-family: 'Cinzel', serif; }
.p-tbl td { border-bottom: 1px solid var(--p-soft); height: 15px; padding: 1px 2px; font-size: 9.5px; }
.p-coins { display: flex; gap: 4px; margin-bottom: 4px; } .p-coins div { flex: 1; border: 1.2px solid var(--p-line); border-radius: 4px; text-align: center; }
.p-coins span { font-size: 6.5px; display: block; font-family: 'Cinzel', serif; } .p-coins b { display: block; min-height: 13px; font-size: 10px; }
.p-lines { min-height: calc(var(--n) * 14px); background-image: linear-gradient(transparent 13px, #bbb 13px, #bbb 14px); background-size: 100% 14px; line-height: 14px; font-size: 10px; white-space: normal; overflow-wrap: anywhere; }
.p-c3 { display: flex; flex-direction: column; }
.p-portrait { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; margin: 0 auto 7px; display: block; border: 2px solid var(--p-line); }
.p-symbol { height: 130px; display: grid; place-items: center; } .p-symbol img { max-height: 130px; max-width: 100%; }
.p-appear img { float: left; width: 90px; height: 90px; border-radius: 50%; object-fit: cover; margin: 0 8px 4px 0; }
.p-lv { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; font-family: 'Cinzel', serif; font-size: 9px; }
.p-lv b { border: 1.5px solid var(--p-line); border-radius: 4px; width: 18px; height: 18px; display: grid; place-items: center; }
.p-lv span { margin-left: auto; font-size: 8px; } .p-lv u { text-decoration: none; border-bottom: 1px solid var(--p-soft); min-width: 16px; display: inline-block; text-align: center; }
.p-ul { flex: 1; border-bottom: 1px solid #bbb; min-height: 13px; }
.p-spl { margin-bottom: 7px; }

@page { size: letter; margin: 0; }
@media print {
  html.printing body { background: #fff !important; }
  html.printing .top, .no-print, .toasts { display: none !important; }
  html.printing .print-wrap { padding: 0; }
  .p-page { box-shadow: none; margin: 0; page-break-after: always; break-after: page; height: 11in; overflow: hidden; }
  .p-page:last-child { page-break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (max-width: 520px) { .char-name { font-size: 1.15rem; } .portrait { width: 70px; height: 70px; } }
