/* ============================================================
   Text to Speech page (page-text-to-speech.php)
   Read along layout with the audio controls under the text.
   Light theme by default; dark theme follows the site's .dark class.
   ============================================================ */

.tts2 {
  --t-bg: transparent;
  --t-surface: #f7f8fc;
  --t-card: #ffffff;
  --t-border: #dfe4ee;
  --t-ctl: #8792a8;
  --t-text: #1b2a44;
  --t-head: #1e3a5f;
  --t-muted: #4a5872;
  --t-accent: #e11d48;
  --t-accent-ink: #ffffff;
  --t-bar-off: #c3cbdb;
  --t-cur-bg: #fff1f3;
  --t-cur-bd: #be123c;
  --t-on-bg: #1e3a5f;
  --t-on-fg: #ffffff;
  --t-focus: #be123c;

  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 48px;
  box-sizing: border-box;
  color: var(--t-text);
  font-family: Arial, Helvetica, sans-serif;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dark .tts2 {
  --t-surface: #1b2140;
  --t-card: #161c36;
  --t-border: #2a3250;
  --t-ctl: #5a6590;
  --t-text: #e8ecf5;
  --t-head: #ffffff;
  --t-muted: #a3acc2;
  --t-bar-off: #4a5580;
  --t-cur-bg: #3a2038;
  --t-cur-bd: #fb7185;
  --t-on-bg: #e8ecf5;
  --t-on-fg: #12172b;
  --t-focus: #fda4af;
}
.tts2 *, .tts2 *::before, .tts2 *::after { box-sizing: border-box; }
.tts2 button { font-family: inherit; letter-spacing: normal; }
/* The site stylesheet spaces out headings and paragraphs; inside the tool
   every block keeps the spacing set here. */
.tts2-card h2, .tts2-card p, .tts2-card label, .tts2-card span { margin: 0; padding: 0; letter-spacing: normal; text-align: left; }
.tts2 button:focus-visible,
.tts2 textarea:focus-visible,
.tts2 input:focus-visible { outline: 2px solid var(--t-focus); outline-offset: 2px; }

/* ---------- Title row and language ---------- */
.tts2-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }.tts2-lang { display: flex; align-items: center; gap: 10px; }
.tts2-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--t-muted); }
.tts2 .tts-lang-select { flex: none; width: 280px !important; max-width: 100%; margin: 0 !important; }
.tts2 .tts-lang-select .cld-trigger { min-height: 44px; }

/* ---------- Layout ---------- */
.tts2-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "text read" "topad topad" "audio audio";
  gap: 20px;
}
.tts2-text  { grid-area: text; }
.tts2-read  { grid-area: read; }
.tts2-audio { grid-area: audio; }

.tts2-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--t-border);
  border-radius: 14px;
  background: var(--t-card);
}
.tts2-text, .tts2-audio { background: var(--t-surface); }
.tts2-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tts2-card-title { margin: 0; font-size: 16px; font-weight: 700; color: var(--t-head); }
.tts2-muted { font-size: 14px; color: var(--t-muted); }
.tts2-hint { margin: 0; }

/* ---------- Text box ---------- */
/* One bordered box holds the text and, after Vocalise, the ad under it. */
.tts2-inputbox {
  display: flex;
  flex-direction: column;
  min-height: 340px;
  background: var(--t-card);
  border: 1px solid var(--t-ctl);
  border-radius: 10px;
  overflow: hidden;
}
.tts2-inputbox:focus-within { outline: 2px solid var(--t-focus); outline-offset: 2px; }
.tts2-textarea {
  flex: 1 1 auto;
  width: 100%;
  min-height: 140px;
  resize: none;
  padding: 16px;
  background: transparent;
  color: var(--t-text);
  border: 0;
  font-family: Roboto, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.65;
}
.tts2 .tts2-textarea:focus-visible { outline: none; }
.tts2-textarea::placeholder { color: var(--t-muted); opacity: 1; }
/* Paste, Clear, Translate and Vocalise: four equal buttons across the card. */
.tts2-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }

/* ---------- Buttons ---------- */
.tts2-btn {
  min-height: 44px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--t-card);
  color: var(--t-head);
  border: 1px solid var(--t-ctl);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.tts2-btn-primary { padding: 0 20px; border: 0; background: var(--t-accent); color: var(--t-accent-ink); font-size: 15px; font-weight: 700; }
.tts2-btn-outline { min-height: 48px; padding: 0 20px; background: transparent; border: 2px solid var(--t-head); font-size: 15px; font-weight: 700; }
.tts2-btn[disabled] { opacity: .55; cursor: default; }
/* Pressed feedback: the button changes color while it is being clicked,
   and for a moment afterwards (the script adds .is-pressed). */
