:root {
  --bg: #16130f;
  --bg-soft: #211c16;
  --panel: #2a241c;
  --edge: #43392c;
  --ink: #ece3d2;
  --ink-dim: #a99c86;
  --accent: #d8a93f;
  --accent-ink: #231b0c;
  --danger: #d1604c;
  --silver: #c9d4e0;
  --defender: #4c7fb8;
  --attackerA: #b4503c;
  --attackerB: #4f8c55;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, #2d261c 0%, transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

.screen { padding: 24px 16px 40px; max-width: 1180px; margin: 0 auto; }
.screen[hidden] { display: none; }

.title {
  font-size: clamp(32px, 7vw, 56px);
  margin: 12px 0 4px;
  letter-spacing: .04em;
  text-align: center;
  text-shadow: 0 2px 0 #0008;
}
.tagline { text-align: center; color: var(--ink-dim); max-width: 60ch; margin: 0 auto 28px; line-height: 1.5; }
.code { color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: .18em; }

.panels { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }

.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h2 { margin: 0 0 6px; font-size: 20px; }
.hint { color: var(--ink-dim); font-size: 14px; line-height: 1.45; margin: 0 0 14px; }

label { display: block; font-size: 13px; color: var(--ink-dim); margin-bottom: 10px; }
input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 11px;
  background: #15110c; color: var(--ink);
  border: 1px solid var(--edge); border-radius: 8px; font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--edge); background: #342c22; color: var(--ink);
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: #b4882c; }
button.wide { width: 100%; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-dim); font-size: 12px; margin: 14px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--edge); }

.error { color: var(--danger); text-align: center; margin-top: 16px; }

.rules { margin: 28px auto 0; max-width: 70ch; border-top: 1px solid var(--edge); padding-top: 14px; }
.rules summary { cursor: pointer; color: var(--accent); }
.rules-body p { color: var(--ink-dim); line-height: 1.55; font-size: 14px; }
.rules-body b { color: var(--ink); }

.players { list-style: none; padding: 0; max-width: 420px; margin: 0 auto 14px; }
.players li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border: 1px solid var(--edge); border-radius: 8px;
  background: var(--bg-soft); margin-bottom: 8px;
}
.players .dot { width: 9px; height: 9px; border-radius: 50%; background: #6e8f5a; }
.players .dot.off { background: #6b5f4d; }

/* --- экран партии --- */

.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top" "board side";
  gap: 14px;
  height: 100vh;
  padding: 12px;
}

.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--bg-soft); border: 1px solid var(--edge);
  border-radius: var(--radius); padding: 10px 14px;
}
.meter { display: flex; flex-direction: column; line-height: 1.15; }
.meter-label { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-dim); }
.meter b { font-size: 17px; font-variant-numeric: tabular-nums; }
.turn-meter { margin-left: auto; text-align: right; }
.timer { font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; }

