* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: #0c0f14;
  color: #e8ecf1;
  line-height: 1.45;
}
.top {
  padding: 1.25rem 1.5rem;
  background: #121822;
  border-bottom: 1px solid #2a3344;
}
.top-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.mode-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.btn-play {
  background: #2a9d6f !important;
}
.btn-secondary {
  background: #4a5568 !important;
}
.btn-danger {
  background: #8b3a3a !important;
}
.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}
.world-pockets-label {
  display: block;
  margin-top: 0.5rem;
}
.world-pockets-label textarea {
  display: block;
  width: 100%;
  max-width: 640px;
  margin-top: 0.35rem;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
  background: #0a0d12;
  border: 1px solid #3d4a5f;
  color: #e8ecf1;
  border-radius: 6px;
  resize: vertical;
}
.world-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.75rem;
}
.world-subh {
  margin: 0.75rem 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}
.world-pocket-neutral-block {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #2a3344;
}
.world-color-block {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #2a3344;
}
.world-color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin: 0.5rem 0;
}
.world-color-pick input[type="color"] {
  width: 56px;
  height: 36px;
  padding: 2px;
  border: 1px solid #3d4a5f;
  border-radius: 6px;
  cursor: pointer;
  vertical-align: middle;
}
#world-player-color-hex {
  width: 7.5rem;
  padding: 0.35rem 0.5rem;
  background: #0c0f14;
  border: 1px solid #3d4a5f;
  color: #e8ecf1;
  border-radius: 4px;
}
.world-tone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem 1rem;
  margin-top: 0.5rem;
}
.world-tone-grid select {
  margin-left: 0.35rem;
  padding: 0.3rem 0.45rem;
  background: #0c0f14;
  border: 1px solid #3d4a5f;
  color: #e8ecf1;
  border-radius: 4px;
  max-width: 100%;
}
.hint.small {
  font-size: 0.8rem;
  margin: 0.35rem 0;
}
.hidden {
  display: none !important;
}
.top h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}
.sub {
  margin: 0;
  opacity: 0.85;
  max-width: 900px;
  font-size: 0.92rem;
}
.panel {
  margin: 1rem 1.5rem;
  padding: 1rem 1.1rem;
  background: #141a24;
  border: 1px solid #2a3344;
  border-radius: 8px;
  max-width: 960px;
}
.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}
.admin-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 1rem;
  padding: 0.65rem 0.85rem;
  background: #0f141c;
  border: 1px solid #2a3344;
  border-radius: 8px;
  font-size: 0.82rem;
}
.admin-step {
  opacity: 0.9;
}
.admin-step-main {
  color: #7dffb8;
  font-weight: 600;
}
.admin-section {
  max-width: 1100px;
}
.admin-section-shot input[readonly] {
  opacity: 0.85;
  cursor: default;
}
.admin-section-enemies {
  border-color: #3d5a48;
  background: #121a16;
}
.admin-section-enemies h2 {
  color: #9ed4a8;
}
.enemy-count-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 1rem;
  font-weight: 600;
  max-width: 280px;
}
.enemy-count-label input {
  margin-left: 0;
  width: 100%;
  font-size: 1.1rem;
  padding: 0.5rem 0.65rem;
}
.admin-section-publish {
  border-color: #2a5a44;
  background: #101a14;
}
.admin-section-publish .btn-play {
  font-size: 1rem;
  padding: 0.65rem 1.2rem;
}
.hint {
  font-size: 0.85rem;
  opacity: 0.8;
  margin: 0.25rem 0 0.75rem;
}
label {
  display: block;
  margin: 0.5rem 0;
}
input[type="text"],
input[type="number"],
input[type="password"] {
  margin-left: 0.35rem;
  padding: 0.35rem 0.5rem;
  width: min(420px, 100%);
  background: #0c0f14;
  border: 1px solid #3d4a5f;
  color: #e8ecf1;
  border-radius: 4px;
}
button {
  margin-top: 0.5rem;
  padding: 0.45rem 0.9rem;
  background: #2d6cdf;
  border: none;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
}
button:hover {
  filter: brightness(1.08);
}
.mono {
  background: #0a0d12;
  padding: 0.75rem;
  border-radius: 6px;
  overflow: auto;
  max-height: 220px;
  font-size: 0.82rem;
}
.mono.small {
  max-height: 140px;
}
.editor-toolbar {
  margin-bottom: 0.5rem;
}
.editor-toolbar button {
  margin-right: 0.35rem;
}
#level-canvas {
  display: block;
  background: #0a0d12;
  border: 1px solid #2a3344;
  border-radius: 6px;
  cursor: crosshair;
  max-width: 100%;
  height: auto;
}
code {
  background: #1a2230;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
kbd {
  background: #2a3344;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
}
.play-toolbar {
  margin: 0.5rem 0 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
.play-toolbar label.play-proc-alg {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.play-toolbar #procedural-algorithm {
  max-width: 12rem;
  font-size: 0.85rem;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  border: 1px solid #3a4a62;
  background: #141a24;
  color: #c8d4e8;
}
.play-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: min(88vh, 1400px);
  overflow: auto;
}
.play-gen-panel {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.75rem 0.25rem;
  border: 1px solid #2a3344;
  border-radius: 8px;
  background: #0f141c;
}
.play-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid #2a3344;
  border-radius: 8px;
  cursor: default;
  touch-action: none;
}
.play-wrap canvas:active {
  cursor: default;
}
.btn-ball-pocket {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 46px;
  height: 46px;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border-radius: 50%;
  /* Глиф ◎ КРУПНЫЙ (по многократной просьбе) — заметная кнопка возврата в лунку. */
  font-size: 34px;
  /* ПРАВИЛО центрирования иконки-глифа в круглой кнопке: flex center + line-height:1 +
     нулевые padding/border-box (см. memory ui-icon-centering). grid place-items ненадёжен
     для «голого» текст-глифа. */
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #2a4a6f;
  border: 2px solid #4a7ab0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  z-index: 2;
}
.btn-ball-pocket:hover {
  filter: brightness(1.12);
}

