/* 布局参照：搜索结果式列表——上方搜索框 + 选项链接 + 标签页，下方带边框的结果框，每行左封面右信息。 */
:root {
	--bg: #f4f7f9;
	--panel: #ffffff;
	--ink: #23272b;
	--ink-2: #5b6168;
	--ink-3: #9aa1a8;
	--line: #dde2e6;
	--line-2: #e9edf0;
	--accent: #3f9fc2;
	--accent-ink: #ffffff;
	--accent-soft: #e3f1f7;
	--field: #ffffff;
	--btn: #eef1f3;
	--danger: #c0392b;
	--title-color: #000000; /* 标题：黑色隶书 */
	--shadow: 0 1px 3px rgb(30 50 70 / 0.18);
	--sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #16191c;
		--panel: #1e2226;
		--ink: #e6e9ec;
		--ink-2: #b2b8be;
		--ink-3: #7d858c;
		--line: #343a40;
		--line-2: #2a2f34;
		--accent: #6cc0de;
		--accent-ink: #0d1a20;
		--accent-soft: #1d3440;
		--field: #121518;
		--btn: #2a2f34;
		--danger: #ef8a7e;
		--title-color: #f2f2f2; /* 深色背景上纯黑看不见，改用近白 */
		--shadow: 0 1px 3px rgb(0 0 0 / 0.5);
		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(--bg);
	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; }

.page {
	max-width: 760px;
	margin: 0 auto;
	padding: 0 16px;
}

/* ---------- 开头书法图 ---------- */
.hero {
	margin: 0 -16px;
	padding-top: env(safe-area-inset-top);
}
.hero img {
	display: block;
	width: 100%;
	height: auto;
}
@media (min-width: 761px) {
	.hero { margin: 24px 0 0; }
	.hero img { border-radius: 4px; box-shadow: var(--shadow); }
}

/* ---------- 标题（隶书，左对齐） ---------- */
.titlebar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin: 22px 0 18px;
}
.brand {
	margin: 0;
	height: 46px;
	aspect-ratio: 1062 / 172;
	max-width: 70%;
	background: var(--title-color);
	-webkit-mask: url("/title.svg") no-repeat left center / contain;
	mask: url("/title.svg") no-repeat left center / contain;
}

/* ---------- 搜索框 ---------- */
.searchbar {
	display: flex;
	height: 54px;
	background: var(--field);
	border: 1px solid #c9dbe5;
	box-shadow: 0 2px 6px rgb(63 159 194 / 0.18);
}
@media (prefers-color-scheme: dark) {
	.searchbar { border-color: var(--line); box-shadow: none; }
}
.searchbar input {
	flex: 1;
	min-width: 0;
	border: 0;
	background: transparent;
	padding: 0 16px;
	font-size: 17px;
	outline: none;
}
.searchbar input::-webkit-search-cancel-button { cursor: pointer; }
.searchbar:focus-within { border-color: var(--accent); }
.search-btn {
	flex: none;
	width: 58px;
	border: 0;
	border-left: 1px solid var(--line);
	background: var(--btn);
	display: grid;
	place-items: center;
	color: var(--ink);
}
.search-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }

/* ---------- 排序选项（虚线链接） ---------- */
.options-link {
	margin: 14px 0 0;
	padding: 2px 0;
	border: 0;
	background: none;
	color: var(--ink-3);
	font-size: 16px;
	border-bottom: 1.5px dashed currentColor;
	line-height: 1.3;
}
.options-link[aria-expanded="true"] { color: var(--accent); }
.options-panel {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 12px;
}
.options-panel button {
	border: 1px solid var(--line);
	background: var(--panel);
	color: var(--ink-2);
	padding: 4px 14px;
	font-size: 14px;
	min-height: 32px;
}
.options-panel button[aria-pressed="true"] {
	border-color: var(--accent);
	color: var(--accent);
	background: var(--accent-soft);
}

/* ---------- 标签页 + 升降序 ---------- */
.tabs-row {
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	margin-top: 34px;
}
.tabs { display: flex; gap: 10px; }
.tabs button {
	border: 1px solid var(--line);
	border-bottom: 0;
	border-radius: 8px 8px 0 0;
	background: transparent;
	color: var(--ink-2);
	padding: 8px 18px;
	font-size: 16px;
	margin-bottom: -1px; /* 压住下方结果框的上边框 */
	position: relative;
}
.tabs button[aria-selected="true"] {
	background: var(--panel);
	color: var(--accent);
	z-index: 1;
}
.tab-count { margin-left: 2px; }
.sort-dir {
	border: 0;
	background: none;
	padding: 4px;
	margin-bottom: 6px;
	color: var(--accent);
	width: 44px;
	height: 40px;
}
.sort-dir svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sort-dir .lines { stroke: var(--ink-3); }
.sort-dir[data-dir="desc"] .arrow-up,
.sort-dir[data-dir="asc"] .arrow-down { opacity: 0.3; }

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

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

