/**
 * Стили экрана забега.
 * Единый стиль прокрутки: класс .cm-scroll-wood (инвентарь, эффекты, скиллы).
 */

:root {
  --wood-deep: #1e1410;
  --wood-panel: #2d2118;
  --wood-mid: #3d2c22;
  --wood-light: #4a3628;
  --wood-grain: rgba(0, 0, 0, 0.18);
  --bronze-dark: #5c4518;
  --bronze: #8b6914;
  --bronze-bright: #c4a35a;
  --gold: #e8d4a8;
  --gold-dim: #a89870;
  --text: #f2e6d4;
  --text-muted: #b9a48c;
  --hp: #c42b2b;
  --hp-track: #3a1818;
  --mana: #2b6fc4;
  --mana-track: #152a45;
  --xp: #7b3fc9;
  --xp-track: #2a1845;
  --log-loot: #e8c84a;
  --log-good: #6ecf7a;
  --log-bad: #e85a5a;
  --log-info: #6ab8e8;
  --slot-inner: #1a120e;
  --shadow-inset: inset 0 2px 8px rgba(0, 0, 0, 0.45);
  --radius-panel: 6px;
  --font-ui: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-panel-title: "Cinzel", "Palatino Linotype", Palatino, Georgia, serif;
  /* Лёгкое зерно поверх панелей (SVG noise) */
  --wood-noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.12'/%3E%3C/svg%3E");
  --inv-cell: 64px;
  --inv-gap: 6px;
  --inv-cols: 4;
  /* Высота области прокрутки: число видимых рядов без изменений */
  --inv-visible-rows: 4;
  --inv-viewport-height: calc(
    var(--inv-visible-rows) * var(--inv-cell) + (var(--inv-visible-rows) - 1) * var(--inv-gap)
  );
  /* Горизонтальный зазор между сеткой и полосой прокрутки (ширина колонки учитывает это) */
  --inv-scrollbar-h-gap: 10px;
  /* Экипировка: квадратный слот, сторона = бывший max-height слота */
  --equip-slot-size: 72px;
  /* Два блока эффекта по умолчанию без скролла (высота вьюпорта ≈ 2 карточки + зазор) */
  --effect-card-min: 58px;
  --effects-viewport-max: calc(2 * var(--effect-card-min) + var(--cm-gap-sub));
  --skills-visible-default: 3;
  --skills-row-height: 31px;
  /* Единые отступы макета */
  --cm-pad: 10px;
  --cm-gap: 10px;
  --cm-gap-sub: 8px;
  --cm-gap-xs: 4px;
  --cm-scroll-gutter: 6px;
  /* Правая колонка: 5 колонок инвентаря + зазор под скролл + паддинги .cm-panel__body + рамка панели */
  --cm-right-col: calc(
    var(--inv-cols) * var(--inv-cell) + (var(--inv-cols) - 1) * var(--inv-gap) + 2 * var(--cm-pad) + 4px + var(--inv-scrollbar-h-gap)
  );
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background-color: var(--wood-deep);
  background-image: radial-gradient(ellipse 120% 80% at 50% 0%, #3a2820 0%, transparent 55%), var(--wood-noise);
  background-size: auto, 180px 180px;
  min-height: 100vh;
  overflow-x: auto;
}

/* Экран забега: без вертикального скролла документа — приложение + футер = высота вьюпорта */
html:has(.cm-app--game),
body:has(.cm-app--game) {
  height: 100%;
  overflow-y: hidden;
}

body:has(.cm-app--game) #app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* --- Единый стиль скролла (дерево / бронза) --- */
.cm-scroll-wood {
  scrollbar-width: thin;
  scrollbar-color: var(--bronze-bright) var(--wood-deep);
}

.cm-scroll-wood::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.cm-scroll-wood::-webkit-scrollbar-track {
  background: linear-gradient(90deg, var(--wood-deep), #120d0a);
  border-radius: 5px;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.65);
  border: 1px solid #0d0806;
}

.cm-scroll-wood::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #d4c090, var(--bronze-dark));
  border-radius: 5px;
  border: 1px solid #0d0806;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.cm-scroll-wood::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--gold), var(--bronze));
}

.cm-scroll-wood::-webkit-scrollbar-corner {
  background: var(--wood-deep);
}

