:root {
  --bg: #0d1117;
  --panel: rgba(16, 20, 28, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #e8edf5;
  --muted: #9aa7b8;
  --accent: #ffb43a;
  --accent-2: #46e0a0;
}

* { box-sizing: border-box; }

/* Любое правило с display у класса перебивает браузерное [hidden],
   и элемент перестаёт прятаться. Ставим это один раз для всех,
   иначе каждый новый блок с display рискует залипнуть на экране. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  overflow: hidden;
}

#map { position: absolute; inset: 0; }

/* ── верхняя панель ─────────────────────────────── */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px;
  background: linear-gradient(180deg, rgba(6, 9, 14, 0.85), transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; letter-spacing: 0.06em; }
.brand b { font-size: 15px; }
.brand .sub { color: var(--muted); font-size: 12px; letter-spacing: 0; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ── поиск ──────────────────────────────────────── */
.search { position: relative; flex: 1; max-width: 380px; margin: 0 12px; }
.search input {
  width: 100%; font: inherit; font-size: 13px;
  background: rgba(10, 14, 20, 0.82); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px;
}
.search input:focus { outline: none; border-color: var(--accent); }
.search ul {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  margin: 0; padding: 5px; list-style: none; z-index: 10;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; backdrop-filter: blur(14px);
  max-height: 46vh; overflow-y: auto;
}
.search li {
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 12px;
}
.search li:hover { background: rgba(255, 255, 255, 0.08); }
.search li.empty { color: var(--muted); cursor: default; }
.badge {
  font-size: 11px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; background: rgba(10, 14, 20, 0.65);
  white-space: nowrap;
}
.badge.code b { color: var(--accent); letter-spacing: 0.08em; }
.donate {
  font-size: 12px; font-weight: 600; text-decoration: none; cursor: pointer;
  color: #16202c; background: var(--accent); border: 0;
  padding: 7px 15px; border-radius: 999px; font-family: inherit;
}

/* ── окно доната ────────────────────────────────── */
.modal {
  position: absolute; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 20px;
  background: rgba(4, 7, 11, 0.72); backdrop-filter: blur(4px);
}
.modal-box {
  position: relative; width: min(560px, 100%);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 22px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
}
.modal-box h2 { margin: 0 0 8px; font-size: 18px; }
.modal-note { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.modal-note b {
  color: var(--accent); font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 0.08em;
}
.modal-box { max-height: calc(100vh - 40px); overflow-y: auto; }

/* ── пакеты токенов ─────────────────────────────── */
.packs { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 7px; }
.packs li {
  display: flex; align-items: baseline; gap: 12px;
  border: 1px solid var(--line); border-radius: 11px; padding: 10px 13px;
  background: rgba(0, 0, 0, 0.25);
}
.packs b { font-size: 16px; min-width: 66px; }
.packs span { font-size: 12.5px; color: var(--muted); }
.packs i { font-style: normal; color: var(--accent-2); }
.packs .best { border-color: rgba(255, 180, 58, 0.45); background: rgba(255, 180, 58, 0.07); }
.packs .best b { color: var(--accent); }
.code-note { margin-bottom: 7px !important; }

/* ── инструкция ─────────────────────────────────── */
.intro-box { width: min(620px, 100%); }
.steps { margin: 0 0 14px; padding-left: 22px; display: grid; gap: 9px; font-size: 14px; }
.steps b { color: var(--accent); font-weight: 600; }
.intro-note {
  margin: 0 0 16px; font-size: 12.5px; color: var(--muted);
  border-left: 2px solid var(--line); padding-left: 11px;
}

#donate-frame iframe {
  width: 100%; height: 230px; border: 0; border-radius: 12px;
  background: #f7f7f7;
}

/* ── выбор масштаба ─────────────────────────────── */
.modes {
  position: absolute; z-index: 6; left: 50%; top: 52px;
  transform: translateX(-50%);
  display: flex; gap: 4px; padding: 4px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; backdrop-filter: blur(14px);
}
.modes button {
  display: flex; align-items: center; gap: 6px;
  font: 12px/1 inherit; color: var(--muted); cursor: pointer;
  background: none; border: 0; border-radius: 999px; padding: 7px 14px;
}
.modes button:hover { color: var(--text); }
.modes button.on { background: var(--accent); color: #16202c; font-weight: 700; }
.modes button i {
  font-style: normal; font-size: 10px; opacity: 0.65;
  border: 1px solid currentColor; border-radius: 999px; padding: 1px 5px;
}

/* ── подсказка ──────────────────────────────────── */
.hint {
  position: absolute; z-index: 4; left: 50%; top: 96px;
  transform: translateX(-50%);
  background: rgba(10, 14, 20, 0.8); border: 1px solid var(--line);
  padding: 6px 14px; border-radius: 999px; font-size: 12px; color: var(--muted);
  transition: opacity 0.4s;
}

/* ── панель правки ──────────────────────────────── */
.panel {
  position: absolute; z-index: 6; right: 14px; top: 60px; width: 320px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px;
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.panel h2 { margin: 0 0 2px; font-size: 15px; }
.panel .muted { margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.panel .close, .modal-box .close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: 0; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer;
  padding: 4px 8px;
}
.panel .close:hover, .modal-box .close:hover { color: var(--text); }
textarea {
  width: 100%; resize: none; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35);
  color: var(--text); padding: 10px; font: inherit;
}
textarea:focus { outline: none; border-color: var(--accent); }
/* ── настроение правки ──────────────────────────── */
.styles { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.styles button {
  font: inherit; font-size: 11px; cursor: pointer; color: var(--muted);
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 11px;
}
.styles button:hover { color: var(--text); }
.styles button.on { background: var(--accent-2); color: #10201a; font-weight: 700; border-color: transparent; }

.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.ghost {
  font-size: 15px; cursor: pointer; line-height: 1;
  background: rgba(255, 255, 255, 0.08); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px;
}
.primary {
  background: var(--accent); color: #16202c; font-weight: 700;
  border: 0; border-radius: 10px; padding: 9px 16px; cursor: pointer;
}
.primary:disabled { opacity: 0.5; cursor: default; }
.status { font-size: 12px; color: var(--muted); }
.status.err { color: #ff8080; }
.note { margin: 12px 0 0; font-size: 11px; color: var(--muted); }

.modes button.paid { color: var(--accent); }
.modes button.paid.on { color: #16202c; }
.modes button.paid i { opacity: 1; }

/* машина времени по месту */
.history {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--line);
}
.history-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--muted);
}
.history-nav { display: flex; gap: 4px; }
.history-nav button {
  width: 26px; height: 24px; cursor: pointer;
  background: rgba(255, 255, 255, 0.08); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
  font-size: 14px; line-height: 1;
}
.history-nav button:disabled { opacity: 0.3; cursor: default; }
.history p { margin: 7px 0 0; font-size: 12px; }
.history p b { color: var(--accent-2); }

/* уведомление «твоё закрасили» */
.alert.over {
  background: linear-gradient(135deg, #5b6bff, #8f46e0);
  color: #f2f5ff;
}

.pay {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--line);
}
.pay p { margin: 0 0 9px; font-size: 12px; color: var(--muted); }
.pay .primary { display: inline-block; text-decoration: none; margin-bottom: 8px; }

.share {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--line);
}
.share p { margin: 0 0 7px; font-size: 12px; color: var(--muted); }
.share-row { display: flex; gap: 6px; }
.share-row input {
  flex: 1; min-width: 0; font: 11px/1 monospace;
  background: rgba(0, 0, 0, 0.35); color: var(--accent-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px;
}
.share-row button {
  flex: none; font-size: 11px; cursor: pointer;
  background: rgba(255, 255, 255, 0.1); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}

/* ── левая колонка: лента и чат ─────────────────── */
.rail {
  position: absolute; z-index: 5; left: 14px; bottom: 14px;
  width: 268px; max-height: calc(100vh - 130px);
  display: flex; flex-direction: column; gap: 10px;
}

.feed, .chat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; backdrop-filter: blur(14px);
  display: flex; flex-direction: column; overflow: hidden;
}
.feed { max-height: 30vh; }
.chat { max-height: 34vh; }

.feed h3, .chat h3 {
  margin: 0; padding: 11px 14px; font-size: 12px;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.chat ul {
  margin: 0; padding: 7px; list-style: none;
  overflow-y: auto; display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; min-height: 60px;
}
.chat li { display: flex; gap: 6px; align-items: baseline; }
.chat li .who {
  flex: none; font-family: ui-monospace, Consolas, monospace;
  font-size: 10px; color: var(--muted);
}
.chat li.me .who { color: var(--accent); }
.chat li .msg { word-break: break-word; }
.chat li .pin {
  flex: none; cursor: pointer; opacity: 0.55;
  background: none; border: 0; color: var(--accent-2); font-size: 11px; padding: 0;
}
.chat li .pin:hover { opacity: 1; }
.chat li.sys { color: var(--muted); font-style: italic; }

#chat-form { display: flex; gap: 6px; padding: 7px; border-top: 1px solid var(--line); }
#chat-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 12px;
  background: rgba(0, 0, 0, 0.35); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px;
}
#chat-form input:focus { outline: none; border-color: var(--accent); }
#chat-form button {
  flex: none; cursor: pointer; font-size: 13px;
  background: rgba(255, 255, 255, 0.1); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; padding: 0 11px;
}
.feed h3 {
  margin: 0; padding: 11px 14px; font-size: 12px;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.feed ul { margin: 0; padding: 6px; list-style: none; overflow-y: auto; }
.feed li {
  padding: 8px 10px; border-radius: 9px; cursor: pointer;
  font-size: 12px; display: flex; gap: 8px; align-items: baseline;
}
.feed li:hover { background: rgba(255, 255, 255, 0.07); }
.feed li .who { color: var(--accent-2); flex: none; }
.feed li .what { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed li.don { background: rgba(255, 180, 58, 0.1); }
.feed li.don .who { color: var(--accent); font-weight: 700; }

/* карточка правки с картинкой */
.feed li.shot { gap: 10px; align-items: center; }
.feed li.shot img {
  width: 42px; height: 42px; flex: none; object-fit: cover;
  border-radius: 8px; background: #05080c;
}
.feed li.shot .what { display: flex; flex-direction: column; min-width: 0; }
.feed li.shot .what b {
  font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.feed li.shot .what i {
  font-style: normal; font-size: 10px; color: var(--muted);
  font-family: ui-monospace, Consolas, monospace;
}

/* ── донат-алерты ───────────────────────────────── */
.alerts {
  position: absolute; z-index: 20; top: 64px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  pointer-events: none;
}
.alert {
  pointer-events: auto; cursor: pointer;
  min-width: 320px; max-width: 460px;
  background: linear-gradient(135deg, #ffb43a, #ff7a59);
  color: #16202c; border-radius: 14px; padding: 12px 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  animation: drop 0.45s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.alert b { font-size: 15px; }
.alert .amt { float: right; font-weight: 800; }
.alert .msg { font-size: 13px; margin-top: 3px; }
.alert .go { font-size: 11px; opacity: 0.75; margin-top: 5px; }
@keyframes drop {
  from { transform: translateY(-24px) scale(0.94); opacity: 0; }
}

/* ── полоса сканирования во время генерации ─────
   Десять-двадцать секунд без обратной связи ощущаются как зависание.
   Полоса показывает, что машина работает. */
.scanline {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: rgba(6, 9, 14, 0.28);
}
.scanline i {
  position: absolute; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 22px rgba(255, 180, 58, 0.65);
  animation: sweep 1.9s ease-in-out infinite;
}
@keyframes sweep {
  0%   { top: 6%;  opacity: 0; }
  12%  { opacity: 1; }
  88%  { opacity: 1; }
  100% { top: 94%; opacity: 0; }
}

/* ── нижняя панель вкладок (только телефон) ─────── */
.tabbar { display: none; }
.rail-close { display: none; }

@media (prefers-reduced-motion: reduce) {
  .scanline i, .dot { animation: none; }
}

/* ══ ТЕЛЕФОН ════════════════════════════════════ */
@media (max-width: 760px) {
  /* Шапка ужимается: место на экране дороже украшений. */
  .topbar { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .brand .sub { display: none; }
  .brand b { font-size: 13px; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  .search input { padding: 9px 13px; font-size: 16px; } /* 16px — иначе iOS зумит форму */
  .topbar-right { gap: 6px; }
  .badge.name { display: none; }
  .badge { font-size: 10px; padding: 3px 8px; }
  .donate { padding: 6px 12px; font-size: 11px; }

  /* Масштабы — лентой с прокруткой, чтобы влезли все четыре. */
  .modes {
    top: auto; bottom: calc(58px + env(safe-area-inset-bottom));
    left: 8px; right: 8px; transform: none;
    border-radius: 14px; overflow-x: auto;
    justify-content: flex-start; scrollbar-width: none;
  }
  .modes::-webkit-scrollbar { display: none; }
  .modes button { white-space: nowrap; padding: 9px 14px; }

  .hint { top: auto; bottom: calc(112px + env(safe-area-inset-bottom)); font-size: 11px; }

  /* Панель правки — шторкой снизу: до верхнего угла на телефоне
     не дотянуться большим пальцем. */
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    max-height: 82vh; overflow-y: auto;
    border-radius: 18px 18px 0 0;
    border-left: 0; border-right: 0; border-bottom: 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    animation: sheet 0.24s ease-out;
  }
  @keyframes sheet { from { transform: translateY(100%); } }
  .panel::before {
    content: ''; display: block; width: 40px; height: 4px;
    background: var(--line); border-radius: 999px;
    margin: -6px auto 12px;
  }
  textarea { font-size: 16px; }
  .primary { padding: 12px 18px; font-size: 15px; }
  .ghost { padding: 11px 14px; }

  /* Лента и чат — тоже шторкой, по кнопке снизу. */
  .rail {
    left: 0; right: 0; bottom: 0; width: auto;
    max-height: 72vh;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    backdrop-filter: blur(16px);
    transform: translateY(102%);
    transition: transform 0.26s ease-out;
    z-index: 12;
  }
  .rail.open { transform: none; }
  .rail .feed, .rail .chat { border: 0; background: none; backdrop-filter: none; }
  .rail .feed { max-height: 26vh; }
  .rail .chat { max-height: 40vh; }
  .rail[data-tab="chat"] .feed, .rail[data-tab="feed"] .chat { display: none; }

  .rail-close {
    display: block; width: 44px; height: 26px; margin: 0 auto 2px;
    background: none; border: 0; color: var(--muted); font-size: 15px; cursor: pointer;
  }

  /* Нижняя панель: главное — под большим пальцем. */
  .tabbar {
    display: flex; position: absolute; z-index: 11;
    left: 0; right: 0; bottom: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    gap: 6px;
    background: rgba(10, 14, 20, 0.94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
  }
  .tabbar button {
    flex: 1; font: inherit; font-size: 12px; cursor: pointer;
    background: none; border: 0; color: var(--muted);
    padding: 10px 4px; border-radius: 11px;
  }
  .tabbar button.on { background: rgba(255, 255, 255, 0.09); color: var(--text); }

  .alerts { top: 56px; width: calc(100% - 20px); }
  .alert { min-width: 0; width: 100%; }

  .maplibregl-ctrl-bottom-right { bottom: calc(112px + env(safe-area-inset-bottom)); }

  .modal { padding: 0; align-items: end; }
  .modal-box {
    width: 100%; max-height: 88vh; border-radius: 18px 18px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .steps { font-size: 13.5px; }
}
