:root {
  --tg-bg: #17212b;
  --tg-sidebar: #0e1621;
  --tg-header: #213040;
  --tg-blue: #5288c1;
  --tg-green: #4fae4e;
  --tg-red: #e53935;
  --tg-text: #f5f5f5;
  --tg-subtext: #708a9f;
  --tg-border: rgba(255, 255, 255, 0.06);
  --tg-hover: rgba(255, 255, 255, 0.05);
  --tg-active: rgba(82, 136, 193, 0.15);
}

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

body {
  background-color: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", Helvetica, Arial, sans-serif;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  user-select: none;
}

.hidden {
  display: none !important;
}

/* ═══════════════ COMMON ATOMS ═══════════════ */
.btn-icon {
  background: none;
  border: none;
  color: var(--tg-subtext);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--tg-hover);
  color: var(--tg-text);
}

.avatar-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tg-btn-primary {
  width: 100%;
  height: 48px;
  border-radius: 8px;
  border: none;
  background: var(--tg-blue);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
}

.tg-btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.tg-btn-text {
  background: none;
  border: none;
  color: var(--tg-blue);
  font-size: 14px;
  cursor: pointer;
  margin-top: 12px;
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tg-btn-text:hover {
  text-decoration: underline;
}

.tg-input {
  width: 100%;
  height: 48px;
  background: #242f3d;
  border: 1px solid var(--tg-border);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--tg-text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.tg-input:focus {
  border-color: var(--tg-blue);
}

.tg-error {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(229, 57, 53, 0.15);
  color: #ff7675;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--tg-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--tg-subtext);
  font-size: 14px;
}

/* ═══════════════ LOGIN SCREEN ═══════════════ */
.login-wrapper {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tg-bg);
  z-index: 2000;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: #242f3d;
  border-radius: 14px;
  padding: 32px 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.tg-plane-icon {
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--tg-subtext);
  margin-bottom: 24px;
  line-height: 1.4;
}

.form-group {
  text-align: left;
  margin-bottom: 16px;
}

.input-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--tg-subtext);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-hint {
  font-size: 12px;
  color: var(--tg-subtext);
  margin-top: 6px;
}

.otp-boxes {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 0;
}

.otp-digit {
  width: 48px;
  height: 52px;
  background: var(--tg-bg);
  border: 1.5px solid var(--tg-border);
  border-radius: 8px;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  color: #fff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.otp-digit:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 2px rgba(82, 136, 193, 0.25);
}