/* ── Upgrade button ──────────────────────────────────────────── */
.btn-upgrade {
  position: absolute;
  right: 10px;
  bottom: 64px;
  width: 46px;
  height: 46px;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border-radius: 50%;
  /* Оптический размер глифа + подогнан под ⚙ кнопки опций. */
  font-size: 30px;
  font-weight: 700;
  /* ПРАВИЛО центрирования иконки-глифа: flex center + line-height:1 (см. memory ui-icon-centering). */
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #1a3a1a;
  border: 2px solid #4aaa6a;
  color: #7edd9a;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: pointer;
  z-index: 3;
  transition: filter 0.15s;
}
.btn-upgrade:hover { filter: brightness(1.18); }

/* ── Dev-кнопки (временные): рестарт / новая карта — иконки-квадраты ──── */
.btn-dev {
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  font-size: 1.15rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 30, 46, 0.82);
  border: 1px solid #3a5578;
  color: #cfe3ff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: filter 0.15s;
}
.btn-dev:hover { filter: brightness(1.25); }
.btn-dev:active { transform: scale(0.94); }

/* ── Upgrade modal ───────────────────────────────────────────── */
#upg-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100020;
  background: rgba(0,0,0,0.55);
  align-items: flex-end;
  justify-content: flex-end;
  padding: max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
#upg-modal.upg-open { display: flex; }

