/* Speak widget — pill button with optional settings popover and chunk highlight */

.speak-widget {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  position: relative;
  vertical-align: middle;
}

.speak-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.4em 0.85em;
  font-family: inherit;
  font-size: 0.875em;
  font-weight: 500;
  line-height: 1.2;
  color: #4f46e5;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.speak-button:hover {
  background: #e0e7ff;
  border-color: #a5b4fc;
}

.speak-button:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

.speak-button.loading {
  background: #fef9c3;
  border-color: #facc15;
  color: #713f12;
  cursor: wait;
}

.speak-button.speaking {
  background: #d1fae5;
  border-color: #6ee7b7;
  color: #065f46;
}

.speak-button[data-kind="error"] {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.speak-icon {
  font-size: 0.85em;
  line-height: 1;
}

.speak-button.speaking .speak-icon::before {
  content: "■";
}
.speak-button:not(.speaking) .speak-icon::before {
  content: "▶";
}

.speak-status {
  font-size: 0.75em;
  font-weight: 400;
  opacity: 0.75;
  margin-left: 0.25em;
}

.speak-status:empty {
  display: none;
}

/* Gear toggle for settings */
.speak-settings-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85em;
  height: 1.85em;
  padding: 0;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  color: #4f46e5;
  border-radius: 50%;
  font-size: 1em;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s ease;
}

.speak-settings-toggle:hover {
  background: #e0e7ff;
  border-color: #a5b4fc;
}

.speak-settings-toggle:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

/* Settings popover */
.speak-controls {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 100;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.85em 1em;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.65em;
  min-width: 280px;
  font-size: 0.875em;
}

.speak-controls[hidden] {
  display: none;
}

.speak-control {
  display: flex;
  align-items: center;
  gap: 0.6em;
}

.speak-control > span:first-child {
  font-weight: 600;
  color: #475569;
  min-width: 3.5em;
  text-transform: uppercase;
  font-size: 0.75em;
  letter-spacing: 0.05em;
}

.speak-voice-select {
  flex: 1;
  padding: 0.35em 0.5em;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-family: inherit;
  font-size: 1em;
  background: white;
}

.speak-rate-slider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #cbd5e1;
  border-radius: 2px;
  outline: none;
}

.speak-rate-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #6366f1;
  cursor: pointer;
}

.speak-rate-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #6366f1;
  cursor: pointer;
  border: none;
}

.speak-rate-value {
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 0.85em;
  color: #475569;
  min-width: 3em;
  text-align: right;
}

/* Currently-being-read block highlight */
.speak-current {
  background-color: #fef9c3;
  border-radius: 4px;
  outline: 2px solid #facc15;
  outline-offset: 2px;
  transition: background-color 0.2s ease, outline-color 0.2s ease;
}

/* Wrapper for the auto-injected button at top of post */
.post-tts {
  margin: 0.5rem 0 1.5rem;
}