/* --- Деревянная панель с бронзовой рамкой и «заклёпками» --- */
.cm-panel {
  position: relative;
  background-color: var(--wood-panel);
  background-image: linear-gradient(165deg, rgba(255, 255, 255, 0.04) 0%, transparent 40%),
    linear-gradient(90deg, var(--wood-mid) 0%, var(--wood-panel) 50%, var(--wood-mid) 100%), var(--wood-noise);
  background-size: auto, auto, 160px 160px;
  border: 2px solid var(--bronze);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-inset), 0 4px 18px rgba(0, 0, 0, 0.5);
}

.cm-panel::before {
  content: "";
  position: absolute;
  inset: var(--cm-gap-xs);
  border: 1px solid rgba(196, 163, 90, 0.25);
  border-radius: calc(var(--radius-panel) - 3px);
  pointer-events: none;
}

.cm-rivet {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #d4c090, #5c4518 70%);
  box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.15);
  z-index: 2;
}

.cm-rivet--tl {
  top: var(--cm-gap-xs);
  left: var(--cm-gap-xs);
}
.cm-rivet--tr {
  top: var(--cm-gap-xs);
  right: var(--cm-gap-xs);
}
.cm-rivet--bl {
  bottom: var(--cm-gap-xs);
  left: var(--cm-gap-xs);
}
.cm-rivet--br {
  bottom: var(--cm-gap-xs);
  right: var(--cm-gap-xs);
}

/* Заголовок без margin снизу: иначе он суммируется с padding-top у .cm-panel__body и зазор под шапкой больше, чем снизу у контента */
.cm-panel__title {
  margin: 0;
  padding: var(--cm-gap-sub) var(--cm-pad);
  font-family: var(--font-panel-title);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
  text-shadow: 0 1px 3px #000, 0 0 12px rgba(196, 163, 90, 0.15);
  background: linear-gradient(180deg, rgba(139, 105, 20, 0.45), rgba(0, 0, 0, 0.35));
  border: 1px solid var(--bronze-dark);
  border-radius: 4px;
}

.cm-panel--collapsible > .cm-panel__title {
  cursor: pointer;
}

.cm-panel--collapsible > .cm-panel__title:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.cm-panel--collapsed > .cm-panel__body {
  display: none;
}

.cm-panel__title::before,
.cm-panel__title::after {
  content: "·";
  opacity: 0.65;
  font-weight: 700;
  margin: 0 0.4em;
  color: var(--bronze-bright);
}

/* --- Корневой лейаут --- */
.cm-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--cm-gap);
  gap: var(--cm-gap);
}

.cm-app.cm-app--game {
  flex: 1;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

.cm-main {
  display: grid;
  grid-template-columns: minmax(240px, 280px) minmax(320px, 1fr) minmax(var(--cm-right-col), var(--cm-right-col));
  gap: var(--cm-gap);
  flex: 1;
  align-items: stretch;
  min-height: 0;
}

/* Футер метаданных: одинаково на welcome / забеге / экране итогов */
.cm-meta-footer {
  container-type: size;
  flex-shrink: 0;
  align-self: stretch;
  width: 100%;
  max-width: none;
  height: 52px;
  min-height: 52px;
  max-height: 52px;
  margin-top: 0;
  padding: 5px 10px;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: flex-end;
  gap: 14px;
  overflow: hidden;
  border: 1px solid rgba(196, 163, 90, 0.35);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(22, 15, 11, 0.7), rgba(15, 10, 8, 0.78));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.cm-meta-footer__brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-right: auto;
  padding-right: 8px;
  font-family: var(--font-panel-title);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 1px 3px #000, 0 0 12px rgba(196, 163, 90, 0.15);
  font-size: clamp(14px, min(68cqh, 11cqw), 38px);
}

.cm-meta-footer__meta {
  flex: 0 1 auto;
  max-width: min(460px, 55%);
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  text-align: right;
}

