:root {
  --bg: #121821;
  --panel: rgba(16, 21, 30, 0.86);
  --panel-2: rgba(28, 36, 50, 0.96);
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef2f7;
  --muted: #94a3b8;
  --accent: #4cc2ff;
  --good: #5ee08a;
  --bad: #ff6b6b;
  --warn: #ffc94d;
  --r: #4cc265;
  --c: #3b9bff;
  --i: #f0b429;
  --o: #9b6bff;
  --safe-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --radius: 14px;
  --top-h: 104px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; font-size: 14px; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:active { transform: scale(0.96); }
#app { position: fixed; inset: 0; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}

/* ---------- верхняя панель ---------- */
#top {
  position: absolute; z-index: 5;
  top: calc(8px + var(--safe-top)); left: 8px; right: 8px;
  max-width: 560px; margin: 0 auto;
  padding: 8px 10px 7px;
  display: flex; flex-direction: column; gap: 6px;
}
#top .row { display: flex; align-items: center; gap: 10px; }
.city { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
.city span { max-width: 100%; font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.city span::after { content: " ✎"; font-size: 11px; color: var(--muted); }
.city small { color: var(--accent); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.money { display: flex; flex-direction: column; align-items: flex-end; }
.money b { font-size: 17px; font-variant-numeric: tabular-nums; }
.money small { font-size: 11px; color: var(--good); font-variant-numeric: tabular-nums; }
.money .neg { color: var(--bad); }
.stat { display: flex; align-items: center; gap: 4px; font-size: 13px; font-variant-numeric: tabular-nums; }
.stat.date { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.speed { display: flex; padding: 2px; border-radius: 10px; background: rgba(255, 255, 255, 0.06); }
.speed button { width: 30px; height: 26px; border-radius: 8px; font-size: 10px; color: var(--muted); letter-spacing: -2px; }
.speed button.on { background: var(--accent); color: #06121c; }
.msbar { position: relative; height: 15px; border-radius: 8px; overflow: hidden; background: rgba(255, 255, 255, 0.07); }
.msbar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, #2678b8, var(--accent)); transition: width 0.4s; }
.msbar span { position: relative; display: block; font-size: 10px; line-height: 15px; text-align: center; color: #e2ecf6; font-weight: 600; }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: rgba(255, 201, 77, 0.15); color: var(--warn); font-weight: 700; }

/* ---------- спрос и боковые кнопки ---------- */
.demand {
  position: absolute; z-index: 4; left: 8px; top: calc(var(--top-h) + 16px + var(--safe-top));
  padding: 8px 7px 6px; display: flex; gap: 5px;
}
.demand .d { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.demand .bar { position: relative; width: 9px; height: 48px; border-radius: 5px; overflow: hidden; background: rgba(255, 255, 255, 0.08); }
.demand .bar i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; border-radius: 5px; transition: height 0.6s; }
.demand .r i { background: var(--r); }
.demand .c i { background: var(--c); }
.demand .i i { background: var(--i); }
.demand .o i { background: var(--o); }
.demand b { font-size: 10px; color: var(--muted); }
.demand .d.locked { opacity: 0.3; }

.side {
  position: absolute; z-index: 4; right: 8px; top: calc(var(--top-h) + 16px + var(--safe-top));
  display: flex; flex-direction: column; gap: 8px;
}
.side button { width: 44px; height: 44px; display: grid; place-items: center; font-size: 20px; }

.task {
  position: absolute; z-index: 4; left: 84px; right: 60px; margin: 0 auto; max-width: 360px;
  top: calc(var(--top-h) + 16px + var(--safe-top));
  padding: 8px 10px; display: flex; gap: 8px; align-items: flex-start; font-size: 12px; line-height: 1.3;
}
.task .ic { font-size: 18px; line-height: 1; }
.task .tx { flex: 1; }
.task b { display: block; color: var(--accent); font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.task .rw { color: var(--good); font-weight: 700; white-space: nowrap; }

.viewbadge {
  position: absolute; z-index: 4; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom)); padding: 6px 8px 6px 12px;
  display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.viewbadge button { width: 24px; height: 24px; border-radius: 50%; background: rgba(255, 255, 255, 0.1); }
.legend { display: inline-block; width: 60px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, hsl(0 80% 48%), hsl(60 80% 48%), hsl(120 80% 48%)); }

/* ---------- нижняя панель ---------- */
#bottom {
  position: absolute; z-index: 5; left: 8px; right: 8px;
  bottom: calc(8px + var(--safe-bottom));
  max-width: 760px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 8px;
}
.catbar { display: flex; align-items: stretch; }
.cats { flex: 1; min-width: 0; display: flex; gap: 2px; padding: 5px; overflow-x: auto; scrollbar-width: none; }
.cats::-webkit-scrollbar, .items::-webkit-scrollbar { display: none; }
/* Лента прокручивается — у правого края затухание, чтобы было видно, что там есть ещё */
.cats.more { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 30px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 30px), transparent); }
.cats button, .catbar .bulldoze {
  flex: 1 0 auto; min-width: 48px; padding: 6px 3px 4px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 20px; line-height: 1;
}
.cats button small, .catbar .bulldoze small { font-size: 10px; color: var(--muted); }
.cats button.on { background: rgba(76, 194, 255, 0.18); box-shadow: inset 0 0 0 1px rgba(76, 194, 255, 0.55); }
.cats button.on small, .catbar .bulldoze.on small { color: var(--text); }
/* «Снос» закреплён справа и не уезжает при прокрутке категорий */
.catbar .bulldoze { flex: 0 0 auto; position: relative; margin: 5px 5px 5px 2px; }
.catbar .bulldoze::before {
  content: ''; position: absolute; left: -3px; top: 6px; bottom: 6px; width: 1px; background: var(--line);
}
.catbar .bulldoze.on { background: rgba(255, 107, 107, 0.2); box-shadow: inset 0 0 0 1px rgba(255, 107, 107, 0.65); }
.items { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 1px; }
.item {
  flex: 0 0 auto; width: 108px; padding: 8px; text-align: left;
  display: flex; flex-direction: column; gap: 3px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.item .ic { font-size: 24px; line-height: 1.1; }
.item .nm { font-size: 12px; font-weight: 600; line-height: 1.15; min-height: 28px; }
.item .pr { font-size: 12px; font-weight: 700; color: var(--good); }
.item .pr.no { color: var(--bad); }
.item .sw { height: 4px; border-radius: 2px; }
.item.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.item.locked { opacity: 0.5; }
.item.locked .pr { color: var(--muted); font-weight: 500; }
.toolhint {
  align-self: center; max-width: 100%;
  display: flex; align-items: center; gap: 10px; padding: 5px 5px 5px 12px;
  border-radius: 20px; font-size: 12px;
}
.toolhint button { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; background: rgba(255, 255, 255, 0.1); }

/* ---------- уведомления и подсказки ---------- */
.toasts {
  position: absolute; z-index: 20; left: 84px; right: 60px; margin: 0 auto; max-width: 380px;
  top: calc(var(--top-h) + 90px + var(--safe-top));   /* под карточкой задания */
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
.toast {
  padding: 8px 12px; border-radius: 12px; font-size: 13px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  animation: tin 0.25s ease-out;
}
.toast.error { border-color: rgba(255, 107, 107, 0.6); }
.toast.good { border-color: rgba(94, 224, 138, 0.6); }
.toast.out { opacity: 0; transition: opacity 0.4s; }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }
.tip {
  position: absolute; z-index: 15; pointer-events: none; transform: translate(-50%, -170%);
  padding: 4px 8px; border-radius: 8px; white-space: nowrap;
  background: rgba(10, 14, 20, 0.92); color: #fff; font-size: 12px; font-weight: 700;
}

/* ---------- нижний лист (панели) ---------- */
.sheet { position: absolute; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; background: rgba(5, 8, 12, 0.45); }
.sheet-card {
  width: 100%; max-width: 560px; max-height: calc(84% - var(--safe-top));
  display: flex; flex-direction: column;
  border-radius: 18px 18px 0 0; padding-bottom: var(--safe-bottom);
  background: rgba(16, 21, 30, 0.97); animation: up 0.22s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0.4; } }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 8px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; }
.sheet-head button { width: 32px; height: 32px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); }
.sheet-body { overflow-y: auto; padding: 2px 16px 16px; -webkit-overflow-scrolling: touch; }

