:root {
  --bg: #0e141b;
  --panel: #1b2838;
  --panel-2: #22364a;
  --line: #2b4157;
  --text: #e6eef5;
  --muted: #8aa2b8;
  --accent: #66c0f4;
  --green: #a4d007;
  --yellow: #f5c542;
  --red: #ff6b6b;
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  min-height: 100vh;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  background: radial-gradient(120% 60% at 50% -10%, #23405a 0%, var(--bg) 60%) fixed;
}

button, input, select { font: inherit; color: inherit; }

/* ---------- шапка ---------- */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 6px;
  max-width: 640px; margin: 0 auto;
}
.top-logo { width: 44px; height: 44px; border-radius: 50%; box-shadow: 0 4px 16px #0008; }
.top-title { font-weight: 700; font-size: 18px; }
.top-sub { color: var(--muted); font-size: 13px; }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px; }

/* ---------- карточки ---------- */
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 6px 20px #0005;
}
.card.tappable { cursor: pointer; transition: transform .08s; }
.card.tappable:active { transform: scale(.985); }

.section-title {
  color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  margin: 18px 4px 8px;
}

.bot-head { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 48px; height: 48px; border-radius: 12px; flex: none;
  background: var(--panel-2) center/cover no-repeat;
  display: grid; place-items: center; font-weight: 700; color: var(--accent); font-size: 20px;
  border: 2px solid var(--line);
}
.avatar.big { width: 72px; height: 72px; border-radius: 18px; font-size: 30px; }
.avatar.s-online { border-color: var(--green); }
.avatar.s-input { border-color: var(--yellow); }
.bot-names { flex: 1; min-width: 0; }
.bot-name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-nick { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: #ffffff10; color: var(--muted);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.st-online { color: var(--green); background: #a4d00718; }
.pill.st-connecting { color: var(--accent); background: #66c0f418; }
.pill.st-input { color: var(--yellow); background: #f5c54218; }
.pill.st-stopped, .pill.st-disabled { color: var(--muted); }

.activity { margin-top: 10px; color: var(--text); font-size: 14px; }
.activity .muted { color: var(--muted); }
.progress { margin-top: 6px; color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

/* ---------- кнопки и поля ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 11px 14px; cursor: pointer;
  background: #ffffff12; color: var(--text); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { filter: brightness(1.2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: #0b1a26; }
.btn.go { background: var(--green); color: #14200a; }
.btn.danger { background: #ff6b6b22; color: var(--red); }
.btn.small { padding: 7px 10px; font-size: 13px; border-radius: 10px; }
.btn.icon { width: 36px; height: 36px; padding: 0; border-radius: 10px; flex: none; }

.field { display: block; margin-top: 10px; }
.field-label { color: var(--muted); font-size: 13px; margin: 0 2px 6px; }
.input {
  width: 100%; border: 1px solid var(--line); background: #0b1118; border-radius: 12px;
  padding: 11px 12px; outline: none;
}
.input:focus { border-color: var(--accent); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; min-width: 0; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: #ffffff20; transition: .2s; cursor: pointer;
}
.switch span::before {
  content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%;
  background: #fff; transition: .2s;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(20px); }

.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }

.banner {
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  background: #f5c54214; border: 1px solid #f5c54255;
}
.banner-title { font-weight: 700; color: var(--yellow); }

/* ---------- игры ---------- */
.game {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-top: 1px solid var(--line);
}
.game:first-child { border-top: 0; }
.game-img {
  width: 92px; height: 35px; border-radius: 6px; flex: none; object-fit: cover;
  background: var(--panel-2);
}
.game-name { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-id { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; }

/* ---------- лог ---------- */
.log-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.seg { display: flex; background: #ffffff10; border-radius: 12px; padding: 3px; flex: none; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--panel-2); color: var(--text); }
.log-controls select { flex: 1; min-width: 0; }
.log {
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #0a0f15; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; height: calc(100vh - 230px); overflow-y: auto; overscroll-behavior: contain;
}
.log-line { padding: 2px 0; word-break: break-word; }
.log-line .t { color: #5f7890; }
.log-line .src { color: var(--accent); }
.log-line.WARN { color: var(--yellow); }
.log-line.ERROR, .log-line.FATAL { color: var(--red); }
.log-line.DEBUG, .log-line.TRACE { color: #6d8296; }

/* ---------- нижние вкладки ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: #0e141be6; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; max-width: 200px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font-size: 12px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
}
.tabs button.active { color: var(--accent); }
.tab-ico { font-size: 20px; line-height: 1.2; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; transition: .25s;
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); text-align: center; z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #b3261ee6; }

.center-screen { text-align: center; padding: 60px 20px; color: var(--muted); }
.center-screen img { width: 96px; border-radius: 50%; margin-bottom: 16px; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- сводка на главной ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.tile-value { font-size: 22px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--muted); font-size: 13px; }
.tile-sub { color: var(--accent); font-size: 12px; margin-top: 2px; }

.toolbar { display: flex; gap: 6px; align-items: center; margin: 4px 0 12px; }
.grow { flex: 1; }

.bot-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.wallet { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.check {
  width: 24px; height: 24px; border-radius: 50%; flex: none; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 14px; color: #0b1a26; font-weight: 700;
}
.check.on { background: var(--accent); border-color: var(--accent); }
.card.selected { border-color: var(--accent); }

.selectbar {
  position: fixed; left: 0; right: 0; z-index: 11; display: none;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding: 10px 12px; background: #16222fee; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  align-items: center; gap: 8px; justify-content: space-between;
}
.selectbar.show { display: flex; }
.selectbar-count { font-weight: 600; font-size: 14px; white-space: nowrap; }
.selectbar-actions { display: flex; gap: 6px; }
body:has(.selectbar.show) main { padding-bottom: 70px; }

/* ---------- страница бота ---------- */
.seg.wide { display: flex; margin: 4px 0 4px; }
.seg.wide button { flex: 1; }
.game.now .game-name { color: var(--green); }
.check-row { display: flex; gap: 12px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.check-row:first-child { border-top: 0; }
.check-row input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--green); flex: none; }
select.input { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.sticky-save {
  position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  background: #0e141bcc; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 8px; border-radius: 14px; border: 1px solid var(--line);
}

/* ---------- ASF и консоль ---------- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kv:first-child { border-top: 0; }
.kv > span:first-child { color: var(--muted); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--line); background: #ffffff0d; color: var(--text); border-radius: 999px;
  padding: 5px 10px; font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; cursor: pointer;
}
.chip:active { filter: brightness(1.3); }
.console-entry { padding: 10px 12px; }
.console-cmd { display: flex; align-items: center; gap: 8px; font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--accent); }
.console-out {
  margin: 8px 0 0; white-space: pre-wrap; word-break: break-word;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text);
  background: #0a0f15; border-radius: 10px; padding: 8px 10px; max-height: 320px; overflow: auto;
}
.console-out.err { color: var(--red); }
a { color: var(--accent); }
