:root {
	--bg: #f4f1eb;
	--bg-glow: #fffaf1;
	--surface: #fffdf9;
	--surface-2: #eee8dd;
	--border: #e0d8cb;
	--border-strong: #cabfae;
	--text: #29241e;
	--muted: #776e62;
	--accent: #a05a26;
	--accent-soft: rgba(160, 90, 38, 0.12);
	--brand-bg: linear-gradient(140deg, #ba7137, #8b471d);
	--brand-fg: #fffaf5;
	--danger: #a33b30;
	--focus: #2274a5;
	--shadow-sm: 0 1px 2px rgba(55, 42, 25, 0.05);
	--shadow-md: 0 18px 40px -28px rgba(55, 42, 25, 0.45);
	--radius: 16px;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #171410;
		--bg-glow: #241e17;
		--surface: #211c17;
		--surface-2: #2c261f;
		--border: #3b332a;
		--border-strong: #55493c;
		--text: #f0e8dd;
		--muted: #a99b8b;
		--accent: #e3a16b;
		--accent-soft: rgba(227, 161, 107, 0.14);
		--brand-bg: linear-gradient(140deg, #cf8d55, #9b5826);
		--brand-fg: #24170b;
		--danger: #f08a7d;
		--focus: #7cc4ff;
		--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
		--shadow-md: 0 22px 50px -28px rgba(0, 0, 0, 0.9);
	}
}

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

html {
	scroll-behavior: smooth;
}

body {
	margin: 0;
	min-height: 100vh;
	color: var(--text);
	background:
		radial-gradient(1200px 500px at 15% -10%, var(--bg-glow), transparent 70%),
		radial-gradient(900px 400px at 100% 0%, var(--accent-soft), transparent 65%),
		var(--bg);
	font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 16px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

[hidden] {
	display: none !important;
}

.wrap {
	width: min(1440px, calc(100% - 40px));
	margin-inline: auto;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Header ------------------------------------------------------------------ */

.site-header {
	position: sticky;
	top: 0;
	z-index: 20;
	background: color-mix(in srgb, var(--bg) 84%, transparent);
	backdrop-filter: blur(18px) saturate(1.25);
	-webkit-backdrop-filter: blur(18px) saturate(1.25);
	border-bottom: 1px solid var(--border);
}

.header-main {
	display: flex;
	align-items: center;
	gap: 24px;
	padding-block: 18px 14px;
	flex-wrap: wrap;
}

.brand {
	display: flex;
	align-items: center;
	gap: 14px;
	min-width: 0;
}

.brand-mark {
	display: grid;
	place-items: center;
	flex: none;
	width: 52px;
	height: 52px;
	border-radius: 15px;
	color: var(--brand-fg);
	background: var(--brand-bg);
	box-shadow:
		0 10px 22px -12px rgba(139, 71, 29, 0.9),
		inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.brand-mark svg {
	width: 28px;
	height: 28px;
}

.brand-copy {
	min-width: 0;
}

.brand-copy h1 {
	margin: 0;
	font-size: clamp(1.25rem, 2.2vw, 1.7rem);
	line-height: 1.15;
	letter-spacing: -0.03em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.brand-copy p {
	margin: 3px 0 0;
	color: var(--muted);
	font-size: 0.84rem;
}

.toolbar {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-left: auto;
	flex-wrap: wrap;
}

.search-field {
	position: relative;
	display: flex;
	align-items: center;
	width: min(390px, 52vw);
}

.search-field input {
	width: 100%;
	padding: 11px 42px 11px 41px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--surface);
	color: var(--text);
	font: inherit;
	font-size: 0.92rem;
	box-shadow: var(--shadow-sm);
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-field input::placeholder {
	color: color-mix(in srgb, var(--muted) 82%, transparent);
}

.search-field input:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 4px var(--accent-soft);
}

.search-field input::-webkit-search-cancel-button {
	display: none;
}

.search-icon {
	position: absolute;
	left: 15px;
	width: 18px;
	height: 18px;
	color: var(--muted);
	pointer-events: none;
}

.search-clear {
	position: absolute;
	right: 8px;
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--surface-2);
	color: var(--muted);
	font-size: 1.2rem;
	line-height: 1;
	cursor: pointer;
}

.search-clear:hover {
	color: var(--text);
}

.search-clear:focus-visible,
.book-link:focus-visible {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

.result-bar {
	padding-bottom: 9px;
	color: var(--muted);
	font-size: 0.78rem;
	letter-spacing: 0.01em;
}

.search-hint {
	margin-left: 8px;
	color: color-mix(in srgb, var(--muted) 78%, transparent);
}

.search-hint::before {
	content: "\00b7";
	margin-right: 8px;
}

/* Library ----------------------------------------------------------------- */

.library {
	padding-block: 18px 28px;
}

.folder {
	margin-top: 34px;
}

.folder:first-child {
	margin-top: 10px;
}

.folder-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 0 2px 11px;
	border-bottom: 1px solid var(--border);
}

.folder[data-depth="1"] > .folder-header {
	border-bottom: 2px solid var(--border-strong);
}

.folder-icon {
	display: grid;
	place-items: center;
	flex: none;
	width: 38px;
	height: 38px;
	border-radius: 11px;
	color: var(--accent);
	background: var(--accent-soft);
}

.folder-icon svg {
	width: 21px;
	height: 21px;
}

.folder-name {
	min-width: 0;
	margin: 0;
	font-size: 1.08rem;
	font-weight: 750;
	letter-spacing: -0.02em;
	line-height: 1.2;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.folder[data-depth="1"] > .folder-header .folder-name {
	font-size: 1.28rem;
}

.folder-count {
	flex: none;
	margin-left: auto;
	padding: 3px 10px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--surface-2);
	color: var(--muted);
	font-size: 0.73rem;
	font-weight: 600;
	white-space: nowrap;
}

.subfolders {
	margin-left: clamp(14px, 2vw, 26px);
	padding-left: clamp(12px, 2vw, 20px);
	border-left: 2px solid color-mix(in srgb, var(--accent) 28%, var(--border));
}

.subfolders > .folder {
	margin-top: 26px;
}

.folder .folder-header {
	padding-bottom: 9px;
}

.folder .folder-icon {
	width: 31px;
	height: 31px;
	border-radius: 9px;
}

.folder .folder-icon svg {
	width: 18px;
	height: 18px;
}

.folder .folder-name {
	font-size: 0.98rem;
}

/* Books ------------------------------------------------------------------- */

.book-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(154px, 1fr));
	gap: 20px 18px;
	padding-block: 14px 4px;
}

.book {
	min-width: 0;
	border: 1px solid var(--border);
	border-radius: 15px;
	background: var(--surface);
	box-shadow: var(--shadow-sm);
	transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.book:hover {
	border-color: var(--border-strong);
	box-shadow: var(--shadow-md);
	transform: translateY(-3px);
}

.book:focus-within {
	border-color: var(--accent);
	box-shadow: 0 0 0 4px var(--accent-soft);
}

.book-link {
	display: flex;
	flex-direction: column;
	gap: 11px;
	height: 100%;
	padding: 10px;
	border-radius: inherit;
	color: inherit;
	text-decoration: none;
}

.cover {
	position: relative;
	display: block;
	aspect-ratio: 2 / 3;
	overflow: hidden;
	border-radius: 12px;
	background:
		linear-gradient(150deg, hsl(var(--cover-hue) 42% 48%), hsl(calc(var(--cover-hue) + 38) 46% 28%));
	box-shadow:
		0 12px 24px -14px rgba(31, 19, 7, 0.65),
		inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.cover::after {
	content: "";
	position: absolute;
	z-index: 2;
	inset: 0 auto 0 0;
	width: 9px;
	background: linear-gradient(90deg, rgba(0, 0, 0, 0.3), transparent);
	pointer-events: none;
}

.cover-fallback {
	position: absolute;
	inset: 0;
	z-index: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 11px;
	padding: 14px;
	text-align: center;
	color: rgba(255, 252, 247, 0.94);
}

.cover-initials {
	font-size: clamp(1.5rem, 2.5vw, 2.15rem);
	font-weight: 800;
	letter-spacing: 0.05em;
	text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.cover-format {
	padding: 2px 8px;
	border: 1px solid rgba(255, 255, 255, 0.36);
	border-radius: 999px;
	font-size: 0.66rem;
	font-weight: 700;
	letter-spacing: 0.16em;
	opacity: 0.86;
}

.cover-image {
	position: relative;
	z-index: 1;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.book-info {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding-inline: 2px;
}

.book-title {
	display: -webkit-box;
	overflow: hidden;
	font-size: 0.9rem;
	font-weight: 650;
	line-height: 1.34;
	letter-spacing: -0.008em;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
}

.book-meta {
	display: flex;
	align-items: center;
	gap: 7px;
	color: var(--muted);
	font-size: 0.72rem;
}

.book-format {
	color: var(--accent);
	font-weight: 800;
	letter-spacing: 0.07em;
}

.book-size::before {
	content: "\00b7";
	margin-right: 7px;
}

/* Notices ----------------------------------------------------------------- */

.notice {
	max-width: 660px;
	margin: 32px auto;
	padding: 28px;
	border: 1px solid var(--border);
	border-radius: 18px;
	background: var(--surface);
	box-shadow: var(--shadow-md);
	text-align: center;
}

.notice h2 {
	margin: 0 0 8px;
	font-size: 1.2rem;
	letter-spacing: -0.02em;
}

.notice p {
	margin: 7px 0;
	color: var(--muted);
}

.notice-error {
	border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.notice-error h2 {
	color: var(--danger);
}

.empty-search {
	margin-top: 18px;
}

code {
	padding: 2px 6px;
	border-radius: 5px;
	background: var(--surface-2);
	color: var(--text);
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.88em;
	overflow-wrap: anywhere;
}

/* Footer ------------------------------------------------------------------ */

.site-footer {
	margin-top: 12px;
	padding-block: 22px 36px;
	border-top: 1px solid var(--border);
	color: var(--muted);
	font-size: 0.8rem;
}

.site-footer p {
	margin: 0;
}

/* Search filtering -------------------------------------------------------- */

.book.is-hidden,
.folder.is-hidden {
	display: none;
}

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

@media (max-width: 980px) {
	.toolbar {
		width: 100%;
		margin-left: 0;
	}

	.search-field {
		flex: 1;
		width: auto;
	}
}

@media (max-width: 620px) {
	.wrap {
		width: min(100% - 24px, 1440px);
	}

	.header-main {
		gap: 14px;
		padding-block: 14px 11px;
	}

	.brand-mark {
		width: 44px;
		height: 44px;
		border-radius: 13px;
	}

	.brand-mark svg {
		width: 24px;
		height: 24px;
	}

	.brand-copy h1 {
		font-size: 1.2rem;
	}

	.library {
		padding-top: 10px;
	}

	.folder {
		margin-top: 26px;
	}

	.folder-header {
		gap: 10px;
		padding-bottom: 9px;
	}

	.folder-icon {
		width: 33px;
		height: 33px;
	}

	.folder-name,
	.folder[data-depth="1"] > .folder-header .folder-name {
		font-size: 1.02rem;
	}

	.folder-count {
		padding-inline: 8px;
		font-size: 0.69rem;
	}

	.subfolders {
		margin-left: 8px;
		padding-left: 11px;
	}

	.subfolders > .folder {
		margin-top: 22px;
	}

	.book-grid {
		grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
		gap: 15px 12px;
	}

	.book-link {
		padding: 7px;
	}

	.book-title {
		font-size: 0.84rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}

	*,
	*::before,
	*::after {
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
	}
}
