.bg-speech-tool {
  --speech-navy: #102044;
  --speech-blue: #3568e8;
  --speech-mint: #0d9f83;
  --speech-paper: #ffffff;
  --speech-line: #dfe5ef;
  --speech-muted: #526078;
  position: relative;
  z-index: 82;
  font-family: inherit;
}

.bg-speech-tool [hidden] {
  display: none !important;
}

.bg-speech-launcher {
  position: fixed;
  z-index: 82;
  right: 24px;
  bottom: 24px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 50px;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 999px;
  padding: 10px 17px 10px 11px;
  background: var(--speech-navy);
  color: #fff;
  box-shadow: 0 14px 34px rgba(16, 32, 68, .28);
  font: inherit;
  font-size: .9rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform .2s ease, background-color .2s ease, box-shadow .2s ease;
}

.bg-speech-launcher:hover {
  transform: translateY(-2px);
  background: #182d59;
  box-shadow: 0 18px 38px rgba(16, 32, 68, .34);
}

.bg-speech-launcher-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fff;
  color: var(--speech-navy);
  font-size: 1rem;
}

.bg-speech-launcher.is-speaking .bg-speech-launcher-icon {
  animation: bg-speech-pulse 1.35s ease-in-out infinite;
}

.bg-speech-launcher.is-paused {
  background: #6a5428;
}

.bg-speech-panel {
  position: fixed;
  z-index: 83;
  right: 24px;
  bottom: 88px;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 112px);
  overflow: auto;
  border: 1px solid var(--speech-line);
  border-radius: 22px;
  padding: 20px;
  background: var(--speech-paper);
  color: #14213d;
  box-shadow: 0 24px 60px rgba(16, 32, 68, .22);
  overscroll-behavior: contain;
}

.bg-speech-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.bg-speech-eyebrow {
  margin: 0 0 4px;
  color: var(--speech-blue);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.bg-speech-header h2 {
  margin: 0;
  color: var(--speech-navy);
  font-size: 1.28rem;
  line-height: 1.2;
}

.bg-speech-close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #edf1f7;
  color: var(--speech-navy);
  font: inherit;
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
}

.bg-speech-intro {
  margin: 13px 0 16px;
  color: var(--speech-muted);
  font-size: .88rem;
  line-height: 1.5;
}

.bg-speech-field {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.bg-speech-field > span,
.bg-speech-rate-heading label {
  color: var(--speech-navy);
  font-size: .8rem;
  font-weight: 850;
}

.bg-speech-field textarea,
.bg-speech-field select {
  width: 100%;
  border: 1px solid #cfd8e8;
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff;
  color: #14213d;
  font: inherit;
  font-size: .9rem;
}

.bg-speech-field textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.5;
}

.bg-speech-text-meta,
.bg-speech-rate-heading,
.bg-speech-rate-scale {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bg-speech-text-meta {
  margin-top: 5px;
  color: #718096;
  font-size: .7rem;
}

.bg-speech-rate-block {
  margin-top: 16px;
  border: 1px solid #e3e8f1;
  border-radius: 14px;
  padding: 12px 13px 10px;
  background: #f7f9fd;
}

.bg-speech-rate-heading output {
  border-radius: 999px;
  padding: 3px 9px;
  background: #eaf0ff;
  color: var(--speech-blue);
  font-size: .78rem;
  font-weight: 900;
}

.bg-speech-rate-block input[type="range"] {
  width: 100%;
  margin: 12px 0 5px;
  accent-color: var(--speech-blue);
  cursor: pointer;
}

.bg-speech-rate-scale {
  color: #718096;
  font-size: .66rem;
}

.bg-speech-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.bg-speech-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  border: 1px solid #d4dcea;
  border-radius: 11px;
  padding: 8px 10px;
  background: #fff;
  color: var(--speech-navy);
  font: inherit;
  font-size: .78rem;
  font-weight: 850;
  cursor: pointer;
}

.bg-speech-play {
  border-color: var(--speech-blue);
  background: var(--speech-blue);
  color: #fff;
}

.bg-speech-action:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.bg-speech-status {
  margin: 14px 0 0;
  border-left: 3px solid #9aabc5;
  border-radius: 0 8px 8px 0;
  padding: 8px 10px;
  background: #f5f7fb;
  color: #42516a;
  font-size: .76rem;
  line-height: 1.45;
}

.bg-speech-status[data-tone="success"] {
  border-left-color: var(--speech-mint);
  background: #e9f8f4;
  color: #086c5b;
}

.bg-speech-status[data-tone="error"] {
  border-left-color: #ba3e4a;
  background: #fff0f1;
  color: #8f2934;
}

.bg-speech-note {
  margin: 9px 1px 0;
  color: #718096;
  font-size: .66rem;
  line-height: 1.4;
}

.bg-speech-launcher:focus-visible,
.bg-speech-close:focus-visible,
.bg-speech-action:focus-visible,
.bg-speech-field textarea:focus-visible,
.bg-speech-field select:focus-visible,
.bg-speech-rate-block input:focus-visible {
  outline: 3px solid #f2ad3e;
  outline-offset: 2px;
}

@keyframes bg-speech-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .28); }
  50% { box-shadow: 0 0 0 7px rgba(255, 255, 255, 0); }
}

@media (max-width: 820px) {
  .bg-speech-launcher {
    right: 12px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    min-height: 45px;
    padding: 8px 13px 8px 8px;
    font-size: .78rem;
  }

  .bg-speech-launcher-icon {
    width: 29px;
    height: 29px;
  }

  .bg-speech-panel {
    right: 12px;
    bottom: calc(139px + env(safe-area-inset-bottom));
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 158px - env(safe-area-inset-bottom));
    border-radius: 18px;
    padding: 17px;
  }
}

@media (max-width: 370px) {
  .bg-speech-launcher > span:last-child {
    display: none;
  }

  .bg-speech-launcher {
    padding-right: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bg-speech-launcher {
    transition: none;
  }

  .bg-speech-launcher.is-speaking .bg-speech-launcher-icon {
    animation: none;
  }
}

@media print {
  .bg-speech-tool {
    display: none !important;
  }
}
