/* ───────────── Базовые токены ───────────── */
:root {
  --scale: 1;
  --bar: #7a2a23;
  --bar-ink: #fff;
  --bg: #f5eedc;
  --panel: #fbf7ec;
  --head: #e6dbbd;
  --field: #ffffff;
  --ink: #2b211b;
  --muted: #7d6f62;
  --line: #a89a85;
  --btn: #dedad3;
  --btn-hover: #cfcac1;
  --accent: #7a2a23;
  --accent-ink: #fff;
  --danger: #a3261b;
  --ok: #2f6b3a;
  --radius: 4px;
  --gap: 0.75rem;
  --shadow: 0 2px 10px rgba(40, 20, 10, .18);
}

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--scale)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.35;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .4rem 0 .8rem; letter-spacing: .02em; }
h2 { font-size: 1.15rem; margin: .8rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.hidden { display: none !important; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.right { margin-left: auto; }

/* ───────────── Поля и кнопки ───────────── */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=number], input:not([type]), select, textarea {
  background: var(--field); border: 1px solid transparent; border-bottom: 1px solid var(--line);
  border-radius: 2px; padding: .45rem .55rem; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(122, 42, 35, .35); outline-offset: 0; }
textarea { resize: vertical; min-height: 3.2rem; }
textarea.auto { overflow: hidden; resize: none; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input.bare { background: transparent; border: 0; border-bottom: 1px solid var(--line); text-align: center; padding: .15rem .2rem; }

button, .btn {
  background: var(--btn); border: 0; border-radius: var(--radius); padding: .4rem .7rem;
  cursor: pointer; line-height: 1.2; text-decoration: none; color: var(--ink); display: inline-flex;
  align-items: center; justify-content: center; gap: .3rem; white-space: nowrap; min-height: 2rem;
  box-shadow: 0 1px 0 rgba(0,0,0,.12);
}
button:hover, .btn:hover { background: var(--btn-hover); }
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.1); }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; box-shadow: none; }
button.sq { width: 2rem; padding: 0; }
button.tiny { min-height: 1.6rem; padding: .15rem .45rem; font-size: .85rem; }

label.lbl, .lbl { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin: .55rem 0 .25rem; color: var(--ink); }