.tts2-actions .tts2-btn { transition: background-color .12s ease, color .12s ease, border-color .12s ease; }
.tts2-actions .tts2-btn:hover { border-color: var(--t-head); }
.tts2-actions .tts2-btn:active,
.tts2-actions .tts2-btn.is-pressed { background: var(--t-on-bg); color: var(--t-on-fg); border-color: var(--t-on-bg); }
.tts2-actions .tts2-btn-primary:hover { background: #be123c; }
.tts2-actions .tts2-btn-primary:active,
.tts2-actions .tts2-btn-primary.is-pressed { background: #881337; color: #ffffff; }
.tts2-toggle[aria-pressed="true"] { background: var(--t-on-bg); color: var(--t-on-fg); border-color: var(--t-on-bg); }

/* ---------- Audio panel ---------- */
.tts2-audio { gap: 16px; }
.tts2-row { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 20px; }
.tts2-row-settings { align-items: flex-end; gap: 14px 24px; padding-top: 16px; border-top: 1px solid var(--t-border); }
.tts2-transport { display: flex; align-items: center; gap: 8px; }
.tts2-round {
  width: 44px; height: 44px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--t-head);
  border: 1px solid var(--t-ctl); border-radius: 50%; cursor: pointer;
}
.tts2-round[disabled] { opacity: .4; cursor: default; }
.tts2-play {
  width: 64px; height: 64px; padding: 0; flex: none;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: var(--t-accent); color: var(--t-accent-ink); cursor: pointer;
}
.tts2-play .tts2-i-pause { display: none; }
.tts2.is-playing .tts2-play .tts2-i-play { display: none; }
.tts2.is-playing .tts2-play .tts2-i-pause { display: block; }
.tts2.is-loading .tts2-play { opacity: .7; }

.tts2-progress { flex: 1 1 280px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.tts2-wave { height: 56px; display: flex; align-items: center; gap: 3px; overflow: hidden; }
.tts2-wave span { flex: 1 1 0; min-width: 2px; border-radius: 2px; background: var(--t-bar-off); }
.tts2-wave span.is-done { background: var(--t-accent); }
.tts2-times { display: flex; justify-content: space-between; font-size: 13px; color: var(--t-muted); font-variant-numeric: tabular-nums; }

.tts2-pitch { flex: 1 1 160px; max-width: 260px; display: flex; flex-direction: column; gap: 6px; }
.tts2-pitch input { width: 100%; min-height: 28px; accent-color: var(--t-accent); }
.tts2-pitch[hidden] { display: none; }

.tts2-group { display: flex; flex-direction: column; gap: 6px; }
.tts2-group-voice { flex: 1 1 420px; min-width: 0; }/* Voice buttons: one picture per voice, grouped by gender. */
.tts2-voices { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 32px; }
.tts2-voice-group { display: flex; flex-direction: column; gap: 4px; }
.tts2-card .tts2-voice-gender { font-size: 14px; font-weight: 700; color: var(--t-head); }
.tts2-voice-tiles { display: flex; flex-wrap: wrap; gap: 4px; }
.tts2-voice {
  width: 80px; padding: 6px 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: transparent; border: 0; cursor: pointer; color: var(--t-text);
}
.tts2-card .tts2-voice-pic {
  position: relative; display: flex; padding: 3px;
  border: 3px solid transparent; border-radius: 50%;
}
.tts2-voice-pic svg { display: block; width: 56px; height: 56px; border-radius: 50%; }
.tts2-voice[aria-pressed="true"] .tts2-voice-pic { border-color: var(--t-accent); }
.tts2-card .tts2-voice-n {
  position: absolute; right: -4px; bottom: -4px;
  min-width: 22px; height: 22px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 11px; border: 2px solid var(--t-surface);
  background: var(--t-card); color: var(--t-head);
  font-size: 13px; font-weight: 700; line-height: 1;
}
.tts2-voice[aria-pressed="true"] .tts2-voice-n { background: var(--t-accent); color: var(--t-accent-ink); }
.tts2-card .tts2-voice-cap { font-size: 13px; color: var(--t-muted); white-space: nowrap; }
.tts2-card .tts2-voice[aria-pressed="true"] .tts2-voice-cap { color: var(--t-head); font-weight: 700; }
.tts2-voices > .tts2-muted { align-self: center; }

/* ---------- Ad inside the text box ---------- */
/* Sits at the bottom of the box, under the text, with a rule and a label
   between the two so the ad is not mistaken for part of the text. */
.tts2-ad { flex: none; margin: 0 12px 12px; padding-top: 10px; border-top: 1px solid var(--t-border); display: flex; flex-direction: column; gap: 6px; }
.tts2-ad[hidden] { display: none; }
.tts2-card .tts2-ad-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--t-muted); }
.tts2-ad-slot { min-height: 100px; overflow: hidden; line-height: 0; text-align: center; }
.tts2-ad-slot ins.adsbygoogle { display: block; width: 100%; }
.tts2-ad.is-empty { display: none; }

