/*
 * Reader styles. The palette is the Children of America / Just Read one from the
 * original reader: a pale ocean sky behind the book, white pill controls with purple
 * text, so the book itself stays the most colourful thing on screen. The stage is a
 * flexible box that bookLayout.js measures; StPageFlip draws the book at the fitted
 * size inside it, so nothing here sets the book's dimensions.
 */
:root {
	--ocean-deep: #0b3d63;
	--ocean-mid: #1f7fb8;
	--ocean-soft: #cdeaf7;
	--sand: #f7ecd6;
	--coa-purple: #7c2d8f;
	--ink: #2a2f3a;
	--lit: #ffd54a;
	--find: #a23bc0;
	--page-radius: 18px;
	--stage-gradient: linear-gradient(180deg, #e8f6fd 0%, #d2ecf8 55%, #bfe3f4 100%);
	--surface: #ffffff;
	--surface-hover: #faf3fc;
	--header-surface: rgba(255, 255, 255, 0.82);
	--control-border: rgba(124, 45, 143, 0.25);
	--lit-glow: rgba(255, 213, 74, 0.45);
	--line: var(--ocean-soft);
	--backdrop: rgba(11, 61, 99, 0.55);
	--shadow-soft: 0 0.25rem 1rem rgba(11, 61, 99, 0.12);
	--shadow-book: 0 0.75rem 2rem rgba(11, 61, 99, 0.24);
	--radius-pill: 999px;
	--control-size: 2.75rem;
	--control-font-size: clamp(12px, 1.3vw, 16px);
	--control-padding: clamp(7px, 0.9vw, 10px) clamp(12px, 1.6vw, 20px);
	--control-transition: transform 0.12s ease, background-color 0.12s ease;
	--control-lift: translateY(-1px);
	/* Kept high enough that purple text on white still clears WCAG AA (about 4.7:1). */
	--control-disabled-opacity: 0.78;
	--gap: 0.75rem;
	font-family: "Nunito", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	color: var(--ink);
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html,
body {
	height: 100%;
	margin: 0;
	overflow: hidden;
}

body {
	background: var(--stage-gradient);
}

[hidden] {
	display: none !important;
}

/*
 * The reader fills the viewport (or the screen in fullscreen) as header, stage,
 * controls. It repeats the body gradient because a fullscreen element is painted
 * over a black backdrop rather than over the body.
 */
.reader {
	display: grid;
	grid-template-rows: auto minmax(0, 1fr) auto;
	height: 100%;
	height: 100dvh;
	background: var(--stage-gradient);
}

.reader:fullscreen {
	height: 100vh;
}

/* ---------- Header: logo, title, tools ---------- */

.reader__header {
	display: flex;
	align-items: center;
	gap: var(--gap);
	padding: 0.625rem 1rem;
	background: var(--header-surface);
	border-bottom: 2px solid var(--line);
	box-shadow: var(--shadow-soft);
}

.reader__logo {
	flex: none;
	width: auto;
	height: 2rem;
}

.reader__title {
	flex: 1 1 auto;
	min-width: 0;
	margin: 0;
	font-size: clamp(1.05rem, 2.4vw, 1.5rem);
	font-weight: 800;
	line-height: 1.2;
	letter-spacing: 0.01em;
	color: var(--coa-purple);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.reader__tools {
	display: flex;
	flex: none;
	gap: 0.5rem;
}

/* ---------- Buttons ---------- */

/*
 * Every control (page turns, Pages, fullscreen, overlay close) is the original
 * reader's white pill, so the chrome reads as one quiet set around the book.
 */
.reader__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.375rem;
	min-width: var(--control-size);
	min-height: var(--control-size);
	padding: var(--control-padding);
	border: 2px solid var(--control-border);
	border-radius: var(--radius-pill);
	font: inherit;
	font-size: var(--control-font-size);
	font-weight: 700;
	color: var(--coa-purple);
	background: var(--surface);
	cursor: pointer;
	transition: var(--control-transition);
}

.reader__button:hover:not(:disabled) {
	transform: var(--control-lift);
	background: var(--surface-hover);
}

.reader__button:active:not(:disabled) {
	transform: none;
}

/*
 * Disabled buttons stay in the layout so the controls never jump as the reader
 * reaches the first or last page; they simply fade and stop responding.
 */
.reader__button:disabled {
	cursor: default;
	opacity: var(--control-disabled-opacity);
}

/* Dashed purple rings are the original reader's focus cue and stand out on the pale sky. */
.reader__button:focus-visible {
	outline: 2px dashed var(--find);
	outline-offset: 2px;
}

/* ---------- Stage and book ---------- */

.reader__stage {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0;
	padding: 1rem;
	overflow: hidden;
	touch-action: pan-y;
}

.reader__book {
	flex: none;
	border-radius: 0.25rem;
	box-shadow: var(--shadow-book);
}

.reader__page {
	background: var(--surface);
	overflow: hidden;
}

.reader__page-image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	user-select: none;
	-webkit-user-drag: none;
}

.reader__message {
	max-width: 32rem;
	margin: auto;
	padding: 1rem 1.5rem;
	border-radius: var(--page-radius);
	font-size: 1.125rem;
	text-align: center;
	color: var(--ink);
	background: var(--surface);
	box-shadow: var(--shadow-soft);
}

/* ---------- Controls and page indicator ---------- */

.reader__controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 1.25rem;
	padding: 0.625rem 1rem calc(0.625rem + env(safe-area-inset-bottom, 0px));
}

/* The indicator shares the pill shape of the buttons beside it but is not clickable. */
.reader__indicator {
	min-width: 9rem;
	margin: 0;
	padding: var(--control-padding);
	border: 2px solid var(--control-border);
	border-radius: var(--radius-pill);
	font-size: var(--control-font-size);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	text-align: center;
	color: var(--ocean-deep);
	background: var(--surface);
}

/* ---------- Responsive rules ---------- */

/*
 * Phones and portrait screens read one page at a time (bookLayout.js decides the
 * layout; these rules only give that single page as much room as possible).
 * There is deliberately no "rotate your device" gate: portrait phones must work.
 */
@media (max-width: 599px), (orientation: portrait) {
	.reader__header {
		padding: 0.5rem 0.75rem;
	}

	.reader__stage {
		padding: 0.5rem;
	}

	.reader__controls {
		gap: 0.75rem;
	}
}

@media (max-width: 599px) {
	.reader__logo {
		height: 1.5rem;
	}

	/* The icon alone labels the Pages button when horizontal room is scarce. */
	.reader__button-text {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}
}

/* Short landscape phones: trim the chrome so the spread keeps its height. */
@media (max-height: 480px) and (orientation: landscape) {
	.reader__header,
	.reader__controls {
		padding-top: 0.25rem;
		padding-bottom: 0.25rem;
	}

	.reader__logo {
		height: 1.5rem;
	}

	.reader__stage {
		padding: 0.375rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.reader__button {
		transition: none;
	}

	.reader__button:hover:not(:disabled) {
		transform: none;
	}
}
