:root {
  color-scheme: dark;
  --bg: #0f1622;
  --bg-2: #131d2e;
  --panel: rgba(23, 33, 51, 0.82);
  --panel-solid: #172133;
  --ink: #eaf0fa;
  --muted: #93a2bd;
  --line: rgba(140, 165, 205, 0.18);
  --line-strong: rgba(140, 165, 205, 0.34);
  --accent: #46c2a0;
  --accent-deep: #2c9b7e;
  --accent-2: #f0884a;
  --accent-2-deep: #d96a2c;
  --gold: #f4c95d;
  --water-a: #1d4f63;
  --water-b: #123246;
  --island-a: #caa45e;
  --island-b: #8fae5e;
  --valid: #f4c95d;
  --danger: #e2614b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.85);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(70, 194, 160, 0.12), transparent 60%),
    radial-gradient(1000px 600px at 100% 0%, rgba(240, 136, 74, 0.1), transparent 55%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  min-height: 38px;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease,
    box-shadow 0.15s ease, opacity 0.15s ease;
}

button:hover {
  border-color: var(--accent);
  background: rgba(70, 194, 160, 0.1);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
  transform: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* Версия сборки — мелким шрифтом в углу, не мешает кликам */
.app-version {
  position: fixed;
  right: 6px;
  bottom: 4px;
  z-index: 50;
  font-size: 10px;
  line-height: 1;
  color: var(--muted);
  opacity: 0.45;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* ---------- Topbar (тонкая) ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.tb-left { display: flex; align-items: center; min-width: 0; }
.tb-center { flex: 1; min-width: 0; display: flex; justify-content: center; }
.tb-right { display: flex; align-items: center; gap: 8px; flex: none; }

h1,
h2,
p {
  margin: 0;
}

h1 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

h1::before {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background:
    linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18),
    0 6px 16px -6px var(--accent);
  flex: none;
}

.turn-status {
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(70, 194, 160, 0.14);
  border: 1px solid rgba(70, 194, 160, 0.3);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.panel h2:first-child {
  margin-top: 0;
}

.actions,
.dice-row,
.mode-grid {
  display: flex;
  gap: 10px;
}

.actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions button {
  padding: 0 16px;
  white-space: nowrap;
  font-weight: 600;
}

.contact-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid rgba(70, 194, 160, 0.46);
  border-radius: var(--radius-sm);
  background: rgba(70, 194, 160, 0.12);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.contact-link:hover {
  border-color: var(--accent);
  background: rgba(70, 194, 160, 0.2);
}

#rollBtn {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #04231b;
  box-shadow: 0 10px 22px -12px var(--accent);
}

#rollBtn:hover:not(:disabled) {
  background: linear-gradient(135deg, #56d2b0 0%, var(--accent) 100%);
}

.ghost {
  background: transparent;
  color: var(--muted);
}

/* ---------- Layout ---------- */
/* ---------- Борд (на всё доступное пространство) ---------- */
.board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  /* Арт карты рисуется внутри SVG (для выравнивания клеток); фон — вода */
  background: linear-gradient(160deg, var(--water-a), var(--water-b));
  touch-action: none; /* жесты пан/зум ловим сами, страница не скроллится/не зумится */
}

#board { touch-action: none; }

.board-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 3;
}

.action-rail {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(13, 19, 25, 0.9);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px);
  touch-action: manipulation;
}

.action-rail .action-art-btn {
  position: relative;
  display: block;
  width: 54px;
  height: 54px;
  min-height: 54px;
  padding: 0;
  gap: 0;
  text-align: initial;
  overflow: hidden;
  border: 1px solid rgba(143, 160, 177, 0.48);
  border-radius: 11px;
  background: #11181f;
  box-shadow: 0 3px 9px rgba(0, 0, 0, 0.36);
}

.action-rail .action-art-btn img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.07);
  pointer-events: none;
  user-select: none;
  transition: filter 0.15s ease, transform 0.15s ease;
}

.action-rail .action-art-btn:hover:not(:disabled) img {
  filter: brightness(1.16);
  transform: scale(1.11);
}

.board-dice {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 6;
  display: flex;
  gap: 7px;
  padding: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(13, 19, 25, 0.9);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px);
}

.board-dice .die {
  width: 52px;
  height: 52px;
  min-height: 52px;
  flex: none;
}

.action-art-btn.mode.active {
  border-color: #66e4c4;
  box-shadow:
    0 0 0 2px rgba(70, 194, 160, 0.68),
    0 0 18px rgba(70, 194, 160, 0.46);
}

.action-art-btn.mode::before {
  display: none;
}

.action-rail .action-art-btn:disabled img {
  filter: grayscale(0.72) brightness(0.54);
}

.action-rail .end-turn-art-btn img {
  transform: scale(1.12);
}

.action-rail .end-turn-art-btn:hover:not(:disabled) img {
  transform: scale(1.16);
}

.action-rail #endTurnBtn {
  border-color: rgba(235, 119, 55, 0.68);
  background: #17100c;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.42);
}

.action-rail #endTurnBtn:hover:not(:disabled) {
  border-color: #ff9a5e;
  background: #17100c;
}

.action-rail #endTurnBtn.attention {
  border-color: #ff9a5e;
  box-shadow:
    0 0 0 2px rgba(240, 136, 74, 0.55),
    0 0 20px rgba(240, 136, 74, 0.6);
}