/* Чекбокс в стиле листа */
.cb {
  appearance: none; -webkit-appearance: none; width: 1.3rem; height: 1.3rem; flex: 0 0 auto;
  border: 2px solid #8a7f72; border-radius: 2px; background: #fff; cursor: pointer; display: inline-grid; place-content: center; margin: 0;
}
.cb:checked { background: var(--accent); border-color: var(--accent); }
.cb:checked::after { content: "✓"; color: #fff; font-size: .9rem; line-height: 1; }
.prof { width: 1.3rem; height: 1.3rem; min-height: 0; padding: 0; border: 2px solid #8a7f72; background: #fff; border-radius: 2px; color: #fff; font-size: .8rem; box-shadow: none; flex: 0 0 auto; }
.prof[data-v="1"] { background: var(--accent); border-color: var(--accent); }
.prof[data-v="2"] { background: #3d1612; border-color: #3d1612; }

/* ───────────── Верхняя панель ───────────── */
.topbar {
  position: sticky; top: 0; z-index: 50; background: var(--bar); color: var(--bar-ink);
  display: flex; align-items: stretch; justify-content: space-around; gap: .25rem; padding: 0 .25rem;
  min-height: 3rem; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.topbar button, .topbar a {
  background: transparent; color: var(--bar-ink); box-shadow: none; border-radius: 0; text-transform: uppercase;
  font-size: .82rem; letter-spacing: .03em; padding: .3rem .5rem; text-decoration: none; display: inline-flex;
  align-items: center; gap: .35rem; min-height: 3rem;
}
.topbar button:hover, .topbar a:hover { background: rgba(255,255,255,.12); }
.topbar .ico { font-size: 1.05rem; text-transform: none; }
.topbar .val { opacity: .8; text-transform: none; }
@media (max-width: 560px) { .topbar .txt { display: none; } .topbar .ico { font-size: 1.25rem; } .topbar .wide-only { display: none; } }
@media (min-width: 561px) { .topbar .narrow-only { display: none; } }
.topbar .caret { font-size: .7rem; margin-left: -.25rem; opacity: .8; }
.top-menu { position: fixed; z-index: 60; background: var(--bar); color: var(--bar-ink); display: flex; flex-direction: column; min-width: 11rem; box-shadow: 0 6px 14px rgba(0,0,0,.35); border-radius: 0 0 .5rem .5rem; overflow: hidden; }
.top-menu button { background: transparent; color: var(--bar-ink); box-shadow: none; border-radius: 0; text-align: left; justify-content: flex-start; display: flex; align-items: center; gap: .6rem; padding: .6rem .9rem; min-height: 2.8rem; font-size: .9rem; }
.top-menu button:hover { background: rgba(255,255,255,.12); }
.top-menu button:disabled { opacity: .45; }
.top-menu .ico { width: 1.5rem; text-align: center; }
.top-menu .val { margin-left: auto; opacity: .8; }

.page { max-width: 1500px; margin: 0 auto; padding: .8rem; }

/* ───────────── Карточки секций листа (многоколоночная вёрстка) ───────────── */
.sheet-cols { column-gap: .8rem; column-count: 1; }
.cols-auto .sheet-cols { column-count: 1; }
@media (min-width: 760px)  { .cols-auto .sheet-cols { column-count: 2; } }
@media (min-width: 1250px) { .cols-auto .sheet-cols { column-count: 3; } }
.cols-1 .sheet-cols { column-count: 1; }
.cols-2 .sheet-cols { column-count: 2; }
.cols-3 .sheet-cols { column-count: 3; }
.cols-1 .page { max-width: 820px; }

.card { break-inside: avoid; -webkit-column-break-inside: avoid; display: inline-block; width: 100%; margin: 0 0 .8rem; background: var(--panel); }
.card > h3 {
  margin: 0; background: var(--head); padding: .5rem .7rem; font-size: .95rem; text-transform: uppercase;
  letter-spacing: .04em; cursor: pointer; user-select: none; display: flex; align-items: center; gap: .4rem;
}
.card > h3::before { content: "▾"; font-size: .8rem; transition: transform .15s; }
.card.collapsed > h3::before { transform: rotate(-90deg); }
.card.collapsed > .card-body { display: none; }
.card-body { padding: .3rem .7rem .7rem; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 .5rem; }
.head-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 520px) { .head-grid { grid-template-columns: 1fr; } }

/* Шапка листа */
.sheet-head { margin-bottom: .8rem; }
.stepper { display: inline-flex; align-items: center; gap: .35rem; }
.stepper input { width: 3.2rem; }
.xp-row { display: flex; gap: .35rem; align-items: center; }
.xp-row input { text-align: center; }

/* Характеристики, спасброски, навыки */
.stat-row { display: grid; grid-template-columns: 1fr auto 2.6rem; align-items: center; gap: .4rem; padding: .3rem 0; }
.stat-row .name { font-weight: 600; font-size: .92rem; }
.stat-row .mod, .check-row .tot { text-align: right; font-weight: 700; }
.check-row { display: grid; grid-template-columns: 1.6rem 1fr 3.2rem 2.6rem; align-items: center; gap: .4rem; padding: .35rem 0; }
.check-row .nm { font-size: .9rem; }
.check-row input { text-align: center; padding: .1rem; }
.passive { margin-top: .4rem; font-size: .85rem; }

/* Бой */
.box-field { background: var(--field); }
.death { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; font-size: .85rem; }

/* Изображение */
.portrait {
  background: var(--head); min-height: 11rem; display: grid; place-items: center; cursor: pointer; text-align: center;
  color: var(--ink); padding: .8rem; position: relative;
}
.portrait img { max-width: 100%; max-height: 22rem; display: block; }
.portrait .rm { position: absolute; top: .4rem; right: .4rem; }

/* Списки предметов / заклинаний / черт */
.entries { display: flex; flex-direction: column; gap: 2px; margin: .4rem 0; }
.entry { display: flex; align-items: center; gap: .4rem; background: var(--field); padding: .35rem .4rem; }
.entry .ic { width: 1.4rem; height: 1.4rem; flex: 0 0 auto; color: var(--accent); }
.entry .txt { flex: 1 1 auto; min-width: 0; cursor: pointer; font-size: .88rem; }
.entry .txt b { font-weight: 600; }
.entry .txt .sum { color: var(--muted); }
.entry .txt:hover b { text-decoration: underline; }
.qty { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.qty input { width: 3rem; text-align: center; background: var(--head); border: 0; padding: .3rem .1rem; }
.qty button { width: 1.8rem; padding: 0; }
.entry.zero { opacity: .55; }
.prep { display: inline-flex; align-items: center; gap: .2rem; font-size: .7rem; color: var(--muted); flex: 0 0 auto; }

.wallet { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; }
.wallet .coin { text-align: center; }
.wallet .coin .lbl { margin: .2rem 0; }
.wallet .coin input { text-align: center; padding: .25rem .1rem; }
.wallet .coin .row { justify-content: center; gap: 2px; margin-top: 2px; flex-wrap: nowrap; }
.wallet .coin button { min-height: 1.7rem; width: 1.7rem; padding: 0; }

.slot-head { display: flex; align-items: center; gap: .4rem; margin-top: .8rem; font-weight: 700; font-size: .82rem; text-transform: uppercase; }
.slot-head .slots { margin-left: auto; display: inline-flex; align-items: center; gap: .3rem; }
.slot-head .slots input { width: 2.6rem; text-align: center; padding: .15rem; }

.counter { margin: .5rem 0; }
.counter .row { flex-wrap: nowrap; }
.counter .cval { flex: 1; text-align: center; font-weight: 700; }
.counter .cval input { width: 3.2rem; text-align: center; padding: .1rem; }

/* Автодополнение */
.ac { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: #fff; box-shadow: var(--shadow);
  max-height: 18rem; overflow-y: auto; border: 1px solid var(--line);
}
.ac-list div { padding: .45rem .6rem; cursor: pointer; font-size: .9rem; border-bottom: 1px solid #eee; }
.ac-list div:hover, .ac-list div.on { background: var(--head); }
.ac-list .custom { color: var(--accent); font-weight: 600; }

/* Сохранение */
.savebar { position: sticky; bottom: 0; z-index: 40; padding: .5rem .8rem; background: linear-gradient(transparent, var(--bg) 35%); }
.savebar button { width: 100%; min-height: 3rem; text-transform: uppercase; letter-spacing: .05em; }
.savebar .state { text-align: center; font-size: .75rem; margin-top: .2rem; color: var(--muted); }
.savebar.dirty .state { color: var(--danger); font-weight: 600; }

/* ───────────── Модальные окна ───────────── */
.modal-back {
  position: fixed; inset: 0; background: rgba(30, 15, 10, .45); z-index: 100; display: flex;
  align-items: flex-start; justify-content: center; padding: 4vh .6rem; overflow-y: auto;
}
.modal {
  background: var(--panel); width: 100%; max-width: 640px; box-shadow: var(--shadow); border-radius: 6px;
  display: flex; flex-direction: column; max-height: 92vh;
}
.modal.wide { max-width: 900px; }
.modal-h { background: var(--bar); color: #fff; padding: .6rem .8rem; display: flex; align-items: center; gap: .5rem; border-radius: 6px 6px 0 0; }
.modal-h b { flex: 1; text-transform: uppercase; letter-spacing: .04em; font-size: .9rem; }
.modal-h button { background: transparent; color: #fff; box-shadow: none; font-size: 1.2rem; }
.modal-c { padding: .8rem; overflow-y: auto; }
.modal-f { padding: .6rem .8rem; display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--head); }

.props-edit .prow { display: grid; grid-template-columns: 1fr 2fr 2rem; gap: .35rem; margin-bottom: .3rem; }
.props-view { display: grid; grid-template-columns: auto 1fr; gap: .2rem .8rem; font-size: .9rem; margin: .5rem 0; }
.props-view dt { color: var(--muted); }
.props-view dd { margin: 0; }
.desc { white-space: pre-wrap; font-size: .92rem; }

/* Справочник */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: .6rem; }
.tabs button { box-shadow: none; border-radius: 0; background: var(--head); }
.tabs button.on { background: var(--accent); color: #fff; }
.comp-list { display: flex; flex-direction: column; gap: 2px; }
.comp-list .entry { cursor: pointer; }
.kind-tag { font-size: .68rem; text-transform: uppercase; background: var(--head); padding: .1rem .35rem; border-radius: 3px; color: var(--muted); flex: 0 0 auto; }

/* Кубы */
.dice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr)); gap: .4rem; }
.die { background: #fff; border-radius: 6px; padding: .45rem; text-align: center; box-shadow: 0 1px 0 rgba(0,0,0,.1); }
.die .face { font-weight: 800; font-size: 1.2rem; color: var(--accent); cursor: pointer; user-select: none; display: block; padding: .1rem 0; }
.die .row { justify-content: center; flex-wrap: nowrap; gap: .2rem; }
.die input { width: 2.4rem; text-align: center; padding: .15rem; }
.die.active { outline: 2px solid var(--accent); }
.roll-result { margin-top: .8rem; background: #fff; padding: .7rem; border-radius: 6px; }
.roll-total { font-size: 2rem; font-weight: 800; color: var(--accent); }
.roll-group { margin: .25rem 0; font-size: .92rem; }
.pip { display: inline-block; min-width: 1.9rem; padding: .1rem .3rem; margin: 2px; text-align: center; background: var(--head); border-radius: 4px; font-weight: 600; }
.pip.max { background: #2f6b3a; color: #fff; }
.pip.min { background: var(--danger); color: #fff; }
.history { margin-top: .6rem; font-size: .8rem; color: var(--muted); max-height: 9rem; overflow-y: auto; }

/* Тосты */
.toasts { position: fixed; bottom: 4.5rem; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .4rem; align-items: center; pointer-events: none; }
.toast { background: #2b211b; color: #fff; padding: .55rem .9rem; border-radius: 6px; box-shadow: var(--shadow); font-size: .9rem; max-width: 90vw; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ───────────── Вход ───────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-box { background: var(--panel); width: 100%; max-width: 360px; box-shadow: var(--shadow); border-radius: 6px; overflow: hidden; }
.login-box .modal-h { border-radius: 0; justify-content: center; padding: 1rem; }
.login-box form { padding: 1rem 1.2rem 1.3rem; }
.login-box button { width: 100%; margin-top: 1rem; min-height: 2.6rem; }
.form-error { color: var(--danger); font-size: .88rem; min-height: 1.2rem; margin-top: .5rem; }

/* ───────────── Список листов ───────────── */
.sheet-list { display: flex; flex-direction: column; gap: .5rem; }
.sheet-item { display: flex; align-items: center; gap: .6rem; background: var(--panel); padding: .55rem .6rem; box-shadow: 0 1px 0 rgba(0,0,0,.08); }
.sheet-item .thumb { width: 2.8rem; height: 2.8rem; flex: 0 0 auto; background: var(--head); display: grid; place-items: center; color: var(--accent); font-weight: 800; font-size: 1.2rem; }
.sheet-item .info { flex: 1 1 auto; min-width: 0; }
.sheet-item .info a { font-weight: 700; text-decoration: none; color: var(--ink); font-size: 1.02rem; }
.sheet-item .info a:hover { text-decoration: underline; }
.sheet-item .acts { display: flex; gap: .25rem; flex-wrap: wrap; justify-content: flex-end; }
.sheet-item .acts button { min-width: 2rem; padding: .3rem .45rem; }
@media (max-width: 600px) {
  .sheet-item { flex-wrap: wrap; }
  .sheet-item .acts { width: 100%; justify-content: flex-start; }
}
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }

/* ───────────── Админка ───────────── */
table.tbl { width: 100%; border-collapse: collapse; background: var(--panel); font-size: .9rem; }
table.tbl th, table.tbl td { padding: .45rem .5rem; border-bottom: 1px solid var(--head); text-align: left; vertical-align: middle; }
table.tbl th { background: var(--head); font-size: .75rem; text-transform: uppercase; }
.tbl-wrap { overflow-x: auto; }
.sub-list { background: #fff; padding: .4rem .6rem; }

/* ───────────── Печать ───────────── */
@media print {
  .topbar, .savebar, .toasts, .ac-list, .no-print, button:not(.icon-pick), .top-menu { display: none !important; }
  body { background: #fff; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .card.collapsed > .card-body { display: block; }
  .sheet-cols { column-count: 1 !important; }
  .card, .entry { break-inside: avoid; }
  input, textarea, select { border: 0 !important; }
  .icon-pick { display: inline-flex !important; border: 0 !important; background: none !important; box-shadow: none !important; padding: 0 !important; }
  .portrait img { display: block !important; max-width: 100% !important; max-height: 14rem !important; }
  /* отметки экипировки и подготовки печатаются пустыми — для заполнения от руки */
  input.cb { -webkit-appearance: none; appearance: none; width: .95rem; height: .95rem; border: 1.5px solid #000 !important; border-radius: 2px; background: #fff !important; }
  input.cb::after { content: none !important; }
}
.ic svg { width: 100%; height: 100%; display: block; }

/* ═════════════ v2: язык, комнаты, кошелёк, иконки, отмена/повтор ═════════════ */
.foot { text-align: center; padding: 1.2rem .5rem 1.6rem; }
.lang-flags { display: inline-flex; gap: .3rem; }
.flag-btn { background: transparent; box-shadow: none; border: 1px solid var(--line); padding: .25rem .55rem; min-height: 1.9rem; font-size: .8rem; color: var(--muted); }
.flag-btn.on { border-color: var(--accent); color: var(--ink); background: var(--panel); font-weight: 700; }
.flag { display: inline-block; width: 1.35rem; height: .9rem; line-height: 0; box-shadow: 0 0 0 1px rgba(0,0,0,.15); vertical-align: middle; }
.flag svg { width: 100%; height: 100%; display: block; }
.login-lang { margin-top: 1rem; text-align: center; }
.tabs .flag { margin-right: .2rem; }

/* Отмена / сохранение / повтор */
.save-row { display: flex; gap: .4rem; align-items: stretch; }
.save-row .primary { min-height: 3rem; text-transform: uppercase; letter-spacing: .05em; }
.sq-lg { min-width: 3rem; font-size: 1.3rem; }
.savebar button { width: auto; }
.savebar .save-row .grow { flex: 1; }

/* Только просмотр */
.ro-banner { background: #fff3cd; border-left: 4px solid #c9a227; padding: .5rem .7rem; font-size: .9rem; margin: .3rem 0 .6rem; }
body.readonly .sheet-cols input:disabled, body.readonly .sheet-head input:disabled, body.readonly textarea:disabled, body.readonly select:disabled { color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); }

/* Кошелёк */
.link-lbl { background: none; box-shadow: none; padding: 0; min-height: 0; border-bottom: 1px dashed var(--accent); border-radius: 0; color: var(--accent); }
.wallet .coin-val { width: 100%; background: var(--field); border-bottom: 1px solid var(--line); border-radius: 2px; box-shadow: none; font-size: 1.05rem; min-height: 2.3rem; }
.wallet .coin-val:hover { background: #fff8e8; }
.wallet .coin-val:disabled { opacity: 1; cursor: default; }
.wallet-total { grid-column: 1 / -1; text-align: right; }
table.rate td, table.rate th { text-align: center; }
table.rate td.same { background: var(--head); font-weight: 700; }

/* Окно-модификатор */
.modal.narrow { max-width: 380px; }
.mod-cur { font-size: 2.4rem; font-weight: 800; text-align: center; color: var(--accent); margin: .2rem 0 .6rem; }
.mod-row { justify-content: center; }
.mod-row .big { min-width: 3.2rem; min-height: 3rem; font-size: 1.6rem; font-weight: 700; }
.mod-input { text-align: center; font-size: 1.3rem; }
.mod-prev { text-align: center; min-height: 1.3rem; margin: .3rem 0; font-weight: 600; }

/* Иконки */
.icon-pick { background: transparent; box-shadow: none; padding: 0; min-height: 0; width: 1.6rem; height: 1.6rem; flex: 0 0 auto; }
.icon-pick:hover { background: var(--head); }
.modal .icon-pick { width: 2.6rem; height: 2.6rem; border: 1px solid var(--line); }
.modal .icon-pick .ic { width: 100%; height: 100%; }
.ic img { width: 100%; height: 100%; object-fit: contain; display: block; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(3.2rem, 1fr)); gap: .35rem; }
.icon-cell { width: 100%; aspect-ratio: 1; padding: .3rem; background: #fff; box-shadow: none; border: 2px solid transparent; }
.icon-cell .ic { width: 100%; height: 100%; }
.icon-cell.on { border-color: var(--accent); }
.check-lbl { gap: .35rem; font-size: .9rem; cursor: pointer; }
.flag-tag { display: inline-block; font-size: .66rem; font-weight: 800; background: var(--accent); color: #fff; border-radius: 3px; padding: 0 .3rem; margin-left: .2rem; vertical-align: 1px; }
.ac-info { display: block; font-size: .8rem; color: var(--accent); font-weight: 600; min-height: 0; margin-top: .2rem; }
.ac-info:empty { display: none; }
.big-num { font-weight: 700; font-size: 1.2rem; }
.hint { margin-top: .4rem; }

/* Карточка справочника */
.card-title { margin: .4rem 0 .2rem; font-size: 1.15rem; }
.kind-tag.ed { background: #3d1612; color: #fff; }
.lang-switch { display: inline-flex; gap: 2px; }
.lang-switch .on { background: var(--accent); color: #fff; }
.filters { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .5rem; }
.filters select { width: auto; flex: 1 1 10rem; }

/* Комнаты */
.section-head { margin-top: .4rem; }
.section-head h2 { margin: .4rem 0; }
.pending-badge { color: var(--danger); }
.join-box { background: var(--panel); padding: .6rem .8rem; }
.join-box select { width: auto; flex: 1 1 10rem; }
.room-head h1 { margin-bottom: .2rem; }
.room-code { font-family: Consolas, monospace; font-size: 1.05rem; letter-spacing: .12em; color: var(--accent); }
.room-tools { margin: .8rem 0; }
.pending-box { background: #fff3cd; padding: .5rem .8rem; margin-bottom: .8rem; border-left: 4px solid #c9a227; }
.pending-box h3 { margin: .1rem 0 .4rem; font-size: .95rem; }
.pending-box .row { padding: .25rem 0; }
.room-table { display: flex; flex-direction: column; gap: 2px; margin-bottom: .6rem; }
.room-row { display: grid; align-items: center; gap: .5rem; background: var(--panel); padding: .4rem .5rem; border-left: 4px solid transparent; }
.room-table.master .room-row { grid-template-columns: 1.2rem minmax(8rem, 1fr) 6.5rem 3.4rem 7.6rem auto; }
.room-table.player .room-row { grid-template-columns: 1.2rem 1fr auto; }
.room-th { background: var(--head); font-size: .72rem; text-transform: uppercase; font-weight: 700; }
.room-row.turn { background: #fff1c9; border-left-color: var(--accent); box-shadow: 0 0 0 1px #e2c56c inset; }
.room-row.down { opacity: .55; }
.room-row.mine .name-cell b { color: var(--accent); }
.room-row.t-enemy { border-left-color: #b4483c; }
.room-row.t-ally { border-left-color: #3d7a4a; }
.room-row.turn.t-enemy, .room-row.turn.t-ally { border-left-width: 6px; }
.turn-mark { color: var(--accent); font-weight: 800; }
.name-btn { background: transparent; box-shadow: none; justify-content: flex-start; text-align: left; white-space: normal; padding: .2rem .3rem; flex-wrap: wrap; }
.name-btn:hover { background: rgba(122, 42, 35, .08); }
.type-tag { font-size: .66rem; text-transform: uppercase; background: var(--head); color: var(--muted); padding: .05rem .3rem; border-radius: 3px; }
.t-enemy .type-tag { background: #f3d6d1; color: #8b2a20; }
.t-ally .type-tag { background: #d6ecd9; color: #2f6b3a; }
.you-tag { font-size: .66rem; background: var(--accent); color: #fff; padding: .05rem .35rem; border-radius: 3px; margin-left: .3rem; }
.stat-btn { background: #fff; border: 1px solid var(--line); box-shadow: none; font-weight: 700; min-height: 2rem; width: 100%; }
.stat-btn:hover { background: #fff8e8; border-color: var(--accent); }
.stat-ro { font-weight: 700; text-align: center; }
.init-cell { display: inline-flex; gap: 2px; align-items: center; }
.init-inp { width: 3.4rem; text-align: center; padding: .25rem; }
.row-acts { display: inline-flex; gap: 2px; }
.your-turn { background: var(--accent); color: #fff; font-weight: 800; text-align: center; padding: .6rem; margin-bottom: .6rem; border-radius: 4px; letter-spacing: .05em; text-transform: uppercase; }
@media (max-width: 640px) {
  .room-table.master .room-th { display: none; }
  .room-table.master .room-row { grid-template-columns: 1.2rem 1fr 1fr auto; grid-template-areas: "m n n n" ". hp ac acts" ". init init init"; }
  .room-table.master .room-row > :nth-child(1) { grid-area: m; }
  .room-table.master .room-row > :nth-child(2) { grid-area: n; }
  .room-table.master .room-row > :nth-child(3) { grid-area: hp; }
  .room-table.master .room-row > :nth-child(4) { grid-area: ac; }
  .room-table.master .room-row > :nth-child(5) { grid-area: init; }
  .room-table.master .room-row > :nth-child(6) { grid-area: acts; }
  .room-table.master .stat-btn::before, .room-table.master .stat-ro::before { content: attr(data-label); }
}

/* ═════════════ v3: каталог, связанные карточки, упорядочивание, портрет, ячейки ═════════════ */
.btn-ico { width: 1.15rem; height: 1.15rem; display: block; }
.btn-ico.light { filter: brightness(0) invert(1); }
.icon-btn { background: transparent; box-shadow: none; padding: .2rem; min-height: 2.4rem; min-width: 2.4rem; }
.icon-btn img { width: 1.7rem; height: 1.7rem; display: block; }
.icon-btn:hover { background: var(--head); }

/* Список листов */
.list-head { display: flex; align-items: center; gap: .5rem; }
.list-tools { margin-bottom: .8rem; }
.sheet-item { cursor: pointer; -webkit-touch-callout: none; }
.sheet-item .thumb { overflow: hidden; }
.sheet-item .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet-item .info a.unnamed { font-style: italic; color: var(--muted); }
body.reordering .sheet-item { user-select: none; -webkit-user-select: none; cursor: grab; }
body.reordering main { padding-bottom: 8rem; }
.sheet-item.dragging { position: fixed; z-index: 120; box-shadow: 0 8px 24px rgba(40, 20, 10, .35); opacity: .95; cursor: grabbing; pointer-events: none; }
.sheet-ph { border: 2px dashed var(--line); background: transparent; }
.drag-handle { touch-action: none; cursor: grab; background: transparent; box-shadow: none; font-size: 1.3rem; padding: 0 .2rem; min-width: 1.8rem; }
.reorder-hint { background: #fff3cd; border-left: 4px solid #c9a227; padding: .5rem .7rem; margin-bottom: .7rem; display: flex; gap: .6rem; align-items: center; font-size: .9rem; }
.reorder-hint .tiny { margin-left: auto; }
.drop-zones { position: fixed; left: 0; right: 0; bottom: 0; z-index: 110; display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; padding: .7rem; background: linear-gradient(transparent, var(--bg) 30%); }
.zone { border: 3px dashed; border-radius: 8px; min-height: 4.2rem; display: flex; align-items: center; justify-content: center; gap: .5rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.zone img { width: 1.6rem; height: 1.6rem; }
.zone.archive { background: #fff1b8; border-color: #c9a227; color: #6b5300; }
.zone.delete { background: #f7d2cc; border-color: var(--danger); color: var(--danger); }
.zone.over { transform: scale(1.03); box-shadow: 0 0 0 3px rgba(0,0,0,.08) inset; }
.zone.archive.over { background: #ffe37a; }
.zone.delete.over { background: #eea79c; }
.edition-pick { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.edition-pick button { flex-direction: column; min-height: 4.4rem; gap: .15rem; }
.edition-pick button b { font-size: 1.2rem; }

/* Справочник: строки, бейджи, связанные карточки */
button.entry { width: 100%; text-align: left; justify-content: flex-start; border-radius: 0; box-shadow: none; background: var(--field); white-space: normal; min-height: 0; font-weight: 400; }
button.entry:hover { background: #fff8e8; }
.comp-row .txt { cursor: pointer; }
.comp-row.big { padding: .55rem .6rem; border-left: 3px solid var(--head); }
.comp-row.big .ic { width: 1.8rem; height: 1.8rem; }
.more-btn { width: 100%; margin-top: .5rem; }
.badge { display: inline-block; font-size: .72rem; background: var(--head); color: var(--ink); border-radius: 3px; padding: .12rem .45rem; margin: .15rem .3rem .15rem 0; }
.badge.warn { background: #fde7c4; color: #7a4a00; }
.src-box { margin-top: .8rem; padding-top: .5rem; border-top: 1px solid var(--head); }
.src-line { margin-top: .2rem; }
.related .lbl { margin-top: 1rem; }
.card-title { display: flex; align-items: center; gap: .45rem; }
.card-title .ic { width: 1.6rem; height: 1.6rem; flex: 0 0 auto; }
.desc { white-space: normal; user-select: text; }
.desc p { margin: .35rem 0; }
.desc h4 { margin: .8rem 0 .3rem; font-size: .95rem; color: var(--accent); }
.desc ul { margin: .3rem 0; padding-left: 1.3rem; }
.desc-tbl { font-size: .85rem; margin: .4rem 0; }
.desc-tbl th, .desc-tbl td { padding: .25rem .4rem; }
.ac-list .ac-row { display: flex; align-items: center; gap: .45rem; }
.ac-list .ac-row .ic { width: 1.3rem; height: 1.3rem; flex: 0 0 auto; }
.icon-grid5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; }
.on-outline { outline: 2px solid var(--accent); }
.attr-link { margin-top: .6rem; font-size: .78rem; }
.foot .attr-link { display: inline-block; }

/* Поля каталога в шапке листа */
.cat-field { gap: .25rem; }
.info-btn { background: transparent; box-shadow: none; color: var(--accent); font-size: 1.15rem; }
.info-btn:hover { background: var(--head); }
.xp-row .xp-big { min-width: 3.6rem; font-weight: 700; }
.xp-row input { flex: 1 1 auto; }

/* Ячейки и счётчики */
.slot-val, .cval-btn { background: var(--field); border-bottom: 1px solid var(--line); border-radius: 2px; box-shadow: none; min-width: 4rem; font-weight: 700; }
.slot-val:disabled, .cval-btn:disabled { opacity: 1; }
.counter .cval { display: flex; justify-content: center; }

/* Портрет */
.portrait { padding: .6rem; }
.portrait img { max-width: 100%; max-height: 24rem; aspect-ratio: 1; object-fit: cover; }
.portrait-add { background: transparent; box-shadow: none; white-space: normal; min-height: 9rem; width: 100%; border: 2px dashed var(--line); color: var(--ink); }
.portrait-acts { position: absolute; top: .9rem; right: .9rem; display: flex; gap: .3rem; }
.portrait-acts button { background: rgba(251, 247, 236, .92); }
.portrait-acts button.danger { background: var(--danger); }
.crop-box { display: flex; flex-direction: column; align-items: center; }
.crop-canvas { touch-action: none; cursor: grab; border-radius: 4px; box-shadow: 0 0 0 1px var(--line); background: #ddd; }
.crop-box input[type=range] { flex: 1; }

/* Кубы: кнопка-пиктограмма и к100 двумя к10 */
.die .face { background: transparent; box-shadow: none; width: 100%; min-height: 0; }
.pip.pair { min-width: auto; font-weight: 500; }

/* Сохранение — значок дискеты в верхней панели; точка — есть несохранённые изменения */
.topbar .save-btn { position: relative; }
.topbar .save-btn svg { display: block; }
.topbar .save-btn.dirty::after { content: ""; position: absolute; top: .55rem; right: .3rem; width: .55rem; height: .55rem; border-radius: 50%; background: #ffd34d; box-shadow: 0 0 0 2px var(--bar); }
.topbar button:disabled { opacity: .45; }
/* Список подсказок открывается вверх, если внизу экрана для него нет места */
.ac-list.up { top: auto; bottom: 100%; }
.spell-from { font-size: .72rem; color: var(--muted); font-style: italic; }
