:root {
	--rata-tts-primary: #2f6fed;
	--rata-tts-primary-soft: #e3ecfd;
	--rata-tts-ink: #14181f;
	--rata-tts-muted: #64748b;
	--rata-tts-line: #e6e9ee;
	--rata-tts-surface: #fff;
	--rata-tts-hover: #f7f9fc;
}

/* Tint of the main color; browsers without color-mix() (Safari < 16.2) keep the fixed tint above. */
@supports (color: color-mix(in srgb, red 50%, white)) {
	:root { --rata-tts-primary-soft: color-mix(in srgb, var(--rata-tts-primary) 14%, #fff); }
}

.rata-tts-root { margin: 0 0 16px; }

.rata-tts-host { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.rata-tts-btn {
	font: inherit; font-size: 14px; font-weight: 600; line-height: 1.2;
	display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0;
	padding: 11px 20px; border-radius: 999px; cursor: pointer;
	border: 1px solid var(--rata-tts-line); background: var(--rata-tts-surface); color: var(--rata-tts-ink);
	box-shadow: 0 1px 2px rgba(20, 24, 31, .06); transition: box-shadow .15s ease;
}
.rata-tts-btn:hover { box-shadow: 0 2px 8px rgba(20, 24, 31, .10); }
.rata-tts-btn:focus-visible, .rata-tts-bar button:focus-visible, .rata-tts-progress:focus-visible { outline: 2px solid var(--rata-tts-primary); outline-offset: 2px; }
.rata-tts-btn .rata-ic {
	width: 22px; height: 22px; border-radius: 999px; flex-shrink: 0;
	display: flex; align-items: center; justify-content: center; gap: 2px;
	background: var(--rata-tts-primary-soft); color: var(--rata-tts-primary);
}
.rata-tts-btn.is-active { background: var(--rata-tts-primary); border-color: transparent; color: #fff; box-shadow: 0 4px 12px rgba(47, 111, 237, .28); }
.rata-tts-btn.is-active .rata-ic { background: rgba(255, 255, 255, .2); color: #fff; }
.rata-tts-btn.is-active .rata-ic span { display: block; width: 3px; border-radius: 1px; background: #fff; animation: rata-tts-eq .9s ease-in-out infinite; }
.rata-tts-btn.is-active .rata-ic span:nth-child(2) { animation-delay: .2s; }
.rata-tts-btn.is-active .rata-ic span:nth-child(3) { animation-delay: .4s; }
@keyframes rata-tts-eq { 0%, 100% { height: 6px; } 50% { height: 14px; } }

.rata-tts-active-block {
	background: var(--rata-tts-hl-block); border-radius: 6px; box-shadow: 0 0 0 4px var(--rata-tts-hl-block);
	transition: background .2s ease; scroll-margin-top: 120px; scroll-margin-bottom: 140px;
}

.rata-tts-bar {
	position: fixed; left: 0; right: 0; bottom: 0; z-index: 99999;
	background: var(--rata-tts-surface); border-top: 1px solid var(--rata-tts-line);
	box-shadow: 0 -10px 26px rgba(20, 24, 31, .10);
	transform: translateY(110%); transition: transform .25s ease;
}
.rata-tts-bar.is-open { transform: translateY(0); }
.rata-tts-progress { height: 6px; background: #eef1f5; cursor: pointer; }
.rata-tts-progress-fill { height: 100%; width: 0; background: var(--rata-tts-primary); transition: width .2s linear; }
.rata-tts-row { display: flex; align-items: center; gap: 14px; padding: 12px 20px; flex-wrap: wrap; }
.rata-tts-play {
	width: 44px; height: 44px; border-radius: 999px; border: 0; flex-shrink: 0; cursor: pointer;
	display: flex; align-items: center; justify-content: center; background: var(--rata-tts-primary); color: #fff; padding: 0;
}
.rata-tts-time { font-size: 13px; color: var(--rata-tts-muted); min-width: 96px; font-variant-numeric: tabular-nums; }
.rata-tts-spacer { flex-grow: 1; }
.rata-tts-chip {
	display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; cursor: pointer; white-space: nowrap;
	border: 1px solid var(--rata-tts-line); background: var(--rata-tts-surface); color: var(--rata-tts-ink); font: inherit; font-size: 13px; font-weight: 600;
}
.rata-tts-chip:hover { background: var(--rata-tts-hover); }
.rata-tts-close {
	width: 36px; height: 36px; border-radius: 999px; flex-shrink: 0; cursor: pointer; padding: 0;
	display: flex; align-items: center; justify-content: center; border: 1px solid #d8dee6; background: #eef1f5; color: #475569;
}
.rata-tts-bar svg { flex-shrink: 0; }

.rata-tts-pop {
	position: fixed; bottom: 78px; z-index: 100000; display: none; padding: 16px; width: 260px;
	background: var(--rata-tts-surface); border: 1px solid var(--rata-tts-line); border-radius: 14px;
	box-shadow: 0 12px 32px rgba(20, 24, 31, .16); font-size: 13px; color: var(--rata-tts-ink);
}
.rata-tts-pop.is-open { display: block; }
.rata-tts-pop h4 { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--rata-tts-ink); }
.rata-tts-voice-opt { display: flex; align-items: center; gap: 8px; padding: 7px 4px; color: #2b3340; cursor: pointer; border-radius: 8px; }
.rata-tts-voice-opt:hover { background: var(--rata-tts-hover); }
.rata-tts-voice-opt.is-static { cursor: default; background: none; font-weight: 600; }
.rata-tts-voice-opt input { accent-color: var(--rata-tts-primary); }
.rata-tts-speed-track { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.rata-tts-speed-btn {
	flex: 1; padding: 7px 0; border-radius: 8px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600;
	border: 1px solid var(--rata-tts-line); background: var(--rata-tts-surface); color: var(--rata-tts-ink);
}
.rata-tts-speed-btn.is-sel { background: var(--rata-tts-primary); border-color: var(--rata-tts-primary); color: #fff; }
.rata-tts-pop-note { margin-top: 10px; font-size: 11px; color: #9aa3b2; line-height: 1.5; }

@media (max-width: 600px) {
	.rata-tts-btn { padding: 10px 14px; }
	.rata-tts-btn .rata-label { font-size: 13px; }
	.rata-tts-row { gap: 10px; padding: 10px 16px; }
	.rata-tts-time { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
	.rata-tts-bar, .rata-tts-progress-fill, .rata-tts-active-block { transition: none; }
	.rata-tts-btn.is-active .rata-ic span { animation: none; height: 10px; }
}
.rata-tts-voice-img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }

/* ------------------------------------------------------------------
 * Theme-proofing. Themes often style every button / span (display: block,
 * width: 100%, floats, text-transform, their own colors), which put the icon
 * and the label on two lines. Doubled classes win over usual theme selectors;
 * !important only on the properties the layout depends on.
 * ------------------------------------------------------------------ */
.rata-tts-btn.rata-tts-btn {
	display: inline-flex !important; flex-direction: row !important; flex-wrap: nowrap !important; align-items: center !important;
	justify-content: flex-start; gap: 8px; width: auto !important; min-width: 0; max-width: 100%; height: auto; min-height: 0;
	float: none; margin: 0; white-space: nowrap !important; text-transform: none; letter-spacing: normal; text-decoration: none;
	line-height: 1.2; color: var(--rata-tts-ink); background: var(--rata-tts-surface); border: 1px solid var(--rata-tts-line); border-radius: 999px;
	box-shadow: 0 1px 2px rgba(20, 24, 31, .06); vertical-align: middle;
}
.rata-tts-btn.rata-tts-btn:hover, .rata-tts-btn.rata-tts-btn:focus { color: var(--rata-tts-ink); background: var(--rata-tts-surface); }
.rata-tts-btn.rata-tts-btn.is-active, .rata-tts-btn.rata-tts-btn.is-active:hover { color: #fff; background: var(--rata-tts-primary); border-color: transparent; }
.rata-tts-btn.rata-tts-btn .rata-ic {
	display: inline-flex !important; flex: 0 0 22px !important; width: 22px !important; height: 22px !important;
	margin: 0 !important; padding: 0; float: none; align-items: center; justify-content: center;
}
.rata-tts-btn.rata-tts-btn .rata-label {
	display: inline !important; float: none; width: auto !important; margin: 0 !important; padding: 0;
	white-space: nowrap !important; color: inherit; font-size: 14px; line-height: 1.2;
}
.rata-tts-btn.rata-tts-btn svg { display: block; width: 14px; height: 14px; margin: 0; }
.rata-tts-btn.rata-tts-btn.is-active .rata-ic span { display: block !important; flex: 0 0 3px; }

.rata-tts-bar.rata-tts-bar .rata-tts-row { display: flex !important; flex-direction: row !important; align-items: center !important; }
.rata-tts-bar.rata-tts-bar button {
	float: none; width: auto; min-width: 0; margin: 0; text-transform: none; letter-spacing: normal; line-height: 1.2; box-shadow: none;
}
.rata-tts-bar.rata-tts-bar .rata-tts-play { display: flex !important; width: 44px !important; height: 44px !important; flex: 0 0 44px; color: #fff; background: var(--rata-tts-primary); }
.rata-tts-bar.rata-tts-bar .rata-tts-close { display: flex !important; width: 36px !important; height: 36px !important; flex: 0 0 36px; }
.rata-tts-bar.rata-tts-bar .rata-tts-chip { display: inline-flex !important; flex-direction: row !important; align-items: center !important; white-space: nowrap !important; color: var(--rata-tts-ink); background: var(--rata-tts-surface); }
.rata-tts-bar.rata-tts-bar .rata-tts-chip span, .rata-tts-pop.rata-tts-pop span { display: inline !important; float: none; margin: 0; }
.rata-tts-pop.rata-tts-pop .rata-tts-speed-btn { display: block; width: 100%; margin: 0; text-transform: none; color: var(--rata-tts-ink); background: var(--rata-tts-surface); }
.rata-tts-pop.rata-tts-pop .rata-tts-speed-btn.is-sel { color: #fff; background: var(--rata-tts-primary); }
.rata-tts-pop.rata-tts-pop .rata-tts-voice-opt { display: flex !important; flex-direction: row !important; align-items: center !important; }

/* One row at every width: the voice chip shrinks and its name gets an ellipsis. */
.rata-tts-bar.rata-tts-bar .rata-tts-row { flex-wrap: nowrap !important; min-width: 0; }
.rata-tts-bar.rata-tts-bar .rata-tts-voice-chip { flex: 0 1 auto; min-width: 0; }
.rata-tts-bar.rata-tts-bar .rata-tts-voice-label { display: inline-block !important; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
@media (max-width: 600px) {
	.rata-tts-bar.rata-tts-bar .rata-tts-row { gap: 8px; padding: 10px 12px; }
	.rata-tts-bar.rata-tts-bar .rata-tts-time { font-size: 12px; min-width: 0; white-space: nowrap; }
	.rata-tts-bar.rata-tts-bar .rata-tts-voice-label { max-width: 72px; }
	.rata-tts-bar.rata-tts-bar .rata-tts-chip { padding: 7px 8px; gap: 4px; }
}

/* Close button: a round button floating above the top-right corner, outside the bar. */
.rata-tts-bar.rata-tts-bar { transform: translateY(calc(100% + 64px)); }
.rata-tts-bar.rata-tts-bar:not(.is-open) .rata-tts-close { visibility: hidden; }
.rata-tts-bar.rata-tts-bar.is-open { transform: translateY(0); }
.rata-tts-bar.rata-tts-bar .rata-tts-close {
	position: absolute !important; top: -40px; right: 16px; z-index: 1;
	width: 32px !important; height: 32px !important; flex: none;
	border: 1px solid var(--rata-tts-line); background: var(--rata-tts-surface); color: #475569;
	box-shadow: 0 4px 12px rgba(20, 24, 31, .16);
}
.rata-tts-bar.rata-tts-bar .rata-tts-close:hover { color: var(--rata-tts-ink); background: var(--rata-tts-hover); }
.rata-tts-bar.rata-tts-bar .rata-tts-close svg { width: 12px !important; height: 12px !important; }
@media (max-width: 600px) {
	.rata-tts-bar.rata-tts-bar .rata-tts-close { right: 12px; }
}

/* 7 speed levels: 4 per row. */
.rata-tts-pop.rata-tts-pop .rata-tts-speed-track { display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 6px; }

/* Follow-along highlight: paragraph (class) + sentence (CSS Custom Highlight API). Translucent tints
   of the main color over the page background, so the text keeps its own color on light and dark themes. */
:root { --rata-tts-hl-block: rgba(47, 111, 237, .14); --rata-tts-hl-sentence: rgba(47, 111, 237, .34); }
@supports (color: color-mix(in srgb, red 50%, transparent)) {
	:root {
		--rata-tts-hl-block: color-mix(in srgb, var(--rata-tts-primary) 14%, transparent);
		--rata-tts-hl-sentence: color-mix(in srgb, var(--rata-tts-primary) 34%, transparent);
	}
}
::highlight(rata-tts-sentence) { background-color: var(--rata-tts-hl-sentence); color: inherit; }
.rata-tts-active-block { transition: background .25s ease, box-shadow .25s ease; }

/* Theme-proofing, part 2: themes give every <button> big padding, font size, min-width and
   borders, which made the speed buttons overflow the popup. Sizes are locked here. */
.rata-tts-pop.rata-tts-pop, .rata-tts-pop.rata-tts-pop *,
.rata-tts-bar.rata-tts-bar, .rata-tts-bar.rata-tts-bar * { box-sizing: border-box; }
.rata-tts-pop.rata-tts-pop h4 { margin: 0 0 10px !important; padding: 0; font-size: 13px !important; line-height: 1.3 !important; font-weight: 700; color: var(--rata-tts-ink); }
.rata-tts-pop.rata-tts-pop .rata-tts-speed-track { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 6px !important; }
.rata-tts-pop.rata-tts-pop .rata-tts-speed-btn {
	width: 100% !important; min-width: 0 !important; height: auto !important; min-height: 0 !important;
	padding: 7px 0 !important; margin: 0 !important; font: inherit; font-size: 12px !important; font-weight: 600; line-height: 1.2 !important;
	border: 1px solid var(--rata-tts-line) !important; border-radius: 8px !important; box-shadow: none !important; white-space: nowrap; text-align: center;
	color: var(--rata-tts-ink) !important; background: var(--rata-tts-surface) !important;
}
.rata-tts-pop.rata-tts-pop .rata-tts-speed-btn:hover { background: var(--rata-tts-hover) !important; }
.rata-tts-pop.rata-tts-pop .rata-tts-speed-btn.is-sel { color: #fff !important; background: var(--rata-tts-primary) !important; border-color: var(--rata-tts-primary) !important; }
.rata-tts-pop.rata-tts-pop .rata-tts-voice-opt { margin: 0; font-size: 13px; line-height: 1.3; }
.rata-tts-pop.rata-tts-pop .rata-tts-voice-opt input { width: auto !important; height: auto; margin: 0 !important; }
.rata-tts-bar.rata-tts-bar .rata-tts-chip {
	height: auto !important; min-height: 0 !important; min-width: 0 !important; padding: 8px 12px !important;
	font: inherit; font-size: 13px !important; font-weight: 600; line-height: 1.2 !important;
	border: 1px solid var(--rata-tts-line) !important; border-radius: 10px !important; box-shadow: none !important;
}
.rata-tts-bar.rata-tts-bar .rata-tts-chip:hover { background: var(--rata-tts-hover) !important; }
.rata-tts-bar.rata-tts-bar .rata-tts-play { padding: 0 !important; min-width: 0 !important; border: 0 !important; border-radius: 999px !important; }
.rata-tts-bar.rata-tts-bar .rata-tts-close { padding: 0 !important; min-width: 0 !important; border-radius: 999px !important; border: 1px solid var(--rata-tts-line) !important; }
@media (max-width: 600px) {
	.rata-tts-bar.rata-tts-bar .rata-tts-chip { padding: 7px 8px !important; }
}
/* Icons keep their own size (themes often force button svg to 20-24px). */
.rata-tts-bar.rata-tts-bar svg[width="12"], .rata-tts-pop.rata-tts-pop svg[width="12"] { width: 12px !important; height: 12px !important; }
.rata-tts-bar.rata-tts-bar svg[width="14"], .rata-tts-btn.rata-tts-btn svg[width="14"] { width: 14px !important; height: 14px !important; }
.rata-tts-bar.rata-tts-bar svg[width="15"] { width: 15px !important; height: 15px !important; }
.rata-tts-bar.rata-tts-bar svg[width="16"] { width: 16px !important; height: 16px !important; }
.rata-tts-bar.rata-tts-bar svg { display: block !important; margin: 0 !important; flex: 0 0 auto; }
.rata-tts-btn.rata-tts-btn.is-unavailable { opacity: .55 !important; cursor: not-allowed !important; }
.rata-tts-novoice { display: inline-block; margin-left: 8px; font-size: 13px; color: #8a6d00; }
.rata-tts-voice-opt small { opacity: .7; }

/* Time bar: click or drag (mouse, finger, pen) to the part to hear. */
.rata-tts-bar.rata-tts-bar .rata-tts-progress { position: relative; height: 6px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.rata-tts-bar.rata-tts-bar .rata-tts-progress::before { content: ""; position: absolute; left: 0; right: 0; top: -10px; bottom: -8px; } /* bigger target */
.rata-tts-bar.rata-tts-bar .rata-tts-progress-fill { position: relative; border-radius: inherit; }
/* The bottom bar's band covers the bar's top border: no line of another colour between band and background. */
.rata-tts-bar.rata-tts-bar.rata-tpl-bar .rata-tts-progress, .rata-tts-bar.rata-tts-bar:not([class*="rata-tpl-"]) .rata-tts-progress { margin-top: -1px; }
.rata-tts-bar.rata-tts-bar .rata-tts-progress-fill::after {
	content: ""; position: absolute; right: -7px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%;
	background: var(--rata-tts-primary); box-shadow: 0 0 0 3px var(--rata-tts-primary-soft); opacity: 0; transition: opacity .15s ease;
}
.rata-tts-bar.rata-tts-bar .rata-tts-progress:hover .rata-tts-progress-fill::after,
.rata-tts-bar.rata-tts-bar .rata-tts-progress.is-dragging .rata-tts-progress-fill::after,
.rata-tts-bar.rata-tts-bar .rata-tts-progress:focus-visible .rata-tts-progress-fill::after { opacity: 1; }
.rata-tts-bar.rata-tts-bar .rata-tts-progress.is-dragging .rata-tts-progress-fill { transition: none; }
.rata-tts-seek-tip {
	position: absolute; bottom: 14px; transform: translateX(-50%); display: none; padding: 2px 6px; border-radius: 4px;
	background: var(--rata-tts-ink); color: #fff; font-size: 11px; line-height: 1.4; font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none;
}
.rata-tts-progress.is-dragging .rata-tts-seek-tip { display: block; }
@media (hover: none) {
	.rata-tts-bar.rata-tts-bar .rata-tts-progress { height: 8px; }
	.rata-tts-bar.rata-tts-bar .rata-tts-progress-fill::after { opacity: 1; }
}
/* Hidden by a player style (floating button, card in the post…): beats the display rules above. */
.rata-tts-btn.rata-tts-btn[hidden] { display: none !important; }
