/*
 * File: workers/src/assets/collection.css
 * Public shared collection page (rendered by workers/src/utils/render.ts).
 */

@font-face {
	font-family: 'Geist';
	src: url('/assets/geist.woff2') format('woff2');
	font-weight: 100 900;
	font-style: normal;
	font-display: swap;
}

:root {
	--bg: #e9eef4;
	--sheet: #f6f8fb;
	--panel: #fbfcfe;
	--chip: #ffffff;
	--pocket: rgba(255, 255, 255, 0.62);
	--pocket-edge: rgba(14, 40, 70, 0.1);
	--sheen: rgba(255, 255, 255, 0.38);
	--frost: rgba(255, 255, 255, 0.82);
	--ink: #0d2138;
	--muted: #5d6f85;
	--line: #d3dbe5;
	--focus: #0f69ae;
	--scrim: rgba(233, 238, 244, 0.72);
	--shadow: rgba(13, 33, 56, 0.2);
	--back: #f4efe2;
	--back-ink: #3d3424;
	--back-line: rgba(61, 52, 36, 0.16);
	--s-sale: #16a34a;
	--s-trade: #0f69ae;
	--s-want: #ea8a0c;
	--s-incoming: #7c3aed;
	--s-sold: #dc2626;
	--col: 230px;
	--stick-top: 0px;
	color-scheme: light;
}

:root[data-theme='dark'] {
	--bg: #0b1420;
	--sheet: #111c2a;
	--panel: #121d2b;
	--chip: #172435;
	--pocket: rgba(255, 255, 255, 0.045);
	--pocket-edge: rgba(255, 255, 255, 0.09);
	--sheen: rgba(255, 255, 255, 0.06);
	--frost: rgba(18, 29, 43, 0.82);
	--ink: #e7eef7;
	--muted: #8597ad;
	--line: #1f2d3e;
	--focus: #5fb0f0;
	--scrim: rgba(5, 10, 17, 0.72);
	--shadow: rgba(0, 0, 0, 0.4);
	--back: #22314a;
	--back-ink: #e6edf6;
	--back-line: rgba(255, 255, 255, 0.1);
	--s-sale: #4ade80;
	--s-trade: #5fb0f0;
	--s-want: #fbbf24;
	--s-incoming: #a78bfa;
	--s-sold: #f87171;
	color-scheme: dark;
}

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

html,
body {
	overflow-x: clip;
}

body {
	background: var(--bg);
	color: var(--ink);
	font-family:
		'Geist',
		system-ui,
		-apple-system,
		'Segoe UI',
		sans-serif;
	-webkit-font-smoothing: antialiased;
	line-height: 1.4;
	transition:
		background-color 0.3s,
		color 0.3s;
}

button,
input,
select {
	font: inherit;
	color: inherit;
}

img {
	display: block;
}

svg {
	display: block;
	flex: none;
}

a {
	color: inherit;
}

[hidden] {
	display: none !important;
}

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

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

body[data-image-size='thumbnail'] {
	--col: 160px;
}

body[data-image-size='large'] {
	--col: 330px;
}

/* ---------- Page ---------- */

.page {
	max-width: 1280px;
	margin: 0 auto;
	padding: 28px 40px;
}

.embed-mode .page {
	padding: 16px;
}

.head h1 {
	font-size: clamp(30px, 3.6vw, 42px);
	font-weight: 700;
	letter-spacing: -0.04em;
	line-height: 1.05;
	text-wrap: balance;
	overflow-wrap: anywhere;
}

.head p {
	margin-top: 8px;
	max-width: 60ch;
	color: var(--muted);
	font-size: 17px;
	line-height: 1.5;
}

/* ---------- Toolbar (sticky, logo at the end) ---------- */

.toolbar {
	position: sticky;
	top: var(--stick-top);
	z-index: 20;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 16px;
	min-height: 62px;
	margin: 24px 0 20px;
	padding: 10px 0;
}