.character-nav {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 4;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(19, 28, 36, 0.88);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  touch-action: manipulation;
}

.character-nav-btn {
  position: relative;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 35%, rgba(91, 128, 79, 0.45), transparent 62%),
    var(--panel-solid);
  border: 1px solid var(--line-strong);
}

.character-nav-portrait {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  filter: brightness(1.6) contrast(1.04);
  pointer-events: none;
  user-select: none;
}

.character-nav-btn.active {
  border-color: var(--accent);
  background: rgba(70, 194, 160, 0.3);
  box-shadow:
    0 0 0 2px rgba(70, 194, 160, 0.72),
    0 0 18px rgba(70, 194, 160, 0.42);
}

.character-nav-btn.active .character-nav-portrait {
  filter: brightness(1.72) contrast(1.06) saturate(1.08);
}

.character-nav-btn.in-combat::after {
  content: "!";
  position: absolute;
  top: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #d84a43;
  color: white;
  font-size: 11px;
  line-height: 16px;
}

.character-nav-btn:disabled {
  opacity: 0.38;
}

.board-ctl {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  border-radius: var(--radius-sm);
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  opacity: 0.88;
}

/* ---------- Док действий ---------- */
.dock {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  z-index: 4;
}

.dock-dice {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.dock-dice .die { flex: none; }

.dock-actions {
  display: flex;
  gap: 10px;
}

.dock-actions button { flex: 1; font-weight: 700; }

@media (max-width: 620px) {
  .dock {
    padding: 8px 6px;
  }

  .action-rail {
    right: 7px;
    bottom: 7px;
    gap: 5px;
    padding: 5px;
  }

  .action-rail .action-art-btn {
    width: 48px;
    height: 48px;
    min-height: 48px;
  }

  .board-dice {
    left: 7px;
    top: 7px;
    gap: 5px;
    padding: 5px;
  }

  .board-dice .die {
    width: 46px;
    height: 46px;
    min-height: 46px;
  }
}

/* ---------- Шторка: инвентарь + журнал ---------- */
.sheet {
  flex: none;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  background: var(--panel-solid);
  z-index: 6;
}

.sheet-handle {
  flex: none;
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.sheet-handle-arrow { display: inline-block; transition: transform 0.2s ease; }
.sheet.open .sheet-handle-arrow { transform: rotate(180deg); }

.sheet-body {
  display: none;
  padding: 0 14px 14px;
  overflow-y: auto;
  max-height: 42dvh;
}

.sheet.open .sheet-body { display: block; }
.sheet-body .log { max-height: none; }
.sheet-body h2:first-child { margin-top: 4px; }

/* ---------- Десктоп: борд слева, рельс (док + шторка) справа ---------- */
@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 1fr clamp(320px, 26vw, 400px);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "topbar topbar"
      "board  dock"
      "board  sheet";
  }
  .topbar { grid-area: topbar; }
  .board-wrap { grid-area: board; min-width: 0; }
  .dock {
    grid-area: dock;
    border-top: none;
    border-left: 1px solid var(--line);
  }
  .sheet {
    grid-area: sheet;
    min-height: 0;
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
  }
  /* На десктопе шторка не сворачивается — журнал и инвентарь всегда видны */
  .sheet-handle { display: none; }
  .sheet-body { display: block; flex: 1; min-height: 0; max-height: none; padding-top: 12px; }
}

#endTurnBtn {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent-2) 0%, var(--accent-2-deep) 100%);
  color: #2a0f02;
  font-weight: 700;
  box-shadow: 0 10px 22px -12px var(--accent-2);
}

#endTurnBtn:hover:not(:disabled) {
  background: linear-gradient(135deg, #ff9a5e 0%, var(--accent-2) 100%);
}

/* ---------- Dice ---------- */
.dice-row {
  justify-content: center;
}

.die {
  display: grid;
  place-items: center;
  width: 68px;
  height: 64px;
  border-radius: 12px;
  background: linear-gradient(155deg, #f6f8fc 0%, #d7deeb 100%);
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: #1a2436;
  font-size: 28px;
  font-weight: 800;
  box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.8),
    inset 0 -4px 8px rgba(40, 60, 90, 0.25), 0 8px 16px -10px rgba(0, 0, 0, 0.7);
}

.die:hover:not(:disabled) {
  border-color: var(--gold);
  background: linear-gradient(155deg, #ffffff 0%, #e3e9f3 100%);
}

.die.selected {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.8),
    inset 0 -4px 8px rgba(40, 60, 90, 0.25), 0 0 22px -4px var(--gold);
}

.die.used {
  background: linear-gradient(155deg, #2a3548 0%, #1e2738 100%);
  color: var(--muted);
  border-color: var(--line);
  box-shadow: none;
}

.die.rollable {
  border-color: var(--gold);
  animation: dice-invite 1.7s ease-in-out infinite;
}

@keyframes dice-invite {
  0%, 100% {
    box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.8),
      inset 0 -4px 8px rgba(40, 60, 90, 0.25), 0 0 0 0 rgba(244, 201, 93, 0);
  }
  50% {
    box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.8),
      inset 0 -4px 8px rgba(40, 60, 90, 0.25), 0 0 20px -2px var(--gold);
  }
}

