/**
 * MangaVerse Drive Sync - Viewer styles
 *
 * Viewer fluide pour la lecture de chapitres, en mode webtoon (par défaut)
 * ou page-par-page. Compatible thème clair et sombre du theme MangaVerse.
 */

:root {
	--mvds-bg:           #0a0a0a;
	--mvds-surface:      rgba(20, 20, 20, 0.92);
	--mvds-text:         #f5f5f5;
	--mvds-text-muted:   #999;
	--mvds-accent:       #e63946;
	--mvds-toolbar-h:    56px;
}

/* Le viewer prend tout l'écran et change le fond global */
body:has(.mvds-viewer) {
	background: var(--mvds-bg) !important;
}

/* Conteneur principal */
.mvds-viewer {
	min-height: 100vh;
	color: var(--mvds-text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
	-webkit-font-smoothing: antialiased;
}

/* -----------------------------------------------------------------------------
   Toolbar (sticky)
   ----------------------------------------------------------------------------- */

.mvds-toolbar {
	position: sticky;
	top: 0;
	z-index: 100;
	background: var(--mvds-surface);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	border-bottom: 1px solid rgba(255,255,255,0.08);
	transition: transform 250ms ease;
}

.mvds-toolbar.is-hidden {
	transform: translateY(-100%);
}

.mvds-toolbar__inner {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: center;
	gap: 16px;
	max-width: 1400px;
	margin: 0 auto;
	padding: 0 16px;
	height: var(--mvds-toolbar-h);
}

.mvds-toolbar__back {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	color: var(--mvds-text);
	text-decoration: none;
	padding: 6px 10px;
	border-radius: 6px;
	max-width: 320px;
	transition: background 150ms;
}

.mvds-toolbar__back:hover {
	background: rgba(255,255,255,0.06);
	color: var(--mvds-text);
}

.mvds-toolbar__back-text {
	font-weight: 600;
	font-size: 14px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.mvds-toolbar__center {
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	line-height: 1.2;
}

.mvds-toolbar__chapter {
	font-weight: 700;
	font-size: 14px;
}

.mvds-toolbar__pages {
	font-size: 12px;
	color: var(--mvds-text-muted);
	margin-top: 2px;
}

.mvds-toolbar__right {
	display: flex;
	justify-content: flex-end;
	gap: 4px;
}

.mvds-toolbar__btn {
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	background: transparent;
	border: 0;
	color: var(--mvds-text);
	border-radius: 6px;
	cursor: pointer;
	transition: background 150ms;
}

.mvds-toolbar__btn:hover {
	background: rgba(255,255,255,0.08);
}

.mvds-toolbar__btn:focus-visible {
	outline: 2px solid var(--mvds-accent);
	outline-offset: 2px;
}

@media (max-width: 640px) {
	.mvds-toolbar__back-text {
		display: none;
	}
}

/* -----------------------------------------------------------------------------
   Pages (mode WEBTOON par défaut : vertical, pas de gap)
   ----------------------------------------------------------------------------- */

.mvds-pages {
	max-width: 900px;
	margin: 0 auto;
	padding: 0;
}

.mvds-page {
	margin: 0;
	padding: 0;
	position: relative;
	background: #000;
}

.mvds-page__img {
	display: block;
	width: 100%;
	height: auto;
	margin: 0 auto;
	max-width: 100%;
	/* aspect-ratio fallback pour éviter le CLS pendant le chargement */
	aspect-ratio: 2 / 3;
	object-fit: contain;
	background: #111;
}

.mvds-page__img[src] {
	aspect-ratio: auto;
}

.mvds-page__num {
	position: absolute;
	top: 12px;
	right: 12px;
	background: rgba(0,0,0,0.6);
	color: #fff;
	font-size: 11px;
	font-weight: 600;
	padding: 3px 8px;
	border-radius: 4px;
	font-variant-numeric: tabular-nums;
	opacity: 0;
	transition: opacity 200ms;
	pointer-events: none;
}

.mvds-page:hover .mvds-page__num {
	opacity: 1;
}

/* -----------------------------------------------------------------------------
   MODE PAGED : une page à la fois
   ----------------------------------------------------------------------------- */

.mvds-viewer[data-mode="paged"] .mvds-pages {
	display: flex;
	height: calc(100vh - var(--mvds-toolbar-h));
	overflow: hidden;
	scroll-snap-type: x mandatory;
	overflow-x: auto;
	scroll-behavior: smooth;
	max-width: none;
}

.mvds-viewer[data-mode="paged"] .mvds-pages::-webkit-scrollbar {
	display: none;
}

.mvds-viewer[data-mode="paged"] .mvds-page {
	flex: 0 0 100%;
	width: 100%;
	height: 100%;
	scroll-snap-align: start;
	display: grid;
	place-items: center;
	background: var(--mvds-bg);
}

.mvds-viewer[data-mode="paged"] .mvds-page__img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: 100%;
	aspect-ratio: auto;
	object-fit: contain;
}

.mvds-viewer[data-mode="paged"] .mvds-page__num {
	top: auto;
	bottom: 16px;
	right: 16px;
	font-size: 13px;
	padding: 6px 12px;
	opacity: 1;
}

/* -----------------------------------------------------------------------------
   Navigation chapitres (en bas)
   ----------------------------------------------------------------------------- */

.mvds-chapter-nav {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	max-width: 900px;
	margin: 32px auto;
	padding: 16px;
	background: var(--mvds-surface);
	border-radius: 12px;
	border: 1px solid rgba(255,255,255,0.08);
}

.mvds-chapter-nav__btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 12px 20px;
	background: rgba(255,255,255,0.04);
	color: var(--mvds-text);
	text-decoration: none;
	border-radius: 8px;
	font-size: 14px;
	font-weight: 600;
	border: 1px solid rgba(255,255,255,0.06);
	transition: all 150ms;
	min-height: 44px;
}

