/* iOS-flavored styling. Light and dark palettes follow Apple's system
   colors (systemGroupedBackground, secondaryLabel, systemBlue, ...);
   dark mode stays automatic via prefers-color-scheme. */

:root {
	--bg: #f2f2f7;                 /* systemGroupedBackground */
	--surface: #ffffff;            /* grouped cell */
	--surface-2: #e5e5ea;          /* fills, segmented track */
	--border: #d8d8dc;
	--border-soft: #e9e9ee;
	--text: #1c1c1e;               /* label */
	--muted: #85858b;              /* secondaryLabel */
	--accent: #007aff;             /* systemBlue */
	--accent-soft: rgba(0, 122, 255, 0.12);
	--danger: #ff3b30;             /* systemRed */
	--danger-soft: rgba(255, 59, 48, 0.12);
	--warn: #ff9500;               /* systemOrange */
	--warn-soft: rgba(255, 149, 0, 0.15);
	--ok: #34c759;                 /* systemGreen */
	--ok-soft: rgba(52, 199, 89, 0.15);
	--fill: rgba(118, 118, 128, 0.12);
	--seg-active: #ffffff;
	--radius: 12px;
	--radius-sm: 9px;
	--hairline: 1px;
	--shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 4%);
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #000000;
		--surface: #1c1c1e;
		--surface-2: #2c2c2e;
		--border: #38383a;
		--border-soft: #2a2a2c;
		--text: #f2f2f7;
		--muted: #98989e;
		--accent: #0a84ff;
		--accent-soft: rgba(10, 132, 255, 0.18);
		--danger: #ff453a;
		--danger-soft: rgba(255, 69, 58, 0.16);
		--warn: #ff9f0a;
		--warn-soft: rgba(255, 159, 10, 0.16);
		--ok: #30d158;
		--ok-soft: rgba(48, 209, 88, 0.16);
		--fill: rgba(118, 118, 128, 0.24);
		--seg-active: #636366;
		--shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 14px rgb(0 0 0 / 25%);
	}
}

* {
	box-sizing: border-box;
}

html {
	color-scheme: light dark;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text",
		system-ui, "Segoe UI", Roboto, sans-serif;
	-webkit-font-smoothing: antialiased;
	-webkit-tap-highlight-color: transparent;
}

