/*
 *	以手機為預設：下面的基準樣式就是手機版，桌機靠最底下的 min-width 查詢加寬。
 *	絕大多數讀者是手機，所以寬版才是例外。
 */

:root {
	--bg: #f7f7f8;
	--surface: #ffffff;
	--border: #e3e3e6;
	--text: #1b1b1f;
	--muted: #6b6b73;
	--accent: #2563eb;
	--accent-text: #ffffff;
	--danger: #d4183d;
	--shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #16161a;
		--surface: #1f1f24;
		--border: #32323a;
		--text: #ececf1;
		--muted: #9a9aa5;
		--accent: #60a5fa;
		--accent-text: #10131a;
		--danger: #ff8099;
		--shadow: none;
	}
}

* { box-sizing: border-box; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.6 -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
	-webkit-text-size-adjust: 100%;
}

/*	safe-area：iPhone 橫放時瀏海那側不會壓到內容	*/
.wrap {
	max-width: 1280px;
	margin: 0 auto;
	padding-left: max(12px, env(safe-area-inset-left));
	padding-right: max(12px, env(safe-area-inset-right));
}

/*	頁首不固定——手機畫面本來就小，說明只在一開始要看，讓它捲走	*/
header {
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	padding: 10px 0;
}

.head-row {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 8px;
}

h1 { margin: 0; font-size: 16px; font-weight: 600; }

.count { color: var(--muted); font-size: 13px; }

button {
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--surface);
	color: var(--text);
	font: inherit;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

button.done {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
}

/*	開發用的檔名開關：上線預設關閉	*/
#toggleFile {
	flex: none;
	min-height: 28px;
	padding: 0 10px;
	margin-left: auto;
	border-radius: 999px;
	color: var(--muted);
	font-size: 12px;
}

#toggleFile[aria-pressed="true"] {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
}

.hint {
	margin: 8px 0 0;
	color: var(--muted);
	font-size: 12px;
	line-height: 1.5;
}

/*	頁籤固定在頂端：捲圖的時候隨時能換分類	*/
.tabbar {
	position: sticky;
	top: 0;
	z-index: 10;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}

.tabs {
	display: flex;
	gap: 6px;
	padding: 8px 0;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
	flex: none;
	min-height: 36px;
	padding: 0 14px;
	border-radius: 999px;
	font-size: 14px;
	white-space: nowrap;
}

.tab[aria-selected="true"] {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
	font-weight: 600;
}

.tab .n { opacity: .65; margin-left: 6px; font-size: 12px; }

/*	頁籤底下那一列：目前分類 ＋ 全選	*/
.bar {
	display: flex;
	align-items: center;
	gap: 10px;
	padding-top: 12px;
}

.bar-title { font-size: 14px; font-weight: 600; }

#selectAll {
	flex: none;
	margin-left: auto;
	min-height: 32px;
	padding: 0 14px;
	border-radius: 999px;
	font-size: 13px;
}

/*	圖片列表：手機兩欄	*/
.grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
	gap: 10px;
	padding: 12px 0 40px;
	/*	不加的話同一列的卡片會被拉成等高，矮圖下面留一大片空白	*/
	align-items: start;
}

/*	勾選清單浮在最底下，墊高一點避免蓋住最後一排	*/
body.has-sheet .grid { padding-bottom: 170px; }

.card {
	position: relative;
	margin: 0;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	overflow: hidden;
	box-shadow: var(--shadow);
	line-height: 0;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.card:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.card img {
	display: block;
	width: 100%;
	height: auto;
	max-height: 260px;
	object-fit: contain;
	background: var(--bg);
}

/*
 *	右上角的勾選圓圈。
 *	pointer-events: none——整張卡片都是點擊區，圓圈只負責顯示狀態。
 */
.card .pick {
	position: absolute;
	top: 6px;
	right: 6px;
	width: 26px;
	height: 26px;
	border: 2px solid #fff;
	border-radius: 50%;
	background: rgba(0, 0, 0, .3);
	box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
	display: grid;
	place-items: center;
	pointer-events: none;
	transition: background .12s ease;
}

.card .pick svg {
	width: 15px;
	height: 15px;
	color: var(--accent-text);
	opacity: 0;
}

.card.picked .pick { background: var(--accent); }

.card.picked .pick svg { opacity: 1; }

.card.picked {
	border-color: var(--accent);
	box-shadow: 0 0 0 2px var(--accent) inset;
}

/*	檔名預設不顯示，靠 .grid.show-file 打開——上線時的樣子就是關閉的狀態	*/
.card .file { display: none; }

.grid.show-file .card .file {
	display: block;
	padding: 5px 8px 6px;
	border-top: 1px solid var(--border);
	color: var(--muted);
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 11px;
	line-height: 1.45;
	word-break: break-all;
}

.msg {
	margin: 24px 0;
	padding: 16px;
	border: 1px solid var(--border);
	border-radius: 10px;
	background: var(--surface);
	color: var(--muted);
	font-size: 14px;
	line-height: 1.7;
}

.msg code {
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	color: var(--text);
	word-break: break-all;
}

/*	勾選清單：沒選東西時整塊 hidden，不佔畫面	*/
.sheet {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 20;
	background: var(--surface);
	border-top: 1px solid var(--border);
	box-shadow: 0 -2px 14px rgba(0, 0, 0, .14);
	padding: 10px 0 max(10px, env(safe-area-inset-bottom));
}

.sheet-row {
	display: grid;
	grid-template-columns: 1fr auto;
	grid-template-areas:
		"head head"
		"text copy";
	gap: 8px;
}

.sheet-head {
	grid-area: head;
	display: flex;
	align-items: center;
	gap: 10px;
}

.sheet-count { font-size: 13px; font-weight: 600; }

.sheet-count.full { color: var(--accent); }

/*	按到上限時閃一下，不跳彈窗	*/
.sheet-count.warn { color: var(--danger); }

.sheet .link {
	margin-left: auto;
	border: none;
	background: none;
	padding: 4px 2px;
	color: var(--accent);
	font-size: 13px;
}

#pickText {
	grid-area: text;
	min-width: 0;
	height: 76px;
	padding: 8px 10px;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--bg);
	color: var(--text);
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	/*	16px 以下 iOS 一聚焦就會自動放大整頁，但這是唯讀框、不會聚焦打字，
		所以維持小字讓它一次看得到多行	*/
	font-size: 12px;
	line-height: 1.5;
	resize: none;
	cursor: pointer;
}

#pickCopy {
	grid-area: copy;
	align-self: stretch;
	padding: 0 18px;
	font-size: 14px;
	white-space: nowrap;
}

/*	平板以上	*/
@media (min-width: 680px) {
	.wrap {
		padding-left: max(16px, env(safe-area-inset-left));
		padding-right: max(16px, env(safe-area-inset-right));
	}

	header { padding: 12px 0; }

	h1 { font-size: 17px; }

	.head-row { align-items: center; gap: 12px; }

	.hint { font-size: 13px; }

	.grid {
		grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
		gap: 14px;
		padding: 18px 0 48px;
	}

	body.has-sheet .grid { padding-bottom: 180px; }

	.card img { max-height: 360px; }

	.card .pick { width: 28px; height: 28px; }

	#pickText { height: 84px; }
}
