/* Скетч-оформление «Зоны»: бумага, тушь, красный маркер — при постапок-содержании */
:root {
  --paper: #f4eddf;
  --card: #faf5ea;
  --ink: #33302b;
  --ink-soft: #5a544b;
  --red: #d9503f;
  --blue: #4a7ba7;
  --green: #7fa856;
  --shadow: rgba(64, 55, 40, 0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- topbar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  z-index: 30;
  pointer-events: none;
}
.brand {
  font-family: Caveat, cursive;
  font-weight: 700;
  font-size: 27px;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-shadow: 0 0 10px var(--paper), 0 0 20px var(--paper);
}
.brand span { color: var(--red); }

.scores {
  display: flex;
  gap: 12px;
  flex: 0 1 520px;
  pointer-events: none;
}
.score {
  flex: 1;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 4px 14px 4px 14px;
  padding: 5px 12px 7px;
  min-width: 120px;
  box-shadow: 3px 3px 0 var(--shadow);
  transform: rotate(-0.5deg);
}
.score.blue { transform: rotate(0.5deg); border-radius: 14px 4px 14px 4px; }
.score .s-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}
.score b {
  float: right;
  font-family: Caveat, cursive;
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score.red .s-name { color: var(--red); }
.score.blue .s-name { color: var(--blue); }
.s-bar {
  margin-top: 4px;
  height: 6px;
  background: rgba(51, 48, 43, 0.12);
  border: 1px solid rgba(51, 48, 43, 0.35);
  border-radius: 3px;
  overflow: hidden;
}
.s-bar i {
  display: block;
  height: 100%;
  width: 50%;
  transition: width 0.5s ease;
}
.score.red .s-bar i { background: var(--red); }
.score.blue .s-bar i { background: var(--blue); }

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
.coord {
  font-size: 11.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  background: rgba(250, 245, 234, 0.85);
  border: 1.4px solid var(--ink);
  padding: 4px 9px;
  border-radius: 4px;
  box-shadow: 2px 2px 0 var(--shadow);
}
.fac-chip {
  font-family: Caveat, cursive;
  font-size: 19px;
  font-weight: 700;
  padding: 3px 14px 5px;
  border-radius: 4px 12px 4px 12px;
  background: var(--fac, #888);
  color: #fff8ef;
  border: 1.6px solid var(--ink);
  box-shadow: 2px 3px 0 var(--shadow);
  transform: rotate(-1deg);
}
.fac-chip.hidden { display: none; }

/* ---------- bottom ---------- */
.bottom-ui {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  z-index: 30;
  pointer-events: none;
}
.modes, .ctrl { display: flex; gap: 8px; pointer-events: auto; }
.chip {
  font-family: Caveat, cursive;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--card);
  border: 1.6px solid var(--ink);
  border-radius: 6px;
  padding: 6px 14px 8px;
  cursor: pointer;
  box-shadow: 2px 3px 0 var(--shadow);
  transform: rotate(-0.6deg);
}
.chip:nth-child(2) { transform: rotate(0.6deg); }
.chip.on {
  color: #fff8ef;
  background: var(--red);
  border-color: var(--ink);
}
.ctrl button {
  width: 46px; height: 46px;
  font-family: Caveat, cursive;
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  background: var(--card);
  border: 1.7px solid var(--ink);
  border-radius: 50% 44% 52% 46%;
  cursor: pointer;
  box-shadow: 2px 3px 0 var(--shadow);
}
.ctrl button:active { transform: scale(0.94); }
.ctrl .wide {
  width: auto;
  padding: 0 16px;
  font-size: 20px;
  border-radius: 6px 16px 6px 16px;
}
.hint {
  font-family: Caveat, cursive;
  font-size: 19px;
  color: var(--ink-soft);
  background: rgba(250, 245, 234, 0.9);
  border: 1.5px dashed var(--ink);
  padding: 7px 16px 9px;
  border-radius: 4px;
  pointer-events: none;
  max-width: 48%;
  text-align: center;
  box-shadow: 2px 2px 0 var(--shadow);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(16px) rotate(-0.6deg);
  background: var(--card);
  border: 1.6px solid var(--ink);
  border-left: 5px solid var(--red);
  color: var(--ink);
  font-family: Caveat, cursive;
  font-size: 21px;
  padding: 8px 18px 10px;
  border-radius: 4px 14px 4px 14px;
  max-width: 86vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
  box-shadow: 3px 4px 0 var(--shadow);
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0) rotate(-0.6deg); }

/* захват клетки — вспышка по краям */
.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 55;
  opacity: 0;
}
.flash.on { animation: flashA 0.9s ease-out; }
@keyframes flashA {
  0% { opacity: 1; box-shadow: inset 0 0 90px 24px rgba(217, 80, 63, 0.65); }
  100% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(217, 80, 63, 0); }
}
.flash.blue.on { animation-name: flashB; }
@keyframes flashB {
  0% { opacity: 1; box-shadow: inset 0 0 90px 24px rgba(74, 123, 167, 0.65); }
  100% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(74, 123, 167, 0); }
}

