/* ===== Остров - тёмная настольная эстетика ===== */
:root {
  --wood-900: #120c09;
  --wood-800: #1a120d;
  --wood-700: #241811;
  --wood-600: #30211a;
  --wood-500: #3f2d22;
  --parch: #e8d9b5;
  --parch-dim: #c9b892;
  --ink: #f1e8d6;
  --ink-muted: #a89c86;
  --ink-faint: #6f6455;
  --gold: #c9a24a;
  --gold-soft: #e2c477;
  --sea: #0d1a22;
  --sea-2: #123040;
  --red: #d94f3d;
  --green: #5fb37a;
  --line: rgba(232, 217, 181, 0.12);
  --line-strong: rgba(232, 217, 181, 0.25);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font-ui: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(201, 162, 74, 0.10), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(18, 48, 64, 0.35), transparent 60%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.012) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, var(--wood-800), var(--wood-900));
  min-height: 100vh;
}
a { color: var(--gold-soft); }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Иконки */
[data-icon] { display: inline-flex; width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: 0 0 auto; }
[data-icon] svg { width: 100%; height: 100%; display: block; }

/* ===== Шапка ===== */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(0,0,0,0.25), transparent);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; color: var(--gold); }
.brand-title { font-family: var(--font-display); font-size: 26px; font-weight: 700; letter-spacing: 0.04em; line-height: 1; color: var(--parch); }
.brand-sub { font-size: 12px; color: var(--ink-muted); margin-top: 3px; }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(232,217,181,0.06); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-muted);
}
.pill-me { color: var(--parch); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); box-shadow: 0 0 0 2px rgba(0,0,0,0.3); }
.dot.on { background: var(--green); box-shadow: 0 0 8px rgba(95,179,122,0.7); }
.dot.warn { background: var(--gold); }
.dot.off { background: var(--red); }

/* ===== Общее ===== */
.screen { padding: 20px; max-width: 1480px; margin: 0 auto; }
.h1 { font-family: var(--font-display); font-weight: 700; font-size: 40px; line-height: 1.05; margin: 0 0 12px; color: var(--parch); letter-spacing: 0.01em; }
.h2 { font-family: var(--font-display); font-weight: 700; font-size: 21px; margin: 0; color: var(--parch); display: flex; align-items: center; gap: 8px; letter-spacing: 0.02em; }
.h2 [data-icon] { color: var(--gold); width: 1em; height: 1em; }
.lead { color: var(--parch-dim); font-size: 15px; margin: 0 0 20px; max-width: 60ch; }
.muted { color: var(--ink-muted); font-size: 12px; }

.card {
  background: linear-gradient(180deg, rgba(232,217,181,0.05), rgba(232,217,181,0.02));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
  position: relative;
}
.card::before {
  content: ''; position: absolute; inset: 6px; border-radius: calc(var(--radius) - 5px);
  border: 1px solid rgba(232,217,181,0.06); pointer-events: none;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.counter { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--gold); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(232,217,181,0.10), rgba(232,217,181,0.04));
  color: var(--ink); font-weight: 600; font-size: 14px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: rgba(232,217,181,0.14); border-color: rgba(232,217,181,0.4); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: linear-gradient(180deg, #d9b45e, #b58a2f); color: #1d1408; border-color: #e6c87a; text-shadow: 0 1px 0 rgba(255,255,255,0.25); }
.btn-primary:hover { background: linear-gradient(180deg, #e6c26d, #c2973a); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: rgba(217,79,61,0.5); color: #f0a196; }
.btn-lg { padding: 13px 22px; font-size: 16px; border-radius: 12px; }
.btn-sm { padding: 6px 8px; font-size: 12px; border-radius: 8px; }
.btn-icon { padding: 9px; }
.btn [data-icon] { width: 1.1em; height: 1.1em; }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); margin-bottom: 6px; font-weight: 600; }
.field-hint { display: block; font-size: 12px; color: var(--ink-faint); margin-top: 6px; text-align: right; }
.field-hint.over { color: var(--red); }
input[type=text], textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 5, 3, 0.45); color: var(--ink);
  outline: none; resize: vertical;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type=text]:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,162,74,0.15); }
textarea::placeholder, input::placeholder { color: var(--ink-faint); }
.form-msg { font-size: 13px; color: var(--gold-soft); margin: 10px 0 0; }
.form-msg.err { color: #f0a196; }

/* ===== Лобби ===== */
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.join-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.joined-box { margin-top: 10px; }
.joined-head { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--green); font-size: 16px; margin-bottom: 12px; }
.joined-head [data-icon] { width: 22px; height: 22px; }
.joined-instr { background: rgba(8,5,3,0.4); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.joined-instr-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); margin-bottom: 6px; }
.joined-instr-text { white-space: pre-wrap; color: var(--parch-dim); font-size: 14px; max-height: 220px; overflow: auto; }