.upg-dialog {
  background: #0c1420;
  border: 1px solid #2a4060;
  border-radius: 14px;
  width: min(340px, 96vw);
  /* Всё должно вмещаться БЕЗ скролла — поднят потолок высоты + ужат внутренний интервал. */
  max-height: min(680px, 94vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
}

.upg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  border-bottom: 1px solid #1e3050;
  flex-shrink: 0;
}
.upg-title {
  font: 700 15px/1 system-ui, sans-serif;
  color: #c8deff;
  letter-spacing: 0.04em;
}
.upg-close {
  background: none;
  border: none;
  color: #7090b0;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.upg-close:hover { color: #c0d8f8; }

.upg-body {
  overflow-y: auto;
  padding: 6px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.upg-gold {
  font: 13px/1 system-ui, sans-serif;
  color: #e8c860;
  padding: 2px 4px 6px;
}
.upg-gold b { font-size: 15px; }

.upg-cat {
  background: rgba(255,255,255,0.03);
  border: 1px solid #1e3050;
  border-radius: 8px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.upg-cat-label {
  font: 700 12px/1 system-ui, sans-serif;
  color: #a0c0e0;
  margin-bottom: 1px;
  letter-spacing: 0.05em;
}

/* ── Bot control (test) ─────────────────────────────────────── */
.upg-bots { border-color: #4a7a4a; background: rgba(80, 200, 120, 0.05); }
.upg-bot-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.upg-bot-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font: 700 18px/1 system-ui, sans-serif;
  color: #cfeddc;
  background: #1c3a24;
  border: 1px solid #4aaa6a;
  cursor: pointer;
}
.upg-bot-btn:hover { filter: brightness(1.2); }
.upg-bot-count {
  min-width: 34px;
  text-align: center;
  font: 700 18px/1 ui-monospace, monospace;
  color: #7edd9a;
}
.upg-bot-presets { display: flex; gap: 4px; margin-left: auto; }
.upg-bot-preset {
  min-width: 28px;
  height: 28px;
  border-radius: 6px;
  font: 600 12px/1 system-ui, sans-serif;
  color: #a8c8e0;
  background: rgba(255,255,255,0.05);
  border: 1px solid #2a4060;
  cursor: pointer;
}
.upg-bot-preset:hover { filter: brightness(1.3); color: #dfeeff; }

.upg-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 5px;
}
.upg-row-label {
  font: 12px/1 system-ui, sans-serif;
  color: #c0d4ee;
  white-space: nowrap;
}
.upg-stars {
  font-size: 11px;
  color: #f0c040;
  letter-spacing: -1px;
}
.upg-desc {
  font: 10px/1 system-ui, sans-serif;
  color: #5878a0;
  white-space: nowrap;
}
.upg-buy {
  background: #1a4a2a;
  border: 1px solid #3a9060;
  border-radius: 6px;
  color: #7de09a;
  font: 700 11px/1 system-ui, sans-serif;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.12s;
}
.upg-buy:hover:not(.disabled) { filter: brightness(1.2); }
.upg-buy.disabled {
  background: #111820;
  border-color: #253040;
  color: #405060;
  cursor: default;
}
.upg-maxed {
  background: #0a2a0a;
  border: 1px solid #2a6030;
  border-radius: 6px;
  color: #3a8050;
  font: 700 11px/1 system-ui, sans-serif;
  padding: 4px 8px;
  white-space: nowrap;
}

.play-drum-hint {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(8, 14, 24, 0.88);
  border: 1px solid rgba(90, 130, 180, 0.45);
  pointer-events: none;
  max-width: min(220px, 55vw);
}
.play-drum-hint.is-hidden {
  display: none;
}
.play-drum-gold {
  font: 700 13px/1.2 system-ui, sans-serif;
  color: #e8c860;
}
.play-drum-hint-text {
  font: 500 10px/1.25 system-ui, sans-serif;
  color: #98a8c0;
}

.play-cam-controls {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: calc(100% - 64px);
  pointer-events: none;
}
.play-cam-controls > * {
  pointer-events: auto;
}
.play-cam-mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.btn-cam-mode {
  margin: 0;
  padding: 0.28rem 0.45rem;
  font-size: 0.72rem;
  line-height: 1.2;
  border-radius: 6px;
  border: 1px solid #3a4a62;
  background: #1a2434;
  color: #b8c4d8;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
.btn-cam-mode.active {
  border-color: #5a8ab8;
  background: #243448;
  color: #e8eef8;
}
.btn-cam-zoom {
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem; /* «zoom»/«150%» — чуть мельче, помещается ровно */
  font-weight: 700;
  line-height: 1;
  background: #2a3d58;
  border: 2px solid #4a6a90;
  color: #d0dce8;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
.btn-cam-zoom:hover {
  filter: brightness(1.1);
}
.play-cam-touchpad {
  position: absolute;
  right: 8px;
  top: 8px;
  width: min(120px, 28vw);
  height: min(100px, 22vh);
  min-width: 72px;
  min-height: 56px;
  border-radius: 10px;
  border: 1px solid rgba(90, 120, 160, 0.45);
  background: rgba(12, 18, 28, 0.72);
  backdrop-filter: blur(4px);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.play-cam-touchpad:active {
  cursor: grabbing;
}
.play-cam-touchpad.is-hidden {
  display: none;
}
.play-cam-touchpad-hint {
  font-size: 1.75rem;
  line-height: 1;
  opacity: 0.35;
  pointer-events: none;
}
@media (max-width: 520px) {
  .play-cam-controls {
    left: 4px;
    bottom: 4px;
    gap: 4px;
  }
  .btn-cam-mode {
    font-size: 0.68rem;
    padding: 0.25rem 0.38rem;
  }
}