.hint {
  min-height: 40px;
  margin-top: 12px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Mode list ---------- */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.mode {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  text-align: left;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.mode::before {
  content: "•";
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 15px;
}

.mode[data-mode="moveSum"]::before { content: "➕"; }
.mode[data-mode="moveDie"]::before { content: "🎲"; }
.mode[data-mode="transfer"]::before { content: "🤝"; }
.mode[data-mode="draw"]::before { content: "🃏"; }
.mode[data-mode="teleport"]::before { content: "✨"; }

.mode.active {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(70, 194, 160, 0.22), rgba(70, 194, 160, 0.08));
  box-shadow: inset 0 0 0 1px rgba(70, 194, 160, 0.35);
}

.mode.active::before {
  background: var(--accent);
}

.primary-action {
  width: 100%;
  margin-top: 12px;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #04231b;
  font-weight: 700;
  box-shadow: 0 10px 22px -12px var(--accent);
}

.primary-action:hover:not(:disabled) {
  background: linear-gradient(135deg, #56d2b0 0%, var(--accent) 100%);
}

/* ---------- Character cards (вертикальные, с артом) ---------- */
.character-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin: 0;
  padding: 12px 8px 10px;
  text-align: center;
  background: linear-gradient(180deg, rgba(70, 194, 160, 0.08), rgba(255, 255, 255, 0.02));
}

.character-card.side-red {
  background: linear-gradient(180deg, rgba(240, 136, 74, 0.1), rgba(255, 255, 255, 0.02));
}

.portrait-img {
  width: 100%;
  max-width: 130px;
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.55));
  -webkit-user-drag: none;
  user-select: none;
}

.character-card strong {
  font-size: 14px;
}

.character-card .meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.character-card.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(70, 194, 160, 0.28), rgba(70, 194, 160, 0.06));
  box-shadow: inset 0 0 0 1px rgba(70, 194, 160, 0.4), 0 8px 20px -12px var(--accent);
}

.character-card.side-red.active {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, rgba(240, 136, 74, 0.3), rgba(240, 136, 74, 0.06));
  box-shadow: inset 0 0 0 1px rgba(240, 136, 74, 0.4), 0 8px 20px -12px var(--accent-2);
}

.card-public-mark {
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 2;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(20, 105, 76, 0.9);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.2;
}

