/* ═══════════════════════════════════════════════════════════════════════
   Piper TTS: texto para voz, no navegador. Visual limpo, em tons de violeta (acento #b388ff e o par #5eead4 do catálogo).
   Tema: claro por padrão, escuro quando o sistema pede (prefers-color-scheme) e as duas escolhas manuais (html[data-theme]).
   Os tokens de cada tema ficam nos três blocos marcados com `@theme`: test/piper-page.test.js confere o contraste de cada par
   (texto sobre fundo, botão, selos, destaque da frase) e que os três blocos declaram as mesmas variáveis. A splash tem o próprio
   arquivo (piper-splash.css). Não depende de tokens.css nem de Bootstrap. Movimento: juice.js põe data-motion="reduced" no <html>.
   ═══════════════════════════════════════════════════════════════════════ */

/* @theme light */
:root {
	color-scheme: light;
	--bg: #f7f5fc;
	--surface: #ffffff;
	--surface-2: #f0ecfa;
	--ink: #15112a;
	--ink-2: #4b4568;
	--ink-3: #625b80;
	--line: #e2dcf3;
	--line-2: #c9c0e6;
	--edge: #8a7dbd;
	--btn: #6a3fd0;
	--btn-hover: #5a2fc0;
	--btn-ink: #ffffff;
	--accent-text: #5b2fc0;
	--danger: #b3261e;
	--danger-ink: #ffffff;
	--ok: #0b6f66;
	--mark: #e5dbff;
	--wave-1: #7a4ddb;
	--wave-2: #0f8f84;
	--logo-1: #b388ff;
	--logo-2: #5eead4;
	--logo-ink: #1b0f3d;
	--shadow: 0 1px 2px rgb(21 17 42 / .05), 0 10px 28px -14px rgb(21 17 42 / .16);
}
@media (prefers-color-scheme: dark) {
	/* @theme dark */
	:root:where(:not([data-theme="light"])) {
		color-scheme: dark;
		--bg: #0c0917;
		--surface: #16112a;
		--surface-2: #201939;
		--ink: #f1edff;
		--ink-2: #cfc6f0;
		--ink-3: #a99fd0;
		--line: #2a2147;
		--line-2: #3a2f63;
		--edge: #7a6db3;
		--btn: #b388ff;
		--btn-hover: #c4a2ff;
		--btn-ink: #160b30;
		--accent-text: #c4a5ff;
		--danger: #ff8f8f;
		--danger-ink: #1a0b0b;
		--ok: #5eead4;
		--mark: #3b2b72;
		--wave-1: #b388ff;
		--wave-2: #5eead4;
		--logo-1: #b388ff;
		--logo-2: #5eead4;
		--logo-ink: #1b0f3d;
		--shadow: 0 1px 2px rgb(0 0 0 / .4), 0 10px 28px -14px rgb(0 0 0 / .65);
	}
}
/* @theme dark */
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #0c0917;
	--surface: #16112a;
	--surface-2: #201939;
	--ink: #f1edff;
	--ink-2: #cfc6f0;
	--ink-3: #a99fd0;
	--line: #2a2147;
	--line-2: #3a2f63;
	--edge: #7a6db3;
	--btn: #b388ff;
	--btn-hover: #c4a2ff;
	--btn-ink: #160b30;
	--accent-text: #c4a5ff;
	--danger: #ff8f8f;
	--danger-ink: #1a0b0b;
	--ok: #5eead4;
	--mark: #3b2b72;
	--wave-1: #b388ff;
	--wave-2: #5eead4;
	--logo-1: #b388ff;
	--logo-2: #5eead4;
	--logo-ink: #1b0f3d;
	--shadow: 0 1px 2px rgb(0 0 0 / .4), 0 10px 28px -14px rgb(0 0 0 / .65);
}

:root {
	--radius: 18px;
	--ease: cubic-bezier(.2, .8, .2, 1);
	--font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
	--accent: var(--accent-text);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	min-height: 100vh;
	min-height: 100dvh;
	margin: 0;
	display: flex;
	flex-direction: column;
	overflow-x: hidden;
	background: var(--bg);
	color: var(--ink);
	font: 400 1rem/1.5 var(--font);
	-webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }
ul, ol { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, p, dl, dd { margin: 0; }
.i { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i--fill { fill: currentColor; }
.flip { transform: scaleX(-1); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--btn); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
kbd { display: inline-block; min-width: 1.6em; padding: .05em .45em; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); font: 600 .78em/1.5 var(--font); text-align: center; }
#app:focus { outline: none; }

/* ───────── Esqueleto de carregamento ───────── */
.sk { display: block; border-radius: 8px; background: linear-gradient(100deg, var(--surface-2) 30%, var(--line) 50%, var(--surface-2) 70%) 0 0 / 220% 100%; animation: shimmer 1.4s linear infinite; }
.sk--line { height: 14px; width: 6.5rem; }
@keyframes shimmer { to { background-position: -220% 0; } }

/* ───────── Topo ───────── */
.top { display: flex; align-items: center; justify-content: space-between; gap: .8rem; width: min(100%, 720px); margin: 0 auto; padding: max(.8rem, env(safe-area-inset-top)) 16px .6rem; }
.pill { display: inline-flex; align-items: center; gap: .5rem; min-height: 40px; padding: .35rem .95rem .35rem .75rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-2); font-size: .88rem; font-weight: 600; text-decoration: none; transition: border-color .2s, color .2s; }
.pill:hover { border-color: var(--line-2); color: var(--ink); }
.brand { display: flex; align-items: center; gap: .5rem; font: 800 1.25rem/1 var(--font); letter-spacing: -.02em; }
.brand__logo { width: 1.8rem; height: 1.8rem; stroke: none; }
.top__tools { display: flex; gap: .3rem; }
.tool { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 1px solid transparent; border-radius: 12px; background: transparent; color: var(--ink-2); transition: background .2s, color .2s; }
.tool:hover { background: var(--surface-2); color: var(--ink); }
.tool[aria-pressed="false"] { color: var(--ink-3); opacity: .65; }

/* ───────── Página: uma coluna no celular, duas no computador ───────── */
.app { flex: 1; display: grid; gap: 1rem; align-content: start; width: min(100%, 720px); margin: 0 auto; padding: .4rem 16px 2rem; }
.nojs { padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.card { margin: 0; padding: 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.card__title { margin: 0 0 .8rem; font-size: 1.05rem; font-weight: 800; letter-spacing: -.01em; }
@media (min-width: 900px) {
	.top { width: min(100%, 1040px); }
	.app { width: min(100%, 1040px); grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); grid-template-areas: "talk voices" "talk tune" "usage usage"; align-items: start; gap: 1.1rem; }
	.talk { grid-area: talk; }
	.voices-card { grid-area: voices; }
	.tune { grid-area: tune; }
	.usage-wrap { grid-area: usage; }
}

/* ───────── Botões ───────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px; padding: .5rem 1.1rem; border: 1px solid transparent; border-radius: 12px; background: transparent; color: var(--ink); font-weight: 600; font-size: .95rem; line-height: 1.2; text-align: center; transition: background .2s, border-color .2s, transform .15s; }
.btn:active { transform: translateY(1px); }
.btn[aria-disabled="true"], .btn:disabled { opacity: .5; cursor: default; }
.btn[aria-disabled="true"]:active { transform: none; }
.btn--primary { background: var(--btn); color: var(--btn-ink); }
.btn--primary:hover:not([aria-disabled="true"]) { background: var(--btn-hover); }
.btn--ghost { border-color: var(--line-2); background: var(--surface); }
.btn--ghost:hover:not([aria-disabled="true"]) { background: var(--surface-2); }
.btn--lg { min-height: 54px; font-size: 1.05rem; font-weight: 700; border-radius: 14px; }
.btn--sm { min-height: 38px; padding: .3rem .85rem; font-size: .88rem; border-radius: 10px; }
.link-btn { display: inline-flex; align-items: center; gap: .35rem; min-height: 36px; padding: 0 .5rem; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); font-size: .86rem; font-weight: 600; text-decoration: underline; text-underline-offset: .2em; }
.link-btn:hover { color: var(--ink); }
.link-btn .i { width: 1em; height: 1em; }
.fine { margin-top: .6rem; color: var(--ink-2); font-size: .86rem; line-height: 1.45; }

/* ───────── O texto ───────── */
.talk__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 0 0 .5rem; }
.talk__label { font-size: 1.05rem; font-weight: 800; letter-spacing: -.01em; }
.count { color: var(--ink-3); font-size: .86rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.count.is-near { color: var(--accent-text); }
.count.is-full { color: var(--danger); }
.field { width: 100%; padding: .7rem .85rem; border: 1px solid var(--edge); border-radius: 14px; background: var(--bg); color: var(--ink); }
.field:focus-visible { outline-offset: 0; }
.area { display: block; min-height: 11rem; max-height: 24rem; resize: vertical; font-size: 1.05rem; line-height: 1.6; }
.area::placeholder { color: var(--ink-3); opacity: 1; }
.reader { position: relative; min-height: 11rem; max-height: 24rem; padding: .7rem .85rem; overflow-y: auto; border: 1px solid var(--edge); border-radius: 14px; background: var(--bg); font-size: 1.05rem; line-height: 1.7; }
.reader:focus { outline: none; }
.reader p + p { margin-top: .7rem; }
.reader .s { padding: .05em .12em; border-radius: 6px; color: var(--ink-2); transition: background-color .25s, color .25s; }
.reader .s.is-done { color: var(--ink-2); }
.reader .s.is-now { background: var(--mark); color: var(--ink); box-shadow: 0 0 0 .14em var(--mark); }
.examples { margin-top: .9rem; }
.examples__label { margin: 0 0 .45rem; color: var(--ink-2); font-size: .86rem; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; min-height: 40px; padding: .35rem .9rem; border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); color: var(--ink); font-weight: 600; font-size: .9rem; transition: background .2s; }
.chip:hover { background: var(--surface-2); }
.chip .i { width: 1em; height: 1em; }

