* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #101118;
  --panel: #191b26;
  --panel-2: #212432;
  --border: #31344a;
  --text: #d8d5c8;
  --muted: #8b8a80;
  --gold: #d4af37;
  --gold-dim: #a58928;
  --accent: #5b8dd9;
  --danger: #c0504d;
}

html, body { height: 100%; }

body {
  display: flex;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

/* В режиме просмотра всё редактирующее спрятано */
body.view-mode .edit-only { display: none !important; }

/* ---------- Сайдбар ---------- */

#sidebar {
  width: 320px;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

#app-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #23253a, var(--panel));
}

#app-header h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  color: var(--gold);
  letter-spacing: 1px;
}

.subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Переключатель режима ---------- */

#mode-toggle {
  display: flex;
  gap: 0;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

#mode-toggle button {
  flex: 1;
  padding: 6px 8px;
  background: var(--bg);
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

#mode-toggle button + button { border-left: 1px solid var(--border); }

#mode-toggle button.active {
  background: var(--panel-2);
  color: var(--gold);
}

/* ---------- Вкладки ---------- */

#tabbar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.tab-btn {
  flex: 1;
  padding: 9px 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.panel { padding: 14px 16px; border-bottom: 1px solid var(--border); }

.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--gold-dim);
  margin-bottom: 10px;
}

#steps-quest-name { color: var(--text); text-transform: none; letter-spacing: 0; }

/* ---------- Списки ---------- */

.item-list { list-style: none; margin-bottom: 10px; }

.item-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}

.item-list li:hover { background: var(--panel-2); }

.item-list li.selected {
  background: var(--panel-2);
  border-color: var(--gold-dim);
}

.item-list li .item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  flex-shrink: 0;
}

.icon-btn:hover { color: var(--danger); background: rgba(192, 80, 77, 0.15); }

.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn:disabled:hover { color: var(--muted); background: none; }

.empty-note { color: var(--muted); font-style: italic; padding: 4px 2px 10px; }

/* ---------- Меню квестов (поиск, подборки) ---------- */

.quest-menu { margin-top: 10px; }

#collection-add-quest select {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px;
  font: inherit;
}

#collection-title { color: var(--text); text-transform: none; letter-spacing: 0; }

/* ---------- Чип цели (/target) ---------- */

.target-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  background: rgba(91, 141, 217, 0.12);
  border: 1px solid var(--accent);
  border-radius: 20px;
  color: var(--accent);
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.target-chip:hover {
  background: rgba(91, 141, 217, 0.25);
  color: #8fb3e8;
}

.target-chip.copied {
  border-color: #6dbf6d;
  color: #8fd48f;
  background: rgba(109, 191, 109, 0.15);
}

.target-chip.compact {
  flex-shrink: 1;
  min-width: 0;
  max-width: 45%;
  padding: 2px 8px;
  font-size: 11px;
}

/* ---------- Шаг в режиме просмотра ---------- */

.step-desc {
  white-space: pre-wrap;
  line-height: 1.45;
}

.step-desc.untitled { color: var(--muted); font-style: italic; }

/* ---------- Формы ---------- */

input[type="text"], textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--gold-dim);
}

textarea { resize: vertical; min-height: 64px; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

.btn:hover { border-color: var(--gold-dim); color: var(--gold); }

.btn.gold {
  background: linear-gradient(180deg, #d9b64a, #b3901f);
  border-color: #8a6d14;
  color: #1c1607;
  font-weight: 600;
}

.btn.gold:hover { filter: brightness(1.1); color: #1c1607; }

.btn.wide { width: 100%; }

.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }

#map-upload-form { display: flex; flex-direction: column; gap: 8px; }

.file-label {
  display: block;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-label:hover { border-color: var(--gold-dim); color: var(--text); }

.inline-form { display: flex; gap: 6px; }
.inline-form input { flex: 1; }

/* ---------- Шаги ---------- */

#steps-list { list-style: none; margin-bottom: 10px; }

.step-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg);
  overflow: hidden;
}

.step-item.selected { border-color: var(--gold); }

.step-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.step-head:hover { background: var(--panel-2); }

.step-num {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
}

.step-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-title.untitled { color: var(--muted); font-style: italic; }

.step-pin-flag { font-size: 11px; color: var(--muted); flex-shrink: 0; }

.step-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
}

.step-editor-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.step-editor-buttons .btn { flex: 1; padding: 6px 8px; font-size: 13px; }

.save-note { font-size: 11px; color: var(--muted); text-align: right; min-height: 14px; }

/* ---------- Карта ---------- */

#viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, #181a24 0%, var(--bg) 100%);
  cursor: grab;
}

#viewport.panning { cursor: grabbing; }
#viewport.placing { cursor: crosshair; }

#world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

#map-img { display: block; user-select: none; -webkit-user-drag: none; }

#marker-layer { position: absolute; inset: 0; }

#viewport-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 16px;
  pointer-events: none;
}

/* ---------- Метки ---------- */

.marker {
  position: absolute;
  width: 0;
  height: 0;
  cursor: pointer;
}

/* В режиме установки метки клики должны попадать в карту, а не в старые метки */
#viewport.placing .marker { pointer-events: none; }

.pin {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2f3350, #1a1c2c);
  border: 2px solid var(--gold);
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.55), 0 2px 4px rgba(0, 0, 0, 0.6);
  transition: width 0.15s, height 0.15s, font-size 0.15s, opacity 0.15s;
}

.marker:hover .pin { box-shadow: 0 0 14px rgba(212, 175, 55, 0.9); }

.marker.dim .pin { opacity: 0.35; }

.marker.active { z-index: 10; }

.marker.active .pin {
  width: 40px;
  height: 40px;
  font-size: 17px;
  background: radial-gradient(circle at 35% 30%, #6a5417, #3d2f08);
  border-color: #ffd964;
  color: #ffe9a0;
  box-shadow: 0 0 20px rgba(255, 217, 100, 0.95), 0 2px 6px rgba(0, 0, 0, 0.6);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 12px rgba(255, 217, 100, 0.6); }
  50% { box-shadow: 0 0 26px rgba(255, 217, 100, 1); }
}

/* ---------- Оверлеи вьюпорта ---------- */

#placing-hint {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 22, 34, 0.92);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 9px 16px;
  color: var(--gold);
  pointer-events: none;
  z-index: 20;
}

.hint-esc { color: var(--muted); margin-left: 6px; font-size: 12px; }

#zoom-controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
}

#zoom-controls button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(25, 27, 38, 0.9);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
}

#zoom-controls button:hover { border-color: var(--gold-dim); color: var(--gold); }