/* ---------- Board ---------- */
/* Поле центрируется в рамке; размер задаёт JS (fitBoard). */
.board {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.board-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Гекс — прозрачная заливка (для клика) + серая векторная обводка. */
.cell {
  fill: var(--cell-fill, transparent);
  fill-opacity: var(--cell-fill-opacity, 0);
  stroke: var(--cell-stroke, #aab6cf);
  stroke-opacity: var(--cell-stroke-opacity, 0.75);
  stroke-width: 1.2;
  stroke-linejoin: round;
  cursor: pointer;
  transition: fill 0.12s ease;
}

.cell:hover {
  fill: rgba(214, 230, 245, 0.16);
}

.cell.fog-hidden {
  fill-opacity: 0 !important;
  stroke-opacity: 0 !important;
  pointer-events: none;
}

.deck-marker.fog-hidden {
  opacity: 0;
}

.cell.start {
  fill: var(--cell-fill, #f4c95d);
}

/* Подсветка валидных клеток.
   Обычные клетки (path) — насыщенная жёлтая заливка.
   Цветные (event/resource/старты/колоды/опушка) — НЕ перекрашиваем, чтобы
   их собственный цвет (красные события и т.п.) оставался виден; только
   жёлтую обводку даём заметно толще. */
.cell.valid {
  fill: rgba(244, 201, 93, 0.7);
  fill-opacity: 1;
  stroke: #fff3cf;
  stroke-opacity: 1;
  stroke-width: 2.2;
}

.cell.valid.colored {
  fill: var(--cell-fill, #dbe8f7);
  fill-opacity: var(--cell-fill-opacity, 0.45);
  stroke: #ffd866;
  stroke-width: 3.4;
}

.cell.occupied {
  fill: rgba(235, 244, 252, 0.5);
  fill-opacity: 1;
}

.cell.selected {
  stroke: var(--accent);
  stroke-opacity: 1;
  stroke-width: 2.6;
}

.start-label {
  fill: #2e2305;
  font-size: 14px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Все фишки кликабельны (свои — выбор, чужие — окно боя/подход).
   Жесты пана/зума всё равно работают: события всплывают на #board. */
.token {
  pointer-events: auto;
}

.token .token-hit-area {
  fill: transparent;
  pointer-events: all;
}

.token.own { cursor: pointer; }
.token.attackable { cursor: crosshair; }

.token .token-halo {
  fill: transparent;
  stroke: rgba(255, 255, 255, 0.38);
  stroke-width: 1.5;
  transition: stroke 0.15s ease, stroke-width 0.15s ease, filter 0.15s ease;
}

.token .token-figure {
  filter: brightness(1.3) drop-shadow(0 2px 2px rgba(3, 8, 12, 0.8));
  pointer-events: none;
}

.token .token-glow {
  opacity: 0;
  pointer-events: none;
}

.token.side-green:not(.role-V) .token-figure {
  filter: brightness(1.69) drop-shadow(0 2px 2px rgba(3, 8, 12, 0.8));
}

.token.side-red .token-figure {
  filter: brightness(1.82) drop-shadow(0 2px 2px rgba(3, 8, 12, 0.8));
}

.token text {
  fill: #fff;
  font-size: 13px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.token .token-hp {
  paint-order: stroke;
  stroke: #f06a18;
  stroke-width: 2px;
  stroke-linejoin: round;
  fill: #fff;
  font-weight: 900;
}

.beast-card-hp {
  paint-order: stroke;
  stroke: #f06a18;
  stroke-width: 2.5px;
  stroke-linejoin: round;
  fill: #fff;
  font-weight: 900;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.95));
}

.token.attackable .token-halo {
  stroke: #ff4d55;
  stroke-width: 4;
  filter: drop-shadow(0 0 8px rgba(255, 50, 60, 0.95));
  animation: attack-target-pulse 0.9s ease-in-out infinite alternate;
}

.damage-float {
  fill: #ff3b42;
  font-weight: 950;
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: #ff8a18;
  stroke-width: 3.2px;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 2px rgba(30, 4, 0, 0.95));
  pointer-events: none;
  animation: damage-float-up 1.5s linear forwards;
}

@keyframes damage-float-up {
  0% { opacity: 1; transform: translate(0, 0); }
  75% { opacity: 1; transform: translate(0, -31.5px); }
  100% { opacity: 0; transform: translate(0, -42px); }
}

.cell.teleport-target {
  fill: rgba(169, 51, 232, 0.7);
  fill-opacity: 1 !important;
  stroke: #e5a8ff;
  stroke-opacity: 1 !important;
  stroke-width: 4;
  pointer-events: auto;
  filter: drop-shadow(0 0 10px rgba(190, 87, 255, 0.95));
  animation: teleport-target-pulse 0.9s ease-in-out infinite alternate;
}

.cell.teleport-destination {
  fill-opacity: 1 !important;
  stroke-opacity: 1 !important;
  pointer-events: auto;
}

@keyframes teleport-target-pulse {
  from { filter: drop-shadow(0 0 4px rgba(190, 87, 255, 0.65)); }
  to { filter: drop-shadow(0 0 14px rgba(225, 168, 255, 1)); }
}

.token.attack-triggered .token-halo {
  animation: attack-click-flash 0.38s ease-out;
}

.token.attack-triggered .token-figure {
  animation: attack-click-hit 0.38s ease-out;
}

.token.in-combat:not(.attackable) .token-halo {
  stroke: #ff9b3d;
  stroke-width: 4;
  filter: drop-shadow(0 0 7px rgba(255, 116, 30, 0.9));
}

.character-card.in-combat {
  box-shadow: inset 0 0 0 2px #ff9b3d, 0 0 10px rgba(255, 116, 30, 0.45);
}

@keyframes attack-target-pulse {
  from { filter: drop-shadow(0 0 3px rgba(255, 50, 60, 0.7)); }
  to { filter: drop-shadow(0 0 10px rgba(255, 50, 60, 1)); }
}

@keyframes attack-click-flash {
  0% { stroke: #fff; stroke-width: 8; filter: drop-shadow(0 0 18px #fff); }
  100% { stroke: #ff4d55; stroke-width: 4; filter: drop-shadow(0 0 8px rgba(255, 50, 60, 0.95)); }
}

@keyframes attack-click-hit {
  0% { transform: translateX(0); filter: brightness(2.2) drop-shadow(0 0 12px #ff4d55); }
  35% { transform: translateX(-3px); }
  70% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

/* Персонаж в бою со зверем (красная клетка): тёмно-красное пульсирующее свечение.
   Бой с игроком (.in-combat) и цель атаки (.attackable) приоритетнее. */
.token.beast-fight:not(.attackable):not(.in-combat) .token-halo {
  stroke: #b3122a;
  stroke-width: 4;
  animation: beast-fight-pulse 1.3s ease-in-out infinite alternate;
}

@keyframes beast-fight-pulse {
  from {
    stroke-opacity: 1;
    filter: drop-shadow(0 0 4px rgba(179, 18, 42, 0.65));
  }
  to {
    stroke-opacity: 0.6;
    filter: drop-shadow(0 0 10px rgba(179, 18, 42, 1));
  }
}

.token.own:hover .token-halo,
.token.own:focus-visible .token-halo {
  stroke: var(--gold);
  stroke-width: 3;
  filter: drop-shadow(0 0 5px rgba(244, 201, 93, 0.9));
}

.token.own:focus-visible {
  outline: none;
}

.token.active .token-halo {
  stroke: var(--gold);
  stroke-width: 3.5;
  animation: token-halo-pulse 1.7s ease-in-out infinite;
}

.token.active .token-glow {
  animation: token-figure-pulse 1.7s ease-in-out infinite;
}

@keyframes token-halo-pulse {
  0%, 100% {
    stroke-opacity: 0.8;
    filter: drop-shadow(0 0 1px rgba(244, 201, 93, 0.4));
  }
  50% {
    stroke-opacity: 1;
    filter: drop-shadow(0 0 4.5px rgba(255, 219, 105, 1));
  }
}

@keyframes token-figure-pulse {
  0%, 100% {
    opacity: 0.12;
    filter: sepia(1) saturate(5) brightness(2)
      drop-shadow(0 0 0.5px rgba(255, 219, 105, 0.3));
  }
  50% {
    opacity: 0.56;
    filter: sepia(1) saturate(6) brightness(2.4)
      drop-shadow(0 0 2px rgba(255, 219, 105, 1))
      drop-shadow(0 0 4.5px rgba(255, 219, 105, 1));
  }
}

/* ---------- Inventory ---------- */
.inventory {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  align-items: start;
  gap: 9px;
}

.inventory > .beast-info,
.inventory > .craft-info,
.inventory > .inventory-actions {
  grid-column: 1 / -1;
}

/* Сводка боя со зверем — первым блоком над картами инвентаря */
.beast-info {
  padding: 10px 12px 10px 14px;
  border: 1px solid rgba(179, 18, 42, 0.5);
  border-left: 4px solid #b3122a;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(179, 18, 42, 0.16), rgba(179, 18, 42, 0.05));
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

.card {
  position: relative;
  padding: 10px 12px 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  font-size: 13px;
  font-weight: 600;
}

.card[role="button"] { cursor: pointer; }
.card.expanded { background: linear-gradient(135deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03)); }

.card.card-face {
  min-width: 0;
  padding: 3px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.inventory-card-art {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 5px;
  filter: brightness(1.5);
  pointer-events: none;
  user-select: none;
}

.card.card-face.card-locked .inventory-card-art {
  filter: grayscale(0.35) brightness(1.08);
}

.card.card-face .card-lock {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(8, 12, 18, 0.84);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.75);
}

.card.card-face .card-caret {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(8, 12, 18, 0.82);
  color: #fff;
}

.card.card-face .card-desc {
  margin: 3px 0 0;
  padding: 8px;
  border: 0;
  border-radius: 5px;
  background: rgba(7, 11, 19, 0.92);
  color: #d9e0ea;
}

.card.card-face::before {
  display: none;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-name { flex: 1; min-width: 0; }

.card-caret { flex: none; font-size: 11px; color: var(--muted); }

.card-desc {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--muted);
}

.card-type {
  flex: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.85;
}

.card-lock { flex: none; font-size: 12px; }

.card-locked .card-name { color: var(--muted); }

.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 3px;
  background: var(--card-accent, var(--gold));
}

/* Цвет акцент-полоски по типу карты */
.card-weapon     { --card-accent: #e0563f; }
.card-armor      { --card-accent: #5b9bd5; }
.card-tool       { --card-accent: #d8a13a; }
.card-ingredient { --card-accent: #7fae54; }
.card-blueprint  { --card-accent: #c08a4a; }
.card-recipe     { --card-accent: #b06fb8; }
.card-companion  { --card-accent: #d8a13a; }
.card-special    { --card-accent: #6fc3c0; }

.empty {
  grid-template-columns: 1fr;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Log ---------- */
.log {
  display: flex;
  overflow: auto;
  flex-direction: column;
  max-height: min(380px, 46vh);
  gap: 0;
  color: var(--muted);
  font-size: 13px;
}

.log-entry {
  position: relative;
  padding: 8px 0 8px 16px;
  border-bottom: 1px solid var(--line);
}

.log-entry::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 13px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.log-my { color: var(--accent); }

.log-opp { color: var(--accent-2); }
.log-opp::before { background: var(--accent-2); }

.log-sys { color: var(--muted); font-style: italic; font-size: 12px; }
.log-sys::before { background: var(--gold); opacity: 0.7; }

.log-err { color: var(--danger); }
.log-err::before { background: var(--danger); }

/* ---------- Connection badge ---------- */
.conn-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
}

/* Счётчик RTT до сервера */
.conn-rtt {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--muted);
}
.conn-rtt:empty { display: none; }
.conn-rtt.rtt-good { color: var(--accent); }
.conn-rtt.rtt-mid  { color: var(--gold); }
.conn-rtt.rtt-bad  { color: #e0563f; }

.conn-connected    { color: var(--accent); border-color: rgba(70,194,160,0.4); background: rgba(70,194,160,0.08); }
.conn-connecting   { color: var(--gold);   border-color: rgba(244,201,93,0.35); }
.conn-disconnected { color: var(--muted);  border-color: var(--line); }
.conn-error        { color: var(--danger); border-color: rgba(226,97,75,0.4); background: rgba(226,97,75,0.08); }

/* ---------- Lobby overlay ---------- */
#lobby {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 24px;
  background: rgba(10, 15, 25, 0.82);
  backdrop-filter: blur(10px);
}

#lobby.hidden { display: none; }

.lobby-card {
  display: flex;
  flex-direction: column;
  width: min(400px, 92vw);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 36px 32px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: var(--shadow), 0 0 80px -20px rgba(70,194,160,0.18);
}

.lobby-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.lobby-logo {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-align: center;
  line-height: 1;
}

.lobby-sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.lobby-status {
  text-align: center;
  font-size: 13px;
  color: var(--gold);
}

.lobby-status:empty {
  display: none;
}

.lobby-card input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease;
}

.lobby-card input[type="text"]:focus {
  border-color: var(--accent);
}

.lobby-btns {
  display: flex;
  gap: 10px;
}

.lobby-btns button {
  flex: 1;
  font-weight: 700;
}

.lobby-btns button:first-child {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #04231b;
  box-shadow: 0 8px 18px -10px var(--accent);
}

.lobby-join {
  display: flex;
  gap: 10px;
}

.lobby-join input { flex: 1; }

.hidden { display: none !important; }

.lobby-code {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(70,194,160,0.1);
  border: 1px solid rgba(70,194,160,0.3);
  font-size: 15px;
  text-align: center;
}

.lobby-code strong {
  font-size: 28px;
  letter-spacing: 0.15em;
  color: var(--accent);
  display: block;
  margin: 4px 0;
}

.lobby-code-hint {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.lobby-cancel-btn {
  width: 100%;
  margin-top: 14px;
  border-color: rgba(226, 97, 75, 0.45);
  background: rgba(226, 97, 75, 0.08);
  color: #ffb7aa;
  font-weight: 700;
}

.lobby-cancel-btn:hover {
  border-color: var(--danger);
  background: rgba(226, 97, 75, 0.16);
}

.lobby-view.is-waiting > #playerName,
.lobby-view.is-waiting > .lobby-btns,
.lobby-view.is-waiting > .lobby-vsai-btn,
.lobby-view.is-waiting > .lobby-check,
.lobby-view.is-waiting > .lobby-join,
.lobby-view.is-waiting > .lobby-list {
  display: none;
}

.lobby-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.lobby-check input { accent-color: var(--accent); }

.lobby-list {
  border-top: 1px solid var(--line-strong);
  padding-top: 12px;
  text-align: left;
}

.lobby-list-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.lobby-list-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.lobby-list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line-strong);
}

.lobby-list-name {
  flex: 1;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-list-count {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.lobby-list-join {
  padding: 6px 14px;
  font-weight: 700;
  font-size: 13px;
}

.lobby-list-empty {
  font-size: 13px;
  color: var(--muted);
  opacity: 0.7;
  text-align: center;
  padding: 8px 0;
}

.lobby-vsai-btn {
  width: 100%;
  font-weight: 700;
  border-color: rgba(244, 201, 93, 0.4);
  background: rgba(244, 201, 93, 0.07);
  color: var(--gold);
}

.lobby-vsai-btn:hover:not(:disabled) {
  border-color: var(--gold);
  background: rgba(244, 201, 93, 0.15);
}

.lobby-bottom-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 2px;
}

.lobby-link-btn {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 13px;
  align-self: center;
  min-height: 32px;
}
.lobby-link-btn:hover { color: var(--ink); border-color: var(--line); }

.lobby-settings-title {
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  color: var(--ink);
  margin-bottom: 4px;
}

.lobby-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.lobby-label input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}
.lobby-label input:focus { border-color: var(--accent); }

.lobby-label-hint {
  font-size: 12px;
  color: var(--muted);
  margin: -4px 0 4px;
  opacity: 0.7;
}

/* Кнопка меню в шапке */
.topbar-menu-btn {
  padding: 0 16px;
  font-weight: 700;
  border-color: var(--line-strong);
}

/* Игровое меню (пауза) */
#gameMenu {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 15, 25, 0.75);
  backdrop-filter: blur(8px);
}
#gameMenu.hidden { display: none; }

.menu-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(320px, 90vw);
  padding: 32px 28px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

.menu-title {
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}

.menu-card button {
  width: 100%;
  font-weight: 700;
  min-height: 44px;
}

.menu-card button:first-of-type {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #04231b;
  box-shadow: 0 8px 18px -10px var(--accent);
}
.menu-card button:first-of-type:hover {
  background: linear-gradient(135deg, #56d2b0 0%, var(--accent) 100%);
}

#matchResult {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 15, 25, 0.72);
  backdrop-filter: blur(7px);
}

#matchResult.hidden {
  display: none;
}

.match-result-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(420px, 92vw);
  padding: 32px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  text-align: center;
}

.match-result-title {
  color: var(--accent-2);
  font-size: 36px;
  font-weight: 900;
}

#matchResult.is-win .match-result-title {
  color: var(--accent);
}

.match-result-text {
  color: var(--muted);
}

.match-result-card button:first-of-type {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #04231b;
  font-weight: 800;
}

/* Настройки — отдельный оверлей */
#settingsOverlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 15, 25, 0.82);
  backdrop-filter: blur(10px);
}
#settingsOverlay.hidden { display: none; }

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(400px, 92vw);
  padding: 36px 32px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

.settings-title {
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  color: var(--ink);
  letter-spacing: 0.04em;
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.settings-toggle input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.settings-toggle span {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings-toggle small {
  color: var(--muted);
  line-height: 1.3;
}

/* ---------- Responsive ---------- */
@media (max-width: 620px) {
  /* Тач-таргеты крупнее */
  .mode,
  .character-card {
    min-height: 44px;
  }

  #lobby {
    align-items: flex-start;
    padding: 12px;
  }

  .lobby-card {
    width: 100%;
    max-height: calc(100dvh - 24px);
    padding: 24px 18px;
  }

  .lobby-btns {
    flex-direction: column;
  }
}

@media (max-height: 700px) {
  #lobby {
    align-items: flex-start;
    padding-block: 12px;
  }

  .lobby-card {
    max-height: calc(100dvh - 24px);
    padding-block: 22px;
  }

  .lobby-logo {
    font-size: 34px;
  }
}

/* ---------- «Ящик» карт команды (drag-and-drop передача) ---------- */
.cardbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(7, 11, 19, 0.72);
  backdrop-filter: blur(4px);
}
.cardbox-overlay.hidden { display: none; }

.cardbox {
  display: flex;
  flex-direction: column;
  width: min(920px, 100%);
  max-height: calc(100dvh - 24px);
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.cardbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.cardbox-title { font-weight: 700; }
.cardbox-close {
  width: 34px; height: 34px; padding: 0;
  font-size: 16px; line-height: 1;
  background: transparent; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); color: var(--ink);
}

.cardbox-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
}

.cbx-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.12s ease, background 0.12s ease;
}
.cbx-row.drop-target {
  border-color: var(--accent);
  background: rgba(70, 194, 160, 0.12);
}

.cbx-portrait {
  position: relative;
  flex: none;
  width: 78px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.cbx-portrait img {
  width: 72px;
  height: 102px;
  object-fit: cover;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.42);
  filter: brightness(1.5);
}
.cbx-portrait.side-red  { color: #e98f7a; }
.cbx-portrait.side-green { color: #9ec97a; }
.cbx-hp {
  position: absolute;
  left: 50%;
  bottom: 5px;
  transform: translateX(-50%);
  min-width: 30px;
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.84);
  color: #fff;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.75);
  font-size: 11px;
  font-weight: 900;
  line-height: 17px;
  text-align: center;
}

.cbx-slots {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
}
.cbx-empty { color: var(--muted); font-size: 12px; align-self: center; opacity: 0.7; }

.cbx-card {
  position: relative;
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 76px;
  min-height: 102px;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  font-size: 10px;
  font-weight: 600;
  overflow: hidden;
  touch-action: none; /* перетаскивание не должно скроллить список */
}
.cardbox.can-transfer .cbx-card,
.cardbox-overlay.can-transfer .cbx-card { cursor: grab; }
.cbx-card-art {
  display: block;
  width: 68px;
  height: 96px;
  object-fit: cover;
  object-position: center;
  border-radius: 5px;
  filter: brightness(1.5);
  pointer-events: none;
  user-select: none;
}
.cbx-card-name {
  width: 100%;
  min-width: 0;
  padding: 0 2px 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  line-height: 14px;
}
.cbx-card.card-locked .cbx-card-art {
  filter: grayscale(0.35) brightness(1.08);
}
.cbx-card.card-locked .cbx-card-name { color: var(--muted); }
.cbx-lock {
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(10, 13, 19, 0.82);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.8);
  font-size: 12px;
}
.cbx-card.dragging { opacity: 0.35; }

.cbx-ghost {
  position: fixed;
  z-index: 90;
  margin: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-3deg);
  box-shadow: 0 12px 28px -10px rgba(0, 0, 0, 0.7);
  opacity: 0.95;
}

.cardbox-hint {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Beast card on hex / terrain cards ---------- */
.beast-card-on-hex {
  filter: drop-shadow(0 0 12px rgba(255, 60, 60, 0.7)) drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6));
  transition: filter 0.15s ease, transform 0.15s ease;
  user-select: none;
}
.beast-card-on-hex image {
  filter: brightness(1.5);
}
.beast-card-on-hex:hover {
  filter: drop-shadow(0 0 22px rgba(255, 80, 80, 0.95)) drop-shadow(0 4px 14px rgba(0, 0, 0, 0.8));
}
.terrain-card {
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
  transition: filter 0.15s ease, transform 0.15s ease;
}
.terrain-card:hover {
  filter: drop-shadow(0 0 14px rgba(244, 201, 93, 0.6)) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
}
.terrain-card image {
  user-select: none;
}

.terrain-card-flip-bg {
  fill: rgba(11, 20, 29, 0.92);
  stroke: #f06a18;
  stroke-width: 1.5px;
}

.terrain-card-flip-icon {
  fill: #fff;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.terrain-card-flip:hover .terrain-card-flip-bg,
.terrain-card-flip:focus-visible .terrain-card-flip-bg {
  fill: #f06a18;
  filter: drop-shadow(0 0 5px rgba(240, 106, 24, 0.95));
}

.card-flip-btn {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 3;
  width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 50%;
  background: rgba(8, 12, 18, 0.88);
  color: #fff;
}

.card-used-mark {
  position: absolute;
  right: 7px;
  bottom: 7px;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(8, 12, 18, 0.86);
  color: var(--muted);
  font-size: 10px;
}

.card-exhausted .inventory-card-art,
.card-face-down .inventory-card-art,
.cbx-card.card-exhausted .cbx-card-art {
  filter: brightness(0.85);
}

/* Drag ghost из инвентаря */
.inv-drag-ghost {
  position: fixed;
  z-index: 90;
  width: 120px;
  margin: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-3deg);
  box-shadow: 0 12px 28px -10px rgba(0, 0, 0, 0.7);
  opacity: 0.92;
  border-radius: 8px;
  overflow: hidden;
}
.inv-drag-ghost img {
  display: block;
  width: 100%;
}
.card.card-face.dragging {
  opacity: 0.35;
}

/* ---------- Event Overlay (Found Card) ---------- */
.event-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s ease-out;
}

.event-overlay.hidden { display: none; }

.event-card-reveal {
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  width: 90%;
  max-width: 320px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
  animation: card-pop 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.event-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 16px;
}

.event-card-display {
  margin-bottom: 24px;
}

.event-card-display .card {
  display: block;
  margin: 0 auto;
  text-align: left;
  transform: scale(1.1);
}

.event-ok-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.event-return-btn {
  width: 100%;
  margin-bottom: 8px;
  padding: 11px;
  border-color: rgba(244, 201, 93, 0.65);
  background: rgba(244, 201, 93, 0.14);
  color: var(--gold);
  font-weight: 700;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes card-pop {
  from { transform: scale(0.8) translateY(20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

/* Подсказка крафта в инвентаре */
.craft-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid rgba(244, 201, 93, 0.45);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-sm);
  background: rgba(244, 201, 93, 0.08);
  font-size: 12px;
  font-weight: 600;
}
.craft-info button {
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  border-color: transparent;
  background: linear-gradient(135deg, var(--gold) 0%, #d8a13a 100%);
  color: #2a1c02;
}
.craft-info button:disabled { opacity: 0.5; }

.inventory-actions {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(244, 201, 93, 0.45);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-sm);
  background: rgba(244, 201, 93, 0.08);
}

.inventory-actions-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.inventory-action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(244, 201, 93, 0.2);
  font-size: 12px;
  font-weight: 600;
}

.inventory-action-row button {
  flex: none;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  border-color: transparent;
  background: linear-gradient(135deg, var(--gold) 0%, #d8a13a 100%);
  color: #2a1c02;
}

.inventory-action-row button:disabled { opacity: 0.5; }

@media (max-width: 620px) {
  .inventory-action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .inventory-action-row button {
    width: 100%;
  }
}

/* Подсветка «Конец хода», когда кубики потрачены и действий не осталось */
#endTurnBtn.attention { animation: end-turn-pulse 1.4s ease-in-out infinite; }
@keyframes end-turn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 136, 74, 0.45); }
  50% { box-shadow: 0 0 0 7px rgba(240, 136, 74, 0); }
}

