:root {
  --bg: #0e0c12; --bg2: #16131c; --bg3: #1e1a27; --panel: #191622; --line: #3a3248; --gold: #c9a24b; --gold2: #e6c779; --text: #ece7f2; --muted: #9a92a8;
  --red: #b3263a; --red2: #e0475c; --ok: #4aa36b; --warn: #d9a441; --radius: 10px;
  --serif: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: radial-gradient(1200px 600px at 50% -200px, #261a33 0%, var(--bg) 60%); color: var(--text); font: 15px/1.45 var(--sans); min-height: 100vh; }
h1, h2, h3, h4 { font-family: var(--serif); color: var(--gold2); margin: .2em 0 .4em; letter-spacing: .02em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; }
a { color: var(--gold2); }
code { background: var(--bg3); padding: 1px 5px; border-radius: 4px; }
.boot { text-align: center; color: var(--muted); padding: 40px; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .center { text-align: center; } .error { color: var(--red2); }
.page { max-width: 1100px; margin: 0 auto; padding: 14px 16px 60px; }
.page.narrow { max-width: 460px; padding-top: 40px; }
.logo { font-size: 3rem; text-align: center; }
.row { display: flex; align-items: center; } .row.gap, .gap { gap: 8px; } .row.between { justify-content: space-between; } .row.end { justify-content: flex-end; } .wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; } .grow { flex: 1; }
.footer { margin-top: 40px; font-size: .72rem; color: var(--muted); text-align: center; max-width: 700px; margin-left: auto; margin-right: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.login { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; text-align: left; }

input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit; min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.btn { background: var(--bg3); color: var(--text); border: 1px solid #5b4f73; border-radius: 8px; padding: 9px 14px; font: inherit; cursor: pointer; min-height: 40px; }
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn.primary { background: linear-gradient(#d4ab4d, #a67f28); color: #1a1205; border-color: #e6c779; font-weight: 600; }
.btn.danger { border-color: var(--red); color: var(--red2); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--gold2); cursor: pointer; text-decoration: underline; font: inherit; padding: 4px; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 6px 10px; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
section { margin: 18px 0; }
.char-card { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; flex-wrap: wrap; }
.char-card.active { border-color: var(--gold); }
.char-info { flex: 1; min-width: 160px; cursor: pointer; }
.char-name { font-family: var(--serif); font-size: 1.1rem; color: var(--gold2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.avatar { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); background: var(--bg3); flex: none; }
.avatar.ph { display: flex; align-items: center; justify-content: center; font-size: 1.6rem; }
.badge { font: 600 .65rem var(--sans); background: var(--gold); color: #1a1205; border-radius: 999px; padding: 2px 8px; letter-spacing: .04em; text-transform: uppercase; }
.badge.alt { background: var(--bg3); color: var(--gold2); border: 1px solid var(--line); }
.chip { display: inline-block; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; }
.chip.on { border-color: var(--gold); background: #2b2412; color: var(--gold2); }
.chip:disabled { opacity: .4; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- wizard ---------- */
.wiz { max-width: 1180px; margin: 0 auto; padding-bottom: 110px; }
.wiz-head { position: sticky; top: 0; z-index: 20; background: rgba(14, 12, 18, .96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.wiz-tabs { display: flex; overflow-x: auto; gap: 2px; padding: 6px 8px 0; scrollbar-width: none; }
.wiz-tab { flex: none; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); padding: 8px 10px; font: 600 .78rem var(--sans); text-transform: uppercase; letter-spacing: .05em; cursor: pointer; white-space: nowrap; }
.wiz-tab.done { color: var(--text); } .wiz-tab.cur { color: var(--gold2); border-color: var(--gold); } .wiz-tab:disabled { opacity: .35; cursor: default; }
.wiz-tab .n { display: inline-block; width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 50%; background: var(--bg3); margin-right: 5px; font-size: .7rem; }
.wiz-tab.done .n { background: var(--ok); color: #06210f; }
.statbar { display: flex; gap: 8px; padding: 8px 10px 10px; overflow-x: auto; align-items: stretch; scrollbar-width: none; }
.stat { flex: none; min-width: 58px; text-align: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.stat .v { font: 700 1.15rem var(--serif); color: var(--gold2); } .stat .l { font-size: .62rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat.sep { border: 0; background: none; width: 1px; padding: 0; min-width: 1px; }
.shield { flex: none; width: 54px; text-align: center; background: linear-gradient(#2a2237, #1b1626); border: 1px solid var(--gold); border-radius: 8px 8px 22px 22px; padding: 3px 2px 8px; position: relative; }
.shield .v { font: 700 1.1rem var(--serif); color: var(--text); } .shield .l { font-size: .58rem; text-transform: uppercase; color: var(--gold2); letter-spacing: .03em; }
.shield.spell::after { content: '✦'; position: absolute; top: -6px; right: -4px; color: var(--gold2); font-size: .8rem; }
.wiz-body { padding: 14px 12px; }
.wiz-foot { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: rgba(14, 12, 18, .97); border-top: 1px solid var(--line); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.wiz-foot .step-label { font: 600 .78rem var(--sans); color: var(--muted); letter-spacing: .1em; text-align: center; }
.notice { background: #2b2412; border: 1px solid var(--gold); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; font-size: .9rem; }
.errors { background: #2a1217; border: 1px solid var(--red); border-radius: 8px; padding: 8px 12px; margin: 10px 0; font-size: .88rem; color: #f3b9c2; }
.two { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 14px; align-items: start; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
@media (max-width: 760px) { .two { grid-template-columns: 1fr; } }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--text); font: inherit; cursor: pointer; display: flex; gap: 10px; align-items: center; width: 100%; }
.item:hover:not(:disabled) { border-color: var(--gold); }
.item.sel { border-color: var(--gold); background: #261f10; box-shadow: inset 0 0 0 1px var(--gold); }
.item:disabled { opacity: .4; cursor: not-allowed; }
.item .em { font-size: 1.4rem; width: 34px; text-align: center; flex: none; }
.item .t { font-family: var(--serif); font-weight: 700; color: var(--gold2); } .item .s { font-size: .8rem; color: var(--muted); }
.detail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.detail h2 { margin-top: 0; }
details.fold { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; background: var(--bg2); }
details.fold > summary { cursor: pointer; padding: 9px 12px; font-family: var(--serif); color: var(--gold2); font-weight: 700; }
details.fold > div { padding: 0 12px 10px; }
.md p { margin: .4em 0; } .md ul { margin: .3em 0; padding-left: 1.2em; } .md strong { color: #fff; }
.tag { display: inline-block; font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; border: 1px solid var(--gold); color: var(--gold2); border-radius: 999px; padding: 1px 8px; margin-right: 4px; }
.tag.bane { border-color: var(--red2); color: var(--red2); } .tag.lock { border-color: var(--line); color: var(--muted); }
.fcard { border: 1px solid var(--gold); border-radius: 8px; padding: 10px 12px; background: linear-gradient(#211a2c, #181320); }
.fcard.locked { opacity: .5; border-color: var(--line); }
.fcard h4 { margin: 0 0 4px; }
.avatar-big { width: 120px; height: 120px; border-radius: 50%; border: 3px solid var(--gold); object-fit: cover; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-size: 3rem; cursor: pointer; }
.traits-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.trait-pick { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.trait-pick .l { font: 700 .8rem var(--serif); color: var(--gold2); text-transform: uppercase; letter-spacing: .05em; }
.dcard { background: linear-gradient(#211a2c, #181320); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.dcard.sel { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.dcard.off { opacity: .45; }
.dcard .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.dcard .nm { font: 700 1rem var(--serif); color: var(--gold2); }
.dcard .meta { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.adv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; }
.boxes { display: inline-flex; gap: 3px; vertical-align: middle; }
.box { width: 16px; height: 16px; border: 2px solid var(--gold); border-radius: 3px; display: inline-block; background: transparent; }
.box.on { background: var(--gold); }
table.t { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.t th, table.t td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--gold2); font-weight: 600; }

/* ---------- modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal { background: var(--panel); border: 1px solid var(--gold); border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px 8px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body, .drawer-body { padding: 14px 16px; overflow: auto; }
.drawer-overlay { justify-content: flex-end; padding: 0; align-items: stretch; }
.drawer { background: var(--panel); border-left: 1px solid var(--gold); width: min(560px, 100%); display: flex; flex-direction: column; }
#toast { position: fixed; left: 50%; top: 12px; transform: translate(-50%, -20px); background: #2b2412; border: 1px solid var(--gold); color: var(--text); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 200; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); } #toast.bad { border-color: var(--red2); background: #2a1217; }

/* ---------- sheet ---------- */
.sheet { max-width: 1280px; margin: 0 auto; padding: 10px 12px 80px; }
.s-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 6px 0 12px; border-bottom: 1px solid var(--line); }
.s-head .name { font: 700 1.6rem var(--serif); color: var(--gold2); }
.s-head .sub { color: var(--muted); font-size: .9rem; }
.s-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.s-traits { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 12px 0; overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); padding: 9px 14px; font: 600 .85rem var(--sans); text-transform: uppercase; letter-spacing: .05em; cursor: pointer; white-space: nowrap; }
.tab.cur { color: var(--gold2); border-color: var(--gold); }
.panels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-items: start; }
@media (max-width: 980px) { .panels { grid-template-columns: 1fr 1fr; } }
@media (max-width: 680px) { .panels { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.panel > h3 { margin-top: 0; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
.big { font: 700 1.6rem var(--serif); color: var(--gold2); }
.track { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.slot { width: 28px; height: 28px; border: 2px solid var(--gold); border-radius: 5px; background: transparent; color: var(--text); font: 700 .95rem var(--sans); cursor: pointer; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.slot.o { background: var(--gold); color: #1a1205; }
.slot.x { background: var(--red); border-color: var(--red2); color: #fff; }
.slot.hunger.on { background: #6b1020; border-color: var(--red2); }
.slot.will.on { background: #2b4a8a; border-color: #7fa2ee; }
.slot.armor.on { background: #556; border-color: #99a; }
.slot.bat { width: 20px; height: 20px; border-radius: 3px; } .slot.bat.on { background: #4aa36b; border-color: #7fd69c; }
.slot.off { opacity: .25; cursor: default; }
.legend { font-size: .75rem; color: var(--muted); margin-top: 4px; }
.cond { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.item-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.item-row .nm { flex: 1; cursor: pointer; } .item-row .nm b { color: var(--gold2); font-family: var(--serif); }
.qty { width: 56px !important; min-height: 32px !important; padding: 4px 6px !important; text-align: center; }
.flag { display: inline-block; font-size: .7rem; padding: 1px 7px; border-radius: 999px; background: #3a2610; color: var(--warn); border: 1px solid var(--warn); }
.flag.bad { background: #3a1018; color: var(--red2); border-color: var(--red2); }
.journal-item { border-bottom: 1px solid var(--line); padding: 8px 0; }
.editor { min-height: 180px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; }
.editor:focus { outline: 2px solid var(--gold); }
.readonly-banner { background: #1d2538; border: 1px solid #5a78c8; border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
.saving { position: fixed; right: 12px; bottom: 10px; font-size: .72rem; color: var(--muted); z-index: 30; }
.sticky-hint { position: sticky; top: 0; }

/* ---------- GM ---------- */
.gm-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.gm-table th, .gm-table td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.gm-table th { background: var(--bg3); color: var(--gold2); position: sticky; top: 0; }
.gm-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.hook { border-left: 3px solid var(--red2); padding: 4px 8px; margin: 4px 0; background: var(--bg2); border-radius: 0 6px 6px 0; font-size: .85rem; }
.hook.warn { border-color: var(--warn); }
.pinned { box-shadow: 0 0 0 1px var(--gold); }
.scroll-x { overflow-x: auto; }

@media (max-width: 480px) { h1 { font-size: 1.4rem; } .wiz-foot .btn { padding: 9px 10px; } }

/* GM light theme */
.gm.light { --bg: #f6f2ea; --bg2: #fff; --bg3: #ece6d8; --panel: #fffdf8; --line: #cfc6b0; --gold: #8a6a1e; --gold2: #6d5214; --text: #1d1a14; --muted: #6b6455; --red2: #b3263a; background: var(--bg); color: var(--text); border-radius: 8px; }
.gm.light .btn { color: var(--text); } .gm.light .md strong { color: #000; } .gm.light .chip.on { background: #f1e3b8; }
@media (max-width: 480px) { .avatar-big { width: 84px; height: 84px; font-size: 2.2rem; } }

.btn.x { min-width: 34px; font-weight: 700; color: #fff; background: #8b1a2b; border-color: #c0394f; }
.btn.x:hover { background: #a3203a; }
.opt-line { display: flex; align-items: center; gap: 12px; margin: 14px 0 2px; color: var(--gold); font-size: .9rem; font-style: italic; }
.opt-line::before, .opt-line::after { content: ''; flex: 1; height: 1px; background: var(--gold); opacity: .6; }
.opt-line span { text-align: center; max-width: 70%; }

.crop-wrap { position: relative; margin: 0 auto; border-radius: 8px; overflow: hidden; touch-action: none; }
.crop-canvas { display: block; cursor: grab; touch-action: none; }
.crop-ring { position: absolute; inset: 0; pointer-events: none; border-radius: 50%; box-shadow: 0 0 0 999px rgba(0, 0, 0, .55); border: 2px solid var(--gold); }

/* ---------- online sheet: fixed top + tabs ---------- */
.s-top { margin-top: 10px; }
.thr-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.thr-btn { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 4px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); cursor: pointer; font-family: var(--sans); }
.thr-btn:hover:not(:disabled) { border-color: var(--gold); }
.thr-btn:disabled { opacity: .5; cursor: default; }
.thr-btn .tn { font: 700 .7rem var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--gold2); }
.thr-btn .tr { font: 700 1.05rem var(--serif); }
.thr-btn .tm { font-size: .68rem; color: var(--muted); }
.thr-btn.t2 { border-color: #7a5a1c; } .thr-btn.t3 { border-color: var(--red2); background: #2a1219; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 12px; align-items: start; }
.panel.cat .feat { margin-bottom: 10px; } .panel.cat .feat h4 { margin: 0 0 3px; color: var(--gold2); font-family: var(--serif); }
.panel.cat.dim { opacity: .6; }
.panel.cat .md p:last-child { margin-bottom: 0; }

.logo-img { display: block; width: min(220px, 60vw); height: auto; margin: 0 auto 6px; border-radius: 10px; }