/* ═══════════════ MAIN APP LAYOUT ═══════════════ */
.app-layout {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ═══════════════ SIDEBAR ═══════════════ */
.sidebar {
  width: 320px;
  height: 100%;
  background: var(--tg-sidebar);
  border-right: 1px solid var(--tg-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
}

.sidebar-header {
  height: 56px;
  padding: 0 16px;
  background: var(--tg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--tg-border);
  flex-shrink: 0;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.user-meta {
  overflow: hidden;
}

.user-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-status-text {
  font-size: 12px;
  color: var(--tg-subtext);
}

.search-wrapper {
  padding: 10px 14px;
  border-bottom: 1px solid var(--tg-border);
  flex-shrink: 0;
}

.search-box {
  display: flex;
  align-items: center;
  background: #242f3d;
  border-radius: 20px;
  padding: 7px 12px;
  gap: 8px;
}

.search-box svg {
  color: var(--tg-subtext);
  flex-shrink: 0;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--tg-text);
  font-size: 14px;
  width: 100%;
}

.search-box input::placeholder {
  color: var(--tg-subtext);
}

.dialogs-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.dialog-item {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.dialog-item:hover {
  background: var(--tg-hover);
}

.dialog-item.active {
  background: var(--tg-active);
}

.dialog-info {
  flex: 1;
  min-width: 0;
}

.dialog-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.dialog-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dialog-type-tag {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--tg-subtext);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.dialog-subtitle {
  font-size: 13px;
  color: var(--tg-subtext);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 30px;
  color: var(--tg-subtext);
  font-size: 14px;
}

/* ═══════════════ VC ROOM (RIGHT PANEL) ═══════════════ */
.vc-room {
  flex: 1;
  height: 100%;
  background: var(--tg-bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.welcome-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.welcome-box {
  max-width: 380px;
}

.welcome-icon {
  margin-bottom: 20px;
  color: var(--tg-blue);
}

.welcome-box h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.welcome-box p {
  font-size: 14px;
  color: var(--tg-subtext);
  line-height: 1.5;
}

/* ─── VC VIEW ─── */
.vc-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.vc-header {
  height: 56px;
  background: var(--tg-header);
  border-bottom: 1px solid var(--tg-border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 5;
}

.vc-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.vc-header-info {
  overflow: hidden;
}

.vc-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vc-group-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(79, 174, 78, 0.2);
  color: var(--tg-green);
  border: 1px solid rgba(79, 174, 78, 0.4);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.live-dot {
  width: 6px;
  height: 6px;
  background: var(--tg-green);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--tg-green);
  animation: pulseDot 1.2s infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.vc-subtext {
  font-size: 12px;
  color: var(--tg-subtext);
}

.mobile-only {
  display: none;
}

/* ─── PRE-JOIN VIEW ─── */
.pre-join-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.pre-join-card {
  text-align: center;
  max-width: 320px;
}

.vc-stage-preview {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}

.preview-avatar-pulse {
  position: relative;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(82, 136, 193, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-avatar {
  font-size: 40px;
}

.pre-join-card h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.pre-join-card p {
  font-size: 13px;
  color: var(--tg-subtext);
  line-height: 1.4;
  margin-bottom: 24px;
}

.tg-btn-join {
  width: 100%;
  min-height: 48px;
  border-radius: 24px;
  border: none;
  background: var(--tg-blue);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(82, 136, 193, 0.4);
  transition: transform 0.15s, opacity 0.15s;
}

.tg-btn-join:active {
  transform: scale(0.96);
}

/* ─── LIVE VC STAGE ─── */
.vc-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px 20px 110px 20px;
  overflow-y: auto;
  position: relative;
}

.participants-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 24px;
  flex: 1;
  margin-bottom: 20px;
}

.participant-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 96px;
}

.participant-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: #fff;
  font-size: 28px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  border: 3px solid transparent;
  transition: all 0.25s ease;
  user-select: none;
}

.participant-circle.speaking {
  animation: tgPulse 1.4s infinite;
  border-color: var(--tg-green);
}

@keyframes tgPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(79, 174, 78, 0.8);
    border-color: var(--tg-green);
  }
  65% {
    box-shadow: 0 0 0 14px rgba(79, 174, 78, 0);
    border-color: var(--tg-green);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(79, 174, 78, 0);
    border-color: var(--tg-green);
  }
}

.badge-mute {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--tg-red);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--tg-bg);
}

.participant-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--tg-text);
  text-align: center;
  max-width: 96px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* My own avatar at bottom center */
.my-avatar-container {
  display: flex;
  justify-content: center;
  margin-top: auto;
  padding-top: 10px;
}

.my-avatar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.my-circle {
  border: 3px solid rgba(82, 136, 193, 0.4);
}

.my-name-tag {
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-blue);
  background: rgba(82, 136, 193, 0.12);
  padding: 2px 10px;
  border-radius: 10px;
}

/* ─── CONTROLS BAR AT BOTTOM (70px circle buttons) ─── */
.vc-controls-bar {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 28px;
  z-index: 20;
  pointer-events: none;
}

.vc-circle-btn {
  pointer-events: auto;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #fff;
  transition: transform 0.15s, background-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.vc-circle-btn:active {
  transform: scale(0.92);
}

.circle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
}

.circle-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.btn-mute {
  background: var(--tg-blue);
}

.btn-mute.is-muted {
  background: var(--tg-red);
}

.btn-settings {
  background: #24303f;
}

.btn-settings:hover {
  background: #2d3b4d;
}

.btn-leave {
  background: #24303f;
}

.btn-leave:hover {
  background: var(--tg-red);
}