.embed-mode .toolbar {
	margin-top: 0;
}

.toolbar::before {
	content: '';
	position: absolute;
	inset: 0 -100vmax;
	z-index: -1;
	opacity: 0;
	background: color-mix(in srgb, var(--bg) 96%, transparent);
	backdrop-filter: blur(14px) saturate(1.2);
	border-bottom: 1px solid var(--line);
	pointer-events: none;
	transition: opacity 0.2s;
}

.toolbar.stuck::before {
	opacity: 1;
}

.tools {
	display: flex;
	align-items: center;
	gap: 8px;
}

.tools-main {
	min-width: 0;
}

.tool {
	height: 42px;
	background: var(--sheet);
	border: 1px solid var(--line);
	border-radius: 12px;
}

.icon-btn {
	display: grid;
	place-items: center;
	width: 42px;
	height: 42px;
	border: 0;
	border-radius: 12px;
	background: none;
	color: var(--muted);
	cursor: pointer;
	text-decoration: none;
}

.icon-btn:hover {
	color: var(--ink);
	background: var(--sheet);
}

.icon-btn.tool {
	color: var(--ink);
	border: 1px solid var(--line);
	background: var(--sheet);
}

.icon-btn.tool[aria-expanded='true'] {
	background: var(--ink);
	color: var(--bg);
	border-color: var(--ink);
}

.icon-btn.copied {
	color: var(--s-sale);
}

#filter-toggle-btn {
	position: relative;
}

#filter-toggle-btn.active::after {
	content: '';
	position: absolute;
	top: 7px;
	right: 7px;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--focus);
}

.search {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 300px;
	padding: 0 14px;
	color: var(--muted);
	cursor: text;
}

.search input {
	width: 100%;
	border: 0;
	outline: 0;
	background: none;
	color: var(--ink);
}

.search input::placeholder {
	color: var(--muted);
}

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

.search:focus-within {
	outline: 2px solid var(--focus);
	outline-offset: 2px;
}

.sort {
	display: flex;
	align-items: center;
}

.sort select {
	appearance: none;
	height: 100%;
	padding: 0 12px 0 14px;
	border: 0;
	outline: 0;
	background: none;
	font-weight: 500;
	cursor: pointer;
}

.sort select:focus-visible {
	outline: 2px solid var(--focus);
	outline-offset: -2px;
	border-radius: 11px 0 0 11px;
}

.sort-dir {
	display: grid;
	place-items: center;
	width: 40px;
	height: 100%;
	border: 0;
	border-left: 1px solid var(--line);
	background: none;
	cursor: pointer;
}

.sort-dir svg {
	transition: transform 0.2s;
}

.sort-dir[data-order='desc'] svg {
	transform: rotate(180deg);
}

.sort-mini {
	position: relative;
	display: none;
}

.sort-menu {
	position: absolute;
	top: calc(100% + 8px);
	right: 0;
	z-index: 10;
	width: 220px;
	padding: 6px;
	border-radius: 14px;
	background: var(--panel);
	border: 1px solid var(--line);
	box-shadow: 0 20px 40px -16px var(--shadow);
}

.sort-menu button {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	height: 38px;
	padding: 0 12px;
	border: 0;
	border-radius: 9px;
	background: none;
	font-size: 14px;
	text-align: left;
	cursor: pointer;
}

.sort-menu button[aria-checked='true'] {
	font-weight: 600;
	background: var(--sheet);
}

.sort-menu hr {
	margin: 6px 4px;
	border: 0;
	border-top: 1px solid var(--line);
}

.share-links {
	display: flex;
	align-items: center;
	gap: 0;
}

.brand {
	display: flex;
	align-items: center;
	height: 28px;
	margin-left: 4px;
	padding-left: 14px;
	border-left: 1px solid var(--line);
}