.cm-meta-footer__line {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  font-size: 10px;
  line-height: 1.25;
  flex-shrink: 0;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cm-meta-footer__label {
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.cm-meta-footer__value {
  color: var(--gold);
  font-weight: 600;
}

.cm-meta-footer__note {
  flex-shrink: 1;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  font-size: 9px;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

@media (max-width: 1100px) {
  .cm-main {
    grid-template-columns: 1fr;
  }

  .cm-col--center {
    order: -1;
  }

  .cm-col--left {
    order: 0;
  }

  .cm-col--right {
    order: 1;
  }

  .cm-meta-footer {
    align-self: stretch;
    text-align: left;
  }

  .cm-meta-footer__line {
    justify-content: flex-start;
  }

  .cm-meta-footer__meta {
    text-align: left;
    max-width: none;
  }
}

.cm-col {
  display: flex;
  flex-direction: column;
  gap: var(--cm-gap);
  min-height: 0;
}

/* Левая колонка на всю высоту строки сетки */
.cm-col--left {
  height: 100%;
  min-height: 0;
}

/* Панель «Герой» забирает свободную высоту колонки; тело растягивается под фон «дерева» */
.cm-col--left > .cm-panel.cm-panel--hero {
  flex: 1 1 auto;
  min-height: 0;
}

.cm-panel--hero .cm-panel__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.cm-col--center {
  min-height: 420px;
}

.cm-col--right {
  height: 100%;
  min-height: 0;
}

/* --- Портрет --- */
.cm-hero-portrait {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--cm-gap-sub);
  margin-bottom: calc(var(--cm-gap-sub) + 12px);
}

.cm-portrait-ring {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  padding: var(--cm-gap-xs);
  background: linear-gradient(145deg, var(--bronze-bright), var(--bronze-dark));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.cm-portrait-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  background: var(--slot-inner);
  border: 2px solid #0d0806;
}

.cm-portrait-inner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cm-level-badge {
  position: absolute;
  left: 50%;
  bottom: -12px;
  transform: translateX(-50%);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  background: radial-gradient(circle at 35% 30%, #6f553f, #2a1e16 72%);
  border: 2px solid var(--bronze);
  border-radius: 50%;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 2px 6px rgba(0, 0, 0, 0.55);
  z-index: 2;
}

/* --- Полосы ресурсов --- */
.cm-bar {
  margin-bottom: var(--cm-gap-sub);
}

.cm-bar:last-child {
  margin-bottom: 0;
}

.cm-bar__row {
  display: flex;
  align-items: center;
  gap: var(--cm-gap-sub);
}

.cm-bar__icon-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  align-self: center;
}

.cm-bar__icon {
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}

.cm-bar__content {
  flex: 1;
  min-width: 0;
}

.cm-bar__label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--cm-gap-xs);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold-dim);
  font-family: var(--font-ui);
}

.cm-bar__track {
  height: 14px;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid #0d0806;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}

.cm-bar__fill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent 45%);
  transition: width 0.2s ease;
}

.cm-bar--hp .cm-bar__track {
  background: var(--hp-track);
}
.cm-bar--hp .cm-bar__fill {
  background: linear-gradient(180deg, #ff6b6b, var(--hp));
}

.cm-bar--mana .cm-bar__track {
  background: var(--mana-track);
}
.cm-bar--mana .cm-bar__fill {
  background: linear-gradient(180deg, #6ab0ff, var(--mana));
}

.cm-bar--xp .cm-bar__track {
  background: var(--xp-track);
}
.cm-bar--xp .cm-bar__fill {
  background: linear-gradient(180deg, #c090ff, var(--xp));
}

/* --- Статы с плюсом --- */
.cm-stats {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cm-stat-row {
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  align-items: center;
  gap: var(--cm-gap-sub);
  padding: var(--cm-gap-xs) 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
}

.cm-stat-row:last-child {
  border-bottom: 0;
}

.cm-stat-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  opacity: 0.9;
}

.cm-stat-name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.cm-stat-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
  min-width: 2ch;
  text-align: right;
}

.cm-stat-plus {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--bronze-dark);
  border-radius: 4px;
  background: linear-gradient(180deg, #5c4834, #35261c);
  color: var(--gold);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 2px 4px rgba(0, 0, 0, 0.35);
}

.cm-stat-plus:hover:not(:disabled) {
  background: linear-gradient(180deg, #6d5640, #3d2c22);
  border-color: var(--bronze-bright);
  color: #fff;
}

.cm-stat-plus:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.cm-stat-plus:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

/* --- Эффекты: по умолчанию ровно 2 карточки по высоте, далее скролл --- */
.cm-effects-viewport {
  max-height: var(--effects-viewport-max);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: var(--cm-scroll-gutter);
}

.cm-effects {
  display: flex;
  flex-direction: column;
  gap: var(--cm-gap-sub);
}

.cm-effect {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: var(--cm-gap-sub);
  padding: var(--cm-gap-sub) var(--cm-pad);
  min-height: var(--effect-card-min);
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(139, 105, 20, 0.35);
  border-radius: 4px;
}

.cm-effect__icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: var(--slot-inner);
  border-radius: 4px;
  border: 1px solid var(--bronze-dark);
}

.cm-effect__name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold);
}

