/*
 * Ultralight web tier - hand-written, no framework, no generated CSS.
 * Budget is 20KB gzipped (05 §S4); this sits far under it.
 *
 * Layout is flexbox + normal document flow ONLY. CSS Grid appears exactly once,
 * inside @supports, as a Tier-A enhancement - using it as the primary layout
 * collapses on the KaiOS 2.5 reference device.
 *
 * No web fonts and no icon fonts: zero bytes downloaded for typography, glyphs are
 * Unicode. No animations - Tier C strips them and they cost paint time on Tier B.
 *
 * Every visual device here is free at the network layer. Album artwork is the obvious
 * thing a music app would reach for and it is deliberately absent: STB serves only
 * full-size 1000x1000 art (~160KB each, no thumbnail variant), which one home page
 * would multiply into megabytes. The list tiles below buy the same scannability with
 * markup instead of images.
 */

:root {
	--accent: #4f46e5;
	--bg: #ffffff;
	--bg-alt: #fafafa;
	--bg-sunk: #f4f4f6;
	--ink: #111111;
	--ink-soft: #3d3d46;
	--muted: #666666;
	--line: #e5e5e5;
	--line-soft: #f0f0f2;
	--btn-ink: #ffffff;
	--ok: #10b981;
	--err: #ef4444;
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--ink);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 16px;
	line-height: 1.45;
}

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

/*
 * Focus styling is not cosmetic here. KaiOS and other feature phones navigate with a
 * D-pad, so the focus ring IS the cursor - without it the page is unusable by keypad.
 * It stays the loudest thing on the page on purpose; nothing decorative may outrank it.
 */
a:focus,
button:focus,
input:focus,
select:focus,
[tabindex]:focus {
	outline: 3px solid var(--accent);
	outline-offset: 1px;
}

/* header */
.bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 12px;
	border-bottom: 1px solid var(--line);
	background: var(--bg);
}

.brand {
	font-weight: 700;
	font-size: 18px;
	letter-spacing: -.01em;
	color: var(--ink);
}

/*
 * A word, not a glyph. The old header used U+26B2 as a search icon, which is not a
 * magnifier on any platform and is missing from plenty of feature-phone fonts. Text
 * costs the same zero bytes and is unambiguous everywhere.
 */
.bar-links a {
	font-size: 14px;
	color: var(--accent);
}

/*
 * Keeps the tab bar near the bottom on short pages instead of stranding it mid-screen
 * with white space beneath. Pure normal flow - no flex on body, no fixed positioning -
 * so a browser that ignores vh simply gets today's layout.
 */
main {
	padding: 12px;
	min-height: 62vh;
}

h1 {
	font-size: 21px;
	line-height: 1.25;
	margin: 0 0 4px;
	letter-spacing: -.01em;
}

/*
 * Shelf headings lead rather than whisper. They were 15px muted uppercase - quieter
 * than the rows they label, which is backwards on a page that is nine shelves long.
 */
h2 {
	font-size: 16px;
	font-weight: 700;
	color: var(--ink);
	margin: 0 0 8px;
	padding-left: 8px;
	border-left: 3px solid var(--accent);
	/*
	 * Shelf names come from STB section data and are not consistently cased - the dev
	 * channel has "Top Albums" next to "sunday bangs". The old uppercase transform hid
	 * that; capitalize keeps the headings even without shouting.
	 */
	text-transform: capitalize;
}

.shelf {
	margin-bottom: 22px;
}

/* lists */
ul.list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.row {
	border-bottom: 1px solid var(--line-soft);
}

.row:last-child {
	border-bottom: 0;
}

.row a {
	display: flex;
	align-items: center;
	padding: 9px 4px;
	color: var(--ink);
}

/*
 * min-width:0 is what actually lets the text column shrink far enough for the ellipsis
 * below to fire; a flex item defaults to min-width:auto and refuses to go under its
 * content width.
 */
.row-text {
	flex: 1 1 auto;
	min-width: 0;
}

/*
 * One line each, clipped. Uniform row heights are the difference between a list you can
 * scan and a ragged wall of text - at 240px, titles like "Sabrina Carpenter - Top Hits"
 * were wrapping to three lines. The full name is never lost: it is the h1 of the page
 * the row opens.
 */
