:root {
  --bg: #0e1621;
  --bg-elev: #15202e;
  --bg-card: #17212b;
  --bg-soft: #1f2c3a;
  --border: rgba(255, 255, 255, 0.07);
  --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --text: #f3f6fa;
  --muted: #7f91a4;
  --accent: #3ea6ff;
  --accent-soft: rgba(62, 166, 255, 0.14);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.14);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.15);
  --radius: 14px;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 99px; }

html, body {
  margin: 0; padding: 0;
  background: #0a1018;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body[data-viewport="mobile"] {
  background: #06090e;
  display: flex; justify-content: center; padding: 12px 0;
}
body[data-viewport="mobile"] .app-shell {
  width: 430px; max-width: 100vw; height: calc(100vh - 24px);
  border-radius: 26px; border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.78); overflow: hidden;
}
body[data-viewport="mobile"] .split-2,
body[data-viewport="mobile"] .studio-grid,
body[data-viewport="mobile"] .control-grid,
body[data-viewport="mobile"] .tg-menu-grid { grid-template-columns: 1fr; }

.app-shell {
  width: 100%; max-width: 1180px; margin: 0 auto;
  display: flex; flex-direction: column; min-height: 100vh;
  background: var(--bg);
}

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 16px;
  background: rgba(23, 33, 43, 0.92);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bot-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #2aabee, #6366f1);
  display: grid; place-items: center; color: #fff; flex-shrink: 0;
}
.topbar-title { font-weight: 700; font-size: 14.5px; display: flex; align-items: center; gap: 6px; }
.tg-verified {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.05em;
  padding: 2px 6px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
}
.topbar-sub { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot-red { background: var(--red); box-shadow: 0 0 8px var(--red); }
.dot-muted { background: var(--muted); }

.content { flex: 1; overflow-y: auto; padding: 14px 16px 96px; }
.tab-panel { display: none; animation: fadeIn .16s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

.bot-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--highlight);
  border-radius: var(--radius);
  padding: 14px;
}
.hero-surface {
  background: linear-gradient(160deg, rgba(62,166,255,0.09) 0%, var(--bg-card) 55%);
  border-color: rgba(62,166,255,0.2);
}

.bot-tree-cols {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px;
}
@media (max-width: 680px) { .bot-tree-cols { grid-template-columns: 1fr; } }

.tree-block {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
}
.tree-title { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; color: var(--accent); margin-bottom: 6px; }
.tree-line { font-size: 12.5px; color: #dbe4f0; padding: 2px 0; font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; gap: 8px; }
.tree-line span { color: var(--muted); }

.section-label {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); margin: 14px 0 8px;
}

.tg-menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tg-action-btn {
  background: var(--bg-card); border: 1px solid var(--border); box-shadow: var(--highlight);
  border-radius: 13px; padding: 12px 13px; color: var(--text); text-decoration: none;
  display: flex; align-items: center; gap: 11px; cursor: pointer; text-align: left;
  transition: background .14s, border-color .14s;
}
.tg-action-btn:hover { background: var(--bg-soft); border-color: rgba(62,166,255,0.4); }
.tg-action-btn svg { color: var(--accent); flex-shrink: 0; }
.tg-action-btn b { display: block; font-size: 13.5px; font-weight: 700; }
.tg-action-btn small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 1px; }

.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.studio-grid { display: grid; grid-template-columns: 1.12fr 0.88fr; gap: 12px; align-items: start; }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 820px) { .split-2, .studio-grid, .control-grid { grid-template-columns: 1fr; } }