/* ───────── Onda, progresso e estado ───────── */
.stage { margin-top: 1.1rem; padding: .8rem .9rem .9rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.wave { display: block; width: 100%; height: 56px; }
.meter { height: 6px; margin: .5rem 0 .6rem; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--wave-1), var(--wave-2)); transform: scaleX(var(--p, 0)); transform-origin: 0 50%; transition: transform .3s var(--ease); }
.stage__row { display: flex; align-items: baseline; justify-content: space-between; gap: .8rem; flex-wrap: wrap; }
.status { font-weight: 700; }
.status[data-tone="warn"] { color: var(--accent-text); }
.stage__sub { color: var(--ink-2); font-size: .86rem; font-variant-numeric: tabular-nums; }
.stage[data-state="speaking"] .status, .stage[data-state="rendering"] .status { color: var(--accent-text); }

/* ───────── Aviso de erro acolhedor ───────── */
.alert { display: flex; align-items: center; flex-wrap: wrap; gap: .8rem; margin-top: 1rem; padding: .85rem 1rem; border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line)); border-radius: 14px; background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.alert__icon { width: 1.6rem; height: 1.6rem; color: var(--danger); }
.alert__body { flex: 1; min-width: 12rem; }
.alert__title { font-weight: 800; }
.alert__text { color: var(--ink-2); font-size: .92rem; }

/* ───────── Botões de ação ───────── */
.actions { display: grid; grid-template-columns: repeat(6, 1fr); gap: .6rem; margin-top: 1rem; }
#bSpeak { grid-column: span 4; }
#bStop { grid-column: span 2; }
#bWav, #bCompare { grid-column: span 3; }

/* ───────── Vozes ───────── */
.voices { display: grid; gap: .6rem; }
.voice { display: grid; gap: .3rem; padding: .7rem .8rem .6rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); transition: border-color .2s, background .2s; }
.voice[data-selected] { border-color: var(--btn); background: color-mix(in srgb, var(--btn) 8%, var(--surface)); box-shadow: inset 0 0 0 1px var(--btn); }
.voice[data-locked] .voice__pick { cursor: not-allowed; opacity: .6; }
.voice__pick { display: flex; align-items: center; gap: .7rem; width: 100%; min-height: 44px; padding: 0; border: 0; background: transparent; text-align: left; }
.voice__dot { position: relative; flex: none; width: 20px; height: 20px; border: 2px solid var(--edge); border-radius: 50%; }
.voice__pick[aria-checked="true"] .voice__dot { border-color: var(--btn); }
.voice__pick[aria-checked="true"] .voice__dot::after { content: ''; position: absolute; inset: 3px; border-radius: 50%; background: var(--btn); }
.voice__main { display: grid; gap: .25rem; min-width: 0; }
.voice__name { font-size: 1.05rem; font-weight: 800; letter-spacing: -.01em; }
.voice__tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag { padding: .08rem .55rem; border: 1px solid var(--line); border-radius: 99px; background: var(--surface-2); color: var(--ink-2); font-size: .76rem; font-weight: 700; }
.tag--quiet { color: var(--ink-3); font-weight: 600; }
.voice__meta { padding-left: calc(20px + .7rem); color: var(--ink-2); font-size: .84rem; }
.seal { display: inline-block; margin-left: .2rem; padding: .02rem .45rem; border: 1px solid var(--edge); border-radius: 6px; color: var(--ink); font-size: .72rem; font-weight: 800; }
.seal--warn { border-color: var(--danger); color: var(--danger); }
.voice__foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding-left: calc(20px + .7rem); min-height: 36px; }
.voice__state { display: inline-flex; align-items: center; gap: .4rem; color: var(--ink-2); font-size: .88rem; font-weight: 700; }
.voice__state .i { width: 1em; height: 1em; }
.voice[data-state="ready"] .voice__state { color: var(--ok); }
.voice[data-state="loading"] .voice__state { color: var(--accent-text); }
.voice[data-state="error"] .voice__state { color: var(--danger); }
.voice__bar { height: 6px; margin-left: calc(20px + .7rem); border-radius: 99px; background: var(--line); overflow: hidden; }
.voice__bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--wave-1), var(--wave-2)); transform: scaleX(var(--p, 0)); transform-origin: 0 50%; transition: transform .2s linear; }
.credit { margin-top: .8rem; color: var(--ink-2); font-size: .84rem; line-height: 1.5; }