.timer-box { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; background: rgba(8,5,3,0.4); border: 1px solid var(--line); margin-bottom: 14px; }
.timer-box [data-icon] { width: 28px; height: 28px; color: var(--gold); }
.timer-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); }
.timer-value { font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1; color: var(--parch); font-variant-numeric: tabular-nums; }

.player-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow: auto; }
.player-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(232,217,181,0.04); border: 1px solid transparent; }
.player-list li.me { border-color: rgba(201,162,74,0.5); background: rgba(201,162,74,0.08); }
.player-list .swatch { width: 26px; height: 26px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.player-list .swatch [data-icon] { width: 18px; height: 22px; color: #fff; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6)); }
.player-list .pname { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .pkind { font-size: 11px; color: var(--ink-muted); display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); }
.player-list .pkind.human { color: var(--gold-soft); border-color: rgba(201,162,74,0.4); }

.invite-label, .admin-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.invite-row { display: flex; gap: 6px; }
.invite-row input { font-size: 12px; padding: 8px 10px; }
.admin-box { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line-strong); }
.admin-label { color: var(--gold); }
.admin-btns { display: flex; gap: 6px; flex-wrap: wrap; }

.rules { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 22px; }
.rule { display: flex; gap: 12px; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(232,217,181,0.03); font-size: 13px; color: var(--parch-dim); }
.rule b { color: var(--parch); }
.rule-ic { width: 28px; height: 28px; color: var(--gold); flex: 0 0 auto; }

/* ===== Игра ===== */
.screen-game { padding: 12px 16px 16px; max-width: 1600px; }
.cycle-bar {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center;
  padding: 10px 16px; border-radius: 12px; margin-bottom: 10px;
  background: linear-gradient(180deg, rgba(232,217,181,0.07), rgba(232,217,181,0.03));
  border: 1px solid var(--line);
}
.cycle-num { display: flex; align-items: baseline; gap: 6px; }
.cycle-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-muted); }
.cycle-value { font-family: var(--font-display); font-size: 30px; font-weight: 700; color: var(--gold); line-height: 1; }
.cycle-total { font-size: 12px; color: var(--ink-faint); }
.cycle-event { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--parch); min-width: 0; }
.cycle-event-ic { width: 24px; height: 24px; color: var(--gold-soft); }
.cycle-event.flash { animation: eventFlash 1.2s ease; }
@keyframes eventFlash { 0% { color: #fff; text-shadow: 0 0 14px rgba(226,196,119,0.9);} 100% { color: var(--parch); text-shadow: none; } }
.cycle-timer { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--parch); font-variant-numeric: tabular-nums; }
.cycle-timer [data-icon] { width: 20px; height: 20px; color: var(--gold); }
.cycle-timer.urgent { color: #f0a196; }
.cycle-status { font-family: var(--font-ui); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); font-weight: 600; }
.admin-inline { display: flex; gap: 4px; }

.spectator-banner { display: flex; align-items: center; gap: 8px; padding: 8px 14px; margin-bottom: 10px; border-radius: 10px; border: 1px solid rgba(201,162,74,0.4); background: rgba(201,162,74,0.08); color: var(--gold-soft); font-size: 13px; }

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: auto auto;
  grid-template-areas:
    "map agent"
    "bottom agent";
  gap: 12px;
}
.map-wrap { grid-area: map; position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--line-strong); background: var(--sea); box-shadow: var(--shadow); min-height: 320px; }
#map { width: 100%; height: auto; display: block; aspect-ratio: 10 / 7; }
.panel-agent { grid-area: agent; }
.panel-score, .panel-allies, .panel-log { grid-area: auto; }
.game-grid > .panel-score { grid-area: bottom; }
/* нижние три панели в один ряд */
.game-grid { grid-template-areas: "map agent" "bottom agent"; }
.game-grid .bottom-row { grid-area: bottom; }

.panel {
  background: linear-gradient(180deg, rgba(232,217,181,0.05), rgba(232,217,181,0.02));
  border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; min-height: 0; box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.panel-agent { max-height: calc(100vh - 140px); position: sticky; top: 10px; }

.tabs { display: none; }

.instr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; background: rgba(8,5,3,0.35); }
.instr summary { cursor: pointer; padding: 9px 12px; font-size: 13px; font-weight: 600; color: var(--parch-dim); list-style: none; display: flex; align-items: center; gap: 8px; }
.instr summary::-webkit-details-marker { display: none; }
.instr summary [data-icon] { transition: transform .2s; color: var(--gold); }
.instr[open] summary [data-icon] { transform: rotate(180deg); }
.instr-text { padding: 0 12px 10px; font-size: 13px; color: var(--parch-dim); white-space: pre-wrap; max-height: 180px; overflow: auto; }

