/**
 * Tainacan Narrativas — public player.
 *
 * Tokens mirror the Tainacan theme variables with local fallbacks, so the
 * player blends into the site without external CSS or fonts.
 */
:root {
	--tn-primary: var(--tainacan-primary, var(--tainacan-turquoise5, #298596));
	--tn-secondary: var(--tainacan-secondary, var(--tainacan-blue5, #1f2f56));
	--tn-text: var(--tainacan-gray5, #1d2327);
	--tn-text-light: var(--tainacan-gray4, #5e6c70);
	--tn-bg: var(--tainacan-white, #ffffff);
	--tn-bg-soft: var(--tainacan-gray1, #f2f6f7);
	--tn-border: var(--tainacan-input-border-color, #dbe3e6);
	--tn-radius: var(--tainacan-button-border-radius, 6px);
	--tn-focus: #1a73e8;
	--tn-font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;

	/* Type scale relative to the host theme's root size, so every label in
	   the player is proportionate instead of an arbitrary rem value. */
	--tn-fs-2xs: 0.7em;   /* provenance note, fine print */
	--tn-fs-xs: 0.8em;    /* badge, meta row */
	--tn-fs-sm: 0.875em;  /* time, select, notices, download link */
	--tn-fs-base: 1em;    /* transcript body */
	--tn-fs-lg: 1.1875em; /* title */
}

.tn-player {
	box-sizing: border-box;
	margin: 2rem 0;
	padding: 1.25rem 1.5rem;
	border: 1px solid var(--tn-border);
	border-radius: var(--tn-radius);
	background: var(--tn-bg);
	color: var(--tn-text);
	font-family: var(--tn-font);
	font-size: 1rem;
	line-height: 1.5;
	clear: both;
	max-width: 100%;
}

.tn-player *,
.tn-player *::before,
.tn-player *::after {
	box-sizing: inherit;
}

.tn-player__header {
	display: grid;
	grid-template-columns: auto 1fr;
	grid-template-rows: auto auto;
	column-gap: 0.75rem;
	align-items: center;
	margin-bottom: 0.75rem;
}

.tn-player__icon {
	grid-row: 1 / span 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.5rem;
	height: 2.5rem;
	border-radius: 50%;
	background: var(--tn-bg-soft);
	color: var(--tn-primary);
}

.tn-player__title {
	margin: 0;
	font-size: var(--tn-fs-lg);
	font-weight: 600;
	line-height: 1.3;
	color: var(--tn-text);
}

.tn-player__meta {
	margin: 0;
	font-size: var(--tn-fs-xs);
	color: var(--tn-text-light);
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.3rem 0.75rem;
}

.tn-player__badge {
	display: inline-block;
	padding: 0.05rem 0.55rem;
	border: 1px solid var(--tn-border);
	border-radius: 999px;
	font-size: var(--tn-fs-2xs);
	font-weight: 600;
	line-height: 1.4;
}

/* Native audio element stays for no-JS; JS hides its native controls. */
.tn-player--init .tn-player__audio {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

.tn-player__controls {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.tn-controls__row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex-wrap: wrap;
}

.tn-controls__row--secondary {
	justify-content: flex-end;
	gap: 1rem;
}

.tn-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 2.75rem;
	min-height: 2.75rem;
	padding: 0;
	border: 1px solid var(--tn-border);
	border-radius: 50%;
	background: var(--tn-bg-soft);
	color: var(--tn-text);
	cursor: pointer;
	transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.tn-btn:hover {
	background: var(--tn-border);
}

.tn-btn--play {
	background: var(--tn-primary);
	border-color: var(--tn-primary);
	color: #fff;
	min-width: 3.25rem;
	min-height: 3.25rem;
}

.tn-btn--play:hover {
	background: var(--tn-secondary);
	border-color: var(--tn-secondary);
}

.tn-btn:focus-visible,
.tn-range:focus-visible,
.tn-select:focus-visible,
.tn-player__transcript-toggle:focus-visible,
.tn-player__download a:focus-visible {
	outline: 3px solid var(--tn-focus);
	outline-offset: 2px;
}

.tn-range {
	-webkit-appearance: none;
	appearance: none;
	height: 0.5rem;
	border-radius: 999px;
	background: linear-gradient(to right, var(--tn-primary) 0, var(--tn-primary) var(--tn-progress, 0%), var(--tn-border) var(--tn-progress, 0%), var(--tn-border) 100%);
	cursor: pointer;
	margin: 0;
}

.tn-range--progress {
	flex: 1 1 8rem;
	min-width: 6rem;
}

.tn-range--volume {
	width: 6rem;
	background: var(--tn-border);
}

.tn-range::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 1.1rem;
	height: 1.1rem;
	border-radius: 50%;
	background: var(--tn-bg);
	border: 2px solid var(--tn-primary);
	cursor: pointer;
}

.tn-range::-moz-range-thumb {
	width: 1.1rem;
	height: 1.1rem;
	border-radius: 50%;
	background: var(--tn-bg);
	border: 2px solid var(--tn-primary);
	cursor: pointer;
}

.tn-time {
	font-variant-numeric: tabular-nums;
	font-size: var(--tn-fs-sm);
	color: var(--tn-text-light);
	white-space: nowrap;
	min-width: 6.5rem;
	text-align: right;
}

.tn-select {
	min-height: 2.25rem;
	padding: 0 0.5rem;
	border: 1px solid var(--tn-border);
	border-radius: var(--tn-radius);
	background: var(--tn-bg);
	color: var(--tn-text);
	font-family: inherit;
	font-size: var(--tn-fs-sm);
}

.tn-volume {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	color: var(--tn-text-light);
}

.tn-player__transcript {
	margin-top: 1rem;
	border-top: 1px solid var(--tn-border);
	padding-top: 0.75rem;
}

.tn-player__transcript-toggle {
	cursor: pointer;
	font-size: var(--tn-fs-sm);
	font-weight: 600;
	color: var(--tn-primary);
	list-style: none;
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	padding: 0.25rem 0;
}

.tn-player__transcript-toggle::-webkit-details-marker {
	display: none;
}

.tn-player__transcript-toggle::before {
	content: "";
	width: 0.5rem;
	height: 0.5rem;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(-45deg);
	transition: transform 0.15s ease;
}

.tn-player__transcript[open] > .tn-player__transcript-toggle::before {
	transform: rotate(45deg);
}

.tn-player__transcript-body {
	max-height: 24rem;
	overflow: auto;
	padding: 0.75rem 1rem;
	margin-top: 0.5rem;
	background: var(--tn-bg-soft);
	border-radius: var(--tn-radius);
	font-size: var(--tn-fs-base);
	line-height: 1.6;
}

.tn-player__transcript-body p {
	margin: 0 0 0.75em;
}

.tn-player__transcript-body p:last-child {
	margin-bottom: 0;
}

.tn-sentence {
	cursor: pointer;
	border-radius: 3px;
	transition: background 0.2s ease;
}

.tn-sentence:hover {
	text-decoration: underline dotted;
	text-underline-offset: 3px;
}

.tn-sentence.tn-current {
	background: color-mix(in srgb, var(--tn-primary) 18%, transparent);
	box-shadow: 0 0 0 2px color-mix(in srgb, var(--tn-primary) 18%, transparent);
}

.tn-voice-name {
	margin-left: auto;
	font-size: var(--tn-fs-2xs);
	color: var(--tn-text-light);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 100%;
}

@supports not (background: color-mix(in srgb, #000 10%, transparent)) {
	.tn-sentence.tn-current {
		background: #d9eef1;
		box-shadow: 0 0 0 2px #d9eef1;
	}
}

.tn-player__download {
	margin: 0.75rem 0 0;
	font-size: var(--tn-fs-sm);
}

.tn-player__download a {
	color: var(--tn-primary);
	text-decoration: underline;
}

.tn-player__provenance {
	margin-top: 0.75rem;
	font-size: var(--tn-fs-2xs);
	color: var(--tn-text-light);
}

.tn-player__notice {
	margin: 0.5rem 0 0;
	padding: 0.6rem 0.9rem;
	border-left: 4px solid var(--tn-primary);
	background: var(--tn-bg-soft);
	border-radius: var(--tn-radius);
	font-size: var(--tn-fs-sm);
	line-height: 1.5;
}

@media (max-width: 480px) {
	.tn-player {
		padding: 1rem;
	}

	.tn-player__header {
		grid-template-columns: auto 1fr;
	}

	.tn-time {
		flex-basis: 100%;
		text-align: left;
		min-width: 0;
	}

	.tn-controls__row--secondary {
		justify-content: space-between;
	}
}

@media (prefers-reduced-motion: reduce) {
	.tn-btn,
	.tn-sentence,
	.tn-player__transcript-toggle::before {
		transition: none;
	}
}