/* Фиксированный слот «Бусы телепортации» справа в ряду персонажа (как в физ. ящике) */
.cbx-tele-slot {
  flex: none;
  display: flex;
  align-items: center;
  padding-left: 10px;
  margin-left: 6px;
  border-left: 1px dashed var(--line-strong);
}
.cbx-tele-slot .cbx-card {
  border-color: rgba(111, 195, 192, 0.5);
  box-shadow: 0 0 10px rgba(111, 195, 192, 0.16);
}
.cbx-tele-empty {
  width: 76px;
  min-height: 102px;
  display: grid;
  place-items: center;
  padding: 7px 4px;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  opacity: 0.6;
}

@media (max-width: 620px) {
  .cardbox-rows { padding: 8px; }
  .cbx-row { gap: 6px; padding: 6px; }
  .cbx-portrait { width: 66px; }
  .cbx-portrait img { width: 60px; height: 85px; }
  .cbx-card { width: 68px; min-height: 91px; }
  .cbx-card-art { width: 60px; height: 85px; }
  .cbx-tele-slot { padding-left: 6px; margin-left: 0; }
  .cbx-tele-empty { width: 68px; min-height: 91px; }
}

/* Передача через ящик: подсветка запрета */
.cbx-row.drop-blocked {
  border-color: #e0563f;
  background: rgba(224, 86, 63, 0.12);
}

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 10px 20px;
  border-radius: 30px;
  background: rgba(23, 33, 51, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28),
             toast-out 0.3s 2.7s forwards;
  pointer-events: auto;
}