/* ═══════════════ SETTINGS DRAWER ═══════════════ */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
  z-index: 900;
  transition: opacity 0.3s;
}

.settings-drawer {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 480px;
  max-width: 100vw;
  max-height: 85vh;
  background: #1c2733;
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--tg-border);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-drawer.open {
  transform: translateX(-50%) translateY(0);
}

.drawer-drag-handle {
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
  margin: 10px auto 4px auto;
}

.drawer-header {
  padding: 8px 18px 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--tg-border);
  flex-shrink: 0;
}

.drawer-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.drawer-title {
  font-size: 18px;
  font-weight: 600;
}

.drawer-badge {
  font-size: 10px;
  text-transform: uppercase;
  background: rgba(82, 136, 193, 0.2);
  color: var(--tg-blue);
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 600;
}

.drawer-body {
  padding: 16px 18px 24px 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-subtext);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ─── SINGER PRESETS ─── */
.preset-buttons-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.btn-preset {
  min-height: 56px;
  background: #242f3d;
  border: 1.5px solid var(--tg-border);
  border-radius: 10px;
  color: var(--tg-text);
  padding: 6px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.15s ease;
}

.btn-preset:hover {
  background: #2b394a;
}

.btn-preset.active {
  background: rgba(82, 136, 193, 0.18);
  border-color: var(--tg-blue);
}

.preset-icon {
  font-size: 16px;
}

.preset-name {
  font-size: 12px;
  font-weight: 600;
}

.preset-sub {
  font-size: 9px;
  color: var(--tg-subtext);
  white-space: nowrap;
}

/* ─── VU METER ─── */
.meter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.meter-peak {
  font-size: 11px;
  color: var(--tg-subtext);
  font-family: monospace;
}

.vu-meter-track {
  height: 10px;
  background: #111822;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--tg-border);
}

.vu-meter-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #4fae4e 60%, #fdcb6e 82%, #e53935 96%);
  transition: width 0.05s ease-out;
}

/* ─── FX SLIDERS ─── */
.sliders-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #242f3d;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--tg-border);
}

.slider-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 500;
}

.slider-val {
  color: var(--tg-blue);
  font-weight: 600;
  font-size: 12px;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: #17212b;
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--tg-blue);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.15);
}

/* ─── KARAOKE PLAYER ─── */
.karaoke-card {
  background: #242f3d;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--tg-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.karaoke-upload-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tg-btn-secondary {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  background: #17212b;
  border: 1px solid var(--tg-border);
  color: var(--tg-text);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.tg-btn-secondary:hover {
  background: #202b38;
}

.tg-select {
  flex: 1;
  min-height: 44px;
  background: #17212b;
  border: 1px solid var(--tg-border);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--tg-text);
  font-size: 13px;
  outline: none;
}

.player-controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-play-pause {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--tg-blue);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.btn-play-pause:active {
  transform: scale(0.92);
}

.player-progress-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.player-time-display {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--tg-subtext);
}

/* ─── LYRICS TEXTAREA ─── */
.lyrics-textarea {
  width: 100%;
  background: #242f3d;
  border: 1px solid var(--tg-border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--tg-text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}

.lyrics-textarea:focus {
  border-color: var(--tg-blue);
}

/* ═══════════════ RESPONSIVE BREAKPOINTS ═══════════════ */
@media (max-width: 767px) {
  .sidebar {
    width: 100%;
    display: flex;
  }

  .vc-room {
    display: none;
    width: 100%;
  }

  body.mobile-vc-active .sidebar {
    display: none !important;
  }

  body.mobile-vc-active .vc-room {
    display: flex !important;
  }

  .mobile-only {
    display: flex !important;
  }

  .settings-drawer {
    left: 0;
    right: 0;
    width: 100%;
    transform: translateY(100%);
  }

  .settings-drawer.open {
    transform: translateY(0);
  }

  .preset-buttons-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .sidebar {
    display: flex !important;
  }

  .vc-room {
    display: flex !important;
  }

  .mobile-only {
    display: none !important;
  }
}
