/*!
 * Bezubaan Core — reader styles
 * A quiet, dark room for the pages. Nothing competes with the art.
 */

:root {
	--bz-accent: #b3271e;
	--bz-ink: #0d0c0b;
	--bz-ink-2: #161412;
	--bz-paper: #ece3d4;
	--bz-muted: #9a8f7e;
	--bz-line: rgba(236, 227, 212, 0.14);
	--bz-chrome: 56px;
	--bz-pagewidth: 100%;
	--bz-brightness: 100%;
	--bz-radius: 4px;
	--bz-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html.bz-reader-html,
body.bz-reader {
	margin: 0;
	padding: 0;
	background: var(--bz-ink);
	color: var(--bz-paper);
	font-family: var(--bz-ui);
	-webkit-text-size-adjust: 100%;
	overscroll-behavior-y: none;
}

body.bz-reader {
	min-height: 100vh;
	/* Long-press save, text selection and callouts are noise while reading. */
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	user-select: none;
}

body.bz-reader img {
	-webkit-user-drag: none;
	user-drag: none;
	pointer-events: none;
}

.screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ---------- Progress ---------- */
.bz-progress {
	position: fixed;
	inset: 0 0 auto 0;
	height: 2px;
	background: rgba(255, 255, 255, 0.06);
	z-index: 60;
	pointer-events: none;
}

.bz-progress__fill {
	display: block;
	height: 100%;
	width: 0;
	background: var(--bz-accent);
	transition: width 0.12s linear;
}

/* ---------- Top bar ---------- */
.bz-topbar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 50;
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) minmax(0, 1fr);
	align-items: center;
	gap: 12px;
	height: var(--bz-chrome);
	padding: 0 14px;
	background: linear-gradient(to bottom, rgba(13, 12, 11, 0.96), rgba(13, 12, 11, 0.82));
	backdrop-filter: blur(10px);
	border-bottom: 1px solid var(--bz-line);
	transition: transform 0.25s ease, opacity 0.25s ease;
}

.bz-topbar a { color: inherit; text-decoration: none; }

.bz-topbar__back {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-width: 0;
	font-size: 13px;
	letter-spacing: 0.02em;
	color: var(--bz-muted);
}

.bz-topbar__back:hover { color: var(--bz-paper); }

.bz-topbar__arrow { font-size: 15px; }

.bz-topbar__seriestitle {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-weight: 600;
	color: var(--bz-paper);
}

.bz-topbar__meta {
	display: flex;
	flex-direction: column;
	align-items: center;
	min-width: 0;
	line-height: 1.25;
	text-align: center;
}

.bz-topbar__part {
	font-size: 9.5px;
	letter-spacing: 0.22em;
	text-transform: uppercase;
	color: var(--bz-accent);
	font-weight: 700;
}

.bz-topbar__chapter {
	font-size: 13px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	max-width: 100%;
}

.bz-topbar__num {
	color: var(--bz-muted);
	margin-right: 4px;
}

.bz-topbar__tools {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 6px;
}

.bz-counter {
	font-size: 12px;
	letter-spacing: 0.06em;
	color: var(--bz-muted);
	font-variant-numeric: tabular-nums;
	margin-right: 4px;
}

.bz-counter b { color: var(--bz-paper); font-weight: 600; }

.bz-tool {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 1px solid transparent;
	border-radius: var(--bz-radius);
	background: rgba(255, 255, 255, 0.05);
	color: var(--bz-paper);
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease;
}

.bz-tool:hover,
.bz-tool[aria-expanded="true"] {
	background: rgba(255, 255, 255, 0.12);
	border-color: var(--bz-line);
}

/* ---------- Settings panel ---------- */
.bz-settings {
	position: fixed;
	top: calc(var(--bz-chrome) + 8px);
	right: 12px;
	z-index: 55;
	width: min(320px, calc(100vw - 24px));
	padding: 16px;
	background: var(--bz-ink-2);
	border: 1px solid var(--bz-line);
	border-radius: 8px;
	box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
	font-size: 13px;
}

.bz-settings[hidden] { display: none; }

.bz-settings__group { margin-bottom: 14px; }

.bz-settings__label {
	display: block;
	margin-bottom: 6px;
	font-size: 10px;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	color: var(--bz-muted);
}

.bz-seg {
	display: flex;
	border: 1px solid var(--bz-line);
	border-radius: var(--bz-radius);
	overflow: hidden;
}

