* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2c3b49;
  color: #e8eef3;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}
button { touch-action: none; }

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  opacity: 0.8;
  pointer-events: none;
  z-index: 3;
}

#reset, #menu {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 4;
  padding: 8px 14px;
  font: inherit;
  font-size: 12px;
  color: #e8eef3;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
}

#menu { top: calc(52px + env(safe-area-inset-top)); }

.zone {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 2;
  display: none;
}
#zone-move { left: 0; }
#zone-aim { right: 0; }

@media (pointer: coarse) {
  .zone { display: block; }
}

.stick {
  position: absolute;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.06);
  display: none;
}
.stick.on { display: block; }
.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
}

#start {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 28, 36, 0.78);
}
#start.hidden { display: none; }

.card {
  max-width: 340px;
  text-align: center;
}
.card h1 { font-size: 20px; margin: 0 0 12px; }
.card p { font-size: 13px; line-height: 1.5; margin: 0 0 16px; opacity: 0.85; }
.card .touch { display: none; }
@media (pointer: coarse) {
  .card .touch { display: block; }
  .card .desktop { display: none; }
}
#modes { display: flex; flex-direction: column; gap: 10px; }
.mode-btn {
  padding: 11px 16px;
  font: inherit;
  color: #1c2630;
  background: #f1d48a;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.mode-btn b { display: block; font-size: 15px; }
.mode-btn span { display: block; font-size: 11px; opacity: 0.7; margin-top: 2px; }
.mode-btn:disabled { opacity: 0.5; }
.mode-btn:not(:disabled):hover { background: #ffe3a1; }
#load-error { color: #ff9a8a; margin-top: 14px; }

#hurt {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(160, 0, 0, 0) 45%, rgba(160, 0, 0, 0.85) 100%);
}

#ammo, #prompt {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
#ammo {
  bottom: calc(14px + env(safe-area-inset-bottom));
  font-size: 15px;
  font-weight: 700;
}
#ammo.empty { color: #ff8a7a; }
#prompt {
  bottom: calc(44px + env(safe-area-inset-bottom));
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #ffd866;
  display: none;
}
#prompt.on { display: block; }

#actions {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(140px + env(safe-area-inset-bottom));
  z-index: 4;
  display: none;
  flex-direction: column;
  flex-wrap: wrap-reverse;
  max-height: calc(100dvh - 150px - env(safe-area-inset-bottom));
  gap: 10px;
}
@media (pointer: coarse) {
  #actions { display: flex; }
}
#fire {
  position: fixed;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(34px + env(safe-area-inset-bottom));
  z-index: 4;
  display: none;
  width: 92px;
  height: 92px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: rgba(214, 64, 48, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
}
#actions button.on { background: rgba(120, 200, 120, 0.55); border-color: rgba(255, 255, 255, 0.7); }
#fire.on { background: rgba(240, 84, 60, 0.9); transform: scale(0.94); }
@media (pointer: coarse) {
  #fire { display: block; }
}

#actions button {
  width: 78px;
  height: 46px;
  font: inherit;
  font-size: 12px;
  color: #e8eef3;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
}

/* Прицел: тонкое кольцо с точкой вместо курсора, поверх игры, но под кнопками */
#crosshair {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s, width 0.08s, height 0.08s, margin 0.08s;
}
#crosshair::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
}
#crosshair.on { opacity: 1; }
#crosshair.fire { width: 16px; height: 16px; margin: -8px 0 0 -8px; border-color: rgba(255, 216, 102, 0.8); }
body.mouse-aim #game { cursor: none; }

