/**
 * AnimeHub Player v3 — Skin overlay on top of Vidstack default theme.
 *
 * Order of imports in the consuming bundle:
 *   1. vidstack/player/styles/default/theme.css
 *   2. vidstack/player/styles/default/layouts/video.css
 *   3. this file (skin.css) — overrides + 5 brand variants
 *
 * Skin selection: <body class="ah-skin-{modern|anime|minimal|cinema|default}">
 * Default skin = `default` when no class present.
 */

/* ---------------------------------------------------------------------------
 * 0. Fonts — Gotham Rounded Bold (commercial; place files in assets/fonts/).
 *    Falls back to Nunito/system until the files are uploaded.
 * ------------------------------------------------------------------------ */
@font-face {
	font-family: "Gotham Rounded";
	src: url("../../../fonts/gotham-rounded-bold.woff2") format("woff2"),
	     url("../../../fonts/gotham-rounded-bold.woff") format("woff");
	font-weight: 700;
	font-style: normal;
	font-display: swap;
}

/* ---------------------------------------------------------------------------
 * 1. Base brand vars (always applied)
 * ------------------------------------------------------------------------ */
:root {
	--ah-player-radius: 8px;
	--ah-player-bg: #000;
	--ah-player-accent: #ff6b35;
	--ah-player-accent-2: #ffa600;
	--ah-player-control-color: #fff;
	--ah-player-focus-ring: 2px solid var(--ah-player-accent);
}

/* Map our vars into Vidstack vars. Spec: https://vidstack.io/docs/player/styling */
media-player[data-animehub-player] {
	--media-brand: var(--ah-player-accent);
	--media-focus-ring: var(--ah-player-focus-ring);
	--media-controls-color: var(--ah-player-control-color);
	--video-bg: var(--ah-player-bg);

	border-radius: var(--ah-player-radius);
	overflow: hidden;
	background: var(--ah-player-bg);
	aspect-ratio: 16 / 9;
	width: 100%;
	max-width: 100%;
	display: block;
}

/* Container guard — Vidstack uses display:contents on layouts.
 *
 * P8.H7a — match pre-P8.H7 video page behavior: cap at theme container
 * width only (no 70vh height guard). Player width is consistent across
 * viewport sizes; the height dominance trade-off is accepted per user
 * request. The padding-top:0 reset below (line 76) still prevents the
 * legacy aspect-ratio stacking bug.
 */
.animehub-episode-player-section {
	max-width: var(--animehub-container, 1400px);
	margin-left: auto;
	margin-right: auto;
}
.animehub-player-container,
.ah-player-container {
	position: relative;
	max-width: 100%;
	margin-left: auto;
	margin-right: auto;
}

/* CRITICAL: the legacy theme uses the classic `padding-top: 56.25%` aspect
 * ratio trick on .animehub-player-wrapper so that absolutely-positioned <video>
 * fills 16:9. Vidstack <media-player> renders in flow with its own
 * `aspect-ratio: 16/9` — combining the two stacks heights and makes the player
 * dominate the viewport. Reset the padding for v3 and re-flow normally. */
.animehub-player-wrapper {
	position: relative;
	padding-top: 0 !important;
	height: auto !important;
}

/* Loading + error overlays (we keep custom because Vidstack's are minimal). */
.animehub-player-wrapper { position: relative; }
.animehub-player-wrapper .player-overlay {
	position: absolute; inset: 0; z-index: 5;
	display: flex; flex-direction: column; align-items: center; justify-content: center;
	gap: 12px; background: rgba(0, 0, 0, 0.6); color: #fff;
}

/* ---------------------------------------------------------------------------
 * 2. Skin: default (orange accent, balanced)
 * ------------------------------------------------------------------------ */
body.ah-skin-default media-player[data-animehub-player],
body:not([class*="ah-skin-"]) media-player[data-animehub-player] {
	--ah-player-accent: #ff6b35;
	--ah-player-radius: 8px;
}

/* ---------------------------------------------------------------------------
 * 3. Skin: modern (neon cyan, sharp corners, frosted controls)
 * ------------------------------------------------------------------------ */
body.ah-skin-modern media-player[data-animehub-player] {
	--ah-player-accent: #00e0ff;
	--ah-player-accent-2: #7a5cff;
	--ah-player-radius: 4px;
}
body.ah-skin-modern media-player[data-animehub-player]::part(controls) {
	backdrop-filter: blur(6px);
	background: linear-gradient(to top, rgba(10, 12, 24, 0.85), transparent);
}

/* ---------------------------------------------------------------------------
 * 4. Skin: anime (pink/purple gradient, rounded, playful)
 * ------------------------------------------------------------------------ */