.row-title,
.row-meta {
	display: block;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.row-title {
	font-weight: 600;
	font-size: 15px;
}

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

/*
 * The zero-byte stand-in for album art: the album's first letter on a tint derived from
 * its id, so the same album always draws the same colour. It gives each row an anchor
 * to scan by and costs no request, no decode and no layout shift.
 */
.tile {
	flex: 0 0 auto;
	width: 36px;
	height: 36px;
	margin-right: 10px;
	background: var(--accent);
	color: var(--btn-ink);
	font-size: 17px;
	font-weight: 700;
	line-height: 36px;
	text-align: center;
}

.tile.t0 { background: #4f46e5; }
.tile.t1 { background: #0d9488; }
.tile.t2 { background: #b45309; }
.tile.t3 { background: #be123c; }
.tile.t4 { background: #6d28d9; }
.tile.t5 { background: #0369a1; }

/* Track rows carry a number in place of a tile - cheaper and more useful on an album. */
.num {
	flex: 0 0 auto;
	width: 24px;
	margin-right: 8px;
	color: var(--muted);
	font-size: 13px;
	text-align: right;
}

/* "More <shelf>" link under a home-page shelf preview */
.more {
	margin: 8px 0 0;
	padding: 4px;
	font-size: 14px;
}

/*
 * ads
 *
 * Framed as a slot and visually subordinate to the content. The old treatment let a
 * saturated creative be the loudest element on the page - on the player screen it
 * outweighed the song itself.
 */
.ad {
	display: flex;
	flex-direction: column;
	align-items: center;
	margin: 16px 0;
	padding: 8px;
	background: var(--bg-sunk);
	border: 1px solid var(--line);
}

.ad img {
	max-width: 100%;
	height: auto;
	display: block;
}

.ad-label {
	align-self: flex-start;
	margin-bottom: 6px;
	color: var(--muted);
	font-size: 10px;
	letter-spacing: .08em;
	text-transform: uppercase;
}

.ad-remove {
	font-size: 12px;
	margin-top: 8px;
	color: var(--muted);
	text-decoration: underline;
}

/*
 * player
 *
 * Continues the now-playing block's surface and accent rule so the song and its
 * transport read as one card instead of a heading with a control loose beneath it.
 *
 * The transport's own colours are not ours. Firefox draws it dark grey (measured
 * rgb(72,72,72)) on every page and in both OS themes; Chromium draws it light. That is
 * not something CSS can reach - the internals are UA shadow DOM, color-scheme does not
 * touch them, and replacing the control needs JavaScript the tier does not have
 * (ULT-06, Tier C strips JS entirely). This light surround is the compromise that
 * frames it acceptably in both engines. Do not add color-scheme here expecting a fix:
 * it was tried, measured and reverted.
 */
.player {
	margin: 0 0 14px;
	padding: 0 12px 12px;
	background: var(--bg-alt);
	border-left: 3px solid var(--accent);
}

.player audio {
	width: 100%;
	display: block;
}

/*
 * Now-playing block. The player is the one screen a music app is judged on and it was
 * the emptiest in the tier - a title, an artist and a native audio bar. The album line
 * and position give it context; the controls below give it somewhere to go.
 */
.np {
	padding: 12px 12px 10px;
	margin-bottom: 0;
	background: var(--bg-alt);
	border-left: 3px solid var(--accent);
}

.track-title {
	font-size: 19px;
	font-weight: 700;
	line-height: 1.25;
	margin: 0;
}

.track-artist {
	color: var(--ink-soft);
	margin: 3px 0 0;
}

.track-pos {
	color: var(--muted);
	font-size: 13px;
	margin: 6px 0 0;
}

/* Prev and Next share a row so skipping either way is one keypress from the other. */
.np-nav {
	display: flex;
	margin-top: 16px;
}

.np-nav .btn {
	flex: 1 1 0;
	margin: 0 4px;
	padding: 12px 6px;
}

/* buttons and forms */
.btn {
	display: inline-block;
	padding: 12px 18px;
	border: 1px solid var(--accent);
	color: var(--accent);
	background: var(--bg);
	font-size: 16px;
	font-family: inherit;
	cursor: pointer;
	text-align: center;
}

.btn.solid {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--btn-ink);
}

.btn.block {
	display: block;
	width: 100%;
	margin-top: 10px;
}

/* A disabled-looking end stop, so Prev on track 1 still occupies its half of the row. */
.btn.off {
	border-color: var(--line);
	color: var(--muted);
	background: var(--bg-alt);
}

input[type="text"],
input[type="search"],
input[type="tel"],
select {
	width: 100%;
	padding: 11px;
	border: 1px solid var(--line);
	font-size: 16px;
	font-family: inherit;
	background: var(--bg);
	color: var(--ink);
}

/* Country picker sits above the number field in the same fieldset. */
select {
	margin-bottom: 8px;
}

fieldset {
	border: 1px solid var(--line);
	margin: 0 0 14px;
	padding: 10px 12px;
}

legend {
	color: var(--muted);
	font-size: 13px;
	padding: 0 4px;
}

/*
 * The control's spacing is a margin, not flex "gap": gap in a FLEX container is
 * Firefox 63, and the reference device is Gecko 48, so on a KaiOS handset the checkbox
 * sat flush against its label - absent on the one device this tier exists for.
 */
label.opt {
	display: flex;
	align-items: center;
	padding: 10px 2px;
	border-bottom: 1px solid var(--line);
}

label.opt:last-child {
	border-bottom: 0;
}

label.opt input {
	margin-right: 10px;
}

/* pagination */
.pager {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: 14px;
	padding-top: 10px;
	border-top: 1px solid var(--line);
}

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

/* key/value rows on account */
.kv {
	display: flex;
	justify-content: space-between;
	padding: 11px 2px;
	border-bottom: 1px solid var(--line);
}

.kv span:first-child {
	color: var(--muted);
}

/* status */
.note {
	padding: 12px;
	background: var(--bg-alt);
	border-left: 3px solid var(--accent);
	margin: 0 0 14px;
}

.note.good {
	border-left-color: var(--ok);
}

.note.bad {
	border-left-color: var(--err);
}

.big-ok {
	font-size: 40px;
	color: var(--ok);
	text-align: center;
	margin: 10px 0;
}

.muted {
	color: var(--muted);
}

.center {
	text-align: center;
}

/* Back link above a page title - small, out of the way of the heading it precedes. */
.back {
	display: inline-block;
	margin: 0 0 10px;
	font-size: 14px;
}

/* An empty list should read as an answer, not as a page that failed to load. */
.empty {
	padding: 22px 12px;
	background: var(--bg-alt);
	border: 1px solid var(--line);
	color: var(--muted);
	text-align: center;
}

/*
 * Bottom tabs sit in NORMAL DOCUMENT FLOW, not position:fixed.
 *
 * Fixed positioning is a trap on this floor: Opera Mini (Tier C) renders a server-side
 * snapshot where a fixed bar can strand itself mid-page, and Gecko 48 on KaiOS handles
 * it inconsistently. Flow layout costs nothing and renders identically everywhere,
 * which is the whole reason the spec names flexbox + normal flow as the primitive.
 */
.tabs {
	display: flex;
	background: var(--bg);
	border-top: 1px solid var(--line);
	margin-top: 8px;
}

.tabs a {
	flex: 1 1 0;
	text-align: center;
	padding: 12px 2px;
	font-size: 13px;
	color: var(--muted);
	border-right: 1px solid var(--line);
	border-top: 2px solid transparent;
}

.tabs a:last-child {
	border-right: 0;
}

/* Where you are. A colour change alone would not survive a monochrome screen. */
.tabs a.on {
	color: var(--accent);
	font-weight: 600;
	border-top-color: var(--accent);
	background: var(--bg-alt);
}

/*
 * ---------------------------------------------------------------------------
 * WIDE SCREENS - laptop and monitor presentation.
 *
 * Everything below this line is behind a min-width query, so the 240px KaiOS
 * reference device and every Tier B/C handset render byte-identically to a build
 * with this whole section deleted. Nothing here is load-bearing.
 *
 * The album lists become a card grid, with the row's colour tile blown up into a
 * large square that stands in for cover art. That is the same zero-byte tile the
 * phone uses - no images are introduced, because the only artwork STB offers is
 * 1000x1000 JPEGs at ~160KB apiece (see Album.java).
 * ---------------------------------------------------------------------------
 */

/* Two up on a roomy phone or a small tablet - still list rows, not cards yet. */
@supports (display: grid) {
	@media (min-width: 480px) and (max-width: 699px) {
		.albums {
			display: grid;
			grid-template-columns: 1fr 1fr;
			column-gap: 16px;
		}

		/*
		 * Same min-width:auto trap as the flex row: without this a grid item refuses to
		 * shrink below its content and the second column runs off the right edge instead
		 * of ellipsing.
		 */
		.albums > .row {
			min-width: 0;
		}
	}
}

@media (min-width: 700px) {
	:root {
		--page: 1040px;
		--gutter: 28px;
	}

	main {
		max-width: var(--page);
		margin: 0 auto;
		padding: 20px var(--gutter) 34px;
		/* Keeps the tab bar off the fold on a short page. */
		min-height: 62vh;
	}

	/*
	 * Pull the header and tab bar's CONTENTS into line with the content column while
	 * their rules still span the window. 680px is --page/2, so the first glyph of
	 * "Toqqer" sits directly above the first card. The max() floor takes over below
	 * --page, where the column is already full width.
	 *
	 * Padding rather than an inner wrapper, so no extra markup ships to the handset.
	 */
	.bar,
	.tabs {
		padding-left: max(var(--gutter), calc(50% - 520px + var(--gutter)));
		padding-right: max(var(--gutter), calc(50% - 520px + var(--gutter)));
	}

	.brand {
		font-size: 20px;
	}

	.bar-links a {
		font-size: 15px;
	}

	h1 {
		font-size: 26px;
		margin-bottom: 6px;
	}

	h2 {
		font-size: 18px;
		margin-bottom: 0;
	}

	/*
	 * The shelf turns into a flex row so the heading and its "More" link share one line
	 * with the link pushed right, and the grid drops to the next line on a 100% basis.
	 * Done with order/basis rather than by moving the markup, because on the phone the
	 * "More" link belongs AFTER the list it extends, which is where the HTML puts it.
	 */
	.shelf {
		display: flex;
		flex-wrap: wrap;
		align-items: baseline;
		margin-bottom: 34px;
	}

	.shelf h2 {
		order: 1;
	}

	.shelf .more {
		order: 2;
		margin: 0 0 0 auto;
		font-size: 14px;
	}

	.shelf .albums {
		order: 3;
		flex: 0 0 100%;
		margin-top: 14px;
	}

	/* The between-shelf ad slot is a child of the first shelf; keep it on its own line. */
	.shelf .ad {
		order: 4;
		flex: 0 0 100%;
	}
}

/*
 * The cards themselves. Grid only, and only here - the flex list above remains the
 * primary layout on every device that matters.
 */
@supports (display: grid) {
	@media (min-width: 700px) {
		/*
		 * Fixed column counts, not auto-fill. A home shelf previews exactly five albums
		 * (ShelfPreview.PREVIEW_SIZE), so auto-fill kept computing a sixth track and
		 * leaving a dead column with the "More" link stranded past the last card.
		 */
		.albums {
			display: grid;
			grid-template-columns: repeat(3, 1fr);
			gap: 20px 18px;
		}

		.albums > .row {
			min-width: 0;
			border-bottom: 0;
		}

		.albums .row a {
			display: block;
			padding: 0;
		}

		/*
		 * The tile becomes the artwork: a full-width square with the album initial. Flex
		 * centring replaces the line-height trick the 36px phone tile uses, because the
		 * height is no longer a fixed number.
		 */
		.albums .tile {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: auto;
			/*
			 * min-height is the floor for engines that do grid but not aspect-ratio -
			 * @supports (display: grid) passes from Chrome 57 / Firefox 52, while
			 * aspect-ratio only lands in Chrome 88 / Firefox 89. Without it the tile
			 * collapses to one line of text there and the card becomes a colour strip.
			 * It never binds where aspect-ratio works: the narrowest column is 166px.
			 */
			min-height: 150px;
			aspect-ratio: 1 / 1;
			margin: 0 0 10px;
			font-size: 38px;
			line-height: 1;
		}

		.albums .row-title {
			font-size: 15px;
			margin-bottom: 1px;
		}

		.albums .row-meta {
			font-size: 12px;
		}

		/* A card is a whole target, so the focus ring belongs round the card. */
		.albums .row a:focus {
			outline: 3px solid var(--accent);
			outline-offset: 2px;
		}
	}

	@media (min-width: 820px) {
		.albums {
			grid-template-columns: repeat(4, 1fr);
		}
	}

	/*
	 * Five across is the shelf preview's own size, so a home row fills exactly. The
	 * step-ups happen early on purpose: a column count that holds too long makes the
	 * cards balloon near the top of its band - four across at 1024px drew a 229px card,
	 * larger than the same card at 1440px.
	 */
	@media (min-width: 960px) {
		.albums {
			grid-template-columns: repeat(5, 1fr);
		}
	}
}

/*
 * Track lists are not albums and never become cards - a song has no artwork of its
 * own here, and a numbered row is the right shape for it. They keep the list form at
 * every width, just capped so the rows do not run the full 1360px.
 */
@media (min-width: 700px) {
	.tracklist,
	.ad,
	.np,
	.player,
	.np-nav,
	form,
	.kv,
	.note,
	.empty {
		max-width: 620px;
	}
}
