/* ==========================================================================
   mobile.css
   Loaded after the core and feature stylesheets. It holds viewport-specific
   adjustments for the page shell, results, overlays, and touch controls.
   ========================================================================== */

/* ---------- All sizes: small safety nets ---------- */
html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

button,
.tab,
.mode-btn,
.results-tab,
.topn-btn,
.swatch {
	touch-action: manipulation;
}

/* ---------- <= 880px: tablets and below ---------- */
@media (max-width: 880px) {
	/* 1fr = minmax(auto, 1fr): wide children (the heat map, the compare table)
	   could stretch the column past the screen and make the whole page scroll
	   sideways. minmax(0, 1fr) lets them scroll inside their own box instead. */
	.layout,
	.layout.explanation-mode,
	.layout.updates-mode {
		grid-template-columns: minmax(0, 1fr);
	}

	.sidebar,
	.results,
	.explanation-panel,
	.updates-panel {
		min-width: 0;
	}

	.sidebar {
		position: static;
	}
}

/* ---------- <= 680px: phones ---------- */
@media (max-width: 680px) {
	body {
		min-height: 100vh;
		min-height: 100dvh;
	}

	/* Page padding, with room for the fixed bottom bar and notches */
	.page {
		padding: 14px max(12px, env(safe-area-inset-right, 0px)) calc(76px + env(safe-area-inset-bottom, 0px))
			max(12px, env(safe-area-inset-left, 0px));
	}

	.layout {
		gap: 14px;
	}

	/* ----- Header ----- */
	.topbar {
		gap: 14px;
		padding: 18px 16px;
	}

	.brand {
		flex: 1 1 100%;
		min-width: 0;
	}

	.topbar-actions {
		width: 100%;
		justify-content: space-between;
		gap: 12px;
		margin-top: 0;
	}

	#themeLabel {
		display: none;
	}

	h1 {
		font-size: 40px;
	}

	.subhead {
		font-size: 15px;
	}

	.palette-picker {
		flex: 1;
		flex-wrap: wrap;
		gap: 10px;
	}

	/* Bigger tap targets for the colour dots and the dark/light button */
	.swatch {
		width: 30px;
		height: 30px;
	}

	.theme-toggle {
		min-width: 44px;
		width: 44px;
		height: 44px;
		flex-shrink: 0;
	}

	/* ----- Mode buttons: a tidy 2 x 2 grid ----- */
	.modes {
		display: grid;
		grid-template-columns: 1fr 1fr;
		width: 100%;
		gap: 8px;
		margin: 16px 0 12px;
	}

	.mode-btn {
		min-width: 0;
		min-height: 44px;
		padding: 10px 12px;
	}

	/* ----- Cards ----- */
	.card {
		padding: 16px;
		margin-bottom: 14px;
	}

	.dropzone {
		padding: 26px 12px;
	}

	/* ----- Touch-sized controls ----- */
	.tab,
	.results-tab,
	.topn-btn,
	button.apply-btn,
	button.primary {
		min-height: 44px;
	}

	.row {
		gap: 6px;
	}

	.tab {
		padding-inline: 4px;
	}

	.results-tabs {
		gap: 6px;
	}

	.results-tab {
		flex: 1 1 auto;
		padding: 10px 12px;
	}

	#topNTabs .topn-btn {
		flex: 1;
	}

	/* 16px stops iOS Safari from zooming the page when a field is focused */
	input[type='text'],
	input[type='date'],
	.cmp-controls select {
		font-size: 16px;
		min-height: 44px;
	}

	.date-row input[type='date'] {
		padding-inline: 8px;
	}

	.foot-row {
		flex-wrap: wrap;
	}

	/* ----- Top artists / tracks lists ----- */
	.grid {
		grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
		gap: 8px;
	}

	.item {
		gap: 10px;
		padding: 10px;
	}

	.rank {
		width: 20px;
	}

	.art {
		width: 44px;
		height: 44px;
	}

	.affinity {
		width: 64px;
	}

	.section-title,
	.pattern-section h3 {
		font-size: 18px;
	}

	/* ----- Listening patterns / taste / records ----- */
	.pattern-highlights {
		gap: 10px;
		margin-bottom: 18px;
	}

	.pattern-card {
		padding: 14px;
	}

	.pattern-section {
		margin: 18px 0;
	}

	.pattern-row {
		font-size: 12px;
	}

	/* let long artist names wrap instead of being cut off */
	.pattern-name {
		white-space: normal;
		overflow-wrap: anywhere;
	}

	.pattern-time {
		font-size: 11px;
	}

	.hm-scroll {
		-webkit-overflow-scrolling: touch;
		overscroll-behavior-x: contain;
	}

	/* a 560px box scrolling inside the page is awkward on a phone */
	.disc-scroll {
		max-height: 60vh;
		-webkit-overflow-scrolling: touch;
	}

	/* ----- Compare table: 4 columns won't fit, so it scrolls sideways ----- */
	.cmp-table {
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}

	.cmp-row {
		min-width: 560px;
		grid-template-columns: 1fr 1.4fr 1.4fr 64px;
	}

	/* ----- Explanation + Updates ----- */
	.explanation-card {
		padding: 18px;
	}

	.updates-list {
		gap: 14px;
	}

	.update {
		padding: 16px 16px 16px 20px;
	}

	.update h3 {
		font-size: 17px;
	}

	.update ul {
		padding-left: 16px;
	}

	/* ----- Fixed bottom bar (overlays.css): taller, safe-area aware, never wraps ----- */
	.alertBar {
		height: calc(44px + env(safe-area-inset-bottom, 0px));
		padding: 0 12px env(safe-area-inset-bottom, 0px);
		font-size: 0.95rem;
		letter-spacing: 0.2px;
	}

	.alertBar .alert-link {
		max-width: 100%;
		padding: 10px 0;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
}

/* ---------- Very small phones (<= 360px) ---------- */
@media (max-width: 360px) {
	.page {
		padding-left: max(8px, env(safe-area-inset-left, 0px));
		padding-right: max(8px, env(safe-area-inset-right, 0px));
	}

	.card {
		padding: 14px 12px;
	}

	.tab {
		font-size: 11px;
	}

	.results-tab {
		padding-inline: 8px;
		font-size: 12px;
	}
}

/* ---------- Touch devices: hover effects stick after a tap, so skip the zoom ---------- */
@media (hover: none) {
	button.primary:hover,
	button.apply-btn:hover,
	.swatch:hover,
	.swatch:not(.active):hover {
		transform: none;
	}
}