/* ---------- 结果框 ---------- */
.results {
	background: var(--panel);
	border: 1px solid var(--line);
}

.group-head {
	display: flex;
	align-items: baseline;
	gap: 8px;
	padding: 10px 18px;
	background: var(--bg);
	border-bottom: 1px solid var(--line);
	scroll-margin-top: 12px;
}
.results section + section .group-head { border-top: 1px solid var(--line); }
.group-head h2 { font-size: 16px; font-weight: 600; margin: 0; color: var(--ink); }
.group-head span { color: var(--ink-3); font-size: 13px; }

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

/* 一行一本：左列封面 + 底部小字，右列标题/出版社/作者 + 底部两行 */
.book {
	display: grid;
	grid-template-columns: minmax(84px, 30%) 1fr;
	gap: 0 16px;
	padding: 18px 18px 16px;
	border-bottom: 1px solid var(--line);
}
.book:last-child { border-bottom: 0; }

.book-left, .book-right {
	min-width: 0;
	display: flex;
	flex-direction: column;
}
.book-left { align-items: center; }

.cover-btn {
	display: block;
	width: 100%;
	max-width: 160px;
	padding: 0;
	border: 0;
	background: none;
}
.cover-btn:focus-visible, .book-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.cover {
	width: 100%;
	aspect-ratio: 5 / 7;
	overflow: hidden;
	background: var(--btn);
	box-shadow: 0 1px 2px rgb(0 0 0 / 0.12), 0 3px 8px -2px rgb(0 0 0 / 0.25);
	border: 1px solid rgb(0 0 0 / 0.06);
	border-radius: 2px;
	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-size: 30px;
	font-weight: 600;
	color: rgb(255 255 255 / 0.92);
}

.left-foot {
	margin-top: auto;
	padding-top: 14px;
	font-size: 15px;
	color: var(--ink-3);
	text-align: center;
	white-space: nowrap;
}

.book-title {
	display: block;
	padding: 0;
	border: 0;
	background: none;
	text-align: left;
	font-size: 19px;
	line-height: 1.4;
	color: var(--ink);
	text-decoration: underline;
	text-underline-offset: 3px;
	text-decoration-thickness: 1px;
	overflow-wrap: anywhere;
}
.publisher { margin-top: 4px; font-size: 15px; color: var(--ink-3); overflow-wrap: anywhere; }
.author {
	margin-top: 6px;
	font-size: 16px;
	font-style: italic;
	color: var(--accent);
	overflow-wrap: anywhere;
}

.right-foot {
	margin-top: auto;
	padding-top: 14px;
	font-size: 15px;
	color: var(--ink-2);
	display: grid;
	gap: 2px;
}
.right-foot .review {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	white-space: pre-line;
	overflow-wrap: anywhere;
}
.right-foot .extra {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.reorder { display: flex; gap: 8px; justify-content: center; }
.reorder button {
	width: 36px; height: 36px;
	border-radius: 50%;
	border: 1px solid var(--line);
	background: var(--panel);
	display: grid; place-items: center;
	color: var(--ink-2);
}
.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: 56px 16px;
}
.empty strong { display: block; font-size: 17px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }

/* ---------- 按钮 ---------- */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
	border-radius: 4px;
	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(--btn); border-color: var(--line); cursor: pointer; }
.btn-ghost { background: var(--panel); 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,
.options-link:focus-visible, .tabs button:focus-visible, .sort-dir:focus-visible, .search-btn: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(20 70 90 / 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: 12px;
	background: var(--panel);
	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(15 20 25 / 0.45); }
.sheet-small { width: min(400px, 100vw); }

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

.sheet-body { overflow-y: auto; padding: 22px 20px 8px; flex: 1; }
.sheet-body h2 { font-size: 19px; 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: 4px;
	background: var(--field);
	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: 5 / 7;
	border: 1px dashed var(--line);
	background: var(--bg);
	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; flex: none; }
.detail-head .book-title { text-decoration: none; font-weight: 600; 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: 4px; 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(--panel);
	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; } }
}