/* ---------- Редактор карты ---------- */
.mode-btn.alt { background: rgba(255, 255, 255, 0.16); color: #e8eef3; margin-top: 6px; }
.mode-btn.alt:not(:disabled):hover { background: rgba(255, 255, 255, 0.26); }

#editor {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 6;
  width: 216px;
  padding: 14px 12px;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  gap: 12px;
  background: rgba(20, 28, 36, 0.92);
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  user-select: none;
}
#editor.on { display: flex; }
#editor h2 { margin: 0; font-size: 14px; }
#editor button, #editor select, #editor input {
  font: inherit;
  font-size: 12px;
  color: #e8eef3;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 7px;
  padding: 7px 8px;
  touch-action: manipulation;
}
#editor button { cursor: pointer; }
#editor button:hover { background: rgba(255, 255, 255, 0.2); }
#editor button.on { background: rgba(95, 212, 255, 0.35); border-color: #5fd4ff; }
#editor select option { color: #1c2630; }
.ed-group { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ed-props {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 74px;
  padding: 9px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}
.ed-props b { color: #ffd866; font-size: 13px; }
.ed-props > span { opacity: 0.65; }
.ed-props label { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ed-props input[type=number] { width: 74px; }
.ed-props select { max-width: 130px; }
.ed-step { display: inline-flex; align-items: center; gap: 6px; }
.ed-step i { min-width: 34px; text-align: center; font-style: normal; }
#editor .ed-step button { padding: 4px 9px; }
#editor .ed-play { background: #f1d48a; color: #1c2630; border: 0; font-weight: 700; padding: 10px; }
#editor .ed-play:hover { background: #ffe3a1; }
.ed-hint { margin: 0; line-height: 1.6; opacity: 0.6; font-size: 11px; }

/* В редакторе игровые подписи и кнопки не нужны */
body.editing #hud, body.editing #ammo, body.editing #prompt, body.editing #reset,
body.editing #actions, body.editing #fire, body.editing .zone, body.editing #crosshair { display: none !important; }
body.editing #game { cursor: crosshair !important; }

.ed-models { display: flex; flex-direction: column; gap: 6px; }
.ed-title { display: flex; align-items: center; justify-content: space-between; opacity: 0.85; }
#editor .ed-title button { padding: 3px 8px; }
#ed-models button { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-status { margin: 0; font-size: 11px; line-height: 1.5; opacity: 0.65; }
body.dropping #game { outline: 3px dashed #5fd4ff; outline-offset: -10px; }
#editor > * { flex-shrink: 0; }

/* Плитки палитры с превью */
.ed-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#editor .ed-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px 5px;
  min-width: 0;
}
.ed-tile img { width: 100%; aspect-ratio: 1; object-fit: contain; pointer-events: none; }
.ed-tile span { width: 100%; font-size: 10px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-save { margin: -4px 0 0; font-size: 11px; opacity: 0.6; }
.ed-save.warn { color: #ffb38a; opacity: 1; }
#editor { width: 232px; }

/* Палитра: поиск, фильтр и прокрутка — чтобы сотня объектов не превращалась в простыню */
.ed-palette { display: flex; flex-direction: column; gap: 7px; }
#editor #ed-search { width: 100%; }
.ed-chips { display: flex; gap: 5px; }
#editor .ed-chips button { padding: 4px 6px; flex: 1 1 auto; }
#editor .ed-chips #ed-add-model { flex: 0 0 auto; border-style: dashed; }
.ed-scroll { max-height: 264px; overflow-y: auto; padding-right: 2px; }
.ed-empty { margin: 8px 0; opacity: 0.6; grid-column: 1 / -1; }
#editor .ed-tile.on { background: rgba(95, 212, 255, 0.3); border-color: #5fd4ff; }
.ed-note { font-size: 11px; line-height: 1.4; opacity: 0.6; }
.ed-check { justify-content: flex-start !important; cursor: pointer; }
#editor .ed-check input { width: auto; padding: 0; }
.ed-props input[type=text] { width: 120px; }
.ed-props select { max-width: 128px; }
#editor { overflow-x: hidden; }
.ed-chips { flex-wrap: wrap; }
.ed-props b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-props label { min-width: 0; }
.ed-props label > select, .ed-props label > input[type=number], .ed-props label > input[type=text] { flex: 0 1 112px; min-width: 0; width: auto; max-width: none; }

/* ---------- Инспектор: свойства выбранного объекта в панели справа ---------- */
#inspector {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  width: 248px;
  padding: 14px 12px;
  overflow-x: hidden;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  gap: 10px;
  background: rgba(20, 28, 36, 0.92);
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  user-select: none;
}
#inspector.on { display: flex; }
#inspector h2 { margin: 0; font-size: 14px; }
#inspector button, #inspector select, #inspector input {
  font: inherit;
  font-size: 12px;
  color: #e8eef3;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 7px;
  padding: 6px 8px;
  touch-action: manipulation;
}
#inspector button { cursor: pointer; }
#inspector button:hover { background: rgba(255, 255, 255, 0.2); }
#inspector select option { color: #1c2630; }
#inspector .ed-step button { padding: 4px 9px; }
#inspector .ed-check input { width: auto; padding: 0; }
#inspector .ed-props { background: none; padding: 0; min-height: 0; gap: 8px; }
#inspector .ed-props > b { font-size: 13px; padding-bottom: 2px; }
#inspector h3 {
  margin: 8px 0 0;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
}
.ed-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ed-pair label { gap: 6px; }
.ed-pair label > input[type=number] { flex: 1 1 0; }
.ed-actions { margin-top: 8px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.1); }

