/* Entangle Chat — hlasový režim.
   Karta = portrétní formát, foto Masaryka vyplňuje celou plochu.
   Dole tmavnoucí gradient, na něm bílý text + tlačítko. Aura okolo karty
   se mění podle fáze hovoru a reaguje na hlasitost. */

.entangle-chat--voice {
	--ec-accent: var(--color-primary, #0452aa);
	--ec-level: 0;            /* hlasitost 0..1 — nastavuje JS */

	max-width: 480px;
	margin: 1.5rem auto;
	aspect-ratio: 3 / 4;       /* portrétní karta */
	position: relative;
	overflow: hidden;
	border-radius: 18px;
	background: #1a1a1a;       /* fallback, než se načte foto */
	box-shadow: 0 12px 36px rgba(0, 0, 0, .18);
	font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: #fff;
	transition: box-shadow 200ms ease;
}

/* Avatar — 3 vrstvy aby si transformace nestřihaly:
   1) .avatar (vnější) — mikro-naklony hlavy (rotate)
   2) .face (prostřední) — klidové dýchání / amplitudový scale
   3) .ec-frame × 4 (vnitřní stack) — fotky s různými stavy úst, opacity dle hlasitosti */
.entangle-chat--voice .entangle-chat-voice__avatar {
	position: absolute;
	inset: 0;
	overflow: hidden;
	transform-origin: center 55%;
	animation: ec-headtilt 11s ease-in-out infinite;
	will-change: rotate;
}

.entangle-chat--voice .entangle-chat-voice__face {
	position: absolute;
	inset: -2%;
	transform-origin: center 55%;
	animation: ec-breathe 5.2s ease-in-out infinite;
	transition: scale 80ms ease-out;
	will-change: scale;
}

.entangle-chat--voice .ec-frame {
	position: absolute;
	inset: 0;
	background-size: cover;
	background-position: center 18%;
	opacity: 0;
	will-change: opacity;
	/* Bez CSS transition: opacity řídí JS na 60 fps (requestAnimationFrame).
	   Transition by způsobovala lag a problikávání. */
}
.entangle-chat--voice .ec-frame[data-mouth="0"] { background-image: url("tgm_mouth_closed.jpg"); opacity: 1; }
.entangle-chat--voice .ec-frame[data-mouth="1"] { background-image: url("tgm_mouth_low.jpg"); }
.entangle-chat--voice .ec-frame[data-mouth="2"] { background-image: url("tgm_mouth_low_mid.jpg"); }
.entangle-chat--voice .ec-frame[data-mouth="3"] { background-image: url("tgm_mouth_mid.jpg"); }
.entangle-chat--voice .ec-frame[data-mouth="4"] { background-image: url("tgm_mouth_mid_wide.jpg"); }
.entangle-chat--voice .ec-frame[data-mouth="5"] { background-image: url("tgm_mouth_wide.jpg"); }

/* Mikro-výrazy očí — 4 fotky se subtilní variací očí/obočí. Jejich účel:
   přidat život do tváře během dlouhých mluvících odpovědí, aby oči nevypadaly
   jako naskenované. Opacity záměrně NÍZKÁ (0.55) — chceme, aby se eye area
   změnila, ale mouth animace pod tím dál hrála (jejich fotky mají closed
   mouth, takže s plnou opacitou by ústa „zamrzla"). Fade 320 ms ease-in-out
   tlumí ghost. */
.entangle-chat--voice .ec-expr {
	position: absolute;
	inset: 0;
	background-size: cover;
	background-position: center 18%;
	opacity: 0;
	pointer-events: none;
	transition: opacity 200ms ease-in-out;
	will-change: opacity;
}
.entangle-chat--voice .ec-expr--aside { background-image: url("tgm_eyes_aside.jpg"); }
.entangle-chat--voice .ec-expr--brow  { background-image: url("tgm_brow_raised.jpg"); }
.entangle-chat--voice .ec-expr--warm  { background-image: url("tgm_eyes_warm.jpg"); }
.entangle-chat--voice .ec-expr--down  { background-image: url("tgm_eyes_down.jpg"); }
.entangle-chat--voice.is-expr-aside .ec-expr--aside,
.entangle-chat--voice.is-expr-brow  .ec-expr--brow,
.entangle-chat--voice.is-expr-warm  .ec-expr--warm,
.entangle-chat--voice.is-expr-down  .ec-expr--down {
	opacity: 0.55;
}

/* Úsměv — překryv viditelný během poslouchání. Krátký fade (80 ms), aby
   drobné rozdíly mezi „neutrální" a „smile" fotkou nestihly proběhnout
   jako ghost. */
.entangle-chat--voice .ec-frame-smile {
	position: absolute;
	inset: 0;
	background-image: url("tgm_mouth_smile.jpg");
	background-size: cover;
	background-position: center 18%;
	opacity: 0;
	pointer-events: none;
	transition: opacity 80ms ease-out;
	will-change: opacity;
}
.entangle-chat--voice.is-listening .ec-frame-smile,
.entangle-chat--voice.is-capturing .ec-frame-smile {
	opacity: 1;
}

/* Mrknutí — asymetrická animace (rychlé zavření 28 ms, krátké podržení,
   pomalejší otevření) napodobuje skutečné mrknutí. Peak opacity 1.0 =
   oči se opravdu úplně zavřou (dřívější 0.85 vypadalo jako poloprůsvit). */
.entangle-chat--voice .ec-blink {
	position: absolute;
	inset: 0;
	background-image: url("tgm_eyes_closed.jpg");
	background-size: cover;
	background-position: center 18%;
	opacity: 0;
	pointer-events: none;
	will-change: opacity;
}
.entangle-chat--voice.is-blinking .ec-blink {
	animation: ec-blink 200ms linear;
}
/* Lineární timing + delší fáze „úplně zavřeno" (40 % → 80 ms na opacity 1)
   = oko skutečně přečte „zavřené oči", ne jen přechod. */
@keyframes ec-blink {
	0%   { opacity: 0; }
	15%  { opacity: 1; }    /* zavření za 30 ms */
	55%  { opacity: 1; }    /* DRŽÍ 80 ms na plné neprůhlednosti */
	100% { opacity: 0; }    /* otevření za 90 ms */
}

@keyframes ec-breathe {
	0%, 100% { scale: 1; }
	50%      { scale: 1.014; }
}

@keyframes ec-headtilt {
	0%, 100% { rotate: -0.6deg; }
	25%      { rotate: 0.5deg; }
	55%      { rotate: -0.2deg; }
	80%      { rotate: 0.7deg; }
}

/* Tmavnoucí gradient dole — kvůli čitelnosti textu */
.entangle-chat--voice::after {
	content: "";
	position: absolute;
	inset: auto 0 0 0;
	height: 58%;
	background: linear-gradient(to bottom,
		rgba(0, 0, 0, 0) 0%,
		rgba(0, 0, 0, .35) 30%,
		rgba(0, 0, 0, .78) 70%,
		rgba(0, 0, 0, .92) 100%);
	pointer-events: none;
	z-index: 1;
}

/* Ikonové tlačítko vpravo nahoře — otevře kartu na celou obrazovku */
.entangle-chat--voice .entangle-chat-voice__fullscreen {
	position: absolute;
	top: .55rem;
	right: .55rem;
	z-index: 4;
	width: 36px; height: 36px;
	display: inline-flex; align-items: center; justify-content: center;
	border: 1px solid rgba(255, 255, 255, .3);
	border-radius: 10px;
	background: rgba(0, 0, 0, .35);
	color: #fff;
	cursor: pointer;
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	transition: background 150ms ease, transform 120ms ease;
}
.entangle-chat--voice .entangle-chat-voice__fullscreen:hover { background: rgba(0, 0, 0, .55); transform: translateY(-1px); }
.entangle-chat--voice .entangle-chat-voice__fullscreen .ec-icon { display: inline-block; }
.entangle-chat--voice .entangle-chat-voice__fullscreen .ec-icon--collapse { display: none; }
.entangle-chat--voice.is-fullscreen .entangle-chat-voice__fullscreen .ec-icon--expand { display: none; }
.entangle-chat--voice.is-fullscreen .entangle-chat-voice__fullscreen .ec-icon--collapse { display: inline-block; }

/* Fullscreen — kartu vložíme do <dialog>, kolem 90% tmavé pozadí */
.entangle-chat-voice__dialog {
	border: none; padding: 0; background: transparent; color: inherit;
	max-width: none; max-height: none;
	width: 100vw; height: 100vh;
	margin: 0;
	overflow: visible;
	display: flex; align-items: center; justify-content: center;
}
.entangle-chat-voice__dialog::backdrop { background: rgba(0, 0, 0, .9); }

.entangle-chat--voice.is-fullscreen {
	max-width: none;
	max-height: none;
	margin: 0;
	/* Explicitně počítáme OBA rozměry; aspect-ratio v dialogu (flex container)
	   občas nezafungovalo a karta měla výšku 0 → fotka byla neviditelná. */
	height: min(92vh, calc(92vw * 4 / 3));
	width:  calc(min(92vh, calc(92vw * 4 / 3)) * 3 / 4);
	flex-shrink: 0;
	border-radius: 22px;
	box-shadow: 0 24px 64px rgba(0, 0, 0, .55);
}

/* Transparentní upozornění (CLAUDE.md §5) — drobně nahoře */
.entangle-chat--voice .entangle-chat-voice__note {
	position: absolute;
	top: 0; left: 0; right: 0;
	padding: .55rem .9rem .85rem;
	z-index: 3;
	text-align: center;
	font-size: .72rem;
	letter-spacing: .015em;
	color: rgba(255, 255, 255, .92);
	background: linear-gradient(to bottom, rgba(0, 0, 0, .5), rgba(0, 0, 0, 0));
	text-shadow: 0 1px 3px rgba(0, 0, 0, .55);
	pointer-events: none;
}

/* Obsahový blok dole — sedí na gradientu */
.entangle-chat--voice .entangle-chat-voice__content {
	position: absolute;
	left: 0; right: 0; bottom: 0;
	padding: 1rem 1.25rem 1.25rem;
	z-index: 2;
	text-align: center;
}

.entangle-chat--voice .entangle-chat-voice__status {
	font-size: 1.05rem;
	font-weight: 600;
	color: #fff;
	margin: 0 0 .35rem;
	min-height: 1.5em;
	line-height: 1.35;
	text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
}
.entangle-chat--voice .entangle-chat-voice__status strong { font-weight: 700; }

.entangle-chat--voice .entangle-chat-voice__transcript {
	font-size: .82rem;
	font-style: italic;
	color: rgba(255, 255, 255, .88);
	margin: 0 0 .9rem;
	min-height: 1.3em;
	text-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

.entangle-chat--voice .entangle-chat-voice__buttons { margin-top: .35rem; }

.entangle-chat--voice .entangle-chat-voice__start,
.entangle-chat--voice .entangle-chat-voice__stop {
	border: none;
	border-radius: 999px;
	cursor: pointer;
	font: inherit;
	font-weight: 600;
	color: #fff;
}
.entangle-chat--voice .entangle-chat-voice__start {
	background: var(--ec-accent);
	padding: .75rem 1.7rem;
	font-size: 1rem;
	box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
.entangle-chat--voice .entangle-chat-voice__stop {
	background: rgba(255, 255, 255, .18);
	border: 1px solid rgba(255, 255, 255, .35);
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	padding: .45rem 1.05rem;
	font-size: .85rem;
}
.entangle-chat--voice .entangle-chat-voice__start:hover,
.entangle-chat--voice .entangle-chat-voice__stop:hover { filter: brightness(1.08); }

/* --- vizuální fáze (aura okolo karty) --- */

/* listening — klidný zelený dech */
.entangle-chat--voice.is-listening {
	animation: ec-listen-card 2.6s ease-in-out infinite;
}
@keyframes ec-listen-card {
	0%, 100% { box-shadow: 0 12px 36px rgba(0, 0, 0, .18),
	                       0 0 0 3px  rgba(46, 184, 92, .32); }
	50%      { box-shadow: 0 12px 36px rgba(0, 0, 0, .18),
	                       0 0 0 12px rgba(46, 184, 92, .55); }
}

/* capturing — sytá zelená dle hlasitosti mikrofonu */
.entangle-chat--voice.is-capturing {
	box-shadow:
		0 12px 36px rgba(0, 0, 0, .18),
		0 0 0 calc(5px + var(--ec-level) * 20px) rgba(46, 184, 92, .65);
}

/* transcribing / thinking — jantarový pulz */
.entangle-chat--voice.is-transcribing,
.entangle-chat--voice.is-thinking {
	animation: ec-think-card 1.6s ease-in-out infinite;
}
@keyframes ec-think-card {
	0%, 100% { box-shadow: 0 12px 36px rgba(0, 0, 0, .18),
	                       0 0 0 4px  rgba(228, 159, 5, .35); }
	50%      { box-shadow: 0 12px 36px rgba(0, 0, 0, .18),
	                       0 0 0 14px rgba(228, 159, 5, .55); }
}

/* speaking — modrá záře dle hlasitosti + jemný „dech" fotky */
.entangle-chat--voice.is-speaking {
	box-shadow:
		0 12px 36px rgba(0, 0, 0, .18),
		0 0 0 calc(4px + var(--ec-level) * 24px) rgba(4, 82, 170, .6);
}
/* Při řeči přebírá scale hlasitost (na .face) — tilt na rodičovi pokračuje */
.entangle-chat--voice.is-speaking .entangle-chat-voice__face {
	animation: none;
	scale: calc(1.02 + var(--ec-level) * 0.04);
}

@media (prefers-reduced-motion: reduce) {
	.entangle-chat--voice,
	.entangle-chat--voice .entangle-chat-voice__avatar,
	.entangle-chat--voice .entangle-chat-voice__face,
	.entangle-chat--voice .ec-frame {
		animation: none !important;
		scale: 1 !important;
		rotate: 0 !important;
		transition: none !important;
	}
}

@media (max-width: 540px) {
	.entangle-chat--voice { max-width: none; margin: 1rem .5rem; border-radius: 14px; }
}

/* Debug overlay latence — zapne se přes localStorage.ec_debug = "1" */
.entangle-chat--voice .entangle-chat-voice__debug {
	position: absolute;
	left: 8px;
	bottom: 8px;
	z-index: 5;
	margin: 0;
	padding: 6px 8px;
	font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace;
	color: #fff;
	background: rgba(0, 0, 0, 0.6);
	border-radius: 6px;
	white-space: pre;
	pointer-events: none;
}

/* Video tváře ze služby (Simli / Anam) — leží přes fotografie a ukáže se,
   až renderer ohlásí první snímek (třída is-face-video na kartě). */
.entangle-chat--voice .entangle-chat-voice__video {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	opacity: 0;
	pointer-events: none;
}
.entangle-chat--voice .entangle-chat-voice__audio { display: none; }
.entangle-chat--voice.is-face-video .entangle-chat-voice__video { opacity: 1; }
.entangle-chat--voice.is-face-video .ec-frame,
.entangle-chat--voice.is-face-video .ec-frame-smile,
.entangle-chat--voice.is-face-video .ec-blink { opacity: 0 !important; }