a {
	color: var(--accent);
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

.topbar {
	display: flex;
	align-items: baseline;
	gap: 10px;
	padding: 12px 20px;
	background: var(--bg);
	border-bottom: var(--hairline) solid var(--border-soft);
}

.brand {
	font-weight: 700;
	font-size: 16px;
	color: var(--text);
	letter-spacing: -0.02em;
}

.brand:hover {
	text-decoration: none;
}

/* Top navigation: pushed right, pill-highlighted current page. */
.topnav {
	margin-left: auto;
	display: flex;
	gap: 4px;
	align-items: center;
}

.topnav a {
	padding: 5px 12px;
	border-radius: 999px;
	color: var(--muted);
	font-size: 13px;
	font-weight: 500;
}

.topnav a:hover {
	color: var(--text);
	text-decoration: none;
	background: var(--fill);
}

.topnav a.active {
	color: var(--text);
	background: var(--seg-active);
	box-shadow: 0 1px 3px rgb(0 0 0 / 14%);
}

.wrap {
	max-width: 1240px;
	margin: 0 auto;
	padding: 14px 20px 56px;
}

.searchbar {
	display: flex;
	gap: 8px;
	align-items: stretch;
}

/* Filled iOS search field: no visible border until focus. */
.searchbar input[type="search"] {
	flex: 1;
	min-width: 0;
	padding: 9px 13px;
	font-size: 15px;
	color: var(--text);
	background: var(--fill);
	border: var(--hairline) solid transparent;
	border-radius: var(--radius-sm);
	outline: none;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.searchbar input[type="search"]:focus {
	background: var(--surface);
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}

button,
.btn {
	padding: 8px 16px;
	font: inherit;
	font-size: 14px;
	font-weight: 600;
	color: #fff;
	background: var(--accent);
	border: none;
	border-radius: 999px;
	cursor: pointer;
	white-space: nowrap;
	transition: filter 0.15s ease, transform 0.1s ease;
}

button:hover,
.btn:hover {
	filter: brightness(1.08);
}

button:active,
.btn:active {
	transform: scale(0.97);
}

/* Tinted secondary buttons: soft fill, colored label, no border. */
.btn.ghost {
	background: var(--accent-soft);
	color: var(--accent);
	padding: 6px 12px;
	font-size: 13px;
}

.btn.ghost:hover {
	background: var(--accent-soft);
	color: var(--accent);
	filter: brightness(1.1);
}

.btn.ghost.danger {
	color: var(--danger);
	background: var(--danger-soft);
}

.btn.ghost.danger:hover {
	color: var(--danger);
	background: var(--danger-soft);
	filter: brightness(1.1);
}

.dlbar-x {
	display: inline-flex;
}

.dlbar-x .btn {
	background: transparent;
	color: var(--muted);
	font-size: 12px;
	padding: 0 2px;
	line-height: 1;
	opacity: .6;
}

.dlbar-x .btn:hover {
	color: var(--danger);
	opacity: 1;
	filter: none;
}

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

.actions form {
	margin: 0;
}

.attempt {
	margin-left: 8px;
	font-size: 11.5px;
	font-style: italic;
	color: var(--warn);
}

/* Segmented control. */
.tabs {
	display: flex;
	gap: 2px;
	margin: 12px 0;
	padding: 2px;
	background: var(--fill);
	border-radius: var(--radius-sm);
}

.tab {
	flex: 1;
	max-width: 160px;
	padding: 6px 12px;
	color: var(--text);
	font-size: 13.5px;
	font-weight: 500;
	text-align: center;
	border-radius: 7px;
	transition: background 0.15s ease;
}

.tab:hover {
	text-decoration: none;
	background: color-mix(in srgb, var(--seg-active) 40%, transparent);
}

.tab.active {
	background: var(--seg-active);
	font-weight: 600;
	box-shadow: 0 1px 3px rgb(0 0 0 / 14%);
}

.result-head {
	display: flex;
	gap: 12px;
	align-items: baseline;
	margin: 6px 0 10px;
	font-size: 13px;
	font-weight: 600;
}

.muted {
	color: var(--muted);
	font-weight: 400;
}

.small {
	font-size: 12px;
}

.empty,
.notice {
	padding: 16px;
	background: var(--surface);
	border: none;
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	color: var(--muted);
	font-size: 13.5px;
}

.notice {
	color: var(--warn);
	background: var(--warn-soft);
}

.alert {
	display: block;
	margin: 10px 0;
	padding: 10px 14px;
	font-size: 13px;
	background: var(--danger-soft);
	border: none;
	border-radius: var(--radius-sm);
	color: var(--danger);
}

table.grid {
	width: 100%;
	border-collapse: collapse;
	background: var(--surface);
	border: none;
	border-radius: var(--radius);
	overflow: hidden;
	box-shadow: var(--shadow);
	font-size: 13.5px;
}

table.grid th {
	text-align: left;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	font-weight: 600;
	color: var(--muted);
	padding: 8px 12px;
	border-bottom: var(--hairline) solid var(--border-soft);
	background: var(--surface-2);
	white-space: nowrap;
}

table.grid td {
	padding: 9px 12px;
	border-bottom: var(--hairline) solid var(--border-soft);
	vertical-align: top;
}

table.grid tr:last-child td {
	border-bottom: none;
}

table.grid tbody tr {
	transition: background 0.12s ease;
}

table.grid tbody tr:hover {
	background: color-mix(in srgb, var(--accent-soft) 45%, transparent);
}

.fname {
	font-weight: 500;
	overflow-wrap: anywhere;
}

.fdir {
	font-size: 11.5px;
	color: var(--muted);
	overflow-wrap: anywhere;
	margin-top: 1px;
}

/* Score pill. */
.score {
	display: inline-block;
	min-width: 26px;
	padding: 2px 8px;
	text-align: center;
	border-radius: 999px;
	background: var(--fill);
	color: var(--muted);
	font-size: 11.5px;
	font-variant-numeric: tabular-nums;
	font-weight: 700;
}

.score.good {
	background: var(--accent-soft);
	color: var(--accent);
}

.score.great {
	background: var(--ok-soft);
	color: var(--ok);
}

.badge {
	display: inline-block;
	padding: 2px 9px;
	border-radius: 999px;
	font-size: 11px;
	font-weight: 600;
	background: var(--fill);
	color: var(--muted);
	white-space: nowrap;
}

.badge.active {
	background: var(--accent-soft);
	color: var(--accent);
}

.badge.queued {
	background: var(--warn-soft);
	color: var(--warn);
}

.badge.done {
	background: var(--ok-soft);
	color: var(--ok);
}

.badge.failed {
	background: var(--danger-soft);
	color: var(--danger);
}

.downloads-wrap {
	margin-top: 28px;
}

/* Library page sections. */
.library-section {
	margin-top: 18px;
}

.section-title {
	margin: 0 0 10px;
	font-size: 15px;
	letter-spacing: -0.01em;
}

.card-title {
	font-weight: 600;
	overflow-wrap: anywhere;
}

/* Collapsible downloads bar pinned under the topbar: frosted glass over the
   scrolling content, like an iOS navigation bar. */
.dlbar {
	position: sticky;
	top: 0;
	z-index: 20;
	background: color-mix(in srgb, var(--bg) 70%, transparent);
	backdrop-filter: blur(20px) saturate(180%);
	-webkit-backdrop-filter: blur(20px) saturate(180%);
	border-bottom: var(--hairline) solid var(--border-soft);
}

.dlbar-toggle {
	display: flex;
	align-items: center;
	gap: 9px;
	width: 100%;
	padding: 8px 20px;
	font: inherit;
	font-size: 13px;
	font-weight: 500;
	text-align: left;
	color: var(--text);
	background: transparent;
	border: none;
	border-radius: 0;
}

.dlbar-toggle:hover {
	filter: none;
	background: color-mix(in srgb, var(--fill) 60%, transparent);
}

.dlbar-toggle:active {
	transform: none;
}

.dlbar .chev {
	font-size: 9px;
	color: var(--muted);
	transition: transform 0.15s ease;
	line-height: 1;
}

.dlbar.open .chev {
	transform: rotate(90deg);
}

.dlbar-title {
	font-size: 12px;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	font-weight: 600;
}

.dlbar-progress {
	flex: 1;
	max-width: 300px;
	height: 4px;
	background: var(--fill);
	border: none;
	border-radius: 999px;
	overflow: hidden;
}

.dlbar-progress span {
	display: block;
	height: 100%;
	background: var(--accent);
	transition: width 0.4s ease;
}

.dlbar-body {
	padding: 4px 20px 12px;
	border-top: var(--hairline) solid var(--border-soft);
}

.dlbar:not(.open) .dlbar-body {
	display: none;
}

.dlbar-empty {
	margin: 3px 0;
}

.dlbar-list {
	list-style: none;
	margin: 0;
	padding: 0;
	max-height: 40vh;
	overflow-y: auto;
}

.dlbar-list li {
	padding: 6px 0;
	border-bottom: var(--hairline) solid var(--border-soft);
}

.dlbar-list li:last-child {
	border-bottom: none;
}

.dlbar-row {
	display: flex;
	align-items: baseline;
	gap: 10px;
	margin-bottom: 3px;
}

.dlbar-row .fname {
	flex: 1;
	min-width: 0;
	font-size: 12.5px;
	overflow-wrap: anywhere;
}

.dlbar-stats {
	display: flex;
	gap: 9px;
	white-space: nowrap;
	align-items: baseline;
}

.panel {
	padding: 14px 16px;
	background: var(--surface);
	border: none;
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

.panel-head {
	display: flex;
	align-items: baseline;
	gap: 10px;
	margin-bottom: 10px;
}

.panel-head h2 {
	margin: 0;
	font-size: 15px;
	letter-spacing: -0.01em;
}

.counts {
	margin-left: auto;
	display: flex;
	gap: 5px;
}

.progress {
	height: 4px;
	background: var(--fill);
	border: none;
	border-radius: 999px;
	overflow: hidden;
	min-width: 80px;
}

.progress span {
	display: block;
	height: 100%;
	background: var(--accent);
	transition: width 0.4s ease;
}

.progress-cell {
	min-width: 130px;
}

.err {
	color: var(--danger);
	font-size: 12px;
	overflow-wrap: anywhere;
}

/* Catalog pages (MusicBrainz). */
.page-head {
	display: flex;
	align-items: baseline;
	gap: 10px;
	flex-wrap: wrap;
	margin: 6px 0 14px;
}

.page-head h1 {
	margin: 0;
	font-size: 26px;
	font-weight: 700;
	letter-spacing: -0.02em;
}

.card-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
	gap: 12px;
}

.card {
	display: flex;
	flex-direction: column;
	gap: 3px;
	padding: 10px;
	background: var(--surface);
	border: none;
	border-radius: 14px;
	box-shadow: var(--shadow);
	color: var(--text);
	font-size: 12.5px;
	transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.card:hover {
	text-decoration: none;
	transform: translateY(-1px);
	box-shadow: 0 2px 4px rgb(0 0 0 / 8%), 0 8px 22px rgb(0 0 0 / 8%);
}

.card:active {
	transform: scale(0.98);
}

.card .cover {
	width: 100%;
	aspect-ratio: 1;
	object-fit: cover;
	border-radius: 8px;
	background: var(--fill);
	margin-bottom: 4px;
}

.album-head {
	display: flex;
	gap: 18px;
	align-items: flex-start;
	margin-bottom: 16px;
}

.album-cover {
	width: 150px;
	flex-shrink: 0;
}

/* Cover artwork gets a soft lift in both themes. */
.album-cover,
.card .cover {
	border-radius: 8px;
	box-shadow: 0 2px 8px rgb(0 0 0 / 15%);
}

/* Result rows collapse into stacked cards on phones. Labeled cells carry a
   data-th attribute; plain cells (title, score chip, buttons, progress) do
   not and render without a label. */
table.grid td[data-th]::before {
	content: attr(data-th);
	display: inline-block;
	min-width: 60px;
	margin-right: 8px;
	font-size: 10px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.07em;
	color: var(--muted);
}

/* Horizontal scroll for tables that stay tabular on small screens. */
.table-scroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.album-cover {
	width: 150px;
	flex-shrink: 0;
}


@media (max-width: 760px) {
	.wrap {
		padding: 10px 12px 40px;
	}

	/* Topbar: keep brand and sign-out, drop the tagline. */
	.topbar {
		padding: 10px 14px;
		gap: 8px;
		flex-wrap: wrap;
	}
	.topbar .tagline {
		display: none;
	}

	/* 16px input stops iOS Safari zooming on focus; bigger touch targets. */
	.searchbar input[type="search"] {
		font-size: 16px;
		padding: 10px 13px;
	}
	button,
	.btn {
		padding: 10px 18px;
	}
	.btn.ghost {
		padding: 8px 12px;
	}

	/* Segmented control scrolls sideways instead of overflowing. */
	.tabs {
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none;
	}
	.tab {
		padding: 8px 12px;
		white-space: nowrap;
	}

	.dlbar-toggle {
		padding: 8px 14px;
	}
	.dlbar-body {
		padding: 4px 14px 12px;
	}

	/* Each result row becomes a card. */
	table.grid {
		border: none;
		background: transparent;
		box-shadow: none;
		font-size: 13.5px;
	}
	table.grid:not(.tracklist) thead {
		display: none;
	}
	table.grid:not(.tracklist) tbody tr {
		display: block;
		background: var(--surface);
		border: none;
		border-radius: 14px;
		box-shadow: var(--shadow);
		margin-bottom: 10px;
		padding: 6px 0;
	}
	table.grid:not(.tracklist) tbody tr:hover {
		background: var(--surface);
	}
	table.grid:not(.tracklist) td {
		display: block;
		padding: 3px 12px;
		border-bottom: none;
	}
	table.grid:not(.tracklist) td:first-child {
		padding-top: 8px;
	}
	table.grid:not(.tracklist) td:last-child {
		padding-bottom: 8px;
	}

	/* Action buttons sit on their own right-aligned line. */
	table.grid td.row-actions {
		text-align: right;
	}
	table.grid td.row-actions form {
		display: inline-block;
	}

	/* The tracklist stays a table; scroll it if it overflows. */
	table.tracklist {
		display: block;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}

	/* Album page: cover stacks above the title and actions. */
	.album-head {
		flex-direction: column;
		gap: 10px;
	}
	.album-cover {
		width: 132px;
	}
}

@media (max-width: 560px) {
	/* Tighter artist/album cards: two-to-three per row on a phone. */
	.card-grid {
		grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
		gap: 10px;
	}
}