.cm-effect__main {
  min-width: 0;
}

.cm-effect__desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: var(--cm-gap-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-effect__turns {
  align-self: center;
  justify-self: end;
  min-width: 28px;
  padding: 3px 6px;
  border: 1px solid rgba(196, 163, 90, 0.45);
  border-radius: 999px;
  background: rgba(16, 11, 8, 0.72);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  text-align: center;
  line-height: 1;
}

/* --- Экипировка (правая колонка) --- */
.cm-equip-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--cm-gap-sub);
}

.cm-equip-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--cm-gap-xs);
}

.cm-equip-slot__label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold-dim);
}

.cm-equip-slot__box {
  width: var(--equip-slot-size);
  height: var(--equip-slot-size);
  min-width: var(--equip-slot-size);
  min-height: var(--equip-slot-size);
  max-width: var(--equip-slot-size);
  max-height: var(--equip-slot-size);
  aspect-ratio: 1;
  box-sizing: border-box;
  align-self: center;
  flex-shrink: 0;
  background: var(--slot-inner);
  border: 2px solid var(--bronze-dark);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: var(--shadow-inset);
  font-size: 10px;
  text-align: center;
  color: var(--text-muted);
  overflow: hidden;
}

.cm-equip-slot__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
  margin-bottom: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
  width: 100%;
  height: 100%;
}

.cm-equip-slot__bonus {
  font-size: 10px;
  color: #6ab8e8;
  font-weight: 600;
}

/* --- Центр: фаза + поле --- */
.cm-center-stack {
  display: flex;
  flex-direction: column;
  gap: var(--cm-gap);
  height: 100%;
}