body.ah-skin-anime media-player[data-animehub-player] {
	--ah-player-accent: #ff4d8d;
	--ah-player-accent-2: #b266ff;
	--ah-player-radius: 16px;
}
body.ah-skin-anime media-player[data-animehub-player] {
	box-shadow: 0 0 32px rgba(255, 77, 141, 0.18);
}

/* ---------------------------------------------------------------------------
 * 5. Skin: minimal (mono palette, no border, tight controls)
 * ------------------------------------------------------------------------ */
body.ah-skin-minimal media-player[data-animehub-player] {
	--ah-player-accent: #fafafa;
	--ah-player-radius: 0px;
	--media-controls-color: #fafafa;
}
body.ah-skin-minimal media-player[data-animehub-player] {
	border: 1px solid #1a1a1a;
}

/* ---------------------------------------------------------------------------
 * 6. Skin: cinema (black bars, gold accent, maximum contrast)
 * ------------------------------------------------------------------------ */
body.ah-skin-cinema media-player[data-animehub-player] {
	--ah-player-accent: #d4af37;
	--ah-player-accent-2: #fff5cc;
	--ah-player-radius: 0;
	--video-bg: #050505;
}
body.ah-skin-cinema .animehub-player-wrapper {
	padding: 18px 0;
	background: linear-gradient(180deg, #000 0%, #050505 50%, #000 100%);
}

/* ---------------------------------------------------------------------------
 * 7. Captions / subtitles — Gotham Rounded Bold + static colored glow.
 *    Glow color follows the active skin accent; override --ah-cap-glow to pin
 *    a fixed color. Vidstack reads the --media-captions-* vars; font-family is
 *    applied directly on the rendered cue element (no Vidstack var for it).
 * ------------------------------------------------------------------------ */
media-player[data-animehub-player] {
	--ah-cap-glow: #8b0000;          /* đỏ thẫm — đổi tại đây nếu cần */
	--ah-cap-stroke: 1.8px;          /* độ dày viền đen */
	--media-captions-bg: transparent;
	--media-captions-color: #fff;
	--media-captions-font-size: 1.32em;
	--media-captions-line-height: 1.32;
	/* Viền đen lo bằng -webkit-text-stroke (rule cue bên dưới); text-shadow
	 * chỉ phụ trách quầng glow đỏ thẫm — nhiều lớp cho đậm/nổi. */
	--media-captions-text-shadow:
		0 0 6px var(--ah-cap-glow),
		0 0 16px var(--ah-cap-glow),
		0 0 28px var(--ah-cap-glow);
}

/* Kill Vidstack's default dark cue box (the --media-captions-bg var alone is
 * not enough in this build) — force transparent so only the glow/outline show. */
media-player[data-animehub-player] :where(
	media-captions,
	.vds-captions,
	media-captions [data-part="cue"],
	.vds-captions [data-part="cue"],
	media-captions [data-part="cue-display"]
) {
	background: transparent !important;
	background-color: transparent !important;
	box-shadow: none !important;
	backdrop-filter: none !important;
}

/* Apply the font to the actual cue text element. */
media-player[data-animehub-player] :where(
	media-captions [data-part="cue"],
	.vds-captions [data-part="cue"]
) {
	font-family: "Gotham Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
	font-weight: 700;
	letter-spacing: .3px;
	padding: 0 .15em !important;
	/* Viền đen dày, sắc nét; paint-order giữ phần chữ trắng nằm trên viền. */
	-webkit-text-stroke: var(--ah-cap-stroke) #000;
	paint-order: stroke fill;
}

/* ---------------------------------------------------------------------------
 * 8. Theater mode (body class toggled by custom button)
 * ------------------------------------------------------------------------ */
body.ah-theater .animehub-player-container {
	max-width: 100vw !important;
	width: 100vw !important;
	margin-left: calc(50% - 50vw);
}
body.ah-theater media-player[data-animehub-player] {
	border-radius: 0;
	aspect-ratio: auto;
	height: calc(100vh - 80px);
}

/* ---------------------------------------------------------------------------
 * 9. Controls bar — v3 polish (overrides legacy episode.css)
 *
 * Layout zones:
 *   [Server switcher] [Episode dropdown + nav]   ⟵spacer⟶   [Tools] [Download]
 *
 * Achieved with `margin-left: auto` on the first right-aligned item.
 * ------------------------------------------------------------------------ */
.animehub-episode-controls {
	display: flex;
	flex-wrap: wrap;
	gap: 10px 18px;
	padding: 12px 18px;
	background: linear-gradient(180deg, #1f1f23 0%, #18181b 100%);
	border: 1px solid #2a2a2f;
	border-top: 0;
	border-bottom-left-radius: var(--ah-player-radius);
	border-bottom-right-radius: var(--ah-player-radius);
	align-items: center;
	justify-content: center;
	margin-top: 0;
}

.animehub-episode-controls .control-inline label {
	font-size: 11px;
	font-weight: 600;
	color: #8a8a93;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	white-space: nowrap;
}

/* Subtle divider between groups. */
.animehub-episode-controls .control-item + .control-item:not(.control-item-download) {
	border-left: 1px solid #2a2a2f;
	padding-left: 18px;
	margin-left: 0;
}

/* Server buttons — refined pills. */
.animehub-server-switcher .server-list {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
}
.animehub-server-switcher .server-btn {
	background: #2a2a30;
	border: 1px solid transparent;
	color: #e8e8ed;
	padding: 7px 14px;
	border-radius: 999px;
	cursor: pointer;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.04em;
	line-height: 1;
	transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
	display: inline-flex;
	align-items: center;
	gap: 6px;
}
.animehub-server-switcher .server-btn small {
	font-size: 10px;
	font-weight: 700;
	padding: 2px 5px;
	border-radius: 3px;
	background: rgba(255, 255, 255, 0.08);
	color: #c3c3cb;
	line-height: 1;
}
.animehub-server-switcher .server-btn:hover {
	background: #34343c;
	color: #fff;
	transform: translateY(-1px);
}
.animehub-server-switcher .server-btn.active {
	background: var(--ah-player-accent);
	color: #fff;
	box-shadow: 0 2px 8px rgba(255, 107, 53, 0.35);
}
.animehub-server-switcher .server-btn.active small {
	background: rgba(0, 0, 0, 0.25);
	color: #fff;
}

/* Episode dropdown. */
.animehub-episode-controls .episode-dropdown {
	background: #2a2a30;
	border: 1px solid transparent;
	color: #e8e8ed;
	padding: 7px 28px 7px 12px;
	border-radius: 8px;
	font-size: 12px;
	font-weight: 600;
	cursor: pointer;
	appearance: none;
	-webkit-appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23c3c3cb' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 10px center;
}
.animehub-episode-controls .episode-dropdown:hover {
	background-color: #34343c;
}

/* Prev/Next nav. */
.episode-quick-nav {
	display: inline-flex;
	gap: 4px;
}
.episode-quick-nav .quick-nav-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	background: #2a2a30;
	color: #e8e8ed;
	border-radius: 6px;
	text-decoration: none;
	font-size: 16px;
	line-height: 1;
	transition: background 0.15s ease, color 0.15s ease;
}
.episode-quick-nav .quick-nav-btn:hover {
	background: var(--ah-player-accent);
	color: #fff;
}
.episode-quick-nav .quick-nav-btn.disabled {
	opacity: 0.35;
	pointer-events: none;
}

/* Player tools (theater / future buttons). */
.animehub-episode-controls .player-enhanced-controls {
	margin-left: 0;
}
.animehub-player-controls-enhanced {
	display: inline-flex;
	gap: 6px;
}
.player-control-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	background: #2a2a30;
	color: #e8e8ed;
	border: 0;
	border-radius: 8px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}