.tools-share > .brand:first-child {
	margin-left: 0;
	padding-left: 0;
	border-left: 0;
}

.brand img {
	width: auto;
	height: 24px;
}

/* Phone header row (logo, contact, share); shown only at phone widths */
.brandbar {
	display: none;
}

/* Filter panel */
.filters {
	position: absolute;
	top: calc(100% + 8px);
	left: 0;
	z-index: 10;
	width: 340px;
	padding: 18px;
	border-radius: 18px;
	background: var(--panel);
	border: 1px solid var(--line);
	box-shadow: 0 24px 48px -20px var(--shadow);
}

.filters-label {
	margin-bottom: 10px;
	color: var(--muted);
	font-size: 13px;
	font-weight: 500;
}

.filter-toggles {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	margin-bottom: 18px;
}

.filter-toggle {
	height: 38px;
	border-radius: 10px;
	border: 1px solid var(--line);
	background: var(--sheet);
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
}

.filter-toggle[aria-pressed='true'] {
	background: var(--ink);
	color: var(--bg);
	border-color: var(--ink);
}

.segs {
	display: flex;
	gap: 2px;
	padding: 3px;
	border-radius: 11px;
	background: var(--bg);
}

.segs button {
	flex: 1;
	height: 32px;
	padding: 0 12px;
	border: 0;
	border-radius: 8px;
	background: none;
	color: var(--muted);
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
}

.segs button[aria-pressed='true'] {
	background: var(--panel);
	color: var(--ink);
	box-shadow: 0 1px 2px var(--shadow);
}

.filters-clear {
	width: 100%;
	height: 38px;
	margin-top: 16px;
	border: 0;
	border-radius: 10px;
	background: none;
	color: var(--focus);
	font-weight: 500;
	cursor: pointer;
}

/* ---------- Sheet and grid ---------- */

.sheet {
	padding: 28px;
	border-radius: 28px;
	background: var(--sheet);
	border: 1px solid var(--line);
}

.sheet-bar {
	display: flex;
	justify-content: flex-end;
	margin-bottom: 14px;
}

/* The Details button sits closer to the sheet's top edge than the cards would. */
.sheet:has(> .sheet-bar) {
	padding-top: 16px;
}

.all-flip {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	height: 32px;
	padding: 0 12px;
	border-radius: 999px;
	border: 1px solid var(--line);
	background: var(--panel);
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
}

.grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(var(--col), 1fr));
	gap: 28px 24px;
	align-items: start;
}

.card {
	min-width: 0;
}

.flipper {
	display: grid;
}

.flipper > .pocket {
	grid-area: 1 / 1;
	min-width: 0;
}

.pocket.back {
	visibility: hidden;
}

.card.flipped .pocket.back {
	visibility: visible;
}

.card.flipped .pocket.front {
	visibility: hidden;
}

.pocket {
	position: relative;
	display: grid;
	place-items: center;
	aspect-ratio: 5 / 7;
	padding: 20px 22px;
	border-radius: 14px;
	background: var(--pocket);
	border: 1px solid var(--pocket-edge);
	overflow: hidden;
}

body[data-image-size='thumbnail'] .pocket {
	padding: 12px;
}

.pocket.front::after {
	content: '';
	position: absolute;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	background: linear-gradient(118deg, transparent 30%, var(--sheen) 42%, transparent 52%);
}

.open {
	position: absolute;
	inset: 0;
	z-index: 2;
	border: 0;
	border-radius: inherit;
	background: none;
	cursor: zoom-in;
}

.open:focus-visible {
	outline-offset: -3px;
}

.pocket.front {
	container-type: size;
}

/* Max-edge fit: each image fills the sleeve's inner box by its own shape, so
   portrait cards share one height and landscape cards share one width. */
.pocket img.card-image {
	position: relative;
	z-index: 1;
	width: min(100cqw, 100cqh * var(--ar, 0.714));
	height: auto;
	aspect-ratio: var(--ar, 0.714);
	object-fit: contain;
	border-radius: 5px;
	box-shadow: 0 8px 18px var(--shadow);
}