.cm-phase {
  padding: var(--cm-gap-sub) calc(var(--cm-pad) * 2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  background: linear-gradient(180deg, rgba(74, 56, 40, 0.95), rgba(30, 20, 16, 0.98));
  border: 2px solid var(--bronze);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Плашка фазы хода — внутри игрового поля, правый верхний угол */
.cm-phase--field {
  position: absolute;
  top: var(--cm-pad);
  right: var(--cm-pad);
  z-index: 3;
  max-width: calc(100% - 2 * var(--cm-pad));
  text-align: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.cm-phase--skip-turn {
  cursor: pointer;
}

.cm-phase__hover {
  display: none;
}

.cm-phase--skip-turn:hover .cm-phase__default,
.cm-phase--skip-turn:focus-visible .cm-phase__default {
  display: none;
}

.cm-phase--skip-turn:hover .cm-phase__hover,
.cm-phase--skip-turn:focus-visible .cm-phase__hover {
  display: inline;
}

.cm-field {
  position: relative;
  flex: 1;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: repeating-linear-gradient(
      90deg,
      transparent,
      transparent 48px,
      var(--wood-grain) 48px,
      var(--wood-grain) 49px
    ),
    linear-gradient(180deg, #241a14 0%, #120d0a 100%);
  border: 3px solid var(--bronze);
  border-radius: var(--radius-panel);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.65);
}

.cm-field__main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.cm-field__placeholder {
  text-align: center;
  padding: calc(var(--cm-pad) * 2);
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  max-width: 280px;
  line-height: 1.5;
}

.cm-field__placeholder span {
  display: block;
  margin-top: var(--cm-gap-sub);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: none;
  opacity: 0.85;
}

/* --- Инвентарь: 5 колонок, строки по числу предметов, вертикальный скролл --- */
.cm-inv-wrap {
  max-height: var(--inv-viewport-height);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  padding-right: var(--cm-scroll-gutter);
  padding-bottom: var(--cm-gap-xs);
}

.cm-col--right .cm-panel--inventory {
  flex: 1 1 auto;
  min-height: 0;
}

.cm-col--right .cm-panel--inventory .cm-panel__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.cm-col--right .cm-panel--inventory .cm-inv-wrap {
  flex: 1;
  min-height: calc(var(--inv-cell) * 2 + var(--inv-gap));
  max-height: none;
}

.cm-col--right .cm-panel--skills {
  flex: 0 0 auto;
}

.cm-col--right .cm-panel--skills .cm-panel__body {
  flex: 0 0 auto;
}

.cm-col--right .cm-panel--skills .cm-skills-viewport {
  flex: 0 0 auto;
  min-height: 0;
  max-height: calc(
    var(--skills-visible-default) * var(--skills-row-height) + (var(--skills-visible-default) - 1) * var(--cm-gap-xs)
  );
}

.cm-inv-grid {
  display: grid;
  grid-template-columns: repeat(var(--inv-cols), var(--inv-cell));
  grid-auto-rows: var(--inv-cell);
  gap: var(--inv-gap);
  width: calc(
    var(--inv-cols) * var(--inv-cell) + (var(--inv-cols) - 1) * var(--inv-gap)
  );
}

.cm-inv-cell {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.04), transparent 55%), var(--slot-inner);
  border: 2px solid var(--bronze-dark);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: var(--shadow-inset), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.cm-sprite-stack {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.cm-sprite-stack__frame,
.cm-sprite-stack__body,
.cm-sprite-stack__skill {
  position: absolute;
  display: block;
  image-rendering: pixelated;
}

.cm-sprite-stack--item .cm-sprite-stack__frame {
  inset: 0;
  width: 100%;
  height: 100%;
}

.cm-sprite-stack--item .cm-sprite-stack__body {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
}

.cm-sprite-stack--skill .cm-sprite-stack__skill {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 72%;
  height: 72%;
}

.cm-sprite-fallback {
  font-size: 1em;
  line-height: 1;
}

.cm-sprite-stack img + .cm-sprite-fallback {
  opacity: 0;
  pointer-events: none;
}

.cm-inv-cell__qty {
  position: absolute;
  right: var(--cm-gap-xs);
  bottom: 1px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 1px 2px #000;
}

/* --- Расходники: одна строка ячеек, стиль как инвентарь --- */
.cm-cons-wrap {
  max-height: calc(var(--inv-cell) + var(--cm-gap) + var(--cm-gap-xs));
  overflow-x: auto;
  overflow-y: hidden;
  width: calc(var(--inv-cols) * var(--inv-cell) + (var(--inv-cols) - 1) * var(--inv-gap));
  max-width: 100%;
  padding-bottom: var(--cm-gap-xs);
  padding-right: var(--cm-scroll-gutter);
}

.cm-cons-row {
  display: flex;
  flex-direction: row;
  gap: var(--inv-gap);
  width: max-content;
}

.cm-cons-row .cm-inv-cell {
  width: var(--inv-cell);
  height: var(--inv-cell);
  flex-shrink: 0;
}

/* --- Скиллы --- */
.cm-skills-viewport {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  flex: 1;
  padding-right: var(--cm-scroll-gutter);
}

.cm-skills {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--cm-gap-xs);
}

.cm-skill {
  display: flex;
  align-items: center;
  gap: var(--cm-gap-xs);
  padding: var(--cm-gap-xs) var(--cm-gap-sub);
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(139, 105, 20, 0.3);
  border-radius: 3px;
}

.cm-skill__icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.cm-skill__name {
  flex: 1;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1.2;
}

.cm-skill__mana {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 700;
  color: #7ec8ff;
}

.cm-skill__mana svg {
  width: 10px;
  height: 12px;
  opacity: 0.9;
}

/* --- Журнал --- */
.cm-log {
  display: flex;
  flex-direction: column;
  gap: var(--cm-gap-sub);
  font-size: 12px;
  line-height: 1.3;
}

.cm-log__line {
  margin: 0;
  padding: 4px var(--cm-gap-sub);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.15);
}

.cm-log__line--with-icon {
  display: flex;
  align-items: center;
  gap: var(--cm-gap-sub);
  min-width: 0;
}

.cm-log__mark {
  flex-shrink: 0;
  opacity: 0.95;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8));
}