.seg-tabs {
  display: flex; gap: 4px; background: var(--bg-elev);
  padding: 4px; border-radius: 12px; border: 1px solid var(--border);
  margin-bottom: 12px; overflow-x: auto;
}
.seg-btn {
  flex: 1; white-space: nowrap; border: none; background: transparent; color: var(--muted);
  font-weight: 600; font-size: 12px; padding: 7px 10px; border-radius: 9px; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn.active { background: var(--accent-soft); color: var(--accent); }
.seg-btn span { opacity: 0.85; font-size: 11px; margin-left: 3px; }

.toolbar { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.btn-group { display: flex; gap: 5px; }

.input, .select {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 8px 11px; font-size: 13px; outline: none; flex: 1; min-width: 140px;
}
.input:focus, .select:focus { border-color: var(--accent); }
.select { flex: 0 0 auto; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

.chip-btn, .icon-btn, .primary-btn {
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text);
  border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip-btn:hover, .icon-btn:hover { border-color: rgba(255,255,255,0.22); }
.chip-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.primary-btn { background: var(--accent); border-color: var(--accent); color: #05111b; }
.icon-btn { padding: 7px 8px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px;
  border-radius: 7px; font-size: 11px; font-weight: 700;
  background: var(--bg-soft); color: var(--muted);
}
.badge-cyan { background: var(--accent-soft); color: var(--accent); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-violet { background: var(--violet-soft); color: var(--violet); }

.stack-list { display: flex; flex-direction: column; gap: 7px; }
.item-row {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.item-main { min-width: 0; flex: 1; }
.item-title { font-weight: 650; font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-word; }

.card-title { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.sub-block { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.sub-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }

/* TELEGRAM CHAT VIEW (KOLYA AI) */
.tg-chat-shell {
  background: #0d141d;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.tg-chat-header {
  padding: 10px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.tg-chat-scroll {
  height: clamp(260px, calc(100vh - 345px), 440px);
  overflow-y: auto;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 7px;
  background-image: radial-gradient(rgba(62,166,255,0.04) 1px, transparent 0);
  background-size: 20px 20px;
}
body[data-viewport="mobile"] .tg-chat-scroll {
  height: clamp(240px, calc(100vh - 390px), 410px);
}
.tg-chat-footer {
  padding: 8px 12px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.bubble {
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 13px 13px 13px 4px;
  background: #182533;
  border: 1px solid rgba(255,255,255,0.05);
  align-self: flex-start;
  font-size: 13px;
}
.bubble.is-bot {
  align-self: flex-end;
  border-radius: 13px 13px 4px 13px;
  background: #234263;
  border-color: rgba(62,166,255,0.28);
}
.bubble-head { font-size: 11px; color: var(--muted); margin-bottom: 3px; display: flex; justify-content: space-between; gap: 12px; }
.bubble-head b { color: var(--accent); }
.bubble.is-bot .bubble-head b { color: #7cc4ff; }
.bubble-quote {
  border-left: 2px solid var(--accent);
  background: rgba(62,166,255,0.08);
  padding: 2px 7px; border-radius: 4px;
  font-size: 11px; color: #9fc5e8; margin-bottom: 5px;
}
.bubble-voice-pill {
  display: flex; align-items: center; gap: 9px;
  background: rgba(0,0,0,0.22);
  padding: 7px 9px; border-radius: 10px; margin: 3px 0 4px;
}
.fake-wave { display: flex; align-items: center; gap: 2px; height: 18px; }
.fake-wave i { display: block; width: 2.5px; background: rgba(255,255,255,0.45); border-radius: 2px; font-style: normal; }

/* AUDIO PLAYER */
.voice-play-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--accent); color: #05111b;
  font-size: 12px; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center;
}
.voice-play-btn.playing { background: var(--green); }

.audio-dock {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 68px;
  width: min(520px, calc(100vw - 24px)); z-index: 40;
  background: rgba(23, 33, 43, 0.96); backdrop-filter: blur(18px);
  border: 1px solid rgba(62,166,255,0.35); border-radius: 14px;
  padding: 9px 12px; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
}
.audio-play-btn { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--accent); color: #05111b; cursor: pointer; }
.audio-meta { flex: 1; min-width: 0; }
.audio-title { font-weight: 700; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.audio-progress-wrap { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.audio-progress-bar { flex: 1; height: 4px; background: var(--bg-soft); border-radius: 99px; overflow: hidden; cursor: pointer; }
.audio-progress-fill { width: 0%; height: 100%; background: var(--accent); }
.audio-time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* BOTTOM NAV */
.bottom-nav {
  position: sticky; bottom: 0; z-index: 35;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(23, 33, 43, 0.95); backdrop-filter: blur(18px);
  border-top: 1px solid var(--border); padding: 6px 4px;
}
.nav-btn {
  border: none; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 5px 2px; cursor: pointer; border-radius: 10px;
}
.nav-btn small { font-size: 10.5px; font-weight: 600; }
.nav-btn.active { color: var(--accent); background: var(--accent-soft); }

/* STUDIO & VIDEO GEN */
.tg-message-preview { background: #182533; border-radius: 14px; padding: 12px; border: 1px solid var(--border); }
.tg-cover-box {
  background: linear-gradient(135deg, #223044, #3b1d5e);
  border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-direction: column;
  margin-bottom: 8px; color: #dbeafe; font-weight: 700;
}
.tg-cover-box.crop-16-9 { aspect-ratio: 16 / 9; }
.tg-cover-box.crop-1-1 { aspect-ratio: 1 / 1; max-height: 210px; width: 100%; }
.tg-audio-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 9px; background: rgba(255,255,255,0.04); margin-bottom: 5px; }
.tg-audio-icon { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #05111b; display: grid; place-items: center; font-weight: 800; flex-shrink: 0; }
.tg-tags { font-size: 12.5px; color: #64b5f6; margin: 5px 0; }
.tg-inline-grid { display: grid; gap: 5px; margin-top: 8px; }
.tg-inline-btn { text-align: center; padding: 7px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; background: rgba(255,255,255,0.09); color: #fff; text-decoration: none; }
.tg-inline-btn.sty-primary { background: rgba(62,166,255,0.28); }
.tg-inline-btn.sty-success { background: rgba(52,211,153,0.28); }
.tg-inline-btn.sty-danger { background: rgba(248,113,113,0.28); }

.wave-box { display: flex; align-items: flex-end; gap: 3px; height: 54px; background: var(--bg-elev); padding: 8px; border-radius: 10px; border: 1px solid var(--border); }
.wave-bar { flex: 1; background: #2c3c4f; border-radius: 3px; }
.wave-bar.active { background: var(--accent); }
.range-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-top: 8px; }
.vg-stage { display: flex; justify-content: center; background: var(--bg-elev); padding: 14px; border-radius: 12px; }
.vg-frame { position: relative; width: 100%; max-width: 340px; border-radius: 12px; overflow: hidden; background: linear-gradient(135deg, #1b2838, #3d1c56); display: grid; place-items: center; border: 1px solid rgba(255,255,255,0.16); }
.vg-frame.ratio-16-9 { aspect-ratio: 16 / 9; }
.vg-frame.ratio-1-1 { aspect-ratio: 1 / 1; max-width: 240px; }
.vg-frame.ratio-9-16 { aspect-ratio: 9 / 16; max-width: 195px; }
.vg-cover-art { text-align: center; }
.vg-cover-disc { font-size: 32px; }
.vg-cover-title { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; opacity: 0.85; }
.vg-wm { position: absolute; bottom: 9px; right: 10px; background: rgba(0,0,0,0.48); padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.vg-time-pill { position: absolute; top: 9px; left: 9px; background: rgba(62,166,255,0.25); border: 1px solid rgba(62,166,255,0.45); padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; }

.deck-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; margin: 10px 0 8px; background: var(--bg-elev); }
.deck-text { background: var(--accent); }
.deck-voice { background: var(--green); }
.deck-fish { background: var(--violet); }
.deck-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.deck-legend b { color: var(--text); }

.sim-output { margin-top: 10px; padding: 11px; border-radius: 12px; background: var(--bg-elev); border: 1px solid rgba(62,166,255,0.3); }
.progress-wrap { margin-top: 10px; }
.progress-bar { height: 7px; background: var(--bg-elev); border-radius: 99px; overflow: hidden; }
.progress-fill { width: 0%; height: 100%; background: linear-gradient(90deg, var(--accent), var(--green)); transition: width .18s; }

.log-box, .json-box {
  background: #090e15; border: 1px solid var(--border); border-radius: 12px; padding: 11px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11.5px; line-height: 1.5;
  overflow: auto; max-height: 360px; white-space: pre-wrap; word-break: break-word; margin-top: 6px;
}

.muted-text { color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }
.mb-10 { margin-bottom: 10px; }

.toast { position: fixed; top: 64px; right: 16px; z-index: 60; background: var(--bg-card); border: 1px solid var(--accent); color: var(--text); padding: 9px 13px; border-radius: 10px; font-size: 12.5px; font-weight: 600; box-shadow: 0 10px 28px rgba(0,0,0,0.5); }
.modal-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,0.72); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; width: min(620px, 100%); max-height: 82vh; display: flex; flex-direction: column; padding: 16px; }
.modal-body { overflow-y: auto; font-size: 13px; white-space: pre-wrap; word-break: break-word; }

@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: calc(11px + env(safe-area-inset-top)); }
  .bottom-nav { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}