.toast-success { border-color: var(--accent); color: var(--accent); }
.toast-error { border-color: var(--danger); color: var(--danger); }
.toast-danger { border-color: var(--danger); color: #ff8585; }
.toast-info { border-color: var(--gold); color: var(--gold); }

@keyframes toast-in {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-20px); opacity: 0; }
}

/* Тост события красной клетки — заметно, по центру под шапкой */
.event-toast {
  position: fixed;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 65; /* ниже сцены боя (70) */
  max-width: min(520px, calc(100vw - 24px));
  padding: 12px 18px;
  border: 1px solid rgba(224, 86, 63, 0.65);
  border-left: 5px solid #e0563f;
  border-radius: var(--radius-sm);
  background: var(--panel-solid);
  box-shadow: 0 14px 34px -14px rgba(224, 86, 63, 0.55);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  animation: event-toast-in 0.25s ease-out;
}
.event-toast.hidden { display: none; }
.event-toast b { color: var(--gold); }
@keyframes event-toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}



/* Версия сборки в лобби — под логотипом */
.lobby-version {
  margin-top: -6px;
  margin-bottom: 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
  opacity: 0.6;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* ---------- Чат (в журнале) ---------- */
.chat-input-row {
  position: relative;
  margin-top: 8px;
}
.chat-input-row input {
  width: 100%;
  padding-right: 44px; /* место для кнопки */
}
.chat-input-row button {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 15px;
  border: none;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #04231b;
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.chat-input-row button.visible {
  opacity: 1;
  pointer-events: auto;
}

.sheet-chat { margin: 0 0 10px; }

/* Сообщения чата в журнале */
.log-entry.log-chat { color: var(--accent); font-weight: 600; }



/* Баннер «обновите версию» — поверх всего, блокирует игру старым клиентом */
.version-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: linear-gradient(135deg, #b3122a 0%, #7a0f20 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.7);
}
.version-banner b { font-weight: 800; }
.version-banner button {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}
.version-banner button:hover { background: rgba(255, 255, 255, 0.28); border-color: #fff; }
