:root {
	--wisadapt-dark: #00652c;
	--wisadapt-green: #00873e;
	--wisadapt-lime: #95c11f;
	--wisadapt-orange: #e18800;
	--wisadapt-red: #e42313;
	--wisadapt-blue: #009fe3;
	--paper: #fffef8;
	--viewer-zoom: 1;
}

* {
	box-sizing: border-box;
}

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

body {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: radial-gradient(circle at 50% 30%, #f8faef 0%, #e7eddb 60%, #d5dfc8 100%);
	color: #202520;
	font-family: Arial, sans-serif;
}

button,
input,
.toolbar-link {
	font: inherit;
}

button,
.toolbar-link {
	border: 0;
	border-radius: 0.45rem;
	background: var(--wisadapt-dark);
	color: white;
	cursor: pointer;
	text-decoration: none;
}

button:hover,
button:focus-visible,
.toolbar-link:hover,
.toolbar-link:focus-visible {
	background: var(--wisadapt-green);
	outline: 3px solid color-mix(in srgb, var(--wisadapt-lime), transparent 45%);
	outline-offset: 2px;
}

button:disabled {
	cursor: not-allowed;
	opacity: 0.42;
}

.viewer-header {
	position: relative;
	z-index: 20;
	display: grid;
	grid-template-columns: auto 1fr;
	align-items: center;
	min-height: 4.5rem;
	padding: 0.55rem clamp(0.75rem, 2vw, 1.6rem);
	background: white;
	border-bottom: 0.35rem solid var(--wisadapt-lime);
	box-shadow: 0 3px 16px rgb(0 0 0 / 12%);
}

.brand img {
	display: block;
	width: auto;
	height: 3rem;
}

.viewer-title {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.15rem;
	min-width: 0;
}

.viewer-title strong {
	overflow: hidden;
	max-width: 100%;
	font-family: bai_jamjureesemibold, Arial, sans-serif;
	font-size: clamp(1rem, 2.2vw, 1.35rem);
	text-overflow: ellipsis;
	white-space: nowrap;
}

.viewer-title span {
	color: var(--wisadapt-dark);
	font-size: 0.82rem;
}

.viewer-main {
	position: relative;
	display: grid;
	flex: 1;
	min-width: 0;
	min-height: 0;
	place-items: center;
	overflow: hidden;
}

.cover-view,
.reader-view {
	width: 100%;
	height: 100%;
}

.cover-view {
	display: grid;
	place-items: center;
	perspective: 1800px;
}

.cover-button {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2rem;
	width: min(76vw, 35rem);
	padding: 0;
	background: transparent;
	color: var(--wisadapt-dark);
}

.cover-button:hover,
.cover-button:focus-visible {
	background: transparent;
}

.book-3d {
	position: relative;
	display: block;
	width: min(56vw, 19rem);
	aspect-ratio: 0.707 / 1;
	transform: rotateX(4deg) rotateY(-27deg);
	transform-style: preserve-3d;
	transition: transform 500ms cubic-bezier(.2, .7, .2, 1), filter 500ms ease;
	filter: drop-shadow(28px 30px 25px rgb(0 0 0 / 30%));
}

.cover-button:hover .book-3d,
.cover-button:focus-visible .book-3d {
	transform: rotateX(1deg) rotateY(-8deg) translateY(-0.6rem);
	filter: drop-shadow(18px 34px 23px rgb(0 0 0 / 34%));
}

.book-front,
.book-back,
.book-pages {
	position: absolute;
	inset: 0;
	display: block;
	border-radius: 0 0.35rem 0.35rem 0;
	transform-style: preserve-3d;
}

.book-front {
	overflow: hidden;
	background: linear-gradient(135deg, var(--wisadapt-dark), var(--wisadapt-green));
	box-shadow: inset 7px 0 10px rgb(0 0 0 / 24%), inset -2px 0 rgb(255 255 255 / 16%);
	transform: translateZ(1.25rem);
}

.book-front::after {
	position: absolute;
	inset: 0;
	background: linear-gradient(100deg, rgb(255 255 255 / 8%), transparent 28%, rgb(0 0 0 / 7%));
	content: '';
	pointer-events: none;
}

.book-back {
	background: var(--wisadapt-dark);
	transform: translateZ(-1.15rem);
}

.book-pages {
	inset: 0.3rem -1.15rem 0.3rem 0.35rem;
	background: repeating-linear-gradient(90deg, #eee9dc 0, #fffdf4 2px, #e5dfcf 3px);
	border-radius: 0 0.2rem 0.2rem 0;
	transform: translateZ(0);
}

#cover-canvas {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.cover-placeholder {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1.5rem;
	padding: 2rem;
	color: white;
	text-align: center;
}

.cover-placeholder[hidden] {
	display: none;
}

.cover-placeholder img {
	max-width: 78%;
	filter: brightness(0) invert(1);
}

.cover-placeholder strong {
	font-family: bai_jamjureesemibold, Arial, sans-serif;
	font-size: clamp(1.2rem, 4vw, 2rem);
}

.open-hint {
	padding: 0.75rem 1.2rem;
	border: 2px solid var(--wisadapt-dark);
	border-radius: 2rem;
	background: rgb(255 255 255 / 75%);
	font-family: bai_jamjureesemibold, Arial, sans-serif;
	box-shadow: 0 8px 20px rgb(0 0 0 / 10%);
}

.reader-view {
	display: flex;
	flex-direction: column;
	min-width: 0;
	min-height: 0;
}

.reader-view[hidden],
.cover-view[hidden],
.loading[hidden] {
	display: none;
}

.reader-toolbar {
	position: relative;
	z-index: 10;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.45rem;
	min-height: 3.4rem;
	padding: 0.45rem 0.7rem;
	overflow-x: auto;
	background: rgb(255 255 255 / 94%);
	box-shadow: 0 4px 14px rgb(0 0 0 / 9%);
}

.reader-toolbar button,
.toolbar-link {
	flex: 0 0 auto;
	min-height: 2.35rem;
	padding: 0.45rem 0.75rem;
}

#previous-page,
#next-page,
#zoom-in,
#zoom-out {
	min-width: 2.5rem;
	font-size: 1.25rem;
}

