.tv-assistant {
  --tv-bg: rgba(12, 8, 24, 0.82);
  --tv-panel: rgba(18, 12, 32, 0.92);
  --tv-border: rgba(229, 215, 255, 0.22);
  --tv-text: #fff;
  --tv-muted: rgba(255, 255, 255, 0.68);
  --tv-accent: #8b5cf6;
  --tv-accent-2: #f59e0b;
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 120000;
  font-family: Poppins, Arial, sans-serif;
  color: var(--tv-text);
  transition: opacity 160ms ease, transform 160ms ease;
}

.tv-assistant * {
  box-sizing: border-box;
}

body.dv-tools-collapsed .tv-assistant {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.94);
}

.tv-assistant-button {
  width: 66px;
  height: 66px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  color: #fff;
  background:
    radial-gradient(circle at 34% 26%, rgba(255,255,255,0.72), transparent 18%),
    linear-gradient(135deg, #6d28d9, #9b5cff 54%, #f59e0b);
  box-shadow: 0 18px 44px rgba(56, 26, 112, 0.34), 0 0 0 8px rgba(139, 92, 246, 0.14);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.tv-assistant-button:hover,
.tv-assistant-button:focus-visible {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 22px 54px rgba(56, 26, 112, 0.42), 0 0 0 10px rgba(139, 92, 246, 0.18);
}

.tv-assistant-button svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tv-assistant-panel {
  position: absolute;
  right: 0;
  bottom: 82px;
  width: min(410px, calc(100vw - 28px));
  max-height: min(680px, calc(100dvh - 116px));
  display: grid;
  grid-template-rows: auto auto minmax(150px, 1fr) auto auto;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--tv-border);
  border-radius: 28px;
  background:
    radial-gradient(circle at 12% 0%, rgba(139, 92, 246, 0.36), transparent 32%),
    radial-gradient(circle at 100% 12%, rgba(245, 158, 11, 0.2), transparent 26%),
    var(--tv-panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.44);
  backdrop-filter: blur(18px);
  transform-origin: bottom right;
  animation: tvAssistantIn 0.2s ease both;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-panel {
  position: fixed;
  inset: clamp(18px, 4vw, 56px);
  width: auto;
  max-height: none;
  min-height: min(780px, calc(100dvh - 36px));
  grid-template-rows: auto minmax(300px, 1fr) auto auto auto minmax(92px, 0.22fr);
  align-content: stretch;
  gap: 18px;
  padding: clamp(18px, 2.3vw, 34px);
  border: 2px solid rgba(224, 232, 255, 0.76);
  border-radius: clamp(24px, 3vw, 38px);
  background:
    radial-gradient(circle at 50% 115%, rgba(216, 170, 85, 0.26), transparent 30%),
    radial-gradient(circle at 16% 15%, rgba(139, 92, 246, 0.34), transparent 28%),
    radial-gradient(circle at 80% 22%, rgba(241, 211, 139, 0.18), transparent 32%),
    linear-gradient(145deg, rgba(13, 8, 28, 0.96), rgba(38, 19, 64, 0.94) 48%, rgba(9, 7, 24, 0.98));
  box-shadow:
    0 34px 120px rgba(0, 0, 0, 0.58),
    0 0 0 999px rgba(4, 7, 19, 0.66);
  transform-origin: center;
}

.tv-assistant-panel[hidden] {
  display: none;
}

@keyframes tvAssistantIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.tv-assistant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-head {
  min-height: 72px;
  padding: 0 6px 18px;
  border-bottom: 1px solid rgba(217, 226, 255, 0.14);
}

.tv-assistant-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.tv-assistant-orb {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 999px;
  background:
    radial-gradient(circle at 35% 25%, rgba(255,255,255,0.9), transparent 17%),
    linear-gradient(135deg, #7c3aed, #a78bfa 54%, #f59e0b);
  box-shadow: 0 0 28px rgba(167, 139, 250, 0.52);
}

.tv-assistant[data-state="listening"] .tv-assistant-orb,
.tv-assistant[data-state="speaking"] .tv-assistant-orb {
  animation: tvAssistantPulse 1.1s ease-in-out infinite;
}

@keyframes tvAssistantPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 22px rgba(167, 139, 250, 0.46); }
  50% { transform: scale(1.08); box-shadow: 0 0 38px rgba(245, 158, 11, 0.42); }
}

.tv-assistant-title {
  min-width: 0;
}

.tv-assistant-title strong {
  display: block;
  font-size: 0.94rem;
  font-weight: 950;
  letter-spacing: 0.02em;
}

.tv-assistant-title span {
  display: block;
  color: var(--tv-muted);
  font-size: 0.72rem;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-assistant-icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: #fff;
  background: rgba(255,255,255,0.08);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.tv-assistant-settings {
  margin-left: auto;
}

.tv-assistant-icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tv-assistant-live-stage {
  display: none;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-live-stage {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 20px;
  min-height: 320px;
  padding: clamp(18px, 5vw, 70px) 18px;
  text-align: center;
}

.tv-assistant-live-orb {
  width: clamp(132px, 18vw, 220px);
  aspect-ratio: 1;
  border-radius: 999px;
  background:
    radial-gradient(circle at 26% 22%, rgba(255, 255, 255, 0.58), transparent 11%),
    radial-gradient(circle at 74% 67%, rgba(241, 211, 139, 0.95), transparent 34%),
    radial-gradient(circle at 30% 72%, rgba(0, 138, 120, 0.9), transparent 43%),
    linear-gradient(135deg, #006b5f, #008a78 54%, #d8aa55);
  box-shadow:
    inset 18px 18px 42px rgba(0, 0, 0, 0.34),
    inset -18px -18px 38px rgba(49, 243, 255, 0.14),
    0 0 0 10px rgba(241, 211, 139, 0.12),
    0 34px 90px rgba(0, 138, 120, 0.34);
  animation: tvAssistantLiveOrb 2.8s ease-in-out infinite;
}

.tv-assistant[data-state="listening"] .tv-assistant-live-orb,
.tv-assistant[data-state="speaking"] .tv-assistant-live-orb {
  animation-duration: 1.35s;
}

@keyframes tvAssistantLiveOrb {
  0%, 100% { transform: translateY(0) scale(1); filter: saturate(1); }
  50% { transform: translateY(-7px) scale(1.045); filter: saturate(1.18); }
}

.tv-assistant[data-live-mode="on"] .tv-assistant-live-stage strong {
  color: #f8fbff;
  font-size: clamp(1.55rem, 4vw, 3.7rem);
  font-weight: 950;
  line-height: 1.05;
  text-shadow: 0 18px 54px rgba(0, 0, 0, 0.45);
}

.tv-assistant[data-live-mode="on"] .tv-assistant-live-stage span:not(.tv-assistant-live-orb) {
  max-width: 760px;
  color: rgba(236, 242, 255, 0.86);
  font-size: clamp(1rem, 2vw, 1.7rem);
  font-weight: 850;
  line-height: 1.35;
}

.tv-assistant-live-reply {
  width: min(820px, 100%);
  max-height: 170px;
  overflow: auto;
  margin: 0;
  border: 1px solid rgba(241, 211, 139, 0.22);
  border-radius: 18px;
  padding: 15px 18px;
  color: rgba(255, 248, 231, 0.94);
  background: rgba(255, 255, 255, 0.07);
  font-size: clamp(0.95rem, 1.25vw, 1.12rem);
  font-weight: 700;
  line-height: 1.6;
  text-align: left;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-status {
  justify-self: center;
  min-width: min(560px, 100%);
  border-color: rgba(224, 232, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
}

.tv-assistant-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 18px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.82);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tv-assistant-wave {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.tv-assistant-wave span {
  width: 4px;
  height: 8px;
  border-radius: 999px;
  background: #d8c6ff;
  opacity: 0.45;
}

.tv-assistant[data-state="listening"] .tv-assistant-wave span,
.tv-assistant[data-state="speaking"] .tv-assistant-wave span {
  animation: tvAssistantWave 0.76s ease-in-out infinite;
}

.tv-assistant-wave span:nth-child(2) { animation-delay: 0.08s; }
.tv-assistant-wave span:nth-child(3) { animation-delay: 0.16s; }
.tv-assistant-wave span:nth-child(4) { animation-delay: 0.24s; }
.tv-assistant-wave span:nth-child(5) { animation-delay: 0.32s; }

@keyframes tvAssistantWave {
  0%, 100% { height: 7px; opacity: 0.42; }
  50% { height: 18px; opacity: 1; }
}

.tv-assistant-log {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-log {
  justify-self: center;
  width: min(760px, 100%);
  max-height: 130px;
  padding: 0 8px;
  mask-image: linear-gradient(to bottom, transparent, #000 18%, #000 82%, transparent);
}

.tv-assistant[data-live-mode="on"] .tv-assistant-message {
  justify-self: center;
  max-width: 100%;
  border-color: rgba(224, 232, 255, 0.13);
  background: rgba(255, 255, 255, 0.055);
  text-align: center;
}

.tv-assistant-message {
  max-width: 92%;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 18px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.5;
}

.tv-assistant-message.is-user {
  justify-self: end;
  background: rgba(139, 92, 246, 0.22);
}

.tv-assistant-message.is-error {
  border-color: rgba(255, 126, 126, 0.4);
  color: #ffd6d6;
  background: rgba(120, 24, 34, 0.32);
}

.tv-assistant-controls {
  display: grid;
  grid-template-columns: 1fr 44px 44px;
  gap: 8px;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-controls {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(217, 226, 255, 0.34);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 24px 64px rgba(0, 0, 0, 0.32);
}

.tv-assistant-mic {
  min-height: 46px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #7c3aed, #9f67ff);
  box-shadow: 0 12px 26px rgba(124, 58, 237, 0.28);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 950;
  cursor: pointer;
}

.tv-assistant-mic svg {
  display: none;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-mic,
.tv-assistant[data-live-mode="on"] .tv-assistant-controls .tv-assistant-icon-button {
  width: 76px;
  height: 76px;
  min-height: 76px;
  border: 0;
  border-radius: 999px;
  padding: 0;
  color: #fff;
  background: rgba(111, 135, 202, 0.34);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.22);
}

.tv-assistant[data-live-mode="on"] .tv-assistant-mic {
  display: grid;
  place-items: center;
  min-width: 76px;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-mic svg {
  display: block;
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-mic span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.tv-assistant[data-live-mode="on"] .tv-assistant-mic.is-recording {
  background: linear-gradient(135deg, rgba(39, 90, 255, 0.92), rgba(19, 226, 214, 0.86));
}

.tv-assistant-mic.is-recording {
  background: linear-gradient(135deg, #ef4444, #f97316);
}

.tv-assistant-live-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--tv-muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.tv-assistant-live-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tv-assistant-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.tv-assistant[data-live-mode="on"] .tv-assistant-live-row,
.tv-assistant[data-live-mode="on"] .tv-assistant-input-row {
  justify-self: center;
  width: min(760px, 100%);
}

.tv-assistant-input-row input {
  min-height: 42px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  padding: 0 14px;
  color: #fff;
  background: rgba(255,255,255,0.08);
  font: inherit;
  font-size: 0.8rem;
  outline: none;
}

.tv-assistant-input-row input::placeholder {
  color: rgba(255,255,255,0.48);
}

.tv-assistant-input-row button {
  min-width: 72px;
  border: 0;
  border-radius: 999px;
  color: #1a1028;
  background: #fff;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 950;
  cursor: pointer;
}

@media (max-width: 640px) {
  .tv-assistant {
    right: 12px;
    bottom: max(86px, calc(env(safe-area-inset-bottom) + 72px));
  }

  .tv-assistant-panel {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: max(92px, calc(env(safe-area-inset-bottom) + 78px));
    width: auto;
    max-height: min(72dvh, 640px);
    border-radius: 24px 24px 18px 18px;
    transform-origin: bottom center;
  }

  .tv-assistant[data-live-mode="on"] .tv-assistant-panel {
    inset: 10px;
    min-height: calc(100dvh - 20px);
    max-height: none;
    border-radius: 24px;
    padding: 16px;
    gap: 12px;
  }

  .tv-assistant[data-live-mode="on"] .tv-assistant-head {
    min-height: 58px;
    padding-bottom: 10px;
  }

  .tv-assistant[data-live-mode="on"] .tv-assistant-title span {
    display: none;
  }

  .tv-assistant[data-live-mode="on"] .tv-assistant-live-stage {
    min-height: 270px;
    padding: 16px 4px;
  }

  .tv-assistant[data-live-mode="on"] .tv-assistant-mic,
  .tv-assistant[data-live-mode="on"] .tv-assistant-controls .tv-assistant-icon-button {
    width: 62px;
    height: 62px;
    min-height: 62px;
  }

  .tv-assistant-button {
    width: 52px;
    height: 52px;
    box-shadow: 0 12px 30px rgba(56, 26, 112, 0.28), 0 0 0 7px rgba(139, 92, 246, 0.12);
  }

  .tv-assistant-button svg {
    width: 25px;
    height: 25px;
  }
}
