/* ==============================================
   Text-to-Speech Player — Independent Writer
   ============================================== */

.iw-tts-player {
  background: var(--iw-white);
  border: 1px solid var(--iw-border);
  border-radius: var(--iw-radius-sm);
  padding: 14px 18px;
  margin-bottom: 28px;
  box-shadow: var(--iw-shadow-sm);
}

/* ── Main bar ── */
.iw-tts-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* ── Headphone label ── */
.iw-tts-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--iw-font);
  font-size: var(--iw-fs-sm);
  font-weight: 600;
  color: var(--iw-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Controls group ── */
.iw-tts-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Generic control button ── */
.iw-tts-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--iw-gray-700);
  padding: 6px 8px;
  border-radius: var(--iw-radius-xs);
  font-family: var(--iw-font);
  font-size: var(--iw-fs-xs);
  font-weight: 700;
  line-height: 1;
  transition: background var(--iw-t), color var(--iw-t);
}

.iw-tts-ctrl:hover:not(:disabled) {
  background: var(--iw-gray-100);
  color: var(--iw-navy);
}

.iw-tts-ctrl:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.iw-tts-ctrl:focus-visible {
  outline: 2px solid var(--iw-navy);
  outline-offset: 2px;
}

/* Skip buttons: icon + number side-by-side */
.iw-tts-ctrl--skip {
  flex-direction: row;
  gap: 4px;
}

.iw-tts-skip-num {
  font-size: var(--iw-fs-xs);
  font-weight: 700;
  color: inherit;
}

/* ── Play / Pause button ── */
.iw-tts-ctrl--play {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  justify-content: center;
  background: var(--iw-navy);
  color: var(--iw-white);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(30, 27, 75, 0.28);
  transition: background var(--iw-t), transform var(--iw-t), box-shadow var(--iw-t);
}

.iw-tts-ctrl--play:hover:not(:disabled) {
  background: #2d2a6a;
  color: var(--iw-white);
  transform: scale(1.06);
  box-shadow: 0 4px 14px rgba(30, 27, 75, 0.36);
}

.iw-tts-ctrl--play:active {
  transform: scale(0.97);
}

/* ── Scrubber (progress bar + time) ── */
.iw-tts-scrubber {
  flex: 1;
  min-width: 100px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* Track: the clickable/draggable area */
.iw-tts-track {
  position: relative;
  height: 22px;
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.iw-tts-track-bg {
  width: 100%;
  height: 4px;
  background: var(--iw-gray-200);
  border-radius: 2px;
  overflow: hidden;
}

.iw-tts-track-fill {
  height: 100%;
  width: 0%;
  background: var(--iw-navy);
  border-radius: 2px;
  transition: width 0.2s linear;
}

/* Suppress transition while dragging so it feels instant */
.iw-tts-track.is-dragging .iw-tts-track-fill {
  transition: none;
}

/* Thumb dot */
.iw-tts-track-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  background: var(--iw-navy);
  border: 2px solid var(--iw-white);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  transition: left 0.2s linear;
  pointer-events: none;
}

.iw-tts-track.is-dragging .iw-tts-track-thumb {
  transition: none;
}

.iw-tts-track:focus-visible {
  outline: 2px solid var(--iw-navy);
  outline-offset: 3px;
  border-radius: 3px;
}

/* Time display */
.iw-tts-time {
  display: flex;
  justify-content: space-between;
  font-family: var(--iw-font);
  font-size: var(--iw-fs-xs);
  font-variant-numeric: tabular-nums;
  color: var(--iw-muted);
  line-height: 1;
}

/* ── Speed selector ── */
.iw-tts-speed {
  flex-shrink: 0;
}

.iw-tts-speed select {
  font-family: var(--iw-font);
  font-size: var(--iw-fs-xs);
  font-weight: 600;
  color: var(--iw-gray-700);
  background: var(--iw-gray-100);
  border: 1px solid var(--iw-border);
  border-radius: var(--iw-radius-xs);
  padding: 5px 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  min-width: 52px;
  text-align: center;
  transition: border-color var(--iw-t);
}

.iw-tts-speed select:hover {
  border-color: var(--iw-gray-400);
}

.iw-tts-speed select:focus-visible {
  outline: 2px solid var(--iw-navy);
  outline-offset: 2px;
}

/* ── Error / info notice ── */
.iw-tts-notice {
  font-family: var(--iw-font);
  font-size: var(--iw-fs-xs);
  color: #c53030;
  margin-top: 8px;
  line-height: 1.5;
}

/* ── Accessibility helper ── */
.iw-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 640px) {
  .iw-tts-bar {
    gap: 12px;
  }

  /* Hide text label on very small screens, keep icon */
  .iw-tts-label span {
    display: none;
  }

  .iw-tts-ctrl--play {
    width: 40px;
    height: 40px;
  }

  /* Speed picker moves below on smallest screens */
  .iw-tts-speed {
    order: 10;
  }
}

@media (max-width: 420px) {
  .iw-tts-player {
    padding: 12px 14px;
  }

  .iw-tts-scrubber {
    min-width: 80px;
  }
}
