:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel2: #1f2733;
  --ink: #e6e9ef;
  --muted: #8b98ac;
  --accent: #5aa9e6;
  --accent2: #2f7fc4;
  --gold: #c8a951;
  --ok: #3fb950;
  --danger: #e5534b;
  --line: #2a3340;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 400px at 50% -10%, #1a2230 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--ink);
  line-height: 1.5;
}

/* ---------- Layout ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.topbar nav { display: flex; gap: .8rem; align-items: center; }

.container { max-width: 960px; margin: 0 auto; padding: 1rem .8rem 3rem; }

h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h1, h2, h3 { margin: .3rem 0 .6rem; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .8rem; }
.pre { white-space: pre-wrap; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 1rem; margin-bottom: 1rem;
}
.card.narrow { max-width: 380px; margin: 2rem auto; }

.row { display: flex; gap: .5rem; align-items: center; }
.row.spread { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.gap { gap: 1rem; }
.inline { display: inline; margin: 0; }

.panels { display: grid; grid-template-columns: 1fr; gap: .8rem; margin-bottom: 1rem; }
.grid3 { display: grid; grid-template-columns: 1fr; gap: .5rem; }
.grid5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; }

/* ---------- Forms ---------- */
label { display: block; margin: .5rem 0; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  width: 100%; margin-top: .2rem; padding: .55rem .6rem;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink); font: inherit;
}
input[type="checkbox"] { width: auto; transform: scale(1.2); }
input[type="file"] { padding: .4rem; }
label.tiny input { width: 5rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 1rem 0; padding: .6rem .8rem; }
legend { color: var(--gold); padding: 0 .4rem; font-size: .85rem; }
.icon-preview { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }

/* ---------- Buttons ---------- */
button, .button {
  display: inline-block; cursor: pointer; text-decoration: none; text-align: center;
  padding: .6rem 1rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); font: inherit; min-height: 42px;
}
button:hover, .button:hover { border-color: var(--accent); }
button:active, .button:active { transform: translateY(1px); }
.primary { background: var(--accent2); border-color: var(--accent); color: #fff; }
.ok { background: var(--ok); border-color: var(--ok); color: #06210f; }
.danger { background: var(--danger); border-color: var(--danger); color: #2a0606; }
.link { background: none; border: none; color: var(--accent); padding: 0; min-height: auto; }

.hp-big { font-size: 1.6rem; font-weight: 700; margin: .2rem 0 .6rem; }
.temp { font-size: .9rem; color: var(--ok); font-weight: 500; }

button.small, .button.small { padding: .35rem .7rem; min-height: 34px; font-size: .85rem; }

/* icon-only buttons (header) */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; min-height: 40px; padding: 0; font-size: 1.15rem;
  border-radius: 8px; text-decoration: none;
}

/* equipped state */
.qty-btn.on { background: var(--accent2); border-color: var(--accent); }
.ability.equipped .tile { border-color: var(--ok); box-shadow: 0 0 10px rgba(63,185,80,.5), 0 0 0 1px #000 inset; }
.equip-mark {
  position: absolute; top: 3px; right: 3px; z-index: 2;
  background: var(--ok); color: #06210f; font-weight: 800; font-size: .72rem;
  border-radius: 50%; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  border: 1px solid #06210f;
}
.equip-line { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin-top: .2rem; }
.equip-chip { font-size: .72rem; background: var(--panel2); border: 1px solid var(--ok); color: var(--ok); border-radius: 999px; padding: .1rem .5rem; }
.equip-chip.abil { border-color: var(--accent); color: var(--accent); }

/* death saves */
.stat.dying { color: var(--danger); }
.death-saves { display: flex; flex-direction: column; gap: .35rem; margin: .4rem 0 .2rem;
  padding: .5rem; border: 1px solid var(--danger); border-radius: 8px; background: rgba(229,83,75,.08); }
.death-row { display: flex; align-items: center; gap: .35rem; }
.death-label { font-size: .8rem; font-weight: 700; min-width: 3.5rem; }
.death-label.ok { color: var(--ok); }
.death-label.danger { color: var(--danger); }
.pip { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ok); display: inline-block; }
.pip.on { background: var(--ok); }
.pip.fail { border-color: var(--danger); }
.pip.fail.on { background: var(--danger); }

/* slot pools by level */
.slots-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.slot-lvl { font-size: .85rem; background: var(--panel2); border: 1px solid var(--accent2); border-radius: 8px; padding: .15rem .5rem; }
.slot-lvl b { color: var(--gold); }

/* damage roll button on ability card */
.use-btn.dmg { background: var(--panel2); border-color: var(--gold); color: var(--gold); font-weight: 600; }

/* drag-reorder */
.abilities-grid.reorder [data-id] { cursor: grab; }
.sortable-ghost { opacity: .4; }
.sortable-chosen .tile { box-shadow: 0 0 12px rgba(200,169,81,.7); }

/* action log */
.log-list { list-style: none; padding: 0; margin: 0; max-height: 260px; overflow: auto; }
.log-item { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); font-size: .82rem; }
.log-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-time { color: var(--muted); flex: none; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; top: .8rem; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: .5rem;
  width: max-content; max-width: 90vw; pointer-events: none;
}
.toast {
  background: var(--panel2); color: var(--ink);
  border: 1px solid var(--accent2); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: .6rem 1rem; box-shadow: 0 6px 18px rgba(0,0,0,.5);
  opacity: 0; transform: translateY(-10px); transition: opacity .3s, transform .3s;
  font-weight: 600;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.roll { border-left-color: var(--gold); }
.toast.crit { border-left-color: var(--ok); }
.toast.fail { border-left-color: var(--danger); }

/* ---------- Two-column layout ---------- */
.layout { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
.main { min-width: 0; }
.side { display: flex; flex-direction: column; gap: 1rem; }
@media (min-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .side { position: sticky; top: 4rem; }
}

/* ---------- Info tooltips ---------- */
.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; cursor: help;
  background: var(--panel2); border: 1px solid var(--accent2); color: var(--accent);
  font-size: .72rem; font-weight: 800; font-style: normal; vertical-align: middle;
  position: relative;
}
.info[data-tip]:hover::after, .info[data-tip]:focus::after,
.ac-badge[data-tip]:hover::after, .ac-badge[data-tip]:focus::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
  width: max-content; max-width: 240px; white-space: normal; text-align: left;
  background: #0b0f14; color: var(--ink); border: 1px solid var(--accent2);
  border-radius: 8px; padding: .5rem .65rem; font-size: .78rem; font-weight: 500;
  line-height: 1.4; box-shadow: 0 6px 18px rgba(0,0,0,.6);
}
.ac-badge { position: relative; cursor: help; }

/* ---------- Memory search ---------- */
.mem-search { margin-bottom: .6rem; }
.mem-results { display: flex; flex-direction: column; gap: .3rem; max-height: 320px; overflow: auto; }
.mem-line {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: .35rem .55rem; font-size: .88rem; white-space: pre-wrap;
}
.mem-line mark { background: var(--gold); color: #1a1a1a; border-radius: 3px; padding: 0 2px; }

/* ---------- Compact panels ---------- */
.card.mini { padding: .7rem .8rem; }
.dice-out { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.stat-line { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.stat { font-size: 1.15rem; font-weight: 700; }
.stat b { color: var(--gold); font-weight: 800; margin-right: .15rem; }
.row.tight { gap: .3rem; margin-bottom: .35rem; }
.ac-badge {
  font-size: 1.05rem; font-weight: 800; color: var(--accent);
  background: var(--panel2); border: 1px solid var(--accent2);
  border-radius: 8px; padding: .1rem .5rem;
}
.chip {
  padding: .3rem .6rem; min-height: 32px; font-size: .8rem; border-radius: 999px;
  background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
}
.chip.on { background: var(--accent2); color: #fff; border-color: var(--accent); }
.more { margin-top: .3rem; }
.more > summary { cursor: pointer; color: var(--muted); font-size: .8rem; list-style: none; }
.more > summary::before { content: "▸ "; }
.more[open] > summary::before { content: "▾ "; }

/* ---------- Money (compact colored coins) ---------- */
.coins { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.coin { display: flex; align-items: center; gap: .2rem; margin: 0; }
.coin-dot {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: .52rem; font-weight: 800; color: #1a1a1a;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.4);
}
.coin input { width: 3rem; margin: 0; padding: .3rem .35rem; }
.c-pp .coin-dot { background: linear-gradient(145deg, #eef3f8, #c3ccd6); }
.c-gp .coin-dot { background: linear-gradient(145deg, #f2d675, #c8a300); }
.c-ep .coin-dot { background: linear-gradient(145deg, #cfd18a, #9fa544); }
.c-sp .coin-dot { background: linear-gradient(145deg, #d7dde3, #9aa4ae); }
.c-cp .coin-dot { background: linear-gradient(145deg, #d99a63, #a5591f); }

/* ---------- Dice ---------- */
.dice-total { font-size: 1rem; display: inline-flex; align-items: center; gap: .4rem; }
.dice-total b { color: var(--gold); font-size: 1.3rem; }
#dice-seq { font-size: .9rem; }
.dice-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.dice-btn {
  flex: 1 1 auto; min-width: 44px; font-weight: 700; padding: .4rem .5rem; min-height: 38px;
  background: linear-gradient(160deg, #263241, #141a22); border-color: var(--accent2);
}
.dice-btn:hover { border-color: var(--gold); box-shadow: 0 0 8px rgba(200,169,81,.4); }

/* ---------- Inventory ---------- */
.inv-list { list-style: none; padding: 0; margin: 0; }
.inv-item {
  display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  flex-wrap: wrap; padding: .6rem .2rem; border-bottom: 1px solid var(--line);
}
.inv-main { min-width: 40%; }
.inv-controls { display: flex; align-items: center; justify-content: center; gap: .25rem; flex-wrap: wrap; margin-top: .3rem; }
.qty-btn { min-height: 32px; min-width: 32px; padding: .15rem .4rem; font-weight: 700; font-size: 1rem; }
.qty { min-width: 2rem; text-align: center; font-weight: 700; font-size: 1.05rem; }
.ability .button.small { padding: .25rem .5rem; min-height: 32px; }

/* ---------- Memory ---------- */
.memory-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.memory-grid h3 { font-size: 1rem; margin: .2rem 0 .4rem; }
@media (min-width: 640px) { .memory-grid { grid-template-columns: 1fr 1fr; } }

.char-list { list-style: none; padding: 0; }
.char-list li a { display: flex; justify-content: space-between; padding: .9rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; text-decoration: none; color: var(--ink); }

/* ---------- Ability tiles (Dota-style) ---------- */
.abilities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: .8rem;
}
.ability {
  display: flex; flex-direction: column; align-items: center; text-align: center;
}

.tile {
  position: relative; width: 84px; height: 84px; border-radius: 10px;
  overflow: hidden; cursor: pointer; user-select: none;
  background: linear-gradient(160deg, #263241, #141a22);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 1px #000 inset, 0 3px 8px rgba(0,0,0,.5);
  transition: transform .08s, box-shadow .12s, filter .2s;
}
.tile:hover { box-shadow: 0 0 10px rgba(200,169,81,.6), 0 3px 8px rgba(0,0,0,.5); }
.tile:active { transform: scale(.96); }
.tile-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-fallback {
  display: flex; align-items: center; justify-content: center; height: 100%;
  font-size: 1.6rem; font-weight: 800; color: var(--gold); letter-spacing: 1px;
}

/* add (+) tile */
.add-tile { text-decoration: none; color: inherit; }
.tile.add {
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--accent2); background: var(--panel2); box-shadow: none;
}
.tile.add:hover { border-color: var(--accent); box-shadow: 0 0 10px rgba(90,169,230,.4); }
.tile.add .plus { font-size: 2.6rem; font-weight: 300; color: var(--accent); line-height: 1; }

/* blocked = on cooldown look */
.tile.blocked { cursor: not-allowed; border-color: #4a4033; }
.tile.blocked .tile-img,
.tile.blocked .tile-fallback { filter: grayscale(1) brightness(.5); }
.cooldown {
  position: absolute; inset: 0; background: rgba(6,10,16,.55);
  display: flex; align-items: center; justify-content: center;
}
.cd-x { color: var(--danger); font-size: 1.8rem; font-weight: 800; text-shadow: 0 1px 3px #000; }

/* badges */
.badge {
  position: absolute; min-width: 20px; padding: 1px 5px; font-size: .78rem; font-weight: 700;
  border-radius: 6px; line-height: 1.3; text-shadow: 0 1px 2px #000;
}
.badge.slot { top: 3px; left: 3px; background: rgba(20,26,34,.85); color: var(--gold); border: 1px solid var(--gold); }
.badge.charges { bottom: 3px; right: 3px; background: var(--accent2); color: #fff; border: 1px solid #0a1420; }

/* used flash + check */
.use-check {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--ok); font-size: 2.2rem; font-weight: 800; text-shadow: 0 1px 4px #000;
  animation: fadeCheck 1s ease forwards;
}
@keyframes fadeCheck {
  0% { opacity: 0; transform: scale(.6); }
  25% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.1); }
}
.used-flash .tile { animation: flashTile .5s ease; }
@keyframes flashTile {
  0% { box-shadow: 0 0 0 2px #fff, 0 0 18px #fff; }
  100% { box-shadow: 0 0 0 1px #000 inset, 0 3px 8px rgba(0,0,0,.5); }
}

.tile-name { margin-top: .35rem; font-size: .82rem; font-weight: 600; max-width: 96px; }
.tags { list-style: none; padding: 0; margin: .35rem 0 0; display: flex; flex-wrap: wrap; gap: .25rem; justify-content: center; }
.tag { font-size: .68rem; background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: .1rem .45rem; }
.tag.consume { border-color: var(--gold); color: var(--gold); }
.use-error { color: var(--danger); font-size: .75rem; margin: .3rem 0 0; max-width: 130px; }
.edit-link { font-size: .72rem; margin-top: .25rem; opacity: .8; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
table.items th, table.items td, .req-table th, .req-table td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); font-size: .9rem; }

.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--line); }

/* ---------- Wider screens ---------- */
@media (min-width: 640px) {
  .container { padding: 1.25rem; }
  h1 { font-size: 1.7rem; }
  .panels { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .grid3 { grid-template-columns: repeat(3, 1fr); }
  .tile { width: 92px; height: 92px; }
}