.sec { margin: 14px 0 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv span { color: #cfd8e3; }
.kv b { font-variant-numeric: tabular-nums; text-align: right; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card { padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
.card small { display: block; color: var(--muted); font-size: 11px; }
.card b { font-size: 16px; font-variant-numeric: tabular-nums; }
.card b.stars { color: var(--warn); letter-spacing: 1px; }
.card b.stars i { font-style: normal; color: rgba(255, 255, 255, 0.26); }
.meter { height: 6px; margin-top: 5px; border-radius: 3px; overflow: hidden; background: rgba(255, 255, 255, 0.08); }
.meter i { display: block; height: 100%; border-radius: 3px; }
.tax { padding: 8px 0; border-bottom: 1px solid var(--line); }
.tax .top { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 14px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.note { margin: 8px 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.chart { display: block; width: 100%; height: 96px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 14px; border-radius: 12px; background: var(--accent); color: #06121c; font-weight: 700;
}
.btn.ghost { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.btn.danger { background: rgba(255, 107, 107, 0.15); color: var(--bad); }
.btn.wide { width: 100%; }
.btns { display: flex; gap: 8px; margin-top: 12px; }
.btns .btn { flex: 1; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch { width: 44px; height: 26px; border-radius: 13px; background: rgba(255, 255, 255, 0.15); position: relative; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left 0.2s; }
.switch.on { background: var(--accent); }
.switch.on::after { left: 21px; }

.tabs { display: flex; padding: 3px; margin-bottom: 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); }
.tabs button { flex: 1; padding: 8px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--accent); color: #06121c; }
.views { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.views button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border-radius: 12px; font-size: 22px; background: rgba(255, 255, 255, 0.05); }
.views button small { font-size: 11px; color: var(--muted); text-align: center; }
.views button.on { background: rgba(76, 194, 255, 0.18); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------- рейтинг ---------- */
.lb-row { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--line); }
.lb-row.me { border-radius: 10px; background: rgba(76, 194, 255, 0.12); }
.lb-rank { width: 30px; text-align: center; font-weight: 700; color: var(--muted); font-size: 14px; }
.lb-rank.medal { font-size: 22px; }
.ava { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background-size: cover; background-position: center; }
.lb-main { flex: 1; min-width: 0; }
.lb-main b, .lb-main small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-main b { font-size: 14px; }
.lb-main small { color: var(--muted); font-size: 12px; }
.lb-val { text-align: right; font-weight: 700; color: var(--good); font-variant-numeric: tabular-nums; }
.lb-val small { display: block; color: var(--muted); font-weight: 500; font-size: 11px; }
.lb-me {
  position: sticky; bottom: 0; margin-top: 10px; padding: 10px;
  display: flex; align-items: center; gap: 10px; border-radius: 12px;
  background: rgba(30, 42, 58, 0.98); border: 1px solid rgba(76, 194, 255, 0.4);
}
.empty { padding: 26px 8px; text-align: center; color: var(--muted); }

/* ---------- окна ---------- */
.modal { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(5, 8, 12, 0.6); }
.modal-card {
  width: min(100%, 360px); padding: 22px 20px 18px; text-align: center; border-radius: 20px;
  background: rgba(18, 24, 34, 0.98); border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.modal-card .big { font-size: 52px; line-height: 1.1; }
.modal-card h3 { margin: 8px 0 4px; font-size: 20px; }
.modal-card p { margin: 6px 0 12px; color: var(--muted); line-height: 1.45; }
.modal-card input {
  width: 100%; margin-bottom: 4px; padding: 11px 12px; border-radius: 10px; font: inherit; font-size: 16px;
  color: var(--text); background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); user-select: text;
}
.unlocks { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 8px 0 14px; }
.unlocks span { padding: 4px 8px; border-radius: 8px; font-size: 12px; background: rgba(255, 255, 255, 0.07); }

/* ---------- загрузка ---------- */
.loading {
  position: absolute; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, #1d2a3d, #0d121a); transition: opacity 0.4s;
}
.loading .logo { font-size: 64px; animation: bob 1.6s ease-in-out infinite; }
.loading h1 { margin: 10px 0 4px; font-size: 28px; letter-spacing: 0.02em; }
.loading p { color: var(--muted); }
.loading.fade { opacity: 0; pointer-events: none; }
@keyframes bob { 50% { transform: translateY(-8px); } }

@media (max-height: 620px) {
  :root { --top-h: 96px; }
  .demand .bar { height: 38px; }
  .side button { width: 40px; height: 40px; font-size: 18px; }
}
@media (min-width: 900px) {
  .side button { width: 48px; height: 48px; }
  .item { width: 120px; }
}
