/* Дизайн-система «мультяшная стратегия» (единый стиль с городами/юнитами карты): яркие сочные цвета,
   пухлые скругления, толстые тёмно-синие контуры, глянец. Ассеты: toon-resources.png (спрайт бейджей 2×2),
   toon-title.png (баннер лобби). Имена классов не менять — их строит JS. */
:root {
  --sky: #4aa8e8;          /* светлая вода/акценты */
  --deep: #1c5a96;         /* глубокий синий (HUD) */
  --navy: #17324d;         /* контуры/текст на светлом */
  --cream: #fff6e3;        /* карточки */
  --cream-2: #ffeecb;
  --sun: #ffc843;          /* золото */
  --sun-2: #ffaa2b;
  --leaf: #58b64e;         /* зелёный */
  --coral: #ff6b57;        /* главные кнопки */
  --coral-2: #e2453a;
  --ink: #23405c;

  --font: 'Trebuchet MS', 'Segoe UI', Verdana, sans-serif;
  --radius: 14px;
  --dur: 180ms;
  --ease: cubic-bezier(0.34, 1.56, 0.64, 1); /* мультяшный пружинистый овершут */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #1d4468;
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#map:active { cursor: grabbing; }

/* ── HUD: сочная синяя плашка с золотой кромкой ── */
.hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px 12px; row-gap: 6px;
  padding: 6px 12px 8px; pointer-events: none; flex-wrap: wrap;
  background: linear-gradient(#2f7ec4, #1c5a96);
  border-bottom: 4px solid var(--sun);
  box-shadow: 0 4px 16px rgba(10, 30, 55, 0.45);
}
.hud-brand {
  font-size: clamp(1.1rem, 1rem + 1vw, 1.55rem); font-weight: 900; letter-spacing: 0.04em;
  color: var(--sun);
  text-shadow: -1px -1px 0 var(--navy), 1px -1px 0 var(--navy), -1px 1px 0 var(--navy), 2px 2px 0 var(--navy);
}
.hud-info { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.hud-chip {
  font-size: 0.76rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.25); background: rgba(13, 40, 68, 0.55);
  color: #eaf4ff; white-space: nowrap;
}
.hud-chip b { color: var(--sun); }
#hud-status[data-state="connecting"], #hud-status[data-state="reconnecting"] { color: #ffd9a0; }
#hud-status[data-state="connected"] b { color: #8df09a; }

.hud-btn { pointer-events: auto; cursor: pointer; min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid rgba(255,255,255,0.3); border-radius: 12px; background: rgba(13,40,68,0.55); color: #eaf4ff; }
.hud-btn.off { opacity: 0.4; }
.btn[disabled], .build-row[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ── ресурсы: мультяшные бейджи (спрайт 2×2: 🪙 ЛВ, 🌾 ПВ, 📖 ЛН, ✝ ПН) ── */
.resbar { display: flex; gap: 8px; pointer-events: none; flex-wrap: wrap; align-items: center; }
.res-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px 3px 3px; border-radius: 999px;
  background: var(--cream); border: 3px solid var(--navy);
  font-size: 1rem; font-weight: 900; color: var(--navy);
  box-shadow: 0 3px 0 rgba(13, 34, 56, 0.55);
}
.res-ic { width: 32px; height: 32px; background-image: url('/assets/toon-resources.png'); background-size: 200% 200%; border-radius: 50%; }
.res-ic.gold { background-position: 0 0; }
.res-ic.food { background-position: 100% 0; }
.res-ic.science { background-position: 0 100%; }
.res-ic.faith { background-position: 100% 100%; }

/* ── боковые кнопки (Древо/Религия): пухлые жетоны ── */
.side { position: fixed; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; z-index: 15; }
.side-btn {
  font-family: var(--font); font-weight: 900; font-size: 0.95rem;
  min-height: 50px; min-width: 96px; padding: 8px 14px; border-radius: 16px;
  background: linear-gradient(#5fb9f2, #2f7ec4); color: #fff; border: 3px solid var(--navy);
  border-bottom-width: 6px;
  box-shadow: 0 4px 12px rgba(10, 30, 55, 0.35); cursor: pointer;
  text-shadow: 1px 1px 0 rgba(13, 34, 56, 0.6);
  transition: transform var(--dur) var(--ease);
}
.side-btn:hover { transform: translateY(-2px); }
.side-btn:active { transform: translateY(1px); border-bottom-width: 3px; }
.side-btn .badge { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; background: var(--coral); color: #fff; font-size: 0.75rem; border: 2px solid var(--navy); }

/* ── древо / религия ── */
.tree-branch { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 12px 14px;
  border: 3px solid rgba(35, 64, 92, 0.25); border-radius: 14px; margin-bottom: 8px; background: rgba(255,255,255,0.55); }
.tree-branch.active { border-color: var(--sun-2); background: rgba(255, 200, 67, 0.22); }
.tree-name { font-weight: 900; }
.tree-desc { grid-column: 1; font-size: 0.8rem; color: #5a7691; }
.tree-pips { grid-column: 2; grid-row: 1 / span 2; align-self: center; letter-spacing: 2px; color: var(--sun-2); font-size: 1.15rem; }
.tree-branch .btn { grid-column: 1 / span 2; margin-top: 6px; }
.rel-stat { font-size: 1rem; margin: 8px 0; }
/* древо v2 — мостовой диалог (полная страница — #8) */
.tree-active { padding: 8px 12px; margin: 6px 0 10px; border-radius: 12px; background: rgba(255, 200, 67, 0.22);
  border: 2px solid var(--sun-2); font-size: 0.92rem; }
.tree-active.tree-idle { background: rgba(255, 107, 87, 0.15); border-color: var(--coral); font-weight: 700; }
.tree-progress { float: right; font-weight: 900; color: var(--coral-2); }
.tree-mono { display: inline-block; width: 1.4em; margin-right: 4px; font-weight: 900; }

/* ── баннер эпохи ── */
.epoch-banner {
  position: fixed; left: 50%; top: 84px; transform: translateX(-50%) scale(0.9);
  padding: 12px 30px; border-radius: 16px; z-index: 28; text-align: center;
  background: linear-gradient(#ff8a5c, #e2453a); color: #fff; border: 3px solid var(--navy); border-bottom-width: 6px;
  font-size: 1.25rem; font-weight: 900; letter-spacing: 0.03em; opacity: 0;
  box-shadow: 0 8px 24px rgba(10, 30, 55, 0.4); text-shadow: 1px 1px 0 rgba(13,34,56,0.5);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.epoch-banner.show { opacity: 1; transform: translateX(-50%) scale(1); }

@media (max-width: 480px) {
  .side { top: 64px; bottom: auto; right: 8px; transform: none; } /* топфикс №8: под HUD, вне зоны панели */
  .side-btn { min-width: 80px; font-size: 0.84rem; }
  /* компактный HUD (аудит #13): 5 ресурс-чипов + инфо не переносятся в 3 ряда → баннер/тосты не накрывают кнопки */
  .hud { gap: 4px 6px; padding: 4px 8px 6px; }
  .res-chip, .hud-chip { padding: 2px 8px; font-size: 0.82rem; }
  .res-ic { width: 18px; height: 18px; }
}

/* ── лобби / финал ── */
.lobby, .final {
  position: fixed; inset: 0; z-index: 40; overflow-y: auto; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(120% 100% at 50% 0%, #3f97d8, #1c5a96 55%, #143f6d);
}

/* ── экран входа (US-01a): создать/подключиться, поверх всего ── */
.entry {
  position: fixed; inset: 0; z-index: 46; overflow-y: auto; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(120% 100% at 50% 0%, #4aa8e8, #1c5a96 55%, #143f6d);
}
.entry[hidden] { display: none; }
.entry-card {
  width: min(440px, 100%); text-align: center;
  background: var(--cream); border: 4px solid var(--navy); border-bottom-width: 8px;
  border-radius: 24px; padding: 22px 24px 26px; box-shadow: 0 18px 50px rgba(8, 25, 45, 0.5);
}
.entry-logo img { width: min(320px, 84%); height: auto; display: block; margin: 0 auto 4px; }
.entry-sub { font-weight: 800; color: #5a7691; font-size: 1rem; margin-bottom: 14px; }
.entry-err { color: var(--coral-2, #e0563a); font-weight: 800; font-size: 0.92rem; margin: 4px 0 12px; }
.entry-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.entry-big { min-height: 56px; font-size: 1.15rem; }
.entry-code {
  width: 100%; margin: 6px 0 4px; padding: 14px 16px; border-radius: 16px;
  border: 3px solid rgba(35, 64, 92, 0.35); background: #fff;
  font-family: var(--font); font-weight: 900; font-size: 1.6rem; letter-spacing: 0.24em;
  text-align: center; text-transform: uppercase; color: var(--navy);
}
.entry-code:focus { border-color: var(--sun-2); box-shadow: 0 0 0 3px rgba(255, 170, 43, 0.35); outline: none; }
.entry-code::placeholder { letter-spacing: 0.12em; color: #a8b8c8; }
.lb-card, .fn-card {
  width: min(760px, 100%); position: relative;
  background: var(--cream);
  border: 4px solid var(--navy); border-bottom-width: 8px;
  border-radius: 24px; padding: 20px 24px;
  box-shadow: 0 18px 50px rgba(8, 25, 45, 0.5);
}
.lb-hero { display: block; width: min(540px, 100%); margin: -4px auto 8px; }
.lb-hero img { width: 100%; height: auto; display: block; border-radius: 16px; border: 3px solid var(--navy); }
.lb-title, .fn-title { font-size: clamp(1.4rem, 1rem + 3vw, 2.1rem); font-weight: 900; color: var(--coral-2); text-align: center; text-shadow: 1px 1px 0 rgba(255,255,255,0.6); }
.lb-code { text-align: center; margin: 10px 0 16px; font-size: 1.05rem; font-weight: 700; }
.lb-code b { color: var(--coral-2); letter-spacing: 0.2em; font-size: 1.35rem; }
.lb-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.lb-h { font-weight: 900; margin-bottom: 8px; color: #5a7691; letter-spacing: 0.06em; text-transform: uppercase; font-size: 0.85rem; }
.lb-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.lb-list li { padding: 7px 11px; background: #fff; border: 2px solid rgba(35,64,92,0.18); border-radius: 12px; font-weight: 700; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 5px; border: 2px solid var(--navy); margin-right: 6px; vertical-align: -2px; }
.sw.big { width: 22px; height: 22px; }
.tag { font-size: 0.72rem; padding: 1px 8px; border-radius: 999px; background: var(--sun); color: var(--navy); border: 2px solid var(--navy); font-weight: 900; }
.muted { color: #7d94aa; font-size: 0.85rem; }
.power-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.power {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; min-height: 50px;
  border: 3px solid var(--navy); border-bottom-width: 5px; border-radius: 14px;
  background: linear-gradient(color-mix(in oklab, var(--pc) 55%, #fff), color-mix(in oklab, var(--pc) 75%, #fff));
  color: var(--navy); font-family: var(--font); font-weight: 900; cursor: pointer;
  transition: transform var(--dur) var(--ease);
}
.power:hover { transform: translateY(-2px) scale(1.02); }
.power.mine { outline: 4px solid var(--sun); box-shadow: 0 0 0 2px var(--sun-2), 0 6px 16px rgba(255, 178, 43, 0.45); }
.power[disabled] { opacity: 0.4; cursor: not-allowed; }
.power .mono { font-size: 1.3rem; width: 1.5em; text-align: center; }
.lb-settings { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.lb-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-weight: 700; }
.lb-row input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--coral); }
.segs { display: inline-flex; gap: 6px; }
.seg { min-height: 40px; padding: 6px 14px; border-radius: 12px; cursor: pointer; font-family: var(--font); font-weight: 700;
  border: 3px solid rgba(35,64,92,0.3); background: #fff; color: var(--ink); }
.seg.on { background: linear-gradient(#5fb9f2, #2f7ec4); color: #fff; border-color: var(--navy); text-shadow: 1px 1px 0 rgba(13,34,56,0.5); }
.lb-start { width: 100%; margin-top: 18px; min-height: 56px; font-size: 1.2rem; }
.lb-wait { text-align: center; color: #7d94aa; margin-top: 18px; font-style: italic; }

/* ── финал ── */
.fn-winner { text-align: center; font-size: 1.4rem; font-weight: 900; margin: 12px 0 18px; }
.fn-table { width: 100%; border-collapse: collapse; }
.fn-table th, .fn-table td { text-align: left; padding: 8px 10px; border-bottom: 2px solid rgba(35,64,92,0.15); }
.fn-table th { color: #5a7691; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.fn-table td.vp { font-weight: 900; color: var(--coral-2); }
.fn-table td.brk { font-size: 0.82rem; color: #7d94aa; }
.fn-table tr.win td { background: rgba(255, 200, 67, 0.3); }
.fn-table tr.dead { opacity: 0.55; }
#fn-again { width: 100%; margin-top: 18px; min-height: 52px; }

@media (max-width: 560px) { .lb-cols { grid-template-columns: 1fr; } .fn-table td.brk { display: none; } }

/* ── кнопки: пухлые, с толстым контуром и «дном» (мультяшная глубина) ── */
.btn {
  font-family: var(--font); font-size: 1rem; font-weight: 900;
  padding: 10px 18px; min-height: 44px; border-radius: var(--radius);
  border: 3px solid var(--navy); border-bottom-width: 6px;
  background: linear-gradient(#ffe08a, #ffc843); color: var(--navy);
  cursor: pointer; transition: transform var(--dur) var(--ease);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px); border-bottom-width: 3px; }
.btn-primary { background: linear-gradient(#ff8a5c, #e2453a); color: #fff; text-shadow: 1px 1px 0 rgba(13,34,56,0.5); }
.btn-ghost { background: rgba(255,255,255,0.75); }

/* ── контекстная панель региона ── */
.panel {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  width: min(540px, calc(100vw - 24px)); max-height: 46vh;
  padding: 14px 18px; border-radius: 20px; z-index: 18; /* выше side/marches(15) и fab(16) — крестик кликается */
  background: var(--cream);
  border: 4px solid var(--navy); border-bottom-width: 7px;
  box-shadow: 0 12px 36px rgba(8, 25, 45, 0.45);
  display: flex; flex-direction: column; overflow: hidden; /* крестик на нескроллящейся панели, скроллится .panel-scroll */
}
.panel-scroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
.panel-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-right: 34px; /* резерв под крестик */ }
.panel-title { font-size: 1.2rem; font-weight: 900; display: inline-flex; align-items: center; gap: 8px; }
.panel-title b { color: var(--coral-2); }
.panel-sub { font-size: 0.95rem; color: #5a7691; font-weight: 700; }
.panel-hint { font-size: 1rem; color: #5a7691; }
.panel-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.panel-actions:empty { display: none; }
.swatch { width: 15px; height: 15px; border-radius: 5px; border: 2px solid var(--navy); display: inline-block; }
.panel-chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.chip { font-size: 0.78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: rgba(255,200,67,0.35); border: 2px solid rgba(35,64,92,0.3); }
.slots { font-size: 0.78rem; color: #7d94aa; margin-left: auto; }

/* ── постройки ── */
.build-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; overflow-y: auto; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
.build-row { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; text-align: left; gap: 2px 10px; align-items: center; padding: 10px 14px; }
.build-name { font-weight: 900; grid-column: 1; grid-row: 1; }
.build-desc { grid-column: 1; grid-row: 2; font-size: 0.82rem; color: #5a7691; }
.build-cost { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-weight: 900; color: var(--coral-2); white-space: nowrap; }
.build-row.is-disabled { opacity: 0.5; cursor: not-allowed; }

/* ── диалог количества ── */
.dialog { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(12, 32, 54, 0.55); z-index: 50; } /* выше тостов/баннеров(25-30) — их клики не перехватывают контролы модалки */
.dlg-card {
  width: min(380px, calc(100vw - 32px)); padding: 22px;
  background: var(--cream);
  border: 4px solid var(--navy); border-bottom-width: 8px; border-radius: 22px;
  box-shadow: 0 16px 44px rgba(8, 25, 45, 0.55); text-align: center;
  position: relative;                    /* якорь для крестика .dlg-x */
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);       /* влезает в экран (учёт браузерной панели на мобиле) */
  display: flex; flex-direction: column; /* заголовок сверху, список скроллится, кнопки закреплены снизу */
}
/* крестик закрытия — во всех диалогах, всегда виден в углу (не уезжает при длинном списке) */
.dlg-x {
  position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--navy); background: var(--cream-2, #fdeed3); color: #23405c;
  font-weight: 900; cursor: pointer; line-height: 1; z-index: 1;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dlg-x:hover { background: var(--coral); color: #fff; transform: scale(1.08); }
.dlg-title { font-size: 1.15rem; font-weight: 900; color: var(--coral-2); padding: 0 30px; flex: none; }
.dlg-actions { flex: none; }
.dlg-value { font-size: 2.1rem; font-weight: 900; margin: 6px 0; }
.dlg-card input[type="range"] { width: 100%; accent-color: var(--coral); }
.dlg-hint { min-height: 1.4em; margin: 8px 0; font-size: 0.95rem; font-weight: 700; }
.dlg-hint .sure { color: #2f9e4f; } .dlg-hint .risky { color: var(--sun-2); } .dlg-hint .loss { color: var(--coral-2); }
.dlg-quick, .dlg-actions { display: flex; gap: 10px; margin-top: 10px; }
.dlg-quick .btn, .dlg-actions .btn { flex: 1; }

/* ── тост / баннеры ── */
/* тосты-стек (топфикс №2): позиционирует контейнер, пилюли складываются колонкой */
.toast-stack { position: fixed; left: 50%; top: 96px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 30; align-items: center; pointer-events: none; }
.toast { transform: translateY(-8px);
  padding: 10px 18px; border-radius: 999px; background: var(--navy); color: #fff;
  border: 3px solid rgba(255,255,255,0.25); font-size: 0.95rem; font-weight: 700; opacity: 0;
  box-shadow: 0 6px 18px rgba(8, 25, 45, 0.5); pointer-events: auto;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.clickable { cursor: pointer; }
.toast.clickable:active { transform: scale(0.96); }
.banner { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 16px 30px; border-radius: 18px; z-index: 25; text-align: center;
  background: linear-gradient(#2f7ec4, #1c5a96); color: #fff;
  font-size: 1.15rem; font-weight: 900; letter-spacing: 0.02em;
  border: 3px solid var(--navy); border-bottom-width: 6px; box-shadow: 0 10px 32px rgba(8,25,45,0.55); }

@media (max-width: 480px) {
  .panel { width: calc(100vw - 12px); bottom: 8px; }
  .lobby, .final { padding: 8px; }
  .lb-card, .fn-card, .dlg-card { padding: 14px 15px; border-radius: 18px; }
  .lb-hero { width: 100%; }
  .power { padding: 9px 8px; gap: 6px; }
  .power .mono { font-size: 1.15rem; width: 1.3em; }
}
@media (prefers-reduced-motion: reduce) { .btn, .toast, .power, .side-btn { transition: none; } }

/* чип суммарной армии (метрика владельца) */
.res-chip.res-army { padding: 3px 12px; gap: 4px; background: #ffe6d9; }

/* ── полки (v2 #15): жетоны состава, слайдеры полка, слоты войска ── */
.unit-token { cursor: help; }
.slots-mil { color: var(--coral-2); border-color: rgba(255, 107, 87, 0.4); }
.reg-rows { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; overflow-y: auto; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
.reg-row { display: flex; align-items: center; gap: 8px; }
.reg-ic { flex: none; width: 26px; text-align: center; font-size: 1.05rem; }
.reg-name { flex: none; width: 118px; font-weight: 800; font-size: 0.82rem; color: #23405c;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reg-range { flex: 1; }
.reg-n { flex: none; width: 34px; text-align: right; font-weight: 900; color: var(--coral-2); }
.unit-star { color: var(--sun-2); }
@media (max-width: 480px) { .reg-name { width: 84px; font-size: 0.76rem; } }

/* ── СТРАНИЦА ДРЕВА (v2 #8): полноэкранный слой, пан/зум transform, узлы-кнопки, svg-лианы ── */
.treepage { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column;
  background: radial-gradient(120% 100% at 50% 0%, #3f97d8, #1c5a96 55%, #143f6d); }
.tp-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; flex: none;
  background: rgba(13, 40, 68, 0.6); border-bottom: 3px solid var(--navy); z-index: 41; }
.tp-title { font-weight: 900; font-size: 1.15rem; color: var(--cream); text-shadow: 1px 1px 0 rgba(13,34,56,.6); }
.tp-head .hud-chip { margin-left: auto; }
.tp-head .hud-chip + .hud-chip { margin-left: 0; }
.tp-canvas { position: relative; flex: 1; overflow: hidden; touch-action: none; cursor: grab; }
.tp-canvas:active { cursor: grabbing; }
.tp-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.tp-band { position: absolute; left: 12px; border-top: 2px dashed rgba(255, 252, 240, 0.25);
  color: rgba(255, 252, 240, 0.55); font-weight: 900; font-size: 0.8rem; padding-top: 2px; }
.tp-sphere-head { position: absolute; top: 0; width: 132px; text-align: center; font-weight: 900;
  font-size: 0.85rem; text-shadow: 1px 1px 0 rgba(13, 34, 56, 0.7); }
.tp-edges { position: absolute; left: 0; top: 0; pointer-events: none; }
.tp-link { fill: none; stroke-width: 2.5; opacity: 0.25; }
.tp-link.is-met { opacity: 0.85; stroke-width: 3; }
.tp-node { position: absolute; width: 132px; height: 56px; padding: 6px 10px; text-align: left;
  background: var(--cream); border: 3px solid var(--sph, var(--navy)); border-bottom-width: 5px;
  border-radius: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 1px;
  font-family: var(--font); transition: transform var(--dur) var(--ease); }
.tp-node:hover { transform: translateY(-2px); }
.tp-node .tp-name { font-weight: 900; font-size: 0.78rem; color: #23405c; line-height: 1.1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-node .tp-cost { font-weight: 800; font-size: 0.72rem; color: #7d94aa; align-self: flex-end; }
.tp-node.is-done { background: #d9f2d9; border-color: #2e8b57; }
.tp-node.is-done .tp-cost { color: #2e8b57; }
.tp-node.is-open { box-shadow: 0 0 0 3px rgba(255, 200, 67, 0.55); animation: tp-pulse 1.6s infinite; }
.tp-node.is-poor .tp-cost { color: var(--coral-2); }
.tp-node.is-locked-era { filter: grayscale(1); opacity: 0.45; }
.tp-node.is-locked-req { opacity: 0.55; }
.tp-node.is-active { background: rgba(255, 200, 67, 0.35); border-color: var(--sun-2); }
.tp-node.is-queued { border-style: dashed; border-color: var(--sun-2); }
@keyframes tp-pulse { 0%, 100% { box-shadow: 0 0 0 3px rgba(255, 200, 67, 0.55); } 50% { box-shadow: 0 0 0 6px rgba(255, 200, 67, 0.25); } }
.tp-card { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 42;
  width: min(400px, calc(100vw - 24px)); background: var(--cream); border: 4px solid var(--navy);
  border-bottom-width: 7px; border-radius: 18px; padding: 12px 16px;
  max-height: calc(100% - 92px); overflow-y: auto; overscroll-behavior: contain; /* верх (эффекты) не обрезается */
  box-shadow: 0 12px 36px rgba(8, 25, 45, 0.45); }
.tp-card-name { font-weight: 900; font-size: 1.1rem; }
.tp-card-cost { font-weight: 800; color: #7d94aa; margin: 2px 0 6px; }
.tp-card-fx { margin: 2px 0; font-size: 0.85rem; font-weight: 700; color: #23405c; }
.tp-card-req { margin: 6px 0 0; font-size: 0.8rem; color: var(--coral-2); font-weight: 700; }
.tp-card-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.tp-card-state { align-self: center; margin-right: auto; font-weight: 900; color: var(--sun-2); }
.tp-dock { flex: none; display: flex; align-items: center; gap: 14px; padding: 8px 14px; z-index: 41;
  background: rgba(13, 40, 68, 0.75); border-top: 3px solid var(--navy); color: var(--cream); min-height: 52px; }
.tp-dock-active { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; font-weight: 800; }
.tp-bar { flex: 1; max-width: 220px; height: 10px; border-radius: 999px; background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.3); overflow: hidden; }
.tp-bar-fill { height: 100%; background: linear-gradient(#ffd76a, #ffaa2b); transition: width 0.6s var(--ease); }
.tp-dock-eta { font-size: 0.82rem; opacity: 0.9; white-space: nowrap; }
.tp-dock-next { font-size: 0.85rem; opacity: 0.85; white-space: nowrap; }
.tp-dock-hint { font-weight: 800; opacity: 0.9; }
@media (prefers-reduced-motion: reduce) { .tp-node.is-open { animation: none; } .tp-node, .tp-bar-fill { transition: none; } }
@media (max-width: 720px) { .tp-card { bottom: 64px; } .tp-dock-next { display: none; } }

/* ── онбординг первой партии (топфикс №3) ── */
.onb-scrim { position: fixed; inset: 0; background: rgba(12, 32, 54, 0.35); z-index: 44; }
.onb-tip { position: fixed; z-index: 45; max-width: 240px; padding: 10px 14px;
  background: var(--cream); border: 3px solid var(--navy); border-bottom-width: 6px; border-radius: 16px;
  box-shadow: 0 10px 28px rgba(8, 25, 45, 0.45); }
.onb-tip::after { content: ''; position: absolute; left: 50%; top: -9px; transform: translateX(-50%);
  border: 9px solid transparent; border-bottom-color: var(--navy); border-top: none; }
.onb-tip.above::after { top: auto; bottom: -9px; border-bottom: none; border-top: 9px solid var(--navy); }
.onb-text { margin: 0 0 10px; font-weight: 700; font-size: 0.9rem; color: #23405c; }
.onb-actions { display: flex; gap: 8px; justify-content: flex-end; }
.onb-actions .btn { min-height: 36px; padding: 4px 12px; font-size: 0.82rem; }

/* ── HUD «⋯» (топфикс №7): служебные чипы в выпадашке ── */
.hud-info { position: relative; }
.hud-more-pop { position: absolute; top: 100%; right: 8px; margin-top: 6px;
  display: flex; flex-direction: column; gap: 6px; background: rgba(13, 40, 68, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.25); border-radius: 14px; padding: 8px; z-index: 20; }
.hud-more-pop .hud-chip { white-space: nowrap; }
.hud-more-pop[hidden] { display: none; }

/* ── панель: портрет города + доход (№4), бейджи статуса (№6), слои кнопок (№5) ── */
.panel-city { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.panel-city-ic { width: 80px; height: 80px; border-radius: 50%; border: 3px solid var(--navy);
  background: var(--cream-2, #fdeed3); box-shadow: 0 3px 0 rgba(13, 34, 56, 0.4);
  display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none; }
.panel-city-ic img { width: 72px; height: 72px; object-fit: contain; }
.panel-city-lvl { font-size: 1.6rem; font-weight: 900; color: var(--coral-2); display: block; }
.panel-city-pips { color: var(--sun-2); font-size: 1rem; letter-spacing: 2px; }
.panel-income { display: flex; align-items: center; gap: 4px; font-weight: 800; font-size: 0.9rem; color: #23405c; margin-top: 4px; }
.panel-income .res-ic { width: 18px; height: 18px; }
.panel-stats { display: flex; gap: 8px; margin: 6px 0; flex-wrap: wrap; }
.stat-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  background: #fff; border: 2px solid rgba(35, 64, 92, 0.25); font-weight: 900; font-size: 0.85rem; }
.stat-shock { background: rgba(255, 170, 43, 0.25); border-color: var(--sun-2); color: var(--coral-2); }
.panel-actions .btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 110px; }
.act-label { font-weight: 900; }
.act-cost { font-size: 0.78rem; opacity: 0.85; align-self: flex-end; }
.act-reason { flex-basis: 100%; font-size: 0.72rem; color: var(--coral-2); margin: 2px 0 0; }

/* ── иконки построек (№10): спрайт-лист toon-buildings.png 4×2 в чипах и диалоге постройки ── */
.chip[class*="b-"]::before { content: ''; display: inline-block; width: 16px; height: 16px; margin-right: 4px;
  vertical-align: -3px; background-image: url('/assets/toon-buildings.png'); background-size: 400% 200%; border-radius: 50%; }
.chip.b-farm::before { background-position: 0 0; }
.chip.b-fort::before { background-position: 33.33% 0; }
.chip.b-market::before { background-position: 66.66% 0; }
.chip.b-port::before { background-position: 100% 0; }
.chip.b-temple::before { background-position: 0 100%; }
.chip.b-library::before { background-position: 33.33% 100%; }
.chip.b-wonder::before { background-position: 66.66% 100%; }
.build-ic { display: inline-block; width: 22px; height: 22px; margin-right: 6px; vertical-align: -5px;
  background-image: url('/assets/toon-buildings.png'); background-size: 400% 200%; border-radius: 50%; }
.build-ic.b-farm { background-position: 0 0; }
.build-ic.b-fort { background-position: 33.33% 0; }
.build-ic.b-market { background-position: 66.66% 0; }
.build-ic.b-port { background-position: 100% 0; }
.build-ic.b-temple { background-position: 0 100%; }
.build-ic.b-library { background-position: 33.33% 100%; }
.build-ic.b-wonder { background-position: 66.66% 100%; }

/* ── FAB «домой» (топфикс №1): к своей столице; прячется под открытой панелью ── */
.fab-home {
  position: fixed; left: 12px; bottom: 12px; z-index: 16;
  width: 54px; height: 54px; border-radius: 50%;
  border: 3px solid var(--navy); border-bottom-width: 6px;
  background: var(--cream) url('/assets/toon-icon-home.png') center / 70% no-repeat;
  box-shadow: 0 4px 12px rgba(10, 30, 55, 0.35); cursor: pointer;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.fab-home:hover { transform: translateY(-2px); }
.fab-home:active { transform: translateY(1px); border-bottom-width: 3px; }
body.has-panel .fab-home, body.has-panel .marches, body.has-panel .side { opacity: 0; pointer-events: none; } /* панель не перехватывается плавающими */

/* ── панель: кнопка закрытия + режим прицела похода (топфикс №9) ── */
.panel-close {
  position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--navy); background: var(--cream-2, #fdeed3); color: #23405c;
  font-weight: 900; cursor: pointer; line-height: 1;
}
.panel.is-targeting { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(255, 107, 87, 0.35), 0 12px 36px rgba(8, 25, 45, 0.45); }
.panel.is-targeting .panel-hint { font-size: 1.05rem; font-weight: 900; }
.panel.is-targeting .pnl-target-ic { display: inline-block; margin-right: 6px; animation: pnl-pulse 1.2s infinite; }
@keyframes pnl-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .panel.is-targeting .pnl-target-ic, .fab-home { animation: none; transition: none; } }

/* ── АРТ v2 (#18): спрайт-листы Higgsfield 4×2 — юниты/сферы/террейн/военные здания ── */
.unit-ic { display: inline-block; width: 20px; height: 20px; border-radius: 50%; vertical-align: -4px;
  background-image: url('/assets/units-ui.png'); background-size: 400% 200%; }
.unit-ic.u-inf { background-position: 0 0; } .unit-ic.u-spear { background-position: 33.33% 0; }
.unit-ic.u-arch { background-position: 66.66% 0; } .unit-ic.u-lcav { background-position: 100% 0; }
.unit-ic.u-hcav { background-position: 0 100%; } .unit-ic.u-siege { background-position: 33.33% 100%; }
.unit-ic.u-ship { background-position: 66.66% 100%; } .unit-ic.u-eleph { background-position: 100% 100%; }
.unit-ic.unit-ic-lg { width: 28px; height: 28px; vertical-align: -8px; }
.sph-ic { display: inline-block; width: 22px; height: 22px; border-radius: 50%; vertical-align: -5px;
  background-image: url('/assets/tree-spheres.png'); background-size: 400% 200%; }
.sph-ic.sph-war { background-position: 0 0; } .sph-ic.sph-sea { background-position: 33.33% 0; }
.sph-ic.sph-craft { background-position: 66.66% 0; } .sph-ic.sph-trade { background-position: 100% 0; }
.sph-ic.sph-farm { background-position: 0 100%; } .sph-ic.sph-faith { background-position: 33.33% 100%; }
.sph-ic.sph-admin { background-position: 66.66% 100%; }
.ter-ic { display: inline-block; width: 18px; height: 18px; border-radius: 50%; vertical-align: -4px;
  background-image: url('/assets/terrain-ui.png'); background-size: 400% 200%; }
.ter-ic.t-plains { background-position: 0 0; } .ter-ic.t-steppe { background-position: 33.33% 0; }
.ter-ic.t-hills { background-position: 66.66% 0; } .ter-ic.t-forest { background-position: 100% 0; }
.ter-ic.t-mountains { background-position: 0 100%; } .ter-ic.t-desert { background-position: 33.33% 100%; }
.ter-ic.t-tundra { background-position: 66.66% 100%; } .ter-ic.t-sea { background-position: 100% 100%; }
/* военные здания (лист toon-buildings-2.png) — те же чип/диалог классы, что у гражданских */
.chip.b-barracks::before, .chip.b-archery_range::before, .chip.b-stable::before, .chip.b-siege_yard::before,
.chip.b-shipyard::before, .chip.b-elephant_yard::before, .chip.b-citadel::before, .chip.b-road::before,
.build-ic.b-barracks, .build-ic.b-archery_range, .build-ic.b-stable, .build-ic.b-siege_yard,
.build-ic.b-shipyard, .build-ic.b-elephant_yard, .build-ic.b-citadel, .build-ic.b-road {
  background-image: url('/assets/toon-buildings-2.png'); }
.chip.b-barracks::before, .build-ic.b-barracks { background-position: 0 0; }
.chip.b-archery_range::before, .build-ic.b-archery_range { background-position: 33.33% 0; }
.chip.b-stable::before, .build-ic.b-stable { background-position: 66.66% 0; }
.chip.b-siege_yard::before, .build-ic.b-siege_yard { background-position: 100% 0; }
.chip.b-shipyard::before, .build-ic.b-shipyard { background-position: 0 100%; }
.chip.b-elephant_yard::before, .build-ic.b-elephant_yard { background-position: 33.33% 100%; }
.chip.b-citadel::before, .build-ic.b-citadel { background-position: 66.66% 100%; }
.chip.b-road::before, .build-ic.b-road { background-position: 100% 100%; }

/* ── стек активных походов (#5/#6): под side-кнопками, мультяшные карточки ── */
.marches { position: fixed; right: 12px; bottom: 130px; display: flex; flex-direction: column; gap: 6px; z-index: 15; max-width: 240px;
  max-height: calc(100dvh - 210px); overflow-y: auto; overscroll-behavior: contain; } /* крестики отмены не уезжают за экран */
.march-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px;
  background: var(--cream); border: 3px solid var(--navy); border-bottom-width: 5px; border-radius: 14px;
  box-shadow: 0 4px 10px rgba(10, 30, 55, 0.3); font-size: 0.82rem; font-weight: 800; color: #23405c; }
.march-info { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.march-left { margin-left: 6px; color: #7d94aa; font-weight: 700; }
.march-cancel { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid var(--navy);
  background: var(--coral); color: #fff; font-weight: 900; cursor: pointer; line-height: 1;
  transition: transform var(--dur) var(--ease); }
.march-cancel:hover { transform: scale(1.12); }
@media (max-width: 720px) {
  .marches { bottom: 150px; max-width: 190px; max-height: calc(100dvh - 230px); }
  .side { top: 64px; bottom: auto; transform: none; } /* top-anchor: не сталкивается с bottom-anchor .marches */
}

/* ── ЛОББИ V2 (спека дизайн-комитета) ── */
.lb-shell { width: min(920px, 100%); position: relative; background: var(--cream); border: 4px solid var(--navy); border-bottom-width: 8px;
  border-radius: 24px; padding: 20px 24px; box-shadow: 0 18px 50px rgba(8,25,45,.5); }
.lb-exit { position: absolute; top: 12px; left: 12px; z-index: 2; padding: 6px 14px; border-radius: 12px;
  border: 3px solid var(--navy); background: var(--cream-2, #fdeed3); color: #23405c; font-family: var(--font);
  font-weight: 900; cursor: pointer; transition: transform var(--dur) var(--ease), background var(--dur) var(--ease); }
.lb-exit:hover { background: var(--coral); color: #fff; transform: translateY(-1px); }
.lb-roomrow { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 8px 0; }
.lb-name-row { display: flex; align-items: center; gap: 10px; margin: 10px 0 6px; font-weight: 700; }
.lb-name-input { flex: 1; max-width: 280px; padding: 10px 14px; border-radius: 12px; border: 3px solid rgba(35,64,92,.3);
  font-family: var(--font); font-size: 1rem; font-weight: 700; }
.lb-name-input:focus { border-color: var(--sun-2); box-shadow: 0 0 0 3px rgba(255,170,43,.35); outline: none; }
.lb-steps { display: flex; gap: 16px; margin: 10px 0; font-size: .85rem; font-weight: 700; flex-wrap: wrap; }
.lb-step.done { color: #7d94aa; text-decoration: line-through; }
.lb-step.done::before { content: '✓ '; color: var(--leaf); }
.lb-step.active { color: var(--coral-2); }
.lb-step.muted { color: #7d94aa; }
.lb-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 20px; }
.lb-tabs { display: inline-flex; gap: 6px; margin-bottom: 10px; }
.lb-tab { min-height: 38px; padding: 6px 16px; border-radius: 12px; cursor: pointer; font-family: var(--font);
  font-weight: 900; border: 3px solid rgba(35,64,92,.3); background: #fff; color: var(--ink); }
.lb-tab.on { background: linear-gradient(#5fb9f2, #2f7ec4); color: #fff; border-color: var(--navy); }
.lb-worldmap { position: relative; width: 100%; aspect-ratio: 2 / 1; border-radius: 16px; overflow: visible;
  margin-top: 26px; /* запас под тело северных пинов (Дания/Русь) — не обрезаются */
  border: 3px solid var(--navy); background: linear-gradient(#3f97d8, #1c5a96); }
.lb-worldmap-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; border-radius: 13px; }
.lb-pin { position: absolute; width: 44px; height: 44px; transform: translate(-50%, -100%); background: none; border: none;
  padding: 0; cursor: pointer; display: flex; align-items: flex-end; justify-content: center;
  animation: lb-pop var(--dur) var(--ease) both; animation-delay: calc(var(--i, 0) * 25ms); }
.lb-pin-dot { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(45deg); transform-origin: bottom center;
  background: radial-gradient(color-mix(in oklab, var(--pc) 55%, #fff), color-mix(in oklab, var(--pc) 85%, #fff));
  border: 3px solid var(--navy); box-shadow: 0 3px 0 rgba(13,34,56,.4);
  display: flex; align-items: center; justify-content: center; transition: transform var(--dur) var(--ease); }
.lb-pin-dot .mono { transform: rotate(-45deg); font-size: .8rem; font-weight: 900; color: var(--navy); }
.lb-pin:hover .lb-pin-dot { transform: rotate(45deg) translateY(-4px) scale(1.18); }
.lb-pin.mine .lb-pin-dot { outline: 3px solid var(--sun); box-shadow: 0 0 0 2px var(--sun-2), 0 6px 16px rgba(255,178,43,.5); }
.lb-pin[disabled] { opacity: .35; cursor: not-allowed; }
.lb-search-row { margin-bottom: 8px; }
.lb-search { width: 100%; padding: 10px 14px; border-radius: 12px; border: 3px solid rgba(35,64,92,.3);
  font-family: var(--font); font-size: 1rem; font-weight: 700; }
.lb-search:focus { border-color: var(--sun-2); outline: none; }
.lb-region-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.lb-region-chip { cursor: pointer; font-family: var(--font); }
.lb-region-chip.on { background: var(--sun); border-color: var(--navy); }
.lb-power-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); max-height: 46vh; overflow-y: auto; padding-right: 4px; }
.power { animation: lb-pop var(--dur) var(--ease) both; animation-delay: calc(var(--i, 0) * 20ms); }
.lb-settings-wrap { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.lb-advanced { border: 3px dashed rgba(35,64,92,.25); border-radius: 14px; padding: 8px 14px; }
.lb-advtoggle { cursor: pointer; font-weight: 900; color: #5a7691; }
.lb-advanced-body { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.lb-player-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lb-player-row.offline { opacity: .5; }
.lb-status.waiting { border: 2px dashed rgba(35,64,92,.3); border-radius: 999px; padding: 2px 8px; color: #7d94aa; font-size: .8rem; }
.lb-footer { margin-top: 14px; }
.lb-start-hint { text-align: center; color: #7d94aa; font-size: .85rem; margin-top: 6px; }
@keyframes lb-pop { from { opacity: 0; transform: scale(.6) translateY(8px); } to { opacity: 1; transform: none; } }
.lb-pin { transform: translate(-50%, -100%); } /* пин позиционируется остриём в столицу — не перебивать анимацией */
@keyframes lb-pop-pin { from { opacity: 0; } to { opacity: 1; } }
.lb-pin { animation-name: lb-pop-pin; }
@media (max-width: 560px) {
  .lb-grid { grid-template-columns: 1fr; }
  .lb-picker { order: 1; } .lb-players { order: 2; }
  .lb-footer { position: sticky; bottom: 0; background: var(--cream); box-shadow: 0 -6px 16px rgba(8,25,45,.15); padding: 8px 0 2px; }
  /* финал (аудит #10): «Сыграть ещё» закреплён снизу над длинной таблицей 22 держав */
  #fn-again { position: sticky; bottom: 0; background: var(--cream); box-shadow: 0 -6px 16px rgba(8,25,45,.15); padding-bottom: 4px; }
}
@media (prefers-reduced-motion: reduce) { .lb-pin, .lb-pin-dot, .power { animation: none; transition: none; } }
.res-ic.army { background-image: url('/assets/toon-icon-army.png'); background-size: cover; background-position: center; }