.bz-seg button {
	flex: 1;
	padding: 7px 6px;
	border: 0;
	background: transparent;
	color: var(--bz-muted);
	font: inherit;
	font-size: 12px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.bz-seg button + button { border-left: 1px solid var(--bz-line); }

.bz-seg button.is-active {
	background: var(--bz-accent);
	color: #fff;
}

.bz-settings input[type="range"] {
	width: 100%;
	accent-color: var(--bz-accent);
}

.bz-settings output {
	display: inline-block;
	margin-top: 4px;
	font-size: 11px;
	color: var(--bz-muted);
	font-variant-numeric: tabular-nums;
}

.bz-settings__hint {
	margin: 0;
	font-size: 11px;
	color: rgba(154, 143, 126, 0.8);
}

/* ---------- Stage ---------- */
.bz-stage {
	padding: calc(var(--bz-chrome) + 10px) 0 0;
	min-height: 100vh;
	filter: brightness(var(--bz-brightness));
}

.bz-pages {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	margin: 0 auto;
	padding: 0 0 12px;
}

.bz-page {
	position: relative;
	margin: 0;
	width: min(var(--bz-pagewidth), 100%);
	max-width: 980px;
	display: flex;
	justify-content: center;
	background: #f6efe2;
	border-radius: 2px;
	overflow: hidden;
	box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}

.bz-page img {
	display: block;
	width: 100%;
	height: auto;
}

.bz-page__folio {
	position: absolute;
	right: 8px;
	bottom: 6px;
	padding: 1px 6px;
	font-size: 10px;
	font-variant-numeric: tabular-nums;
	color: rgba(20, 16, 12, 0.45);
	background: rgba(246, 239, 226, 0.7);
	border-radius: 20px;
	pointer-events: none;
}

.bz-page__wm {
	position: absolute;
	max-width: 70%;
	padding: 2px 8px;
	font-size: 11px;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	color: rgba(20, 16, 12, 0.9);
	opacity: var(--bz-wm-opacity, 0.14);
	pointer-events: none;
}

.bz-page__wm--bottom-right { right: 12px; bottom: 26px; }
.bz-page__wm--bottom-left { left: 12px; bottom: 26px; }
.bz-page__wm--center { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.bz-page__wm--top-right { right: 12px; top: 12px; }

/* Single / double page modes */
.bz-pages--single .bz-page,
.bz-pages--double .bz-page { display: none; }

.bz-pages--single .bz-page.is-active,
.bz-pages--double .bz-page.is-active,
.bz-pages--double .bz-page.is-active + .bz-page.is-active { display: flex; }

.bz-pages--double { flex-direction: row; justify-content: center; align-items: flex-start; flex-wrap: wrap; }
.bz-pages--double .bz-page { width: min(48%, var(--bz-pagewidth)); }
/* .bz-pages already carries direction: rtl, which lays the spread out
   right-to-left; row-reverse here would cancel it and put the opening
   page on the left, where manga readers would read it last. */
.bz-stage[data-direction="rtl"] .bz-pages--double { flex-direction: row; }
.bz-stage[data-direction="rtl"] .bz-pages { direction: rtl; }

/*
 * Paged modes are for reading one spread at a time, so the whole page has to
 * be on screen at once — no scrolling inside a page. Fit by height as well as
 * width, and centre what is left.
 */
.bz-pages--single,
.bz-pages--double {
	min-height: calc(100vh - var(--bz-chrome) - 54px);
	min-height: calc(100dvh - var(--bz-chrome) - 54px);
	justify-content: center;
	padding-bottom: 0;
}

.bz-pages--single .bz-page,
.bz-pages--double .bz-page {
	width: auto;
	max-width: min(var(--bz-pagewidth), 100%);
	max-height: calc(100vh - var(--bz-chrome) - 54px);
	max-height: calc(100dvh - var(--bz-chrome) - 54px);
	align-items: center;
}

.bz-pages--single .bz-page img,
.bz-pages--double .bz-page img {
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: calc(100vh - var(--bz-chrome) - 54px);
	max-height: calc(100dvh - var(--bz-chrome) - 54px);
	object-fit: contain;
}

/* The page numbers and watermark sit on the artwork, so keep them inside it. */
.bz-pages--single .bz-page__folio,
.bz-pages--double .bz-page__folio { bottom: 4px; right: 6px; }

.bz-empty {
	padding: 25vh 20px;
	text-align: center;
	color: var(--bz-muted);
}

/* Canvas shield */
.bz-page canvas {
	display: block;
	width: 100%;
	height: auto;
}

.bz-page img.bz-hidden { display: none; }

/* ---------- Bottom bar ---------- */
.bz-bottombar {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 45;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 8px 14px calc(8px + env(safe-area-inset-bottom, 0px));
	background: linear-gradient(to top, rgba(13, 12, 11, 0.97), rgba(13, 12, 11, 0.7));
	border-top: 1px solid var(--bz-line);
	font-size: 12px;
	transition: transform 0.25s ease, opacity 0.25s ease;
}

.bz-bottombar__hint {
	color: var(--bz-muted);
	font-size: 11px;
	letter-spacing: 0.04em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.bz-navbtn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 7px 12px;
	border: 1px solid var(--bz-line);
	border-radius: var(--bz-radius);
	color: var(--bz-paper);
	text-decoration: none;
	font-size: 12px;
	white-space: nowrap;
	transition: background 0.15s ease;
}

.bz-navbtn:hover { background: rgba(255, 255, 255, 0.08); }

/* The start-over control is a <button>, so it needs the reset a link gets
   for free — same height, same look, no platform chrome. */
.bz-navbtn--restart {
	background: none;
	font: inherit;
	font-size: 12px;
	line-height: inherit;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.bz-navbtn--restart:hover { border-color: var(--bz-accent, #b3271e); }

.bz-navbtn.is-disabled {
	opacity: 0.32;
	pointer-events: none;
}

/* Chrome auto-hide while scrolling */
.bz-reader.is-immersive .bz-topbar { transform: translateY(-100%); opacity: 0; }
.bz-reader.is-immersive .bz-bottombar { transform: translateY(100%); opacity: 0; }
.bz-reader.is-immersive .bz-stage { padding-top: 8px; }

/* ---------- End card ---------- */
.bz-endcard {
	max-width: 620px;
	margin: 40px auto 96px;
	padding: 32px 24px;
	background: var(--bz-ink-2);
	border: 1px solid var(--bz-line);
	border-radius: 8px;
	text-align: center;
}

.bz-endcard__eyebrow {
	margin: 0 0 8px;
	font-size: 10px;
	letter-spacing: 0.24em;
	text-transform: uppercase;
	color: var(--bz-accent);
	font-weight: 700;
}

.bz-endcard__title {
	margin: 0 0 12px;
	font-size: clamp(19px, 3vw, 26px);
	line-height: 1.2;
	font-weight: 700;
}

.bz-endcard__note,
.bz-endcard__credits {
	margin: 0 auto 14px;
	max-width: 46ch;
	font-size: 13.5px;
	line-height: 1.65;
	color: rgba(236, 227, 212, 0.78);
}

.bz-endcard__credits {
	font-size: 11.5px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--bz-muted);
}

.bz-endcard__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	justify-content: center;
	margin: 22px 0 16px;
}

.bz-endcard__last {
	font-size: 13px;
	color: var(--bz-muted);
	align-self: center;
}

.bz-endcard__serieslink {
	margin: 0;
	font-size: 12px;
	color: var(--bz-muted);
}

.bz-endcard__serieslink a { color: var(--bz-paper); }

/* ---------- Buttons ---------- */
.bz-btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 10px 18px;
	border: 1px solid var(--bz-line);
	border-radius: var(--bz-radius);
	background: transparent;
	color: var(--bz-paper);
	font-family: inherit;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.02em;
	text-decoration: none;
	cursor: pointer;
	transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.bz-btn:hover { transform: translateY(-1px); }

.bz-btn--accent {
	background: var(--bz-accent);
	border-color: var(--bz-accent);
	color: #fff;
}

.bz-btn--ghost:hover { border-color: var(--bz-paper); }

.bz-btn--lg { padding: 14px 26px; font-size: 14px; }

/* Buttons stay legible even when other plugin stylesheets load later. */
body.bz-reader .bz-btn {
	border: 1px solid var(--bz-line);
	background: transparent;
	color: var(--bz-paper);
	border-radius: var(--bz-radius);
	font-family: inherit;
	font-size: 13px;
	font-weight: 600;
	text-decoration: none;
}

body.bz-reader .bz-btn--accent {
	background: var(--bz-accent);
	border-color: var(--bz-accent);
	color: #fff;
}

body.bz-reader .bz-btn--ghost:hover,
body.bz-reader .bz-btn--outline:hover {
	border-color: var(--bz-paper);
}

body.bz-reader .bz-follow {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
}

body.bz-reader .bz-follow__dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--bz-muted);
}

body.bz-reader .bz-follow.is-following .bz-follow__dot {
	background: #4ec07d;
}

body.bz-reader .bz-follow.is-following {
	border-color: #4ec07d;
	color: #b6e7c9;
}

/* ---------- Locked chapter ---------- */
.bz-lock {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 78vh;
	padding: 40px 20px;
}

.bz-lock__inner {
	max-width: 440px;
	width: 100%;
	padding: 34px 28px;
	background: var(--bz-ink-2);
	border: 1px solid var(--bz-line);
	border-radius: 8px;
	text-align: center;
}

.bz-lock__eyebrow {
	margin: 0 0 8px;
	font-size: 10px;
	letter-spacing: 0.24em;
	text-transform: uppercase;
	color: var(--bz-accent);
	font-weight: 700;
}

.bz-lock__title {
	margin: 0 0 14px;
	font-size: 24px;
	line-height: 1.2;
}

.bz-lock__text {
	margin: 0 0 18px;
	font-size: 13.5px;
	line-height: 1.65;
	color: rgba(236, 227, 212, 0.75);
}

.bz-lock__error {
	margin: 0 0 14px;
	font-size: 12.5px;
	color: #ff8d84;
}

.bz-lock__form {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	justify-content: center;
}

.bz-lock__form input[type="password"] {
	flex: 1 1 180px;
	min-width: 0;
	padding: 11px 13px;
	border: 1px solid var(--bz-line);
	border-radius: var(--bz-radius);
	background: rgba(255, 255, 255, 0.04);
	color: var(--bz-paper);
	font: inherit;
	font-size: 13px;
}

.bz-lock__links {
	display: flex;
	gap: 16px;
	justify-content: center;
	margin: 20px 0 0;
	font-size: 12.5px;
}

.bz-lock__links a { color: var(--bz-muted); }
.bz-lock__links a:hover { color: var(--bz-paper); }

/* ---------- Toast ---------- */
.bz-toast {
	position: fixed;
	left: 50%;
	bottom: 74px;
	transform: translateX(-50%) translateY(12px);
	z-index: 70;
	padding: 9px 16px;
	background: rgba(20, 18, 16, 0.95);
	border: 1px solid var(--bz-line);
	border-radius: 40px;
	font-size: 12px;
	color: var(--bz-paper);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.bz-toast.is-visible {
	opacity: 1;
	transform: translateX(-50%) translateY(0);
}

/* ---------- Print is not a reading mode ---------- */
@media print {
	body.bz-reader { background: #fff !important; }
	.bz-page,
	.bz-page img,
	.bz-pages { display: none !important; }
	.bz-stage::after {
		content: "Bezubaan is meant to be read online. Printing and downloading are not permitted.";
		display: block;
		padding: 40px;
		font: 14px/1.6 var(--bz-ui);
		color: #000;
		text-align: center;
	}
	.bz-topbar,
	.bz-bottombar,
	.bz-settings,
	.bz-progress { display: none !important; }
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
	:root { --bz-chrome: 50px; }

	.bz-topbar {
		grid-template-columns: auto minmax(0, 1fr) auto;
		gap: 8px;
		padding: 0 10px;
	}

	.bz-topbar__seriestitle,
	.bz-counter { display: none; }

	.bz-topbar__meta { align-items: flex-start; text-align: left; }
	.bz-page { border-radius: 0; box-shadow: none; }
	.bz-pages { gap: 3px; }
	.bz-bottombar__hint { display: none; }
	.bz-navbtn { padding: 7px 10px; }
	.bz-pages--double .bz-page { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
	* { transition: none !important; animation: none !important; }
}

/* A page that failed to load: say it plainly, never leave a black box. */
.bz-page.is-broken {
	min-height: 46vh;
	background: repeating-linear-gradient(
		135deg,
		#201a14,
		#201a14 12px,
		#241d16 12px,
		#241d16 24px
	);
}

.bz-page.is-broken img {
	opacity: 0;
}

.bz-page__error {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 24px;
	text-align: center;
	color: #f6efe2;
}

.bz-page__error-title {
	margin: 0;
	font-family: var(--bz-font-ui, system-ui, sans-serif);
	font-size: 15px;
	letter-spacing: 0.02em;
}

.bz-page__error-url {
	max-width: 100%;
	font-size: 10px;
	line-height: 1.4;
	color: rgba(246, 239, 226, 0.55);
	word-break: break-all;
	user-select: text;
}