/* ---------- маркеры POI ---------- */
.markers { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
.poi-marker {
  position: absolute;
  left: 0; top: 0;
  width: 44px; height: 44px;
  margin: -46px 0 0 -22px;
  border: 2px solid var(--ink);
  border-radius: 50% 50% 50% 4px;
  background: var(--fac, #888);
  color: #fff8ef;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 2px 3px 0 var(--shadow);
  will-change: transform;
}
.poi-ico { width: 24px; height: 24px; display: block; }
.poi-ico svg { width: 24px; height: 24px; stroke: currentColor; }
.poi-ttl {
  position: absolute;
  top: -22px; left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  font-family: Caveat, cursive;
  font-size: 17px;
  font-weight: 700;
  background: var(--card);
  color: var(--red);
  border: 1.4px solid var(--ink);
  padding: 0 7px 1px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.poi-detail {
  position: fixed;
  transform: translate(-50%, -100%) rotate(-0.5deg);
  background: var(--card);
  border: 1.6px solid var(--ink);
  border-radius: 4px;
  padding: 12px 14px;
  width: 240px;
  z-index: 70;
  box-shadow: 3px 4px 0 var(--shadow);
}
.pd-head { font-weight: 800; letter-spacing: 0.06em; color: var(--red); font-size: 13px; }
.pd-comment { margin-top: 6px; font-size: 14px; line-height: 1.35; }
.pd-meta { margin-top: 8px; font-size: 12px; color: var(--ink-soft); }
.poi-detail .btn.tiny { margin-top: 10px; width: 100%; font-size: 13px; }

/* ---------- модалки ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(44, 40, 32, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 18px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 22px;
  width: min(460px, 100%);
  box-shadow: 6px 8px 0 var(--shadow);
  transform: rotate(-0.4deg);
  max-height: 92vh;
  overflow-y: auto;
}
.modal-title {
  font-family: Caveat, cursive;
  font-size: 30px;
  font-weight: 700;
  color: var(--red);
  line-height: 1;
}
.modal-sub { color: var(--ink-soft); font-size: 13.5px; line-height: 1.4; margin: 8px 0 0; }
.field { display: block; margin-top: 14px; }
.field span {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 6px;
  letter-spacing: 0.06em;
}
.field input {
  width: 100%;
  background: #fffdf6;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  color: var(--ink);
  font-size: 15px;
  padding: 11px 12px;
  outline: none;
}
.field input:focus { box-shadow: 2px 2px 0 var(--red); }

.fac-grid { display: flex; gap: 10px; margin-top: 16px; }
.fac-pick {
  flex: 1;
  background: #fffdf6;
  border: 2px solid var(--ink);
  border-radius: 6px;
  color: var(--ink);
  padding: 16px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.fac-pick b { font-size: 16px; letter-spacing: 0.12em; }
.fac-pick em { font-style: normal; font-size: 12px; color: var(--ink-soft); }
.fp-dot { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--ink); }
.fac-pick.red { box-shadow: 3px 3px 0 rgba(217, 80, 63, 0.35); }
.fac-pick.red .fp-dot { background: var(--red); }
.fac-pick.blue { box-shadow: 3px 3px 0 rgba(74, 123, 167, 0.35); }
.fac-pick.blue .fp-dot { background: var(--blue); }
.fac-pick:active { transform: scale(0.98); }
.rules {
  margin-top: 14px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-soft);
  border-top: 1.5px dashed rgba(51, 48, 43, 0.4);
  padding-top: 12px;
}

/* POI-модалка */
.poi-types {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 14px;
}
.type-btn {
  background: #fffdf6;
  border: 1.6px solid var(--ink);
  border-radius: 6px;
  color: var(--ink-soft);
  padding: 8px 2px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.type-btn svg { width: 26px; height: 26px; stroke: currentColor; }
.type-btn em { font-style: normal; font-size: 10.5px; line-height: 1.1; text-align: center; }
.type-btn.on {
  color: #fff8ef;
  border-color: var(--ink);
  background: var(--red);
  box-shadow: 2px 2px 0 var(--shadow);
}
.ttl-row { margin-top: 14px; }
.ttl-row > span {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 6px;
  letter-spacing: 0.06em;
}
.ttl-chips { display: flex; gap: 8px; }
.ttl-chip {
  flex: 1;
  background: #fffdf6;
  border: 1.6px solid var(--ink);
  color: var(--ink-soft);
  border-radius: 4px;
  padding: 9px 6px;
  font-family: Caveat, cursive;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
}
.ttl-chip.on { color: #fff8ef; background: var(--red); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  flex: 1;
  border-radius: 4px;
  border: 1.7px solid var(--ink);
  background: #fffdf6;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  padding: 12px 10px;
  cursor: pointer;
  box-shadow: 2px 3px 0 var(--shadow);
}
.btn.primary { background: var(--red); border-color: var(--ink); color: #fff8ef; }
.btn.ghost { color: var(--ink-soft); }
.btn:active { transform: scale(0.98); }

/* ---------- тултип уровня клетки ---------- */
.cell-tip {
  position: fixed;
  z-index: 65;
  pointer-events: none;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  padding: 5px 12px 6px;
  font-family: Caveat, cursive;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 2px 3px 0 var(--shadow);
  transform: translate(14px, -110%) rotate(-0.8deg);
  opacity: 0;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}
.cell-tip.on { opacity: 1; }
.cell-tip.red { color: var(--red); }
.cell-tip.blue { color: var(--blue); }

/* ---------- loading ---------- */
.loading {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 90;
  transition: opacity 0.5s ease;
}
.loading.done { opacity: 0; pointer-events: none; }
.load-mark {
  width: 54px; height: 54px;
  border: 3px solid rgba(217, 80, 63, 0.25);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-family: Caveat, cursive;
  font-size: 26px;
  color: var(--ink-soft);
}

@media (max-width: 720px) {
  .brand span { display: none; }
  .coord { display: none; }
  .hint { display: none; }
  .scores { flex: 1 1 auto; }
  .score { min-width: 0; padding: 4px 8px 6px; }
  .poi-types { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- онлайн, кабинет, оружие ---------- */
.online {
  font-family: Caveat, cursive;
  font-size: 19px;
  color: var(--green);
  background: rgba(250, 245, 234, 0.9);
  border: 1.5px dashed var(--ink);
  padding: 4px 14px 6px;
  border-radius: 4px;
  max-width: 34vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 2px 2px 0 var(--shadow);
}
.online:empty { display: none; }

.chip.bomb {
  background: var(--red);
  color: #fff8ef;
}
.chip.bomb.armed {
  animation: bombPulse 0.9s ease-in-out infinite alternate;
}
@keyframes bombPulse {
  from { box-shadow: 2px 3px 0 var(--shadow); }
  to { box-shadow: 0 0 0 4px rgba(217, 80, 63, 0.4); }
}

.p-label {
  position: absolute;
  left: 0; top: 0;
  font-family: Caveat, cursive;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  background: var(--card);
  border: 1.4px solid var(--ink);
  border-left: 5px solid var(--fac, #888);
  padding: 1px 8px 2px;
  border-radius: 3px;
  transform: translate(-50%, -140%);
  box-shadow: 2px 2px 0 var(--shadow);
  white-space: nowrap;
  pointer-events: none;
}

/* взрыв */
.exp-fx {
  position: absolute;
  left: 0; top: 0;
  width: 90px; height: 90px;
  margin: -45px 0 0 -45px;
  pointer-events: none;
  z-index: 24;
}
.exp-fx::before, .exp-fx::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 4px solid var(--red);
  border-radius: 50%;
  animation: expRing 1.4s ease-out forwards;
}
.exp-fx::after { animation-delay: 0.18s; border-color: var(--accent, #c9b458); }
@keyframes expRing {
  0% { transform: scale(0.2); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* кабинет / магазин / админка */
.cab-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.cab-avatar {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  box-shadow: 2px 3px 0 var(--shadow);
}
.cab-rank { font-size: 13px; color: var(--ink-soft); letter-spacing: 0.05em; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.stat {
  background: #fffdf6;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  padding: 8px 6px;
  text-align: center;
}
.stat b { display: block; font-family: Caveat, cursive; font-size: 30px; line-height: 1; color: var(--red); }
.stat span { font-size: 10.5px; color: var(--ink-soft); }
.fac-pick.picked { outline: 3px solid var(--green); }
.shop-title {
  margin-top: 16px;
  font-family: Caveat, cursive;
  font-size: 22px;
  color: var(--red);
}
.shop-list { display: flex; flex-direction: column; gap: 7px; margin-top: 8px; }
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fffdf6;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  padding: 8px 10px;
}
.s-ico { font-size: 22px; }
.s-txt { flex: 1; }
.s-txt b { display: block; font-size: 13.5px; }
.s-txt em { font-style: normal; font-size: 12px; color: var(--ink-soft); }
.btn.tiny { flex: 0 0 auto; padding: 7px 12px; font-size: 13px; font-weight: 700; }
.btn.tiny:disabled { opacity: 0.5; }
.inv-line { margin-top: 10px; font-size: 13px; color: var(--ink-soft); }

.adm-table {
  margin-top: 10px;
  max-height: 46vh;
  overflow: auto;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
}
.adm-row {
  display: grid;
  grid-template-columns: 1.3fr 0.9fr 0.5fr 0.5fr 1.2fr auto;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  font-size: 12.5px;
  border-bottom: 1px solid rgba(51,48,43,0.15);
  background: #fffdf6;
}
.adm-head { font-weight: 800; background: #f0ead9; position: sticky; top: 0; }
.f-red { color: var(--red); font-weight: 700; }
.f-blue { color: var(--blue); font-weight: 700; }
.adm-acts { display: flex; gap: 4px; }
.adm-acts .btn.tiny { padding: 4px 7px; font-size: 11.5px; }
.adm-tools { display: flex; gap: 8px; margin-top: 12px; }

.au-error { color: var(--red); font-size: 13.5px; min-height: 18px; margin-top: 10px; }
.auth-modal { z-index: 95; }