.pocket img.lazy:not(.loaded) {
	opacity: 0;
}

.pocket img.loaded {
	opacity: 1;
	transition: opacity 0.25s;
}

.no-image,
.load-error::before {
	color: var(--muted);
	font-size: 13px;
}

.pocket.load-error img {
	display: none;
}

.pocket.load-error::before {
	content: 'Image unavailable';
}

.status {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 24px;
	padding: 0 10px 0 8px;
	border-radius: 999px;
	background: var(--chip);
	color: var(--ink);
	font-size: 12px;
	font-weight: 600;
	white-space: nowrap;
	box-shadow: 0 1px 3px var(--shadow);
}

.status::before {
	content: '';
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--status-color, var(--muted));
}

.status[data-status='for-sale'] {
	--status-color: var(--s-sale);
}

.status[data-status='for-trade'] {
	--status-color: var(--s-trade);
}

.status[data-status='want-list'] {
	--status-color: var(--s-want);
}

.status[data-status='incoming'] {
	--status-color: var(--s-incoming);
}

.status[data-status='sold'] {
	--status-color: var(--s-sold);
}

.pocket .status {
	position: absolute;
	top: 10px;
	left: 10px;
	z-index: 3;
}

.fav {
	position: absolute;
	top: 10px;
	right: 10px;
	z-index: 3;
	display: grid;
	place-items: center;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	background: var(--chip);
	color: #e11d48;
	box-shadow: 0 1px 3px var(--shadow);
}

.corner {
	position: absolute;
	right: 10px;
	bottom: 10px;
	z-index: 4;
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	border: 1px solid var(--pocket-edge);
	background: var(--frost);
	backdrop-filter: blur(8px);
	color: var(--ink);
	box-shadow: 0 4px 12px -4px var(--shadow);
	cursor: pointer;
	transition: transform 0.2s;
}

.corner:hover {
	transform: scaleX(-1);
}

body[data-image-size='thumbnail'] .corner {
	right: 6px;
	bottom: 6px;
	width: 28px;
	height: 28px;
}

/* Card back */
.pocket.back {
	place-items: stretch;
	padding: 14px;
}

.spec {
	min-height: 0;
	padding: 14px 14px 44px;
	border-radius: 8px;
	background: var(--back);
	color: var(--back-ink);
	overflow-y: auto;
	scrollbar-width: thin;
	box-shadow: 0 8px 18px var(--shadow);
}

.spec-row {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	padding: 7px 0;
	border-top: 1px solid var(--back-line);
	font-size: 12px;
}

.spec-row:first-child {
	padding-top: 0;
	border-top: 0;
}

.spec dt {
	opacity: 0.72;
	white-space: nowrap;
}

.spec dd {
	font-weight: 600;
	text-align: right;
	overflow-wrap: anywhere;
}

.spec-notes {
	margin-top: 6px;
	padding-top: 8px;
	border-top: 1px solid var(--back-line);
	font-size: 12px;
	line-height: 1.45;
	opacity: 0.85;
	overflow-wrap: anywhere;
}

body[data-image-size='thumbnail'] .pocket.back {
	padding: 8px;
}

body[data-image-size='thumbnail'] .spec {
	padding: 10px 10px 36px;
}

/* Caption */
.cap {
	padding: 12px 4px 0;
}