/* Слева теперь только палитра: она забирает всю свободную высоту */
#editor > .ed-palette { flex: 1 1 220px; min-height: 330px; }
#editor .ed-scroll { max-height: none; flex: 1 1 0; min-height: 0; }
body.inspecting #menu { right: calc(248px + 12px); }

/* ---------- Уровни: список, цель, подсказки, итог ---------- */
#levels { display: flex; flex-direction: column; gap: 10px; max-height: 46vh; overflow-y: auto; }
#goal {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  padding: 5px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.4);
  color: #ffe9b0;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}
#goal:empty { display: none; }
#toast {
  position: fixed;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  max-width: min(520px, 86vw);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
#toast.on { opacity: 1; }
#result {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 16, 22, 0.72);
}
#result.on { display: flex; }
#result h1 { font-size: 26px; }
#result h1.won { color: #9cf08f; }
#result h1.lost { color: #ff8a7a; }
#result-actions { display: flex; flex-direction: column; gap: 10px; }
#result-actions [hidden] { display: none; }
body.editing #goal, body.editing #toast { display: none; }

/* ---------- Редактор: уровни, правила, замечания ---------- */
.ed-levels { display: flex; flex-direction: column; gap: 6px; }
#editor .ed-levels select { width: 100%; }
#editor #ed-rules.on { background: rgba(95, 212, 255, 0.3); border-color: #5fd4ff; }
.ed-issues { margin: 0; font-size: 11px; line-height: 1.4; color: #ffc27a; }
.ed-issues:empty { display: none; }
.ed-warn { margin: 0; padding-left: 16px; font-size: 11px; line-height: 1.45; color: #ffc27a; }
.ed-props input[type=text] { flex: 0 1 132px; }

/* Кнопки пары героев видны только на уровнях, где героев двое */
.duo-only { display: none; }
body.duo .duo-only { display: revert; }

#editor #ed-project-name { min-width: 0; flex: 1; width: 100%; }
#editor .ed-levels label { font-size: 12px; opacity: .8; }

/* Graphics controls are HTML: lowering the canvas resolution never blurs them. */
#graphics-open { position: fixed; top: calc(94px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); z-index: 11; padding: 10px 14px; border: 1px solid #8196a4; border-radius: 8px; background: #233440; color: #fff; font: inherit; cursor: pointer; }
body.editing #graphics-open { top: 12px; right: auto; left: 50%; transform: translateX(-50%); }
#frame-stats { position: fixed; right: 12px; top: 140px; z-index: 4; margin: 0; padding: 10px; background: #14202be6; border-radius: 8px; color: #e8eef3; font-size: 12px; line-height: 1.5; pointer-events: none; }
#graphics-dialog { width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; border: 1px solid #829aa9; border-radius: 14px; padding: 24px; background: #182935; color: #f0f5f8; font: 16px/1.4 system-ui, sans-serif; touch-action: pan-y; }
#graphics-dialog::backdrop { background: #08131bc9; }
#graphics-dialog h2 { margin: 0 0 16px; font-size: 23px; }
#graphics-dialog label { display: grid; gap: 6px; margin: 14px 0; }
#graphics-dialog .graphics-check { display: flex; align-items: center; gap: 10px; }
#graphics-dialog select, #graphics-dialog button { width: 100%; min-height: 44px; padding: 8px 12px; color: #f0f5f8; background: #2c4353; border: 1px solid #8399a7; border-radius: 7px; font: inherit; }
#graphics-dialog input { width: 20px; height: 20px; }
#graphics-dialog :focus-visible, #graphics-open:focus-visible { outline: 3px solid #ffe39a; outline-offset: 3px; }
#graphics-dialog .graphics-note { font-size: 14px; color: #c0d1dc; }
#graphics-metrics { white-space: pre-wrap; font-size: 13px; background: #101d26; padding: 12px; border-radius: 6px; }