.mvds-chapter-nav__btn:hover {
	background: var(--mvds-accent);
	border-color: var(--mvds-accent);
	color: #fff;
}

.mvds-chapter-nav__btn--list {
	background: transparent;
	border-color: rgba(255,255,255,0.15);
}

.mvds-chapter-nav__btn--disabled {
	opacity: 0.35;
	cursor: not-allowed;
	pointer-events: none;
}

@media (max-width: 640px) {
	.mvds-chapter-nav {
		flex-direction: column;
		margin: 16px;
	}
	.mvds-chapter-nav__btn {
		width: 100%;
		justify-content: center;
	}
}

/* -----------------------------------------------------------------------------
   Empty state (chapitre sans pages)
   ----------------------------------------------------------------------------- */

.mvds-empty-chapter {
	max-width: 480px;
	margin: 80px auto;
	text-align: center;
	padding: 40px 20px;
	color: var(--mvds-text-muted);
	background: var(--mvds-surface);
	border-radius: 12px;
}

/* -----------------------------------------------------------------------------
   Mode plein écran
   ----------------------------------------------------------------------------- */

.mvds-viewer:fullscreen,
.mvds-viewer:-webkit-full-screen {
	background: var(--mvds-bg);
	overflow-y: auto;
}

/* -----------------------------------------------------------------------------
   Indicateur de progression (top bar de scroll)
   ----------------------------------------------------------------------------- */

.mvds-progress {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	height: 3px;
	background: rgba(255,255,255,0.05);
	z-index: 200;
}

.mvds-progress__bar {
	height: 100%;
	width: 0%;
	background: var(--mvds-accent);
	transition: width 100ms ease-out;
}

/* Respecte prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
	.mvds-toolbar,
	.mvds-toolbar__btn,
	.mvds-chapter-nav__btn,
	.mvds-progress__bar {
		transition: none;
	}
}
