:root {
  --bg: #14110e;
  --surface: #1e1a16;
  --surface-2: #29231d;
  --line: #3a3129;
  --text: #ece3d0;
  --muted: #a39885;
  --accent: #d9b56c;
  --accent-ink: #1a140c;
  --parchment: #efe2c2;
  --parchment-edge: #d8c495;
  --ink: #2b2117;
  --danger: #d0614f;
  --good: #7fb069;
  --blue: #6fa3c9;
  --radius: 14px;
  --tabbar: calc(64px + env(safe-area-inset-bottom));
  --topbar: calc(52px + env(safe-area-inset-top));
  --serif: "Crimson Pro", Georgia, "Times New Roman", serif;
  --display: "Cinzel", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.45 var(--sans); }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > textarea, label > select { margin-top: 5px; }
h1, h2 { font-family: var(--display); font-weight: 700; letter-spacing: .02em; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
p { margin: 0 0 .6em; }
code { background: var(--surface-2); padding: 6px 8px; border-radius: 8px; font-size: 14px; overflow-wrap: anywhere; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 0 4px; }
.mt { margin-top: 10px; }
.wrap { flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .wide { grid-column: 1 / -1; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.btn.big { min-height: 52px; width: 100%; font-size: 17px; margin-top: 12px; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.good { background: var(--good); color: #10200a; }
.danger-text { color: var(--danger) !important; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.toggle {
  min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--muted); font-size: 14px; white-space: nowrap;
}
.toggle.on { background: rgba(217, 181, 108, .18); color: var(--accent); border-color: var(--accent); }
.toggle.small { min-height: 32px; font-size: 13px; padding: 0 10px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { min-height: 38px; padding: 0 12px; border-radius: 9px; color: var(--muted); font-size: 14px; flex: 1; white-space: nowrap; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg.small button { min-height: 32px; padding: 0 10px; font-size: 13px; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none; min-height: 34px; padding: 0 12px; border-radius: 999px; display: inline-flex; align-items: center;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; color: var(--text); white-space: nowrap;
}
.chip.on, .chip.done { border-color: var(--good); color: var(--good); }
.chip.cond { border-color: var(--danger); color: #f0a093; }
.tag {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: rgba(217, 181, 108, .15); color: var(--accent); vertical-align: middle; font-family: var(--sans); letter-spacing: 0;
}
.tag.muted { background: var(--surface-2); color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.form { display: grid; gap: 12px; }
.item-title { font-family: var(--display); font-weight: 600; font-size: 15px; letter-spacing: .02em; }
.section-title { font-family: var(--display); font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 18px 4px 8px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; font-style: italic; font-family: var(--serif); font-size: 18px; }
.empty.small { padding: 10px; font-size: 16px; }

/* Start-up and join */
.center-screen { min-height: 100dvh; display: grid; place-items: center; padding: 20px 16px; }
.brand { color: var(--accent); display: grid; place-items: center; }
.brand svg { width: 52px; height: 52px; }
.ico { display: inline-grid; place-items: center; }
.ico svg { display: block; }
.center-screen > .brand.pulse { width: 52px; height: 52px; border: 2px solid var(--accent); border-radius: 12px; transform: rotate(45deg); }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.join { width: 100%; max-width: 420px; display: grid; gap: 14px; padding: 24px 20px; }
.join h1 { text-align: center; }
.join > p { text-align: center; }

/* Shell */
#app { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  flex: none; height: var(--topbar); padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(var(--bg), rgba(20, 17, 14, .92)); border-bottom: 1px solid var(--line);
}
.topbar .title { font-family: var(--display); font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { flex: none; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.collecting { color: var(--accent); background: rgba(217, 181, 108, .14); }
.pill.resolving { color: var(--blue); background: rgba(111, 163, 201, .15); animation: pulse 1.6s infinite; }

.view {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(var(--tabbar) + 20px);
  max-width: 720px; width: 100%; margin: 0 auto;
}
body.has-composer .view-story { padding-bottom: calc(var(--tabbar) + var(--composer-h, 200px) + 8px); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr); background: rgba(24, 20, 17, .97);
  border-top: 1px solid var(--line); z-index: 20; backdrop-filter: blur(8px);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); position: relative; }
.tab-icon { display: grid; opacity: .75; }
.tab-label { font-size: 11px; font-weight: 600; letter-spacing: .02em; }
.tab.active { color: var(--accent); }
.tab.active .tab-icon { opacity: 1; }
.tab.due .tab-icon::after { content: ""; position: absolute; top: 8px; left: calc(50% + 10px); width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tab.ping::after { content: ""; position: absolute; top: 10px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

.subtabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 12px; padding: 0 16px; }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  color: var(--muted); background: var(--surface); border: 1px solid var(--line);
}
.subtabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Story: scene card */
.scene-card {
  position: sticky; top: -14px; z-index: 5; margin: -14px -16px 14px; padding: 12px 16px;
  background: linear-gradient(180deg, #221d17, #1b1713); border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .35);
}
.scene-head { width: 100%; display: flex; justify-content: space-between; align-items: center; text-align: left; gap: 10px; min-height: 40px; }
.scene-title { font-family: var(--display); font-weight: 700; font-size: 16px; color: var(--accent); }
.chev { color: var(--muted); font-size: 18px; }
.scene-body { margin-top: 8px; font-family: var(--serif); font-size: 17px; line-height: 1.4; max-height: 30vh; overflow-y: auto; }
.scene-body .recap { color: #d9cfbb; }
.scene-body .prompt { color: var(--text); font-style: italic; }
.scene-status { margin-top: 8px; display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.scene-status .who { display: flex; flex-wrap: wrap; gap: 6px; }
.scene-status .chip, .decision-card .chip { min-height: 28px; font-size: 13px; gap: 6px; }
.chip-state { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .8; }
.glow { color: var(--blue); animation: pulse 1.6s infinite; }

/* Story: feed */
.feed { display: flex; flex-direction: column; gap: 10px; }
.load-more { align-self: center; }
.turn-divider { display: flex; align-items: center; gap: 10px; color: var(--accent); font-family: var(--display); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; margin: 12px 0 2px; }
.turn-divider::before, .turn-divider::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--line), transparent); }
.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.msg-head .muted { margin-left: auto; }
.name { font-weight: 700; font-size: 14px; color: var(--accent); }

.msg.narration {
  background: var(--parchment); color: var(--ink); border-radius: 6px 18px 18px 18px; padding: 14px 16px 12px;
  box-shadow: inset 0 0 0 1px var(--parchment-edge), inset 0 0 40px rgba(140, 100, 40, .25), 0 4px 14px rgba(0, 0, 0, .35);
}
.msg.narration .muted { color: #7a6a52; }
.dm-badge { font-family: var(--display); font-weight: 700; font-size: 12px; letter-spacing: .1em; background: var(--ink); color: var(--parchment); padding: 2px 8px; border-radius: 6px; }
.prose { font-family: var(--serif); font-size: 18px; line-height: 1.5; }
.prose p { margin: 0 0 .7em; }
.prose p:last-child { margin-bottom: 0; }
.prose strong { color: #5b2a12; }
.changes { margin-top: 10px; padding-top: 8px; border-top: 1px dashed #bda877; display: grid; gap: 4px; font-size: 14px; color: #4a3b26; }
.changes-title { font-family: var(--display); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #7a5a2a; }
.change-reason { color: #7a6a52; font-style: italic; }
.previously { font-family: var(--serif); font-style: italic; color: #6b5a40; font-size: 16px; margin: 0 0 8px; }
.previously span { font-style: normal; font-family: var(--display); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #7a5a2a; }
.stand { margin-top: 10px; padding-top: 8px; border-top: 1px dashed #bda877; display: grid; gap: 6px; font-family: var(--serif); font-size: 17px; line-height: 1.4; }
.stand-line { padding: 2px 0; }
.stand-line.me { background: rgba(140, 100, 40, .14); border-radius: 8px; padding: 6px 8px; margin: 0 -8px; }
.like-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.like-btn { font-size: 13px; color: #7a5a2a; border: 1px solid #c9b07c; border-radius: 999px; padding: 4px 12px; min-height: 32px; }
.like-btn.on { background: #7a5a2a; color: var(--parchment); border-color: #7a5a2a; }
.msg.decision-card { border: 1px solid var(--accent); border-radius: 14px; padding: 12px 14px; display: grid; gap: 8px; background: var(--surface); }
.msg.decision-card.done { border-color: var(--line); opacity: .8; }
.decision-label { font-family: var(--display); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.decision-card.done .decision-label { color: var(--muted); }
.decision-q { font-family: var(--serif); font-size: 19px; line-height: 1.35; }
.decision-card .who { display: flex; flex-wrap: wrap; gap: 6px; }
.decision-line { font-size: 15px; }
.msg-images { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 10px; }
.msg.narration .pic figcaption { color: var(--ink); }

.msg.action, .msg.ooc, .msg.roll { display: flex; }
.msg.mine { justify-content: flex-end; }
.bubble { max-width: 86%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 18px 18px 18px 6px; padding: 9px 13px; overflow-wrap: anywhere; }
.msg.mine .bubble { border-radius: 18px 18px 6px 18px; background: #2f281f; border-color: #4a3d2c; }
.name.table { color: var(--blue); }
.msg.system { align-self: center; font-size: 13px; color: var(--muted); text-align: center; padding: 2px 12px; }

.roll-card { min-width: 200px; max-width: 86%; background: #1b2026; border: 1px solid #2f3a45; border-radius: 14px; padding: 9px 12px; }
.msg.roll.dm .roll-card { background: #231b1b; border-color: #4a3030; }
.roll-card.crit { border-color: var(--good); box-shadow: 0 0 0 1px var(--good), 0 0 18px rgba(127, 176, 105, .3); }
.roll-card.fumble { border-color: var(--danger); }
.roll-top { display: flex; justify-content: space-between; gap: 10px; }
.roll-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0; }
.faces { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.die { min-width: 28px; height: 28px; padding: 0 5px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); font-weight: 700; font-size: 14px; }
.die.nat20 { background: var(--good); color: #10200a; border-color: var(--good); }
.die.nat1 { background: var(--danger); color: #fff; border-color: var(--danger); }
.die.dropped { opacity: .4; text-decoration: line-through; }
.mod { color: var(--muted); font-weight: 600; }
.total { font-family: var(--display); font-size: 28px; font-weight: 700; color: var(--accent); }

/* Composer */
.composer {
  position: fixed; left: 0; right: 0; bottom: var(--tabbar); z-index: 15;
  background: linear-gradient(rgba(20, 17, 14, 0), var(--bg) 18px); padding: 18px 12px 8px;
  display: grid; gap: 8px; max-width: 720px; margin: 0 auto;
}
.compose-status { font-size: 13px; color: var(--muted); padding: 0 6px; height: 18px; line-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-row { display: flex; align-items: flex-end; gap: 8px; }
.compose-box { flex: 1; position: relative; }
.compose-count { position: absolute; right: 14px; bottom: 4px; font-size: 11px; color: var(--muted); pointer-events: none; }
.compose-count.low { color: var(--danger); }
.compose-box textarea { min-height: 46px; max-height: 160px; overflow-y: hidden; border-radius: 22px; padding: 12px 16px; resize: none; display: block; line-height: 1.35; }
.send { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; }
.dice-btn { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; }
.send { background: var(--accent); color: var(--accent-ink); }
.dice-btn { background: var(--surface-2); border: 1px solid var(--line); color: var(--accent); }
.compose-foot { display: flex; align-items: center; gap: 8px; }
.compose-foot .spacer { flex: 1; }
.checks-btn { min-height: 38px; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.check {
  display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 10px; text-align: left;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.check:active { transform: scale(.97); }
.check-name { flex: 1; min-width: 0; font-size: 14px; line-height: 1.2; }
.check-val { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.sheet-body .section-title { margin: 6px 2px 0; }

/* Bottom sheets */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0); transition: background .2s; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap.open { background: rgba(0, 0, 0, .55); }
.sheet {
  width: 100%; max-width: 640px; max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; border: 1px solid var(--line); border-bottom: 0;
  transform: translateY(100%); transition: transform .22s ease-out; padding-bottom: env(safe-area-inset-bottom);
}
.sheet-wrap.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 18px; }
.sheet-body { overflow-y: auto; padding: 6px 16px 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.sheet-body > p { margin: 0; }
.dice-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.die-btn { min-height: 56px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 700; font-size: 17px; color: var(--accent); }
.expr-row { display: flex; gap: 8px; align-items: center; justify-content: center; }
.expr-row .expr { text-align: center; font-size: 22px; font-weight: 700; font-family: var(--display); }
.big-num { font-size: 32px; font-weight: 700; text-align: center; min-width: 80px; font-family: var(--display); }
input.big-num { height: 64px; }
.sheet .seg { width: 100%; }

#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translate(-50%, -150%);
  z-index: 60; max-width: calc(100% - 32px); padding: 11px 18px; border-radius: 14px;
  background: #2c261f; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  font-weight: 600; transition: transform .25s; text-align: center;
}
#toast.show { transform: translate(-50%, 0); }
#toast.good { border-color: var(--good); color: #bfe3ac; }
#toast.bad { border-color: var(--danger); color: #f6b3a7; }

/* Character */
.sheet-top { margin-bottom: 6px; }
.sheet-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.sheet-tools #saved { flex: 1; text-align: right; }
.char-head { text-align: center; }
.char-name { font-family: var(--display); font-size: 24px; font-weight: 700; color: var(--accent); }
.xp { margin-top: 8px; display: grid; gap: 4px; }
.xpbar, .hpbar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.xpbar > div { height: 100%; background: var(--blue); }
.hpbar > div { height: 100%; background: var(--good); transition: width .3s; }
.hpbar > div.mid { background: #d1a54a; }
.hpbar > div.low { background: var(--danger); }
.hpbar.big { height: 10px; margin-top: 10px; }
.hp-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.hp-big { font-family: var(--display); font-size: 34px; font-weight: 700; }
.hp-big .muted { font-size: 20px; }
.hp-big .temp { font-size: 15px; color: var(--blue); font-family: var(--sans); }
.hp-btns { display: flex; gap: 6px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(62px, 1fr)); gap: 6px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stat-val { font-family: var(--display); font-size: 20px; font-weight: 700; white-space: nowrap; }
.stat-label { font-size: 10px; white-space: nowrap; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tap { cursor: pointer; transition: transform .08s, background .15s; }
.tap:active { transform: scale(.97); background: var(--surface-2); }
.stat.tap .stat-val, .ability.tap .ab-mod { color: var(--accent); }
.death .row-between { margin-top: 8px; }
.pips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pip { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); background: transparent; }
.pip.good.on { background: var(--good); border-color: var(--good); }
.pip.bad.on { background: var(--danger); border-color: var(--danger); }
.pip.gold { border-radius: 7px; transform: rotate(45deg) scale(.8); }
.pip.gold.on { background: var(--accent); border-color: var(--accent); }
.slot-line { margin-top: 10px; }

.ability-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ability { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; text-align: center; display: grid; gap: 2px; }
.ab-name { font-size: 12px; font-weight: 700; letter-spacing: .1em; color: var(--muted); }
.ab-mod { font-family: var(--display); font-size: 28px; font-weight: 700; }
.ab-score { justify-self: center; min-width: 34px; font-size: 13px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); }
.ab-input { text-align: center; font-size: 22px; font-weight: 700; }
.card.list { padding: 4px 0; }
.line { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line-name { flex: 1; }
.line-val { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; }
.line.tap .line-val { color: var(--accent); }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.dot.on { background: var(--accent); border-color: var(--accent); }
.dot.exp { background: var(--accent); border-color: var(--accent); border-radius: 2px; transform: rotate(45deg); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--accent); }

.attack, .spell { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.spell.unprepared { opacity: .6; }
.slot-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.coin-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.coin { text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; }
.coin span { font-weight: 700; font-size: 12px; letter-spacing: .08em; }
.coin.gp span { color: var(--accent); }
.coin.pp span { color: #cfd8e3; }
.coin.sp span { color: #b9bfc6; }
.coin.cp span { color: #c98a5a; }
.coin.ep span { color: #9fc2b4; }
.coin input { padding: 8px 2px; text-align: center; margin-top: 4px; }
.coin-val { font-size: 18px; font-weight: 700; margin-top: 4px; }
.item-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.item-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 10px; }
.stepper button { width: 34px; height: 34px; font-size: 18px; color: var(--accent); }
.stepper span { min-width: 20px; text-align: center; font-weight: 700; }
.qty { font-weight: 700; color: var(--muted); }
.add-row { display: flex; gap: 8px; margin-top: 4px; }

.view-character textarea, .readonly-sheet textarea { font-family: var(--serif); font-size: 17px; }

/* Character builder */
.creator { display: grid; gap: 12px; }
.creator-nav { margin-top: 4px; }
.pool { display: flex; flex-wrap: wrap; gap: 8px; }
.pool-num { padding: 6px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--accent); font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--accent); }
.pool-num.used { opacity: .4; }
.creator .line select { width: auto; min-width: 90px; }
.check.on { border-color: var(--accent); }

/* Party */
.party-card { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; }
.avatar { width: 46px; height: 46px; flex: none; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 20px; background: var(--surface-2); color: var(--accent); border: 1px solid var(--accent); }
.party-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.party-name { font-family: var(--display); font-weight: 700; }
.party-stats { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); }
.party-stats .cond { color: #f0a093; }
.party-state { font-size: 12px; color: var(--muted); text-align: right; max-width: 80px; }
.party-state.done { color: var(--good); font-weight: 600; }
.readonly-sheet .subtabs { margin: 0 -16px 12px; }

/* Pictures */
.pic { margin: 0; display: grid; gap: 4px; cursor: zoom-in; }
.pic img { width: 100%; max-height: 260px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.pic figcaption { font-size: 13px; font-weight: 600; }
.pic-full { width: 100%; height: auto; border-radius: 10px; }
.pack-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pack-grid .pic img { height: 120px; }
.card.warn { border-color: #8a6a2a; background: #2a2115; }
.card.warn p { margin: 0; }
details.help summary { cursor: pointer; color: var(--accent); font-size: 14px; }
details.help p { margin: 8px 0 0; color: var(--muted); }
.card.item.with-pic { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; align-items: start; }
.card.item.with-pic .pic img { height: 96px; max-height: none; }
.item-text { min-width: 0; }

/* DM log */
.log-entry { align-self: start; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.log-entry summary { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 8px; padding: 10px 12px; cursor: pointer; list-style: none; }
.log-entry summary .tag { margin: 0; align-self: start; }
.log-entry summary .muted { grid-column: 2; }
.log-sum { font-size: 14px; overflow-wrap: anywhere; }
.log-entry.error { border-color: var(--danger); }
.tag.bad { background: rgba(208, 97, 79, .2); color: #f0a093; }
.log-json { margin: 0; padding: 10px 12px; max-height: 50vh; overflow: auto; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }

/* World */
.map img { display: block; width: 100%; height: auto; max-height: none; object-fit: contain; border-radius: var(--radius); }
.card.item p { margin: 6px 0 0; font-family: var(--serif); font-size: 17px; }
.card.item.done { opacity: .7; }
.card.item.failed { opacity: .55; }
.journal-entry { border-left: 2px solid var(--accent); padding: 4px 0 4px 14px; margin: 0 0 14px 4px; }
.journal-entry p { font-family: var(--serif); font-size: 17px; margin: 2px 0 0; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code { flex: 1; }

@media (min-width: 760px) {
  .composer { padding-left: 0; padding-right: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Campaign setup */
.setup-head { display: grid; gap: 2px; }
.setup-bar { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.setup-bar > div { height: 100%; background: var(--accent); transition: width .2s; }
.field { display: grid; gap: 8px; }
.field-title { font-size: 13px; color: var(--muted); }
.choice-list { display: grid; gap: 6px; }
.choice { display: grid; gap: 2px; text-align: left; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.choice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice-label { font-weight: 600; }
.choice.on .choice-label { color: var(--accent); }
.choice-help { font-size: 13px; color: var(--muted); line-height: 1.35; }
label.question { color: var(--text); font-size: 14px; line-height: 1.4; }
.code-big { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 26px; letter-spacing: 3px; text-align: center; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--accent); color: var(--accent); }
.stepper { display: inline-flex; align-items: center; gap: 10px; }
.stepper .btn { min-width: 40px; }
.score-in { width: 80px; text-align: center; }
.line.col { display: grid; gap: 4px; }
.line.col p { margin: 0; }
.question-q { font-size: 14px; line-height: 1.4; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-opt { padding: 8px 12px; min-height: 38px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; }
.chip-opt.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Public site: homepage, log in and footer */
.site { height: 100%; overflow-y: auto; display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.site a { color: var(--accent); overflow-wrap: anywhere; }
.site-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; max-width: 760px; margin: 0 auto; padding: 12px 16px; }
.site-logo { display: inline-flex; align-items: center; gap: 8px; color: var(--accent); font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: .04em; }
.site-logo svg { width: 28px; height: 28px; }
.site-main { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; flex: 1; }
.site-auth { flex: 1; display: grid; place-items: center; padding: 12px 16px 28px; }
.hero { text-align: center; padding: 36px 0 28px; display: grid; justify-items: center; gap: 12px; }
.hero-mark { color: var(--accent); }
.hero-mark svg { width: 64px; height: 64px; }
.eyebrow { margin: 0; color: var(--accent); font-family: var(--display); font-size: 13px; letter-spacing: .12em; text-transform: uppercase; }
.hero h1 { font-size: clamp(26px, 7vw, 40px); line-height: 1.15; max-width: 18em; }
.lede { font-family: var(--serif); font-size: 20px; line-height: 1.4; color: var(--text); max-width: 32em; margin: 0; }
.hero-btns { display: grid; gap: 10px; width: 100%; max-width: 360px; grid-template-columns: 1fr 1fr; }
.hero-btns .btn.big { margin-top: 8px; }
.site-section { padding: 22px 0; border-top: 1px solid var(--line); }
.site-section h2 { color: var(--accent); margin-bottom: 12px; }
.site-section > p { font-family: var(--serif); font-size: 18px; line-height: 1.5; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 14px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 34px 1fr; column-gap: 12px; }
.steps li::before { content: counter(step); grid-row: span 2; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--accent); color: var(--accent); display: grid; place-items: center; font-family: var(--display); font-size: 14px; }
.steps p { margin: 2px 0 0; }
.features { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.feature { margin: 0; }
.feature p { margin: 6px 0 0; }
.cta { text-align: center; padding: 26px 0 34px; border-top: 1px solid var(--line); }
.cta .btn.big { max-width: 360px; }
.site-foot { width: 100%; max-width: 760px; margin: 0 auto; padding: 20px 16px 28px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.5; }
.site-foot p { margin: 0 0 10px; }
.site-foot .foot-brand { color: var(--text); font-family: var(--display); font-size: 13px; letter-spacing: .04em; }
.legal-page { position: fixed; inset: 0; z-index: 55; background: var(--bg); }
.legal-title { padding: 18px 0 6px; }
.legal-page .site-section > p { font-size: 16px; overflow-wrap: anywhere; }
.legal-copy { padding: 8px 0 28px; }
.home .site-foot { padding: 16px 0 8px; }

/* Accounts and home */
.auth-links { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: center; }
button.link { color: var(--accent); font-size: 14px; padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; }
.home { max-width: 560px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 12px; height: 100%; overflow-y: auto; align-content: start; }
.home-head { display: flex; align-items: center; gap: 10px; }
.home-head h1 { margin: 0; font-family: var(--display); font-size: 22px; }
.home-head .brand svg { width: 34px; height: 34px; }
.camp-card { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; }
.camp-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.topbar .back { margin-left: -8px; flex: none; }
.topbar .title { flex: 1; min-width: 0; }

/* Admin tab */
.admin-dm { border-radius: 6px 18px 18px 18px; }
.small-prose { font-size: 16px; }
.admin-compose textarea { min-height: 80px; }
.msg.system.glow { font-style: italic; }

/* Story: room to read */
.scene-head-text { flex: 1; min-width: 0; }
.scene-card.collapsed { padding-top: 6px; padding-bottom: 6px; }
.scene-card.collapsed .scene-head { min-height: 32px; }
.scene-card.collapsed .scene-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene-summary { flex: none; font-size: 12px; font-weight: 600; color: var(--muted); }
.topbar { transition: margin-top .2s ease; }
.scene-card { transition: transform .2s ease; }
body.reading .topbar { margin-top: calc(-1 * var(--topbar)); }
body.reading .scene-card { transform: translateY(-130%); }
.turn-btn { flex: none; min-height: 38px; }
.turn-btn.invisible { visibility: hidden; }
.msg.narration.answer { padding: 10px 14px; }
.msg.narration.answer .prose { font-size: 16px; }

/* Spells and level up */
.spell-chooser { display: grid; gap: 10px; }
.filter-chips { flex-wrap: nowrap; }
.filter-chips .chip { min-height: 32px; font-size: 13px; }
.spell-list { display: grid; gap: 6px; }
.spell-row {
  display: grid; grid-template-columns: 44px 1fr; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.spell-row.on { border-color: var(--accent); background: rgba(217, 181, 108, .08); }
.spell-pick { height: 100%; min-height: 52px; display: grid; place-items: center; }
.spell-pick:disabled { opacity: .35; }
.spell-main { text-align: left; padding: 8px 12px 8px 0; min-height: 52px; }
.spell-name { font-weight: 600; }
.spell-desc { grid-column: 1 / -1; padding: 0 12px 10px 14px; border-top: 1px dashed var(--line); }
.spell-desc p { margin: 6px 0 0; white-space: pre-line; }
.feature-head { width: 100%; display: flex; justify-content: space-between; align-items: center; text-align: left; gap: 8px; }
.card.feature p { white-space: pre-line; margin: 6px 0; }
.whats-new { padding: 10px 12px; }
.whats-new + .whats-new { border-top: 1px solid var(--line); }
.whats-new p { margin: 2px 0 0; }
.suggest { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px dashed var(--accent); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.suggest p { margin: 0; }
.card.levelup { border-color: var(--accent); background: rgba(217, 181, 108, .08); }
.choose-spells { margin-bottom: 8px; }
.tag.bad { color: #f0a093; border-color: var(--danger); }
.prep-count { margin: 4px 0 8px; }

/* Origins, equipment, resources and rules on tap */
.equip-step .choice select { margin-top: 6px; }
.res-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.res-line:first-of-type { border-top: 0; }
.card.resources .item-title { margin-bottom: 4px; }
.card.conc { border-color: var(--accent); }
.warn-text { color: #f0a093; margin-top: 6px; }
.linkish { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
.spell-open { text-align: left; background: none; border: 0; padding: 0; color: inherit; flex: 1; min-width: 0; }
.spell-btns { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.rule-text p { margin: 0 0 10px; line-height: 1.5; white-space: pre-line; }
.feature-list .chips { margin-bottom: 4px; }
.item-title.mt { margin-top: 14px; }
.need { color: var(--accent); margin: 8px 0 0; } .need:empty { display: none; }
.awaiting { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); color: var(--accent); font-size: 14px; }
.msg.sheet-change { align-self: center; max-width: 92%; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 14px; text-align: center; }
.msg.sheet-change strong { color: var(--accent); }
.push-nudge { margin: 8px 12px 0; display: grid; gap: 8px; }
.fight-board { display: grid; gap: 4px; margin: 6px 0; }
.fight-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
.fight-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 36px; padding: 4px 10px; border-radius: 10px; background: var(--surface-2); border-left: 3px solid var(--line); }
.fight-row.party { border-left-color: var(--good); }
.fight-row.ally { border-left-color: var(--blue); }
.fight-row.enemy { border-left-color: var(--danger); }
.fight-row.me { box-shadow: 0 0 0 1px var(--accent); }
.fight-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.fight-right { display: flex; align-items: center; gap: 8px; flex: none; }
.fight-hp { display: grid; gap: 2px; width: 64px; text-align: right; }
.fight-row .chip { min-height: 24px; padding: 0 8px; }
.fight-state { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); flex: none; }
.fight-state.s-hurt { color: #d1a54a; }
.fight-state.s-bloodied, .fight-state.s-badly-hurt { color: var(--danger); }
.fight-state.s-down, .fight-state.s-fled { text-decoration: line-through; opacity: .6; }

/* Taps answer at once, even while the server works. */
.btn:active:not(:disabled), .chip:active, .choice:active, .tab:active, .camp-card:active { transform: scale(.97); }
.btn, .chip, .choice, .tab, .camp-card { transition: transform .08s ease-out; }
.camp-card.busy { opacity: .6; pointer-events: none; }
.camp-card.busy .pill::after { content: " · opening"; }
@media (prefers-reduced-motion: reduce) { .btn, .chip, .choice, .tab, .camp-card { transition: none; } }

/* Active or passive play, under the message box. */
.play-mode { flex: none; display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font: inherit; cursor: pointer; }
.play-mode .pm-opt { font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px; color: var(--muted); }
.play-mode .pm-opt.on { background: var(--accent); color: var(--accent-ink); }
.play-mode:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.passive { opacity: .6; }
@media (max-width: 400px) { .play-mode .pm-opt { padding: 6px 8px; } .compose-foot { gap: 6px; } }

/* "While you were away" */
.recap { border-left: 3px solid var(--accent); }
.recap-list { margin: 6px 0; padding-left: 18px; }
.recap-list li { margin: 4px 0; font-family: var(--serif); }