.orders { display: flex; gap: 6px; align-items: stretch; }
.orders textarea { flex: 1; min-height: 44px; font-size: 13px; padding: 9px 11px; }
.orders .btn { align-self: stretch; }

.feed { flex: 1; overflow: auto; margin-top: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 200px; padding-right: 2px; }
.feed-item { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(8,5,3,0.3); font-size: 13px; animation: feedIn .3s ease; }
@keyframes feedIn { from { opacity: 0; transform: translateY(-4px);} to { opacity: 1; transform: none; } }
.feed-item .fi-head { display: flex; align-items: center; gap: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); margin-bottom: 4px; font-weight: 600; }
.feed-item .fi-head [data-icon] { width: 14px; height: 14px; }
.feed-item .fi-cycle { margin-left: auto; color: var(--ink-faint); font-weight: 500; letter-spacing: 0; text-transform: none; }
.feed-item .fi-body { color: var(--parch); }
.feed-item .fi-thought { margin-top: 6px; padding-left: 10px; border-left: 2px solid rgba(201,162,74,0.5); color: var(--parch-dim); font-style: italic; }
.feed-item.fi-action .fi-head { color: var(--gold-soft); }
.feed-item.fi-inbox .fi-head { color: #8fc3e8; }
.feed-item.fi-square .fi-head { color: #b9a5e0; }
.feed-item.fi-order .fi-head { color: var(--green); }
.feed-item.fi-sys .fi-head { color: var(--ink-muted); }
.feed-empty { color: var(--ink-faint); font-size: 13px; text-align: center; padding: 20px 10px; }

.table-wrap { overflow-x: auto; }
.score-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.score-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.score-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.score-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.score-table tr.me td { background: rgba(201,162,74,0.10); }
.score-table tr.dead td { opacity: .45; text-decoration: line-through; }
.score-table .pcell { display: flex; align-items: center; gap: 8px; }
.score-table .sw { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; box-shadow: 0 0 0 1px rgba(0,0,0,0.4); }
.score-table .rep { display: inline-block; min-width: 34px; text-align: right; }
.score-table .rep.low { color: #f0a196; }
.score-table .alli { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--parch-dim); }
.score-table .alli .sw { border-radius: 50%; }
.score-table .score-up { color: var(--green); font-size: 11px; margin-left: 4px; }

.allies { display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.ally { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: rgba(8,5,3,0.3); }
.ally-head { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.ally-head .sw { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0,0,0,0.4); }
.ally-head .ally-stat { margin-left: auto; font-size: 11px; color: var(--ink-muted); }
.ally-members { display: flex; flex-wrap: wrap; gap: 6px; }
.ally-member { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; background: rgba(232,217,181,0.03); }
.ally-member.me { border-color: rgba(201,162,74,0.6); }
.ally-member .sw { width: 9px; height: 9px; border-radius: 2px; }
.ally-member .jc { color: var(--ink-faint); font-size: 11px; }
.ally-member .lead-ic { width: 12px; height: 12px; color: var(--gold); }
.allies-empty, .log-empty { color: var(--ink-faint); font-size: 13px; text-align: center; padding: 20px 10px; }

.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; overflow: auto; font-size: 12.5px; }
.log li { display: flex; gap: 8px; align-items: flex-start; padding: 5px 8px; border-radius: 8px; border-left: 2px solid transparent; }
.log li [data-icon] { width: 14px; height: 14px; margin-top: 3px; color: var(--ink-muted); }
.log li .lc { color: var(--ink-faint); font-variant-numeric: tabular-nums; min-width: 22px; font-size: 11px; margin-top: 2px; }
.log li.attack [data-icon] { color: #f0a196; }
.log li.capture { border-left-color: var(--red); background: rgba(217,79,61,0.06); }
.log li.capture [data-icon] { color: var(--red); }
.log li.ally [data-icon] { color: #8fc3e8; }
.log li.betray { border-left-color: var(--gold); background: rgba(201,162,74,0.08); }
.log li.betray [data-icon] { color: var(--gold); }
.log li.event { border-left-color: rgba(185,165,224,0.6); }
.log li.event [data-icon] { color: #b9a5e0; }
.log li.reinforce [data-icon] { color: var(--green); }
.log li.dead [data-icon] { color: var(--ink-muted); }
.log li.win { border-left-color: var(--gold); background: rgba(201,162,74,0.12); }

/* Нижний ряд: три панели */
.bottom-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 12px; }
.bottom-row .panel { max-height: 360px; }
.bottom-row .table-wrap, .bottom-row .allies, .bottom-row .log { overflow: auto; }

/* ===== Карта ===== */
.map-tip {
  position: absolute; pointer-events: none; z-index: 5;
  min-width: 170px; max-width: 240px;
  padding: 10px 12px; border-radius: 10px;
  background: rgba(20, 13, 9, 0.94); border: 1px solid var(--line-strong);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5); font-size: 12px; color: var(--parch-dim);
}
.map-tip .tt-name { font-family: var(--font-display); font-size: 17px; font-weight: 700; color: var(--parch); }
.map-tip .tt-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 3px; }
.map-tip .tt-row b { color: var(--ink); font-weight: 600; }
.map-tip .tt-owner { display: inline-flex; align-items: center; gap: 6px; }
.map-tip .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.map-tip .tt-nb { margin-top: 6px; color: var(--ink-muted); line-height: 1.4; }
.map-legend { position: absolute; left: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: 70%; font-size: 11px; color: var(--parch-dim); pointer-events: none; }
.map-legend .lg { display: inline-flex; align-items: center; gap: 5px; background: rgba(13,26,34,0.7); padding: 2px 7px; border-radius: 999px; }
.map-legend .sw { width: 9px; height: 9px; border-radius: 2px; }
.map-legend .lg.dead { opacity: .4; }

/* SVG карта */
#map .sea-bg { fill: url(#seaGrad); }
#map .cell { stroke: rgba(20, 13, 9, 0.75); stroke-width: 1.6; stroke-linejoin: round; cursor: pointer; transition: fill .8s ease, filter .3s ease; }
#map .cell.neutral { fill: #8f8367; }
#map .cell:hover { filter: brightness(1.18); }
#map .cell.hit { animation: cellHit .9s ease; }
@keyframes cellHit { 0% { filter: brightness(2.2) saturate(1.4);} 100% { filter: brightness(1);} }
#map .cell.affected { animation: affected 2.4s ease infinite; }
@keyframes affected { 0%,100% { filter: brightness(1);} 50% { filter: brightness(0.7) saturate(0.6);} }
#map .ally-rim { fill: none; stroke-width: 4; stroke-dasharray: 9 5; opacity: .85; pointer-events: none; transition: stroke .6s ease; }
#map .cell-tex { fill: url(#hatch); pointer-events: none; opacity: .35; }
#map .coast { fill: none; stroke: rgba(232,217,181,0.35); stroke-width: 6; stroke-linejoin: round; pointer-events: none; }
#map .coast-outer { fill: none; stroke: rgba(232,217,181,0.10); stroke-width: 20; stroke-linejoin: round; pointer-events: none; }
#map .str-badge { fill: rgba(20,13,9,0.82); stroke: rgba(232,217,181,0.55); stroke-width: 1.2; pointer-events: none; }
#map .str-text { font-family: var(--font-display); font-weight: 700; font-size: 20px; fill: var(--parch); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
#map .t-name { font-family: var(--font-ui); font-size: 10.5px; font-weight: 600; fill: rgba(20,13,9,0.8); text-anchor: middle; pointer-events: none; letter-spacing: 0.02em; }
#map .hero { pointer-events: none; transition: transform .9s cubic-bezier(.4,0,.2,1); }
#map .hero .hero-shadow { fill: rgba(0,0,0,0.35); }
#map .hero.me .hero-ring { fill: none; stroke: var(--gold-soft); stroke-width: 2; stroke-dasharray: 3 3; animation: ringSpin 6s linear infinite; }
@keyframes ringSpin { to { stroke-dashoffset: -60; } }
#map .hero .hero-label { font-family: var(--font-ui); font-size: 10px; font-weight: 700; fill: #fff; text-anchor: middle; paint-order: stroke; stroke: rgba(20,13,9,0.9); stroke-width: 3px; stroke-linejoin: round; }
#map .pulse { fill: none; stroke: #9be0b0; stroke-width: 3; animation: pulse 1.1s ease-out forwards; pointer-events: none; }
@keyframes pulse { from { r: 12; opacity: 1;} to { r: 44; opacity: 0; } }
#map .arrow { fill: none; stroke: #ff8a70; stroke-width: 4; stroke-linecap: round; filter: drop-shadow(0 0 6px rgba(255,120,90,0.8)); pointer-events: none; }
#map .arrow.betray { stroke: var(--gold-soft); filter: drop-shadow(0 0 6px rgba(226,196,119,0.9)); }
#map .arrow-head { fill: #ff8a70; pointer-events: none; }
#map .arrow.betray + .arrow-head { fill: var(--gold-soft); }
#map .flash { fill: #fff; opacity: 0; pointer-events: none; animation: flash .7s ease-out forwards; }
@keyframes flash { 0% { opacity: 0; r: 6;} 25% { opacity: .9;} 100% { opacity: 0; r: 40; } }
#map .ally-link { fill: none; stroke: #8fc3e8; stroke-width: 3; stroke-dasharray: 8 6; stroke-linecap: round; filter: drop-shadow(0 0 5px rgba(143,195,232,0.8)); pointer-events: none; animation: allyLink 2.6s ease forwards; }
@keyframes allyLink { 0% { opacity: 0; stroke-dashoffset: 120;} 20% { opacity: 1;} 80% { opacity: 1;} 100% { opacity: 0; stroke-dashoffset: 0; } }
#map .storm-ic { pointer-events: none; opacity: .9; }
#map .cell.tile-move { transition: fill .8s ease; }

/* ===== Финал ===== */
.final-hero { text-align: center; padding: 36px 20px 24px; }
.final-crown { width: 84px; height: 84px; color: var(--gold); display: inline-flex; filter: drop-shadow(0 6px 20px rgba(201,162,74,0.45)); animation: crownIn 1s ease; }
@keyframes crownIn { from { transform: translateY(-16px) scale(.8); opacity: 0;} to { transform: none; opacity: 1;} }
.final-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: 0.2em; color: var(--gold-soft); margin: 10px 0 6px; font-weight: 600; }
.final-title { font-size: 52px; margin-bottom: 10px; }
.final-hero .lead { margin: 0 auto 20px; }
.final-actions { display: flex; justify-content: center; }
.final-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.final-table td:first-child { color: var(--gold); font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.final-table tr.winner td { background: rgba(201,162,74,0.10); }
.final-table .mult { color: var(--gold-soft); }
.history { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; max-height: 520px; overflow: auto; }
.history li { display: flex; gap: 10px; padding: 8px 10px; border-radius: 8px; background: rgba(8,5,3,0.3); border: 1px solid var(--line); font-size: 13px; }
.history li .hc { font-family: var(--font-display); font-weight: 700; color: var(--gold); min-width: 28px; font-size: 15px; }
.history li [data-icon] { width: 16px; height: 16px; color: var(--ink-muted); margin-top: 2px; flex: 0 0 auto; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); padding: 10px 16px; border-radius: 10px; background: rgba(20,13,9,0.95); border: 1px solid var(--line-strong); color: var(--parch); font-size: 13px; box-shadow: var(--shadow); z-index: 50; animation: feedIn .25s ease; }

/* ===== Адаптив ===== */
@media (max-width: 1180px) {
  .bottom-row { grid-template-columns: 1fr 1fr; }
  .bottom-row .panel-log { grid-column: 1 / -1; }
  .rules { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .screen { padding: 14px; }
  .h1 { font-size: 32px; }
  .top { padding: 10px 14px; }
  .brand-sub { display: none; }
  .lobby-grid { grid-template-columns: 1fr; }
  .rules { grid-template-columns: 1fr; }
  .cycle-bar { grid-template-columns: auto 1fr; grid-template-rows: auto auto; padding: 8px 12px; gap: 6px 12px; }
  .cycle-event { grid-column: 1 / -1; font-size: 13px; order: 3; }
  .cycle-timer { justify-self: end; font-size: 22px; }
  .admin-inline { grid-column: 1 / -1; order: 4; }
  .screen-game { padding: 8px 8px 12px; }

  .game-grid { display: flex; flex-direction: column; gap: 8px; }
  .map-wrap { min-height: 0; }
  .tabs { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(8,5,3,0.5); border: 1px solid var(--line); position: sticky; top: 6px; z-index: 6; }
  .tab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 4px; border-radius: 9px; border: 0; background: transparent; color: var(--ink-muted); font-size: 12px; font-weight: 600; cursor: pointer; }
  .tab.active { background: rgba(232,217,181,0.12); color: var(--parch); }
  .tab [data-icon] { width: 15px; height: 15px; }
  .bottom-row { display: contents; }
  .panel { display: none; max-height: none; position: static; }
  .panel.active { display: flex; }
  .panel-agent { max-height: none; }
  .feed { min-height: 160px; max-height: 50vh; }
  .bottom-row .panel { max-height: 60vh; }
  .map-legend { display: none; }
  .final-grid { grid-template-columns: 1fr; }
  .final-title { font-size: 36px; }
  .btn-lg { width: 100%; justify-content: center; }
}

@media (max-width: 600px) {
  #map .t-name, #map .hero-label { display: none; }
  #map .str-text { font-size: 26px; }
  #map .str-badge { r: 17; }
}

@media (max-width: 480px) {
  .top-right .pill-status span:last-child { display: none; }
  .cycle-value { font-size: 24px; }
  .score-table { font-size: 12px; }
  .score-table th, .score-table td { padding: 6px 5px; }
}

/* ===== Реки и племена на карте ===== */
#map .river-bank { fill: none; stroke: rgba(232,217,181,0.5); stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#map .river { fill: none; stroke: #1d4f66; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#map .tribe-fill { pointer-events: none; stroke-width: 1.8; stroke-opacity: .6; transition: stroke .6s ease; }
.map-legend .lg.tribe { border: 1px solid var(--tc); color: var(--parch); }
.map-legend .lg.tribe .sw { background: repeating-linear-gradient(-40deg, var(--tc) 0 2px, transparent 2px 5px); border: 1px solid var(--tc); width: 12px; height: 12px; }
.map-legend .lg.tribe [data-icon] { width: 12px; height: 12px; color: var(--tc); }
.map-legend .lg-sep { width: 100%; height: 0; }

/* ===== Роли и племена ===== */
.tribe-mark { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; font-weight: 600; line-height: 1.3; }
.tribe-mark [data-icon] { width: 13px; height: 13px; }
.player-list .pmeta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.player-list .prole { font-size: 11px; color: var(--ink-muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.score-table .rolecell { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--parch-dim); }

.role-card { margin: 4px 0 14px; border: 1px solid rgba(201,162,74,0.45); border-radius: 12px; padding: 14px 16px; background: linear-gradient(180deg, rgba(201,162,74,0.10), rgba(201,162,74,0.03)); animation: feedIn .35s ease; }
.role-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--gold-soft); font-weight: 600; margin-bottom: 4px; }
.role-title { font-family: var(--font-display); font-size: 28px; font-weight: 700; color: var(--parch); line-height: 1.1; display: flex; align-items: center; gap: 10px; }
.role-title [data-icon] { width: 28px; height: 28px; color: var(--gold); }
.role-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 10px; }
.role-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--parch-dim); }
.role-chip [data-icon] { width: 13px; height: 13px; }
.role-prompt { font-size: 14px; color: var(--parch-dim); white-space: pre-wrap; line-height: 1.5; }
.role-secret { margin-top: 10px; border-left: 3px solid var(--gold); padding: 8px 12px; background: rgba(8,5,3,0.4); border-radius: 0 8px 8px 0; }
.role-secret-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--gold-soft); display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 4px; }
.role-secret-label [data-icon] { width: 13px; height: 13px; }
.role-secret-text { font-size: 14px; color: var(--parch); }
.role-hint { margin-top: 10px; font-size: 12px; color: var(--ink-muted); display: flex; align-items: flex-start; gap: 6px; }
.role-hint [data-icon] { width: 14px; height: 14px; margin-top: 2px; color: var(--gold); }
.instr .role-mini { padding: 0 12px 10px; }
.instr .role-mini .role-title { font-size: 20px; }
.instr .role-mini .role-prompt { font-size: 13px; }
.instr .role-mini .role-secret { margin-top: 8px; }