.cm-log__text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-log__line:not(.cm-log__line--with-icon) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-log__line--loot {
  color: var(--log-loot);
}
.cm-log__line--good {
  color: var(--log-good);
}
.cm-log__line--bad {
  color: var(--log-bad);
}
.cm-log__line--info {
  color: var(--log-info);
}

/* --- Хотбар --- */
.cm-hotbar-wrap {
  flex-shrink: 0;
}

/* Хотбар внизу внутри игрового поля: компактнее слоты и отступы */
.cm-hotbar-wrap--in-field {
  flex-shrink: 0;
  margin-top: auto;
  margin-left: var(--cm-gap-sub);
  margin-right: var(--cm-gap-sub);
  margin-bottom: var(--cm-gap-sub);
}

/* «Вдавленная» полоса хотбара внутри поля — отличие от ячеек инвентаря */
.cm-hotbar-wrap--recessed.cm-panel {
  background-color: #0d0806;
  background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5), rgba(30, 20, 16, 0.92)), var(--wood-noise);
  background-size: auto, 140px 140px;
  border-color: #2a1810;
  box-shadow: inset 0 5px 22px rgba(0, 0, 0, 0.85), 0 1px 0 rgba(255, 255, 255, 0.04);
}

.cm-hotbar-wrap--recessed .cm-hot-slot {
  background: #0f0b09;
  border-color: #1a120e;
  border-width: 1px;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.75), inset 0 -1px 0 rgba(255, 255, 255, 0.03), 0 1px 0 rgba(0, 0, 0, 0.5);
}

.cm-hotbar-wrap--recessed .cm-hot-slot.active {
  border-color: #00d2ff;
  box-shadow: 
    inset 0 0 12px rgba(0, 210, 255, 0.35), 
    0 0 8px rgba(0, 210, 255, 0.4), 
    0 0 0 1px rgba(0, 210, 255, 0.5);
}

.cm-hotbar-wrap--recessed .cm-hot-slot--empty {
  opacity: 0.35;
}

.cm-hotbar-wrap--in-field .cm-hotbar {
  padding: calc(var(--cm-gap-xs) + 3px) var(--cm-gap-sub);
  gap: var(--cm-gap-xs);
  justify-content: center;
}

.cm-hotbar-wrap--in-field .cm-hot-slot {
  width: 44px;
  height: 44px;
  font-size: 17px;
}

.cm-hotbar {
  display: flex;
  justify-content: center;
  gap: var(--cm-gap-sub);
  padding: var(--cm-pad);
}

.cm-hot-slot {
  position: relative;
  width: 52px;
  height: 52px;
  padding: 0;
  flex-shrink: 0;
  background: var(--slot-inner);
  border: 2px solid var(--bronze);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-inset), 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cm-hot-slot .cm-sprite-stack--item .cm-sprite-stack__frame {
  width: 100%;
  height: 100%;
}

.cm-hot-slot .cm-sprite-stack--item .cm-sprite-stack__body {
  width: 80%;
  height: 80%;
}

.cm-hot-slot .cm-sprite-stack--skill .cm-sprite-stack__skill {
  width: 80%;
  height: 80%;
}

.cm-inv-cell .cm-sprite-stack--item .cm-sprite-stack__body,
.cm-equip-slot__icon .cm-sprite-stack--item .cm-sprite-stack__body {
  width: 80%;
  height: 80%;
}

.cm-hot-slot.active {
  border-color: #00d2ff;
  box-shadow: 
    inset 0 0 12px rgba(0, 210, 255, 0.35), 
    0 0 8px rgba(0, 210, 255, 0.4), 
    0 0 0 1px rgba(0, 210, 255, 0.5);
}

.cm-hot-slot__key {
  position: absolute;
  top: var(--cm-gap-xs);
  left: var(--cm-gap-xs);
  font-size: 9px;
  font-weight: 800;
  color: var(--gold-dim);
  letter-spacing: 0.02em;
}

.cm-hot-slot__qty {
  position: absolute;
  right: var(--cm-gap-xs);
  bottom: var(--cm-gap-xs);
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 3px #000;
}

.cm-hot-slot--empty {
  opacity: 0.45;
  font-size: 11px;
  color: var(--text-muted);
}

.cm-panel__body {
  padding: var(--cm-pad);
}

.cm-scroll-y {
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}

.cm-stat-plus-spacer {
  width: 22px;
  height: 22px;
}