.player-control-btn:hover {
	background: var(--ah-player-accent);
	color: #fff;
}
.player-control-btn .control-icon {
	font-size: 16px;
	line-height: 1;
}

/* Download button — right-most pinned. */
.animehub-episode-controls .control-item-download {
	margin-left: 0;
}
.animehub-episode-controls .download-btn {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	background: var(--ah-player-accent);
	color: #fff;
	padding: 8px 14px;
	border-radius: 8px;
	text-decoration: none;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.04em;
	border: 0;
	box-shadow: 0 2px 8px rgba(255, 107, 53, 0.25);
	transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.animehub-episode-controls .download-btn:hover {
	background: #ff7d50;
	transform: translateY(-1px);
	box-shadow: 0 4px 14px rgba(255, 107, 53, 0.45);
	color: #fff;
}
.animehub-episode-controls .download-btn svg {
	width: 14px;
	height: 14px;
}

/* Mobile collapse. */
@media (max-width: 640px) {
	.animehub-episode-controls {
		padding: 10px 12px;
		gap: 8px 12px;
	}
	.animehub-episode-controls .control-item + .control-item:not(.control-item-download) {
		border-left: 0;
		padding-left: 0;
	}
	.animehub-episode-controls .player-enhanced-controls,
	.animehub-episode-controls .control-item-download {
		margin-left: 0;
	}
}

/* ---------------------------------------------------------------------------
 * 10. Mobile (≤ 768px) — disable some Vidstack hover-only chrome
 * ------------------------------------------------------------------------ */
@media (max-width: 768px) {
	media-player[data-animehub-player] {
		--media-controls-padding-x: 8px;
		--media-controls-padding-y: 6px;
	}
}