.final-roles { margin-top: 20px; }
.roles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.role-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: rgba(8,5,3,0.3); }
.role-item.me { border-color: rgba(201,162,74,0.55); }
.role-item .ri-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.role-item .ri-name .sw { width: 10px; height: 10px; border-radius: 3px; }
.role-item .ri-role { font-family: var(--font-display); font-size: 19px; font-weight: 700; color: var(--parch); margin: 3px 0 4px; }
.role-item .ri-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.role-item .ri-secret { font-size: 12px; color: var(--parch-dim); margin-top: 8px; border-left: 2px solid var(--gold); padding-left: 8px; }
.role-item .ri-secret.done { border-color: var(--green); }
.role-item .ri-secret .st { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); margin-bottom: 2px; }
.role-item .ri-secret.done .st { color: var(--green); }

/* ===== Пульт ведущего, предложения миру, личные победы ===== */
.admin-panel { border: 1px solid rgba(201,162,74,0.4); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; background: rgba(201,162,74,0.06); }
.admin-panel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--gold); font-weight: 600; }
.admin-panel-head [data-icon] { width: 16px; height: 16px; }
.admin-panel-head .btn { text-transform: none; letter-spacing: 0; }
.admin-panel-head .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }
.proposals { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.proposals-empty { font-size: 12px; color: var(--ink-faint); }
.proposal { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; background: rgba(8,5,3,0.35); border: 1px solid var(--line); font-size: 13px; }
.proposal .pr-who { font-weight: 600; color: var(--parch); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.proposal .pr-who .sw { width: 9px; height: 9px; border-radius: 2px; }
.proposal .pr-text { flex: 1; color: var(--parch-dim); min-width: 0; }
.proposal .pr-cycle { font-size: 11px; color: var(--ink-faint); white-space: nowrap; }
.proposal .pr-status { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); white-space: nowrap; }
.proposal.accepted { border-color: rgba(95,179,122,0.5); }
.proposal.accepted .pr-status { color: var(--green); }
.proposal.rejected { opacity: .5; }

.propose summary { justify-content: flex-start; }
.propose .propose-note { margin-left: auto; font-size: 11px; }
.propose .propose-form { padding: 0 10px 10px; }
.propose .propose-msg { padding: 0 12px 10px; margin: 0; }
.feed-item.fi-proposal .fi-head { color: #e2c477; }
.cycle-event .ev-by { font-size: 12px; color: var(--gold-soft); margin-left: 8px; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.cycle-event .ev-by [data-icon] { width: 13px; height: 13px; }
.joined-goal { margin-top: 10px; border-color: rgba(201,162,74,0.35); }
.joined-goal .joined-instr-label { display: flex; align-items: center; gap: 6px; color: var(--gold-soft); }

.final-goals { margin-top: 20px; }
.goals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.goal-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: rgba(8,5,3,0.3); border-left-width: 3px; }
.goal-item.done { border-left-color: var(--green); }
.goal-item.fail { border-left-color: var(--red); }
.goal-item.me { box-shadow: inset 0 0 0 1px rgba(201,162,74,0.45); }
.goal-item .gi-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.goal-item .gi-name .sw { width: 10px; height: 10px; border-radius: 3px; }
.goal-item .gi-verdict { margin-left: auto; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; display: inline-flex; align-items: center; gap: 4px; }
.goal-item.done .gi-verdict { color: var(--green); }
.goal-item.fail .gi-verdict { color: #f0a196; }
.goal-item .gi-verdict [data-icon] { width: 13px; height: 13px; }
.goal-item .gi-goal { font-family: var(--font-display); font-size: 18px; font-weight: 700; color: var(--parch); margin: 4px 0; }
.goal-item .gi-reason { font-size: 12px; color: var(--parch-dim); }
@media (max-width: 900px) {
  .admin-panel-head { font-size: 11px; }
  .proposal { flex-wrap: wrap; }
}

/* ===== Консоль: указание vs разговор, вкладки, чат с чужим агентом ===== */
.console-caption { display: flex; align-items: center; gap: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--gold-soft); font-weight: 600; margin: 4px 0 6px; }
.console-caption [data-icon] { width: 14px; height: 14px; }
.console-caption .muted { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }
.console-tabs { display: flex; gap: 4px; margin-top: 10px; padding: 3px; border-radius: 10px; background: rgba(8,5,3,0.45); border: 1px solid var(--line); }
.ctab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 6px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.ctab.active { background: rgba(232,217,181,0.12); color: var(--parch); }
.ctab [data-icon] { width: 14px; height: 14px; }
.ctab-count { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--gold); color: #1d1408; font-size: 10px; line-height: 18px; }
.talks { flex: 1; display: flex; flex-direction: column; gap: 8px; margin-top: 10px; min-height: 200px; }
.talk-hint { margin: 0; font-size: 12px; color: var(--ink-muted); }
.talk-select { width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line-strong); background: rgba(8,5,3,0.45); color: var(--ink); font: inherit; font-size: 13px; }
.talk-thread { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 6px; min-height: 120px; max-height: 40vh; padding: 4px 2px; }
.talk-empty { color: var(--ink-faint); font-size: 12px; text-align: center; padding: 16px 8px; }
.bubble { max-width: 88%; padding: 8px 11px; border-radius: 12px; font-size: 13px; line-height: 1.4; animation: feedIn .25s ease; }
.bubble.me { align-self: flex-end; background: rgba(201,162,74,0.18); border: 1px solid rgba(201,162,74,0.4); color: var(--parch); border-bottom-right-radius: 3px; }
.bubble.agent { align-self: flex-start; background: rgba(8,5,3,0.45); border: 1px solid var(--line); color: var(--parch-dim); border-bottom-left-radius: 3px; }
.bubble .b-who { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); margin-bottom: 2px; }
.bubble.agent .b-who { color: #8fc3e8; }
.bubble.sys { align-self: center; background: transparent; color: var(--ink-faint); font-size: 11px; }
.btn-talk { padding: 3px 7px; font-size: 11px; border-radius: 7px; gap: 4px; margin-left: 6px; vertical-align: middle; }
.btn-talk [data-icon] { width: 12px; height: 12px; }
.feed-item.fi-talk .fi-head { color: #e9a4c9; }
.feed-item.fi-talk .fi-thought { border-left-color: #8fc3e8; font-style: normal; }
#map .hero { pointer-events: auto; cursor: pointer; }
#map .hero:hover .hero-fig { filter: brightness(1.25); }

/* ===== Ресурсы, племена, пул ===== */
#map .res-ic { pointer-events: none; opacity: .95; }
#map .res-ic circle { fill: rgba(20,13,9,0.8); stroke: rgba(232,217,181,0.45); stroke-width: 1; }
.map-legend .lg.res [data-icon] { width: 12px; height: 12px; }
.pool-line { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; font-size: 12px; color: var(--parch-dim); padding: 7px 10px; border-radius: 9px; background: rgba(8,5,3,0.35); border: 1px solid var(--line); margin-bottom: 8px; }
.pool-line .pl-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); font-weight: 600; margin-right: 2px; }
.pool-line .pl-item { display: inline-flex; align-items: center; gap: 4px; }
.pool-line .pl-item [data-icon] { width: 13px; height: 13px; }
.pool-line .pl-item.deficit { color: #f0a196; font-weight: 600; }
.pool-line .pl-item .pl-why { font-size: 11px; font-weight: 500; color: #f0a196; }
.tribes { display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.tribe { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: rgba(8,5,3,0.3); border-left: 3px solid var(--tc); }
.tribe.mine { box-shadow: inset 0 0 0 1px rgba(201,162,74,0.4); }
.tribe-head { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--parch); }
.tribe-head [data-icon] { width: 16px; height: 16px; color: var(--tc); }
.tribe-head .tr-stat { margin-left: auto; font-size: 11px; color: var(--ink-muted); font-weight: 500; }
.tribe-head .tr-me { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold-soft); font-weight: 600; }
.tribe-res { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.tribe-res .rs { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-radius: 8px; background: rgba(232,217,181,0.04); border: 1px solid var(--line); font-size: 11px; color: var(--ink-muted); }
.tribe-res .rs [data-icon] { width: 16px; height: 16px; }
.tribe-res .rs b { font-family: var(--font-display); font-size: 18px; color: var(--parch); line-height: 1; }
.tribe-res .rs.deficit { border-color: rgba(217,79,61,0.6); background: rgba(217,79,61,0.10); color: #f0a196; }
.tribe-res .rs.deficit b { color: #f0a196; }
.tribe-members { display: flex; flex-wrap: wrap; gap: 5px; }
.tribe-members .ally-member { font-size: 11px; }
.tribes-empty { color: var(--ink-faint); font-size: 13px; text-align: center; padding: 20px 10px; }
@media (min-width: 1400px) { .bottom-row.has-tribes { grid-template-columns: 1.3fr 1fr 1fr 1fr; } }
@media (max-width: 1399px) and (min-width: 901px) { .bottom-row.has-tribes { grid-template-columns: 1.2fr 1fr; } }
@media (max-width: 900px) { .tab { font-size: 11px; padding: 8px 3px; } }

/* Анимация «карта открывается» */
#map.revealing .cell, #map.revealing .cell-tex, #map.revealing .tribe-fill, #map.revealing .ally-rim, #map.revealing .g-labels > g, #map.revealing .res-ic { opacity: 0; }
#map .cell.reveal, #map .g-labels > g.reveal, #map .res-ic.reveal, #map .tribe-fill.reveal, #map .cell-tex.reveal, #map .ally-rim.reveal { animation: cellReveal .55s cubic-bezier(.2,.8,.2,1) forwards; }
@keyframes cellReveal { from { opacity: 0; transform: translateY(14px) scale(.96); transform-origin: center; } to { opacity: 1; transform: none; } }
#map .hero.reveal { animation: heroDrop .6s cubic-bezier(.2,.9,.3,1.2) forwards; }
@keyframes heroDrop { from { opacity: 0; } to { opacity: 1; } }
#map.revealing .hero { opacity: 0; }
#map.revealing .g-rivers { opacity: 0; transition: opacity .8s ease; }

/* grid items must be allowed to shrink - otherwise nowrap tables push the bottom row under the console */
.game-grid > *, .bottom-row > *, .lobby-grid > *, .final-grid > * { min-width: 0; }
.panel .table-wrap { max-width: 100%; }
/* only the figure itself catches clicks - shadow, ring and label let the cell tooltip through */
#map .hero { pointer-events: none; }
#map .hero .hero-fig { pointer-events: auto; cursor: pointer; }