.cm-center-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.cm-center-panel .cm-panel__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--cm-pad);
  min-height: 0;
}

.cm-col .cm-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.cm-col .cm-panel.cm-panel--fill {
  flex: 1;
}

/* Тело панели на всю высоту колонки (скиллы) */
.cm-panel__body--flex-grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* --- Универсальные тултипы --- */
.cm-tooltip-anchor {
  position: relative;
}

.cm-tooltip {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  min-width: 180px;
  max-width: 240px;
  padding: 8px 10px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.04), transparent 48%), #20160f;
  border: 1px solid var(--bronze);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 8px 20px rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
  z-index: 20;
}

.cm-tooltip-anchor:hover .cm-tooltip,
.cm-tooltip-anchor:focus-within .cm-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
  transition-delay: 0s;
}

.cm-tooltip__title {
  margin: 0 0 6px;
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}

.cm-tooltip__list {
  margin: 0;
  padding: 0 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cm-tooltip__row {
  font-size: 11px;
  line-height: 1.25;
  color: var(--text-muted);
}

.cm-anvil-overlay {
  z-index: 40;
  background: transparent;
  pointer-events: none;
}

.cm-anvil-overlay.cm-modal-backdrop {
  background: transparent !important;
}

.cm-anvil-card {
  width: min(760px, calc(100vw - 32px));
  pointer-events: auto;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.cm-anvil-card--floating {
  transform: none;
}

.cm-anvil-drag-handle {
  cursor: move;
  user-select: none;
}

.cm-anvil-subtitle {
  margin: 0 0 10px;
  color: var(--text-muted);
}

.cm-anvil-mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.cm-anvil-mode-card {
  border: 1px solid var(--bronze-dark);
  border-radius: 6px;
  background: linear-gradient(180deg, #4d3a2d, #2a1f18);
  color: var(--text);
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  cursor: pointer;
}

.cm-anvil-mode-card:hover {
  border-color: var(--bronze-bright);
}

.cm-anvil-mode-card__icon {
  font-size: 22px;
}

.cm-anvil-mode-card__title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.cm-anvil-mode-card__desc {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.cm-anvil-back-btn {
  margin-bottom: 10px;
}

.cm-anvil-reforge-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--text-muted);
}

.cm-anvil-reforge-select {
  min-height: 32px;
  border: 1px solid var(--bronze-dark);
  border-radius: 4px;
  background: #1a120e;
  color: var(--text);
}

.cm-anvil-craft-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

.cm-anvil-slots {
  display: grid;
  grid-template-columns: repeat(3, var(--inv-cell));
  gap: var(--inv-gap);
}

.cm-anvil-slot {
  width: var(--inv-cell);
  height: var(--inv-cell);
  padding: 0;
  line-height: 1;
  font-size: 22px;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  appearance: none;
  -webkit-appearance: none;
}

.cm-anvil-slot--drop-target {
  box-shadow: 0 0 0 2px rgba(0, 210, 255, 0.75) inset, 0 0 10px rgba(0, 210, 255, 0.4);
}

.cm-anvil-arrow {
  font-size: 22px;
  color: var(--gold);
}

.cm-anvil-result-wrap {
  position: relative;
}

.cm-anvil-result {
  position: relative;
  isolation: isolate;
  overflow: visible;
  z-index: 1;
  width: var(--inv-cell);
  height: var(--inv-cell);
  padding: 0;
  line-height: 1;
  font-size: 22px;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  appearance: none;
  -webkit-appearance: none;
  filter: brightness(0.78) saturate(0.9);
  opacity: 0.95;
}

.cm-anvil-result--ready {
  cursor: grab;
  filter: brightness(0.82) saturate(0.95);
}

.cm-anvil-result--prob-common {
  border-color: #7a6855;
  box-shadow: inset 0 0 0 1px rgba(122, 104, 85, 0.55);
}

.cm-anvil-result--prob-rare {
  border-color: #00d2ff;
  box-shadow: inset 0 0 0 1px rgba(0, 210, 255, 0.55);
}

.cm-anvil-result--prob-unique {
  border-color: #c445ff;
  box-shadow: inset 0 0 0 1px rgba(196, 69, 255, 0.55);
}

.cm-anvil-note {
  margin: 0 0 10px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}
