/* Reroll Sheet. Colours come from CSS variables; inside Owlbear they are overwritten from the OBR theme. */
:root {
  color-scheme: dark;
  --bg: #1e2231;
  --text: #eceef4;
  --text-dim: #a9afc0;
  --accent: #bb99ff;
  --accent-text: #17131f;
  --dmg: #f0955a;
  --good: #46c98b;
  --bad: #f0616d;
  --surface: color-mix(in srgb, var(--text) 6%, transparent);
  --surface-2: color-mix(in srgb, var(--text) 11%, transparent);
  --line: color-mix(in srgb, var(--text) 17%, transparent);
  --tap: 32px;
  --radius: 7px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f5f5f8;
    --text: #1b1d27;
    --text-dim: #5a6072;
    --accent: #6a3fd0;
    --accent-text: #ffffff;
    --dmg: #b4521a;
    --good: #14804f;
    --bad: #c62b3a;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f8;
  --text: #1b1d27;
  --text-dim: #5a6072;
  --accent: #6a3fd0;
  --accent-text: #ffffff;
  --dmg: #b4521a;
  --good: #14804f;
  --bad: #c62b3a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.35 var(--font);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
a { color: var(--accent); overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px; }
.muted { color: var(--text-dim); }

#app { position: relative; height: 100%; display: flex; flex-direction: column; min-width: 0; }
#scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
#content { padding: 4px 8px 96px; min-width: 0; }

/* ---------- controls */
input[type="text"], input[type="url"], input[type="search"], select, textarea {
  min-height: var(--tap); min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 8px;
}
select { padding-right: 4px; }
select option { background: var(--bg); color: var(--text); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
input.invalid, input[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad) inset; }
input::placeholder, textarea::placeholder { color: var(--text-dim); opacity: .8; }

.btn {
  min-height: var(--tap); min-width: var(--tap); padding: 4px 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  font-weight: 600; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: color-mix(in srgb, var(--text) 18%, transparent); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.icon { padding: 0; width: var(--tap); flex: none; font-size: 15px; line-height: 1; }
.btn.icon.edit-btn { width: auto; padding: 0 8px; font-size: 11px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, var(--text)); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 55%, transparent); }
.btn.link { background: none; border: 0; color: var(--accent); padding: 4px 0; font-weight: 500; text-decoration: underline; justify-self: start; text-align: left; white-space: normal; }
.btn.toggle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.crit-toggle.on { background: var(--good); border-color: var(--good); color: #06150d; }

/* ---------- top bar */
#topbar {
  flex: none; display: flex; align-items: center; gap: 4px; padding: 6px 8px;
  border-bottom: 1px solid var(--line); min-width: 0;
}
.char-select { flex: 1 1 60px; min-width: 60px; font-weight: 700; text-overflow: ellipsis; }
.brand { flex: 1; font-weight: 700; font-size: 14px; }
.status {
  flex: 0 1 auto; min-height: var(--tap); min-width: 0; padding: 2px 8px; border-radius: 999px;
  background: none; border: 1px solid var(--line); color: var(--text-dim); font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status.online { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, transparent); }