.toolbar-divider {
	width: 1px;
	height: 1.9rem;
	background: #ccd4c7;
}

.page-picker {
	display: flex;
	align-items: center;
	gap: 0.35rem;
	white-space: nowrap;
}

.page-picker input {
	width: 4.2rem;
	padding: 0.38rem;
	border: 1px solid #aab6a4;
	border-radius: 0.35rem;
	text-align: center;
}

.zoom-value {
	min-width: 3.3rem;
	color: var(--wisadapt-dark);
	font-size: 0.85rem;
	font-weight: bold;
	text-align: center;
}

.book-viewport {
	position: relative;
	flex: 1;
	min-height: 0;
	overflow: auto;
	overscroll-behavior: contain;
}

.book-stage {
	display: grid;
	width: max(100%, calc(100% * var(--viewer-zoom)));
	height: max(100%, calc(100% * var(--viewer-zoom)));
	min-width: 20rem;
	min-height: 24rem;
	place-items: center;
}

.book-frame {
	width: min(100%, calc((100vh - 8.25rem) * 1.414));
	width: min(100%, calc((100dvh - 8.25rem) * 1.414));
	max-width: 100%;
}

@media (orientation: portrait), (max-width: 760px) {
	.book-frame {
		width: min(100%, calc((100vh - 8.25rem) * 0.707));
		width: min(100%, calc((100dvh - 8.25rem) * 0.707));
	}
}

.flipbook {
	width: 100%;
	transform: scale(var(--viewer-zoom));
	transition: transform 180ms ease;
}

.book-page {
	position: relative;
	overflow: hidden;
	background: var(--paper);
	box-shadow: inset 0 0 24px rgb(65 54 30 / 8%);
}

.book-page canvas {
	display: block;
	width: 100%;
	height: 100%;
}

.book-page-number {
	position: absolute;
	right: 0.55rem;
	bottom: 0.3rem;
	padding: 0.1rem 0.3rem;
	border-radius: 0.2rem;
	background: rgb(255 255 255 / 72%);
	color: #4b5548;
	font-size: 0.68rem;
}

.loading {
	position: absolute;
	z-index: 30;
	display: flex;
	align-items: center;
	gap: 0.8rem;
	padding: 1rem 1.4rem;
	border-radius: 0.7rem;
	background: rgb(255 255 255 / 95%);
	color: var(--wisadapt-dark);
	box-shadow: 0 12px 38px rgb(0 0 0 / 18%);
	font-weight: bold;
}

.spinner {
	width: 1.5rem;
	height: 1.5rem;
	border: 0.22rem solid #dbe7d7;
	border-top-color: var(--wisadapt-green);
	border-radius: 50%;
	animation: spin 750ms linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

.error-message {
	position: absolute;
	z-index: 40;
	display: flex;
	flex-direction: column;
	gap: 0.45rem;
	max-width: min(90vw, 38rem);
	padding: 1.2rem 1.4rem;
	border-left: 0.45rem solid var(--wisadapt-red);
	border-radius: 0.45rem;
	background: white;
	box-shadow: 0 12px 38px rgb(0 0 0 / 18%);
}

.error-message[hidden] {
	display: none;
}

.contents-dialog {
	width: min(90vw, 32rem);
	max-height: min(80vh, 46rem);
	padding: 0;
	border: 0;
	border-radius: 0.7rem;
	box-shadow: 0 24px 70px rgb(0 0 0 / 34%);
}

.contents-dialog::backdrop {
	background: rgb(0 37 17 / 55%);
	backdrop-filter: blur(3px);
}

.dialog-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.8rem 1rem;
	background: var(--wisadapt-dark);
	color: white;
}

.dialog-header h2 {
	margin: 0;
	font-size: 1.15rem;
}

.dialog-header button {
	padding: 0.2rem 0.6rem;
	font-size: 1.5rem;
}

#contents-list {
	padding: 0.8rem;
	overflow-y: auto;
}

.contents-item {
	display: flex;
	width: 100%;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 0.35rem;
	padding: 0.65rem 0.8rem;
	background: #eff4e8;
	color: #18231a;
	text-align: left;
}

.contents-empty {
	padding: 1rem;
	color: #536052;
	text-align: center;
}

@media (max-width: 760px) {
	.viewer-header {
		min-height: 3.8rem;
	}

	.brand img {
		height: 2.4rem;
	}

	.reader-toolbar {
		justify-content: flex-start;
	}

	.toolbar-divider,
	.zoom-value {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
	}
}