.toggle { padding: 6px 10px; font-size: 12px; background: #221d16; color: var(--ink-dim); }
.toggle.active { background: #4a2a24; border-color: var(--danger); color: #ffd9d0; }

.seats { display: flex; gap: 8px; flex-wrap: wrap; }
.seat {
  border: 1px solid var(--edge); border-left-width: 4px;
  border-radius: 8px; padding: 5px 10px; background: #221d16;
  font-size: 13px; line-height: 1.25;
}
.seat.defender { border-left-color: var(--defender); }
.seat.attackerA { border-left-color: var(--attackerA); }
.seat.attackerB { border-left-color: var(--attackerB); }
.seat.active { background: #3a3020; border-color: var(--accent); }
.seat .role { display: block; font-size: 11px; color: var(--ink-dim); }
.seat .score { float: right; margin-left: 10px; color: var(--accent); font-weight: 700; }

.board-wrap { grid-area: board; position: relative; min-height: 320px; }
canvas {
  width: 100%; height: 100%;
  background: #0f0d0a;
  border: 1px solid var(--edge); border-radius: var(--radius);
  display: block; cursor: pointer;
  touch-action: manipulation;
}

.toast {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: #3a1f1a; border: 1px solid var(--danger); color: #ffd9d0;
  padding: 8px 14px; border-radius: 8px; font-size: 14px; max-width: 90%;
  box-shadow: 0 6px 20px #0008;
}

.side {
  grid-area: side;
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto; padding-right: 2px;
}

.resources {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  background: var(--bg-soft); border: 1px solid var(--edge);
  border-radius: var(--radius); padding: 10px;
}
.resources b { font-size: 16px; }
.resources .silver b { color: var(--silver); }
.resources .sub { font-size: 10px; color: var(--ink-dim); display: block; }

/* Голосовая связь */
.voice-row { display: flex; gap: 6px; margin-bottom: 8px; }
.voice-row button { flex: 1; padding: 8px 10px; font-size: 13px; }
.voice-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.voice-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; color: var(--ink-dim);
}
.voice-list .bulb {
  width: 8px; height: 8px; border-radius: 50%;
  background: #6b5f4d; flex: none;
}
.voice-list li.on { color: var(--ink); }
.voice-list li.on .bulb { background: #6e8f5a; }
.voice-list li.speaking .bulb { background: var(--accent); box-shadow: 0 0 0 3px #d8a93f33; }
.voice-list li.me { font-style: italic; }
.voice-error { color: var(--danger); margin: 6px 0 0; }

.elite-shop { border-color: #5d6a78; }
.elite-shop h3 { color: var(--silver); }
.elite-shop .hint { font-size: 11px; margin: -4px 0 8px; }
.shop-item .silver-cost { color: var(--silver); font-weight: 700; font-variant-numeric: tabular-nums; }

/* Хроника и чат делят одну панель: боковая колонка не резиновая. */
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab {
  flex: 1; padding: 5px 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-dim); background: #221d16;
  position: relative;
}
.tab.active { color: var(--ink); border-color: var(--accent); background: #3a3020; }
.badge {
  position: absolute; top: 3px; right: 5px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}

.chat-pane { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.chat-pane[hidden] { display: none; }
.chat-pane ul { list-style: none; margin: 0; padding: 0; font-size: 13px; line-height: 1.45; max-height: 220px; overflow-y: auto; }
.chat-pane li { padding: 4px 0; border-bottom: 1px solid #ffffff0d; word-break: break-word; }
.chat-pane li b { color: var(--ink); }
.chat-pane li.defender b { color: #9cc3ea; }
.chat-pane li.attackerA b { color: #e8a393; }
.chat-pane li.attackerB b { color: #a6d6a9; }
.chat-pane .empty { color: var(--ink-dim); border: 0; }

.chat-form { display: flex; gap: 6px; }
.chat-form input { margin-top: 0; }
.chat-form button { padding: 8px 12px; }

.selected, .shop, .log {
  background: var(--bg-soft); border: 1px solid var(--edge);
  border-radius: var(--radius); padding: 12px;
}
.shop h3, .log h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-dim); }

.sel-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.sel-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.sel-actions button { padding: 6px 10px; font-size: 13px; }

.shop-list { display: grid; gap: 6px; }
.shop-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; text-align: left; padding: 8px 10px; font-size: 14px;
}
.shop-item .cost { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.shop-item.active { border-color: var(--accent); background: #3a3020; }
.shop-item small { display: block; color: var(--ink-dim); font-weight: 400; font-size: 12px; }

.log { flex: 1; min-height: 120px; }
.log ul { list-style: none; margin: 0; padding: 0; font-size: 13px; line-height: 1.45; }
.log li { padding: 3px 0; border-bottom: 1px solid #ffffff0d; color: var(--ink-dim); }
.log li b { color: var(--ink); }
.log li.defender b { color: #9cc3ea; }
.log li.attackerA b { color: #e8a393; }
.log li.attackerB b { color: #a6d6a9; }

.overlay {
  position: fixed; inset: 0; background: #0b0906d9;
  display: grid; place-items: center; padding: 20px; z-index: 10;
}
/* display у .overlay перебивает атрибут hidden — гасим явно. */
.overlay[hidden] { display: none; }
.overlay-card {
  background: var(--panel); border: 1px solid var(--accent);
  border-radius: 14px; padding: 26px; max-width: 460px; width: 100%;
  text-align: center;
}
.overlay-card h2 { margin: 0 0 8px; }
.points { list-style: none; padding: 0; margin: 16px 0 20px; }
.points li { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--edge); }
.points .gain { color: var(--accent); font-weight: 700; }

/* Карта 28×22 широкая: пока окно уже этого порога, боковая колонка
   отбирает у неё слишком много ширины — уводим её под поле. */
@media (max-width: 1150px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "board" "side";
    height: auto;
  }
  /* Высоту считаем от ширины карты, чтобы не оставалось пустых полей. */
  .board-wrap { height: min(72vh, 80vw); }
  .side { overflow: visible; }
  .turn-meter { margin-left: 0; text-align: left; }
}

@media (max-width: 560px) {
  .board-wrap { height: min(60vh, 110vw); }
  .resources { grid-template-columns: repeat(2, 1fr); }
}