.cap h3 {
	overflow: hidden;
	font-size: 16px;
	font-weight: 600;
	letter-spacing: -0.01em;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.card-line {
	margin-top: 3px;
	color: var(--muted);
	font-size: 13px;
}

.chips {
	display: flex;
	flex-wrap: wrap;
	gap: 5px;
	margin-top: 8px;
}

.chip {
	display: inline-flex;
	align-items: center;
	height: 22px;
	padding: 0 8px;
	border-radius: 6px;
	border: 1px solid var(--line);
	background: var(--chip);
	font-size: 12px;
	font-weight: 500;
	white-space: nowrap;
}

.chip-feature {
	background: var(--ink);
	color: var(--bg);
	border-color: var(--ink);
}

.load-more-trigger {
	height: 1px;
}

/* ---------- List layout ---------- */

.table-wrap {
	margin: -8px;
	padding: 8px;
	overflow-x: auto;
}

.collection-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 14px;
}

.collection-table th {
	padding: 0 14px 12px;
	color: var(--muted);
	font-size: 12px;
	font-weight: 500;
	text-align: left;
	white-space: nowrap;
}

.collection-table th button {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

.collection-table th[aria-sort='ascending'] .sort-arrow::after {
	content: '\2191';
}

.collection-table th[aria-sort='descending'] .sort-arrow::after {
	content: '\2193';
}

.collection-table td {
	padding: 10px 14px;
	border-top: 1px solid var(--line);
	vertical-align: middle;
	white-space: nowrap;
}

.collection-table .num {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.collection-table .col-player {
	font-weight: 600;
}

.collection-table .col-notes {
	min-width: 220px;
	max-width: 320px;
	color: var(--muted);
	font-size: 13px;
	white-space: normal;
}

.card-row:hover td {
	background: var(--pocket);
}

.thumb {
	display: grid;
	place-items: center;
	width: 52px;
	aspect-ratio: 5 / 7;
	padding: 4px;
	border-radius: 8px;
	background: var(--pocket);
	border: 1px solid var(--pocket-edge);
}

body[data-image-size='thumbnail'] .thumb {
	width: 40px;
}

body[data-image-size='large'] .thumb {
	width: 72px;
}

.thumb img {
	max-width: 100%;
	max-height: 100%;
	border-radius: 3px;
}

.collection-table .chips {
	flex-wrap: nowrap;
	margin-top: 0;
}

/* ---------- Empty state and pager ---------- */

.empty {
	padding: 72px 16px;
	text-align: center;
}

.empty h2 {
	font-size: 18px;
	font-weight: 600;
}

.empty p {
	margin-top: 6px;
	color: var(--muted);
}

.empty-clear {
	height: 40px;
	margin-top: 18px;
	padding: 0 16px;
	border-radius: 12px;
	border: 1px solid var(--line);
	background: var(--panel);
	font-weight: 500;
	cursor: pointer;
}

.pager {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 16px;
	margin-top: 24px;
}

.pager-btn {
	height: 38px;
	padding: 0 14px;
	border-radius: 10px;
	border: 1px solid var(--line);
	background: var(--panel);
	font-weight: 500;
	cursor: pointer;
}

.pager-btn:disabled {
	opacity: 0.4;
	cursor: default;
}

.pager-info {
	color: var(--muted);
	font-size: 14px;
}

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

.foot {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: center;
	gap: 16px;
	margin-top: 48px;
}

.powered {
	grid-column: 2;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	color: var(--muted);
	font-size: 13px;
	text-decoration: none;
}

.powered img {
	width: auto;
	height: 30px;
}

.theme {
	justify-self: end;
	display: flex;
	gap: 2px;
	padding: 3px;
	border-radius: 12px;
	background: var(--sheet);
	border: 1px solid var(--line);
}

.theme button {
	display: grid;
	place-items: center;
	width: 32px;
	height: 28px;
	border: 0;
	border-radius: 9px;
	background: none;
	color: var(--muted);
	cursor: pointer;
}

.theme button[aria-checked='true'] {
	background: var(--bg);
	color: var(--ink);
}

/* ---------- Expanded card view ---------- */

.viewer {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: grid;
	place-items: center;
	padding: 32px;
	background: var(--scrim);
	backdrop-filter: blur(18px) saturate(1.2);
}

.viewer-panel {
	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 1fr) 360px;
	width: min(1080px, 100%);
	height: min(760px, calc(100dvh - 64px));
	border-radius: 28px;
	background: var(--panel);
	border: 1px solid var(--line);
	box-shadow: 0 40px 80px -30px var(--shadow);
	overflow: hidden;
	animation: viewer-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes viewer-in {
	from {
		opacity: 0;
		transform: translateY(12px) scale(0.985);
	}
}

.viewer-close {
	position: absolute;
	top: 18px;
	right: 18px;
	z-index: 2;
	display: grid;
	place-items: center;
	width: 38px;
	height: 38px;
	border: 0;
	border-radius: 50%;
	background: none;
	color: var(--muted);
	cursor: pointer;
}

.viewer-close:hover {
	background: var(--sheet);
	color: var(--ink);
}

.viewer-stage {
	position: relative;
	display: grid;
	grid-template-rows: auto minmax(0, 1fr) auto;
	gap: 18px;
	min-height: 0;
	padding: 22px;
	background: var(--sheet);
	border-right: 1px solid var(--line);
}

.viewer-top {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: center;
	min-height: 38px;
}

.viewer-count {
	color: var(--muted);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}

.viewer-top .segs button {
	flex: none;
}

.viewer-frame {
	position: relative;
	display: grid;
	place-items: center;
	min-height: 0;
	padding: 28px;
	border-radius: 16px;
	background: var(--pocket);
	border: 1px solid var(--pocket-edge);
	overflow: hidden;
	container-type: size;
}

.viewer-frame img {
	width: min(100cqw, 100cqh * var(--ar, 0.714));
	height: auto;
	aspect-ratio: var(--ar, 0.714);
	border-radius: 8px;
	box-shadow: 0 24px 40px -16px var(--shadow);
	transition: transform 0.25s;
	cursor: zoom-in;
}

.viewer-frame img.zoomed {
	cursor: zoom-out;
}

.viewer-frame.loading img {
	opacity: 0.35;
}

.viewer-frame.loading::after {
	content: '';
	position: absolute;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	border: 3px solid var(--line);
	border-top-color: var(--ink);
	animation: viewer-spin 0.8s linear infinite;
}

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

.viewer-bottom {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.round {
	display: grid;
	place-items: center;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	border: 1px solid var(--line);
	background: var(--panel);
	color: var(--ink);
	cursor: pointer;
}

.round:disabled {
	opacity: 0.35;
	cursor: default;
}

.viewer-zoom {
	display: flex;
	gap: 6px;
}

.viewer-details {
	display: flex;
	flex-direction: column;
	min-height: 0;
	padding: 26px 26px 22px;
	overflow-y: auto;
}

.viewer-details h2 {
	padding-right: 40px;
	font-size: 28px;
	font-weight: 700;
	letter-spacing: -0.03em;
	line-height: 1.1;
	overflow-wrap: anywhere;
}

.viewer-sub {
	margin-top: 6px;
	color: var(--muted);
	font-size: 15px;
}

.viewer-details .status {
	align-self: flex-start;
	margin-top: 14px;
}

.viewer-details .chips {
	margin-top: 14px;
}

.viewer-details dl {
	margin-top: 22px;
	border-top: 1px solid var(--line);
}

.viewer-details .spec-row {
	padding: 13px 0;
	border-top: 0;
	border-bottom: 1px solid var(--line);
	font-size: 14px;
}

.viewer-details .spec-row:first-child {
	padding-top: 13px;
}

.viewer-details dt {
	color: var(--muted);
}

.viewer-details dd {
	font-weight: 500;
	text-align: right;
	overflow-wrap: anywhere;
}

.viewer-notes {
	margin-top: 22px;
}

.viewer-notes h3 {
	color: var(--muted);
	font-size: 13px;
	font-weight: 500;
}

.viewer-notes p {
	margin-top: 6px;
	font-size: 15px;
	line-height: 1.55;
	overflow-wrap: anywhere;
}

/* ---------- Small screens ---------- */

@media (max-width: 860px) {
	.page {
		padding: 20px 16px;
	}

	.tools-main {
		width: 100%;
	}

	.search {
		flex: 1;
		width: auto;
		min-width: 0;
	}

	.tools-share {
		justify-content: space-between;
		width: 100%;
	}

	.tools-share > .brand {
		margin-left: auto;
	}

	.toolbar.stuck {
		flex-wrap: nowrap;
	}

	.toolbar.stuck .tools-main {
		flex: 1;
		width: auto;
	}

	.toolbar.stuck .tools-share {
		width: auto;
	}

	.toolbar.stuck #sort-box,
	.toolbar.stuck #contact-link,
	.toolbar.stuck .share-links {
		display: none;
	}

	.toolbar.stuck .sort-mini {
		display: block;
	}

	.toolbar.stuck .brand {
		margin-left: 0;
		padding-left: 10px;
	}

	.filters {
		width: 100%;
	}

	.sheet {
		padding: 14px;
		border-radius: 20px;
	}

	.sheet:has(> .sheet-bar) {
		padding-top: 10px;
	}

	.sheet-bar {
		margin-bottom: 10px;
	}

	.grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 20px 12px;
	}

	.pocket {
		padding: 12px;
	}

	.pocket.back {
		padding: 8px;
	}

	.spec {
		padding: 10px 10px 44px;
	}

	.spec-row {
		flex-direction: column;
		gap: 1px;
		padding: 6px 0;
	}

	.spec dd {
		text-align: left;
	}

	.foot {
		grid-template-columns: 1fr;
		justify-items: center;
	}

	.powered {
		grid-column: 1;
	}

	.theme {
		justify-self: center;
	}

	.viewer {
		place-items: start stretch;
		padding: 0;
		overflow-y: auto;
	}

	.viewer-panel {
		grid-template-columns: 1fr;
		height: auto;
		min-height: 100dvh;
		border-radius: 0;
		overflow: visible;
	}

	.viewer-stage {
		grid-template-rows: auto auto auto;
		padding: 16px;
		border-right: 0;
		border-bottom: 1px solid var(--line);
	}

	.viewer-top {
		padding-right: 44px;
	}

	.viewer-close {
		top: 12px;
		right: 12px;
		background: var(--panel);
	}

	.viewer-frame {
		height: min(56dvh, 560px);
		padding: 18px;
	}

	.viewer-details {
		padding: 22px 18px 28px;
		overflow: visible;
	}

	.viewer-details h2 {
		padding-right: 0;
	}
}

/* Phones: brand bar on top, one-row toolbar, cards without the sheet frame */
@media (max-width: 600px) {
	.brandbar {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		margin-bottom: 14px;
	}

	.brandbar-logo img {
		width: auto;
		height: 24px;
	}

	.brandbar-actions {
		display: flex;
		align-items: center;
		gap: 6px;
	}

	.brandbar .icon-btn {
		width: 38px;
		height: 38px;
		color: var(--ink);
		border: 1px solid var(--line);
		background: var(--sheet);
	}

	.head h1 {
		font-size: 28px;
	}

	/* Pages rendered before the brand bar existed keep their share row */
	.page:has(> .brandbar) .tools-share {
		display: none;
	}

	.toolbar {
		margin: 12px 0 14px;
	}

	.tools-main {
		flex-wrap: nowrap;
	}

	#sort-box {
		display: none;
	}

	.sort-mini {
		display: block;
	}

	.sheet,
	.sheet:has(> .sheet-bar) {
		padding: 0;
		border: 0;
		border-radius: 0;
		background: none;
	}

	.cap h3 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		white-space: normal;
		overflow-wrap: anywhere;
	}

	.search input {
		text-overflow: ellipsis;
	}

	.chip {
		max-width: 100%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
}

/* Very small phones: one card per row, image beside the text */
@media (max-width: 359px) {
	.grid {
		grid-template-columns: 1fr;
		gap: 10px;
	}

	.card {
		display: grid;
		grid-template-columns: 96px minmax(0, 1fr);
		gap: 12px;
		align-items: center;
		padding: 8px;
		border-radius: 14px;
		border: 1px solid var(--line);
		background: var(--panel);
	}

	.pocket {
		padding: 6px;
		border-radius: 10px;
	}

	.cap {
		padding: 0;
	}

	/* Too small to read a card back; the expanded view still shows every detail */
	.sheet-bar,
	.corner,
	.pocket.back {
		display: none;
	}

	.card.flipped .pocket.front {
		visibility: visible;
	}

	/* Status shrinks to its colored dot */
	.pocket .status {
		top: 5px;
		left: 5px;
		gap: 0;
		width: 16px;
		height: 16px;
		padding: 0;
		justify-content: center;
		font-size: 0;
	}

	.fav {
		top: 5px;
		right: 5px;
		width: 20px;
		height: 20px;
	}

	.page {
		padding: 16px 12px;
	}

	.tools-main {
		gap: 6px;
	}

	.tools-main .icon-btn.tool {
		width: 38px;
	}

	.search {
		gap: 6px;
		padding: 0 10px;
	}
}

/* Narrower still: the text column beside the image gets too thin, so stack them */
@media (max-width: 279px) {
	.card {
		grid-template-columns: minmax(0, 1fr);
	}

	.flipper {
		width: 60%;
		justify-self: center;
	}
}

/* Short screens: small laptops, browser zoom, landscape phones */
@media (max-height: 760px) {
	.viewer {
		padding: 16px;
	}

	.viewer-panel {
		height: calc(100dvh - 32px);
	}

	.viewer-stage {
		gap: 12px;
		padding: 16px;
	}

	.viewer-frame {
		padding: 18px;
	}

	.viewer-details {
		padding: 20px 22px;
	}

	.viewer-details .spec-row {
		padding: 10px 0;
	}
}

@media (max-height: 560px) and (orientation: landscape) {
	.viewer {
		place-items: center;
		padding: 8px;
		overflow: hidden;
	}

	.viewer-panel {
		grid-template-columns: minmax(0, 1fr) 300px;
		height: calc(100dvh - 16px);
		min-height: 0;
		border-radius: 18px;
		overflow: hidden;
	}

	.viewer-stage {
		grid-template-rows: auto minmax(0, 1fr) auto;
		gap: 8px;
		padding: 10px;
		border-right: 1px solid var(--line);
		border-bottom: 0;
	}

	.viewer-top {
		padding-right: 0;
	}

	.viewer-frame {
		height: auto;
		padding: 10px;
	}

	.round {
		width: 34px;
		height: 34px;
	}

	.viewer-close {
		top: 8px;
		right: 8px;
		background: none;
	}

	.viewer-details {
		padding: 14px 16px;
		overflow-y: auto;
	}

	.viewer-details h2 {
		padding-right: 36px;
		font-size: 22px;
	}

	.viewer-details dl {
		margin-top: 14px;
	}

	.viewer-details .spec-row {
		padding: 8px 0;
		font-size: 13px;
	}
}

/* Browsers without container query units (Safari before 16) fit images with object-fit instead. */
@supports not (width: 1cqw) {
	.pocket img.card-image,
	.viewer-frame img {
		width: 100%;
		height: 100%;
		aspect-ratio: auto;
		object-fit: contain;
		box-shadow: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	body,
	.toolbar::before,
	.sort-dir svg,
	.corner,
	.pocket img.loaded,
	.viewer-frame img {
		transition: none;
	}

	.viewer-panel,
	.viewer-frame.loading::after {
		animation: none;
	}
}