/* ───────── Ajustes finos ───────── */
.tune { padding: .4rem 1.1rem; }
.tune > summary { display: flex; align-items: center; gap: .6rem; min-height: 48px; font-weight: 800; letter-spacing: -.01em; list-style: none; cursor: pointer; }
.tune > summary::-webkit-details-marker { display: none; }
.tune__chev { margin-left: auto; transition: transform .2s var(--ease); }
.tune[open] .tune__chev { transform: rotate(180deg); }
.tune__body { padding: .4rem 0 1rem; }
.slider { display: grid; gap: .3rem; margin-bottom: 1rem; }
.slider__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.slider label { font-size: .92rem; font-weight: 700; }
.slider output { color: var(--accent-text); font-weight: 800; font-variant-numeric: tabular-nums; }
.slider input[type="range"] { width: 100%; height: 28px; margin: 0; accent-color: var(--btn); }
.slider__hint { color: var(--ink-2); font-size: .84rem; line-height: 1.4; }

/* ───────── Rodapé, avisos e diálogo ───────── */
.usage-wrap { color: var(--ink); }
.foot { width: min(100%, 720px); margin: 0 auto; padding: 1rem 16px max(1.6rem, env(safe-area-inset-bottom)); color: var(--ink-2); font-size: .85rem; text-align: center; }
@media (min-width: 900px) { .foot { width: min(100%, 1040px); } }
.foot p + p { margin-top: .4rem; }
.foot a { color: var(--ink-2); }
.foot__keys { color: var(--ink-3); }

.toasts { position: fixed; z-index: 50; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: .5rem; width: min(92vw, 28rem); pointer-events: none; }
.toast { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .7rem 1rem; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: .92rem; font-weight: 500; pointer-events: auto; animation: toast-in .25s var(--ease) both; }
.toast--bad { background: var(--danger); color: var(--danger-ink); }
.toast.is-out { animation: toast-out .2s ease both; }
.toast__btn { flex: none; min-height: 32px; padding: .2rem .7rem; border: 1px solid currentColor; border-radius: 8px; background: transparent; font-weight: 700; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

.dlg { width: min(94vw, 26rem); max-height: 92dvh; padding: 0; border: 1px solid var(--line-2); border-radius: 20px; background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgb(0 0 0 / .5); }
.dlg::backdrop { background: rgb(0 0 0 / .5); }
.dlg[open] { animation: dlg-in .22s var(--ease) both; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.dlg__box { margin: 0; }
.dlg__head { padding: 1.1rem 1.2rem .3rem; }
.dlg__head h2 { font-size: 1.2rem; font-weight: 800; letter-spacing: -.01em; }
.dlg__body { padding: .5rem 1.2rem 1rem; color: var(--ink-2); }
.dlg__foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; padding: .8rem 1.2rem 1.1rem; border-top: 1px solid var(--line); }

/* ───────── Telas pequenas, menos movimento, contraste forçado ───────── */
@media (max-width: 480px) {
	.pill span { display: none; }
	.pill { padding: .35rem .75rem; }
	.card { padding: .9rem; }
	.tune { padding: .3rem .9rem; }
}
html[data-motion="reduced"] .wave { display: none; }
html[data-motion="reduced"] .toast, html[data-motion="reduced"] .dlg[open], html[data-motion="reduced"] .sk { animation: none; }
html[data-motion="reduced"] .meter i, html[data-motion="reduced"] .voice__bar i, html[data-motion="reduced"] .tune__chev, html[data-motion="reduced"] .reader .s { transition: none; }
@media (prefers-reduced-motion: reduce) {
	.wave { display: none; }
	.toast, .dlg[open], .sk { animation: none; }
	.meter i, .voice__bar i, .tune__chev, .reader .s { transition: none; }
}
@media (forced-colors: active) {
	.voice, .field, .reader, .stage { border-color: ButtonText; }
	.voice[data-selected] { border-color: Highlight; }
	.reader .s.is-now { background: Highlight; color: HighlightText; }
}
