:root {
	--paper: #f4efe4;
	--paper-2: #ebe4d4;
	--card: #fbf8f1;
	--ink: #2a2520;
	--ink-2: #5d554b;
	--ink-3: #8f8577;
	--line: #ddd3c0;
	--accent: #2f5547;
	--accent-ink: #f4efe4;
	--accent-soft: #dfe7df;
	--danger: #a33a2c;
	--shadow: 0 1px 2px rgb(60 45 25 / 0.08), 0 6px 18px -8px rgb(60 45 25 / 0.25);
	--serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "Noto Serif SC", Georgia, serif;
	--sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
	--radius: 12px;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--paper: #1b1916;
		--paper-2: #24211d;
		--card: #23201c;
		--ink: #ece5d8;
		--ink-2: #b9b0a2;
		--ink-3: #857c70;
		--line: #3a352e;
		--accent: #8fbfa8;
		--accent-ink: #13201a;
		--accent-soft: #2a3a33;
		--danger: #e0806f;
		--shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 20px -10px rgb(0 0 0 / 0.6);
		color-scheme: dark;
	}
}

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

html { -webkit-text-size-adjust: 100%; }

/* 组件里写了 display 的元素也要能被 hidden 属性隐藏 */
[hidden] { display: none !important; }

body {
	margin: 0;
	background: var(--paper);
	color: var(--ink);
	font: 15px/1.6 var(--sans);
	min-height: 100vh;
	padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.visually-hidden {
	position: absolute !important;
	width: 1px; height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

.muted { color: var(--ink-2); margin: 0 0 12px; font-size: 14px; }

/* ---------- 顶部 ---------- */
.masthead { padding: calc(28px + env(safe-area-inset-top)) 16px 8px; }
.masthead-inner, .toolbar-inner, .shelf, .author-index {
	max-width: 760px;
	margin: 0 auto;
}
.masthead-inner { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.masthead h1 {
	font-family: var(--serif);
	font-size: 30px;
	font-weight: 700;
	letter-spacing: 0.04em;
	margin: 0;
	line-height: 1.2;
}
.count { margin: 4px 0 0; color: var(--ink-3); font-size: 13px; }

.toolbar {
	position: sticky;
	top: 0;
	z-index: 5;
	background: color-mix(in srgb, var(--paper) 88%, transparent);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border-bottom: 1px solid var(--line);
	padding: 10px 16px;
}
.toolbar-inner { display: grid; gap: 8px; }
.toolbar-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.search {
	width: 100%;
	height: 40px;
	padding: 0 14px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--card);
	outline: none;
}
.search:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.select-wrap select {
	height: 34px;
	padding: 0 30px 0 12px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%238f8577' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center / 12px;
	appearance: none;
	font-size: 14px;
}

.segmented {
	display: inline-flex;
	border: 1px solid var(--line);
	border-radius: 999px;
	padding: 2px;
	background: var(--card);
	margin-left: auto;
}
.segmented button {
	border: 0;
	background: transparent;
	padding: 4px 12px;
	border-radius: 999px;
	font-size: 14px;
	color: var(--ink-2);
	min-height: 28px;
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.hint { margin: 0; font-size: 12px; color: var(--ink-3); }

/* ---------- 作者索引 ---------- */
.author-index {
	display: flex;
	gap: 6px;
	overflow-x: auto;
	padding: 12px 16px 0;
	scrollbar-width: none;
}
.author-index::-webkit-scrollbar { display: none; }
.author-index a {
	flex: none;
	text-decoration: none;
	color: var(--ink-2);
	border: 1px solid var(--line);
	background: var(--card);
	border-radius: 999px;
	padding: 3px 12px;
	font-size: 13px;
	white-space: nowrap;
}
.author-index a small { color: var(--ink-3); margin-left: 4px; }

/* ---------- 书单 ---------- */
.shelf { padding: 8px 16px 0; }

.group-head {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin: 22px 0 6px;
	padding-bottom: 6px;
	border-bottom: 1px solid var(--line);
	scroll-margin-top: 130px;
}
.group-head h2 { font-family: var(--serif); font-size: 18px; margin: 0; }
.group-head span { color: var(--ink-3); font-size: 13px; }

.book-list { list-style: none; margin: 0; padding: 0; }

.book {
	display: flex;
	align-items: stretch;
	gap: 14px;
	padding: 14px 4px;
	border-bottom: 1px solid var(--line);
}
.book:last-child { border-bottom: 0; }

.book-main {
	flex: 1;
	min-width: 0;
	display: flex;
	gap: 14px;
	text-align: left;
	background: none;
	border: 0;
	padding: 0;
	border-radius: 8px;
}
.book-main:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.cover {
	flex: none;
	width: 84px;
	aspect-ratio: 3 / 4;
	border-radius: 3px 6px 6px 3px;
	overflow: hidden;
	background: var(--paper-2);
	box-shadow: var(--shadow), inset 3px 0 0 rgb(0 0 0 / 0.08);
	position: relative;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-placeholder {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	font-family: var(--serif);
	font-size: 28px;
	color: rgb(255 255 255 / 0.9);
}

.info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; padding-top: 2px; }
.title {
	font-family: var(--serif);
	font-size: 17px;
	font-weight: 700;
	line-height: 1.35;
	margin: 0;
	overflow-wrap: anywhere;
}
.meta { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.meta .dot { margin: 0 6px; color: var(--ink-3); }
.review {
	margin-top: 6px;
	font-size: 14px;
	color: var(--ink);
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	white-space: pre-line;
}
.extra {
	margin-top: 2px;
	font-size: 12.5px;
	color: var(--ink-3);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.reorder { flex: none; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.reorder button {
	width: 36px; height: 36px;
	border-radius: 50%;
	border: 1px solid var(--line);
	background: var(--card);
	display: grid; place-items: center;
}
.reorder button:disabled { opacity: 0.3; cursor: default; }
.reorder svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

.empty {
	text-align: center;
	color: var(--ink-3);
	padding: 64px 16px;
}
.empty strong { display: block; font-family: var(--serif); font-size: 18px; color: var(--ink-2); margin-bottom: 6px; }

/* ---------- 按钮 ---------- */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
	border-radius: 999px;
	min-height: 40px;
	padding: 0 18px;
	border: 1px solid transparent;
	font-size: 15px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
.btn-secondary { background: var(--card); border-color: var(--line); cursor: pointer; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-link { background: none; border: 0; color: var(--danger); font-size: 14px; padding: 4px 0; text-align: left; }
.btn-primary:focus-visible, .btn-secondary:focus-within, .btn-ghost:focus-visible, .btn-danger:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.fab {
	position: fixed;
	right: max(20px, calc((100vw - 760px) / 2));
	bottom: calc(24px + env(safe-area-inset-bottom));
	width: 58px; height: 58px;
	border-radius: 50%;
	border: 0;
	background: var(--accent);
	color: var(--accent-ink);
	box-shadow: 0 10px 24px -8px rgb(30 50 40 / 0.6);
	display: grid; place-items: center;
	z-index: 6;
}
.fab svg { width: 26px; height: 26px; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

/* ---------- 弹窗 ---------- */
.sheet {
	border: 0;
	padding: 0;
	width: min(560px, 100vw);
	max-width: 100vw;
	max-height: min(92vh, 100dvh);
	border-radius: 18px;
	background: var(--card);
	color: var(--ink);
	box-shadow: 0 30px 60px -20px rgb(0 0 0 / 0.45);
	flex-direction: column;
}
.sheet[open] { display: flex; }
.sheet::backdrop { background: rgb(20 15 10 / 0.45); }
.sheet-small { width: min(400px, 100vw); }

@media (max-width: 600px) {
	.sheet {
		margin: auto 0 0;
		width: 100vw;
		border-radius: 18px 18px 0 0;
		max-height: 92dvh;
	}
}

.sheet-body { overflow-y: auto; padding: 22px 20px 8px; flex: 1; }
.sheet-body h2 { font-family: var(--serif); font-size: 20px; margin: 0 0 14px; }
.sheet-actions {
	display: flex;
	gap: 8px;
	align-items: center;
	padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
	border-top: 1px solid var(--line);
}
.spacer { flex: 1; }

.field { display: grid; gap: 4px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--ink-2); }
.field em { color: var(--danger); font-style: normal; }
.field input, .field textarea {
	width: 100%;
	border: 1px solid var(--line);
	border-radius: 10px;
	background: var(--paper);
	padding: 9px 12px;
	font-size: 16px; /* iOS 低于 16px 会自动放大页面 */
	outline: none;
	resize: vertical;
}
.field input:focus-visible, .field textarea:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.form-error { color: var(--danger); font-size: 14px; margin: 0 0 8px; }

.cover-picker { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.cover-preview {
	flex: none;
	width: 96px;
	aspect-ratio: 3 / 4;
	border-radius: 4px 8px 8px 4px;
	border: 1px dashed var(--line);
	background: var(--paper);
	display: grid; place-items: center;
	overflow: hidden;
	color: var(--ink-3);
	font-size: 12px;
	text-align: center;
	padding: 4px;
}
.cover-preview.has-image { border-style: solid; padding: 0; box-shadow: var(--shadow); }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-buttons { display: grid; gap: 8px; }

.detail-head { display: flex; gap: 16px; margin-bottom: 16px; }
.detail-head .cover { width: 110px; }
.detail-head .title { font-size: 20px; }
.detail-section { margin-bottom: 14px; }
.detail-section h3 { font-size: 12px; font-weight: 600; color: var(--ink-3); margin: 0 0 4px; letter-spacing: 0.08em; }
.detail-section p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-cover-full { display: block; margin: 0 0 16px; }
.detail-cover-full img { max-width: 100%; max-height: 60vh; border-radius: 8px; display: block; margin: 0 auto; box-shadow: var(--shadow); }

/* ---------- 提示 ---------- */
.toast {
	position: fixed;
	left: 50%;
	bottom: calc(100px + env(safe-area-inset-bottom));
	transform: translateX(-50%);
	background: var(--ink);
	color: var(--paper);
	padding: 8px 16px;
	border-radius: 999px;
	font-size: 14px;
	z-index: 20;
	max-width: calc(100vw - 32px);
	text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
	.sheet[open] { animation: rise 0.22s ease-out; }
	@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
}