/* ---------- character header */
#sheet-header { padding: 8px 8px 6px; display: grid; gap: 6px; }
.id { display: flex; align-items: center; gap: 8px; min-width: 0; }
.avatar { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-2); }
.avatar-fallback { display: grid; place-items: center; font-size: 20px; font-weight: 700; color: var(--text-dim); }
.id-text { min-width: 0; }
.char-name { font-size: 17px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char-line { color: var(--text-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(42px, 1fr)); gap: 4px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 3px 2px; text-align: center; min-width: 0; }
.stat-val { display: block; font-size: 15px; font-weight: 700; line-height: 1.15; }
.stat-label { display: block; font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.hp { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; position: relative; padding-bottom: 5px; }
.hp-label { font-weight: 700; font-size: 12px; color: var(--text-dim); width: 20px; }
.hp-input { width: 52px; text-align: center; font-size: 16px; font-weight: 700; padding: 2px 4px; }
.hp-input.temp { width: 44px; font-size: 13px; }
.hp-max { color: var(--text-dim); font-weight: 600; margin-right: 2px; }
.hp-temp { display: flex; align-items: center; gap: 4px; margin-left: auto; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.hp-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.hp-fill { height: 100%; background: var(--good); transition: width .2s; }
.hp.hurt .hp-fill { background: var(--dmg); }
.hp.down .hp-input:not(.temp) { color: var(--bad); }
.conc { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 2px 8px; border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.conc-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* ---------- sticky roll bar + tabs */
#sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); box-shadow: 0 4px 8px -6px rgba(0, 0, 0, .5); }
#rollbar { padding: 6px 8px 0; display: grid; gap: 4px; }
.rb-row { display: flex; gap: 4px; align-items: center; min-width: 0; }
.seg { display: flex; flex: 1 1 auto; min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg-btn { flex: 1; min-height: calc(var(--tap) - 2px); padding: 0 6px; background: var(--surface); border: 0; border-right: 1px solid var(--line); font-weight: 600; }
.seg-btn:last-child { border-right: 0; }
.seg-btn.on { background: var(--accent); color: var(--accent-text); }
.seg-btn.seg-adv.on { background: var(--good); color: #06150d; }
.seg-btn.seg-dis.on { background: var(--bad); color: #fff; }
.seg-btn:focus-visible { outline-offset: -2px; }
.vis { flex: 0 1 92px; }
.bonus-wrap { display: flex; align-items: center; gap: 4px; flex: none; }
.bonus-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.bonus { width: 64px; }
.bonus.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.free { flex: 1 1 60px; }
.free-error { color: var(--bad); font-size: 12px; }
.free-error:empty { display: none; }

#tabs { padding: 6px 8px; display: grid; gap: 4px; }
.tablist { display: flex; gap: 2px; background: var(--surface); border-radius: var(--radius); padding: 2px; }
.tab { flex: 1 1 0; min-width: 0; min-height: calc(var(--tap) - 4px); padding: 0 2px; background: none; border: 0; border-radius: 5px; font-weight: 600; font-size: 12px; color: var(--text-dim); }
.tab:hover { color: var(--text); }
.tab.on { background: var(--accent); color: var(--accent-text); }
.tools { display: flex; gap: 4px; }
.search { flex: 1; }

/* ---------- sections and rows */
.sec { margin-top: 8px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; border-bottom: 1px solid var(--line); margin-bottom: 2px; padding: 0 2px 2px; }
.sec-head h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); }
.empty { color: var(--text-dim); padding: 8px 2px; }
.caster-line { color: var(--text-dim); padding: 6px 2px 0; font-weight: 600; }
.coins { padding: 4px 2px; font-weight: 600; }

.row { border-bottom: 1px solid color-mix(in srgb, var(--text) 8%, transparent); }
.row.is-hidden, .skill.is-hidden, .roll.is-hidden { opacity: .5; }
.row-main { display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 3px 0; min-width: 0; }
.row-name { flex: 1 1 90px; min-width: 0; min-height: var(--tap); display: flex; flex-direction: column; justify-content: center; text-align: left; background: none; border: 0; padding: 2px 4px; border-radius: 5px; }
button.row-name:hover { background: var(--surface); }
button.row-name[aria-expanded="true"] .row-name-text { color: var(--accent); }
.row-title { display: flex; align-items: center; gap: 4px; min-width: 0; }
.row-name-text { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--text-dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-chips { display: flex; gap: 3px; flex: none; }
.row-rolls { display: flex; flex: 0 1 auto; flex-wrap: wrap; justify-content: flex-end; gap: 4px; min-width: 0; }
.row-desc { padding: 2px 4px 8px; color: var(--text-dim); }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.45; color: var(--text); opacity: .86; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; font-size: 12px; margin-bottom: 4px; }
.meta dt { color: var(--text-dim); }
.meta dd { overflow-wrap: anywhere; color: var(--text); }
.dot-custom { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }

.chip { display: inline-flex; align-items: center; min-height: 18px; padding: 0 6px; border-radius: 999px; border: 1px solid var(--line); font-size: 10.5px; font-weight: 600; white-space: nowrap; color: var(--text-dim); background: none; }
.chip.dc { color: var(--text); }
.chip.crit { color: var(--good); border-color: var(--good); }
.chip.fumble { color: var(--bad); border-color: var(--bad); }
.chip-btn { min-height: var(--tap); min-width: var(--tap); justify-content: center; border-radius: var(--radius); }
.chip-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.roll {
  min-height: var(--tap); min-width: 44px; padding: 2px 8px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: var(--radius);
}
.roll:hover { background: color-mix(in srgb, var(--accent) 32%, transparent); }
.roll:active { transform: translateY(1px); }
.roll-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roll-val { font-weight: 700; font-size: 13px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roll-damage { background: color-mix(in srgb, var(--dmg) 15%, transparent); border-color: color-mix(in srgb, var(--dmg) 55%, transparent); }
.roll-damage:hover { background: color-mix(in srgb, var(--dmg) 30%, transparent); }
.roll-other { background: var(--surface-2); border-color: var(--line); }
body.rolling .roll { cursor: progress; }
.upcast { min-width: 48px; padding: 2px 2px 2px 6px; }
.add-custom { margin-top: 6px; width: 100%; }

/* ---------- stats tab */
.ab-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding-top: 4px; }
.ab { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; display: grid; gap: 3px; min-width: 0; }
.ab-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px; }
.ab-key { font-weight: 700; font-size: 11px; letter-spacing: .06em; color: var(--text-dim); }
.ab-score { font-size: 11px; color: var(--text-dim); }
.ab-check { min-height: 40px; width: 100%; }
.ab-check.static, .ab-save.static { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); }
.ab-mod { font-size: 20px; font-weight: 700; }
.ab-save { flex-direction: row; gap: 5px; width: 100%; background: none; border-color: var(--line); }
.ab-save:hover { background: var(--surface-2); }
.ab-edit { display: flex; gap: 3px; }
.ab-edit .btn { flex: 1; min-width: 0; padding: 0 2px; font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--text-dim); flex: none; }
.dot.on { background: var(--accent); border-color: var(--accent); }
.dot.expert { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--accent); }

.skills { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px 6px; padding-top: 4px; }
.skill { display: flex; gap: 3px; min-width: 0; }
.skill-btn { flex: 1; min-width: 0; flex-direction: row; justify-content: flex-start; gap: 6px; background: none; border-color: transparent; padding: 2px 6px; }
.skill-btn:hover { background: var(--surface-2); border-color: var(--line); }
.skill-name { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.skill-ab { font-size: 10px; color: var(--text-dim); text-transform: uppercase; }
.skill-btn .roll-val { min-width: 24px; text-align: right; }

/* ---------- spells */
.pips { display: flex; align-items: center; gap: 0; flex-wrap: wrap; justify-content: flex-end; }
.pip { width: 24px; height: 28px; padding: 0; background: none; border: 0; display: grid; place-items: center; }
.pip::before { content: ""; width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid var(--text-dim); transform: rotate(45deg) scale(.8); }
.pip.on::before { background: var(--accent); border-color: var(--accent); }
.pip:hover::before { border-color: var(--text); }
.pips-count { font-size: 11px; color: var(--text-dim); min-width: 26px; text-align: right; }

/* ---------- log */
.log-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 2px 4px; }
.log { display: grid; gap: 4px; }
.log-entry { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 5px 8px; min-height: 44px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.log-entry:hover { background: var(--surface-2); }
.log-total { font-size: 20px; font-weight: 700; min-width: 34px; text-align: center; }
.log-entry.crit .log-total { color: var(--good); }
.log-entry.fumble .log-total { color: var(--bad); }
.log-body { display: grid; min-width: 0; flex: 1; }
.log-what { font-weight: 600; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.log-text, .log-who { font-size: 11px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); margin-right: 5px; }

/* ---------- counters */
.counter { display: flex; align-items: center; gap: 2px; }
.counter-val { min-width: 26px; text-align: center; font-weight: 700; font-size: 14px; }

/* ---------- toast */
#toast { position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 20; pointer-events: none; opacity: 0; transform: translateY(8px); transition: opacity .15s, transform .15s; }
#toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast { display: flex; align-items: center; gap: 10px; padding: 8px 6px 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--bg) 82%, var(--text)); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, .45); min-width: 0; }
.toast-total { font-size: 32px; font-weight: 800; line-height: 1; min-width: 44px; text-align: center; }
.toast.crit { border-color: var(--good); }
.toast.crit .toast-total, .toast.crit .toast-flag { color: var(--good); }
.toast.fumble { border-color: var(--bad); }
.toast.fumble .toast-total, .toast.fumble .toast-flag { color: var(--bad); }
.toast.msg.error { border-color: var(--bad); }
.toast-body { flex: 1; min-width: 0; display: grid; gap: 1px; }
.toast-what { font-weight: 700; display: flex; gap: 8px; flex-wrap: wrap; }
.toast-flag { text-transform: uppercase; letter-spacing: .05em; font-size: 11px; align-self: center; }
.toast-text { overflow-wrap: anywhere; }
.toast-note { font-size: 11px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-close { background: none; border-color: transparent; }

/* ---------- forms, dialogs, welcome */
.welcome { padding: 20px 4px; display: grid; gap: 12px; }
.welcome h1 { font-size: 20px; }
.lead { color: var(--text-dim); }
.form { display: grid; gap: 10px; min-width: 0; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span:first-child { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.field small { font-size: 11px; }
.inline { display: flex; gap: 4px; min-width: 0; }
.inline.wrap { flex-wrap: wrap; }
.inline input { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; min-height: var(--tap); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.form-error { color: var(--bad); font-weight: 600; }
.form-error:empty, .form-status:empty { display: none; }
.form-hint { color: var(--text-dim); margin-top: 4px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.fallback { display: grid; gap: 8px; padding: 10px; border: 1px dashed var(--line); border-radius: var(--radius); }
.fallback h3 { font-size: 13px; }
.steps { padding-left: 18px; display: grid; gap: 4px; }

.dlg { width: min(400px, calc(100vw - 16px)); max-height: calc(100vh - 16px); padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); box-shadow: 0 16px 48px rgba(0, 0, 0, .55); overflow: hidden; }
.dlg[open] { display: flex; flex-direction: column; }
.dlg::backdrop { background: rgba(0, 0, 0, .55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-body { padding: 12px; overflow-y: auto; }
.ed-rolls { display: grid; gap: 6px; }
.ed-roll { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; margin: 0; display: grid; gap: 4px; min-width: 0; }
.ed-roll-line { display: flex; gap: 4px; min-width: 0; }
.ed-roll-line > * { min-width: 0; }
.ed-label { flex: 0 1 110px; }
.ed-notation, .ed-roll-line select { flex: 1 1 100px; }
.field-error { color: var(--bad); font-size: 11px; }
.field-error:empty { display: none; }
.char-list { list-style: none; display: grid; gap: 4px; }
.char-list li { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; flex-wrap: wrap; }
.char-list-text { display: grid; min-width: 0; flex: 1 1 140px; }
.char-list-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char-list-actions { display: flex; gap: 4px; }

/* ---------- narrow panels */
@media (max-width: 380px) {
  .skills { grid-template-columns: minmax(0, 1fr); }
  .bonus-label { display: none; }
  .btn.small { padding: 4px 6px; }
  .status { max-width: 86px; }
  .rb-row:first-child { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