/* ---------- Full-width ad above the audio controls ---------- */
/* Pulled close to the cards above and below it. */
.tts2-topad { grid-area: topad; min-width: 0; margin: -14px 0; text-align: center; line-height: 0; }
.tts2-topad.is-empty { display: none; }
.tts2-topad ins[data-ad-status="unfilled"] { display: none !important; }
.tts2-seg { display: flex; border: 1px solid var(--t-ctl); border-radius: 8px; overflow: hidden; }
.tts2-seg button {
  min-height: 44px; min-width: 56px; padding: 0 10px;
  border: 0; font-size: 14px; cursor: pointer;
  background: transparent; color: var(--t-text);
}
.tts2-seg button[aria-pressed="true"] { background: var(--t-on-bg); color: var(--t-on-fg); }
.tts2-status { margin: 0; min-height: 20px; font-size: 14px; color: var(--t-muted); }
.tts2-status.is-error { color: var(--t-cur-bd); font-weight: 700; }

/* ---------- Read along ---------- */
.tts2-lines { display: flex; flex-direction: column; gap: 6px; }
.tts2-card p.tts2-empty { padding: 18px 14px; border: 1px dashed var(--t-ctl); border-radius: 10px; font-size: 15px; color: var(--t-muted); }
.tts2-line {
  min-height: 48px; width: 100%;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px; text-align: left;
  border: 2px solid var(--t-card); border-radius: 10px;
  background: var(--t-card); color: var(--t-text);
  font-family: Roboto, Arial, sans-serif; font-size: 17px; line-height: 1.5;
  cursor: pointer;
}
.tts2-line-n { flex: none; width: 26px; font-size: 14px; line-height: 1.8; color: var(--t-muted); font-weight: 400; }
.tts2-line.is-current { background: var(--t-cur-bg); border-color: var(--t-cur-bd); font-weight: 700; }

.tts2 .custom-content { margin-top: 14px; }

/* ---------- Tablet and phone: text, then audio, then read along ---------- */
@media (max-width: 900px) {
  .tts2 { padding: 10px 10px 28px; gap: 10px; }  .tts2-topad { margin: -6px 0; }
  .tts2-voice { width: 64px; }
  .tts2-voice-pic svg { width: 48px; height: 48px; }
  .tts2-voices { gap: 10px 16px; }
  /* Room for the large (rectangle) ad on phones. */
  .tts2-ad-slot { min-height: 250px; }
  .tts2-head { gap: 8px; }
  .tts2-head { align-items: stretch; }
  .tts2-lang { width: 100%; }
  .tts2 .tts-lang-select { flex: 1 1 auto; width: auto !important; }
  .tts2-main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "text" "topad" "audio" "read"; gap: 10px; }
  .tts2-card { padding: 12px; gap: 10px; }
  .tts2-audio { gap: 12px; }
  .tts2-row { gap: 12px; }
  .tts2-row-settings { padding-top: 12px; }
  .tts2-actions { gap: 6px; }
  .tts2-actions .tts2-btn { min-width: 0; padding: 0 4px; font-size: 14px; white-space: nowrap; }
  .tts2-inputbox { min-height: 200px; }
  .tts2-textarea { min-height: 120px; }
  .tts2-transport { margin: 0 auto; }
  .tts2-progress { flex-basis: 100%; }
  .tts2-pitch { max-width: none; flex-basis: 100%; }
  .tts2-btn-outline { flex: 1 1 100%; }
  .tts2-toggle { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: no-preference) {
  .tts2-wave span { transition: background-color .15s linear; }
}

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

/* ---------- Same card look as the translation and Voice Translator pages ----------
   "Your text" is the rose card, "Read along" the blue one. */
.tts2-text { background: #fff0f3; border: 2px solid #f6a5b7; border-radius: 22px; }
.tts2-read { background: #eaf1ff; border: 2px solid #a9c3f5; border-radius: 22px; }
.tts2-text .tts2-inputbox { background: rgba(255, 255, 255, .6); border-color: #f6a5b7; border-radius: 14px; }
.tts2-read p.tts2-empty { border-color: #a9c3f5; }
.tts2-text:focus-within { border-color: #e11d48; box-shadow: 0 0 0 3px rgba(225, 29, 72, .18); }
.tts2-text .tts2-inputbox:focus-within { outline: none; }
.dark .tts2-text { background: #2c1622; border-color: #7a2a40; }
.dark .tts2-read { background: #172443; border-color: #33508f; }
.dark .tts2-text .tts2-inputbox { background: rgba(14, 18, 37, .45); border-color: #7a2a40; }
.dark .tts2-read p.tts2-empty { border-color: #33508f; }
.dark .tts2-text:focus-within { border-color: #fb7185; }
@media (max-width: 900px) {
  .tts2-text, .tts2-read { border-radius: 18px; }
}
