/* The track player (includes/components/track-player.php says what it is
   and lists its states). One box: the play button on the left, the song's
   name across the top with pop out at its end, and under the name the seek
   bar and the time. Tokens only, so it repaints with every look; the page
   around it only places it. */
track-player {
	/* The play button is a full fingertip (the control height phone makers
	   ask for); pop out's touch area is the same, its drawing smaller. */
	--toggle-size: var(--control-height);
	--pop-out-drawing: 1.25rem;

	display: grid;
	grid-template-columns: var(--toggle-size) minmax(0, 1fr) auto;
	grid-template-areas:
		'toggle name pop-out'
		'toggle seek time';
	align-items: center;
	column-gap: calc(var(--gutter) * 0.75);
	row-gap: calc(var(--gutter) * 0.25);
	padding: calc(var(--gutter) * 0.75) var(--gutter);
	border: 1px solid var(--stroke-secondary);
	border-radius: var(--corners, 0);

	/* The browser's own controls are only for no-script (below); the
	   script takes them away, and an <audio> with none takes no room. */
	audio {
		display: none;
	}

	/* Play / pause: the ink pill the video players wear - the strongest
	   pair the page has. */
	.toggle {
		grid-area: toggle;
		display: flex;
		align-items: center;
		justify-content: center;
		width: var(--toggle-size);
		height: var(--toggle-size);
		padding: 0;
		border: 0;
		border-radius: 100vmax;
		background: var(--ink-primary);
		color: var(--fill-primary);
		cursor: pointer;
	}

	/* The triangle: play. Nudged right, so it looks centered. */
	.glyph {
		margin-left: 0.15em;
		border-style: solid;
		border-width: 0.4em 0 0.4em 0.7em;
		border-color: transparent transparent transparent currentColor;
	}

	/* Two bars: pause. */
	&[data-state='playing'] .glyph {
		width: 0.7em;
		height: 0.8em;
		margin-left: 0;
		border-width: 0 0.22em;
		border-color: currentColor;
	}

	.name {
		grid-area: name;
		display: flex;
		flex-wrap: wrap;
		align-items: baseline;
		column-gap: 0.5em;
		margin: 0;
		min-width: 0;
	}

	.scrubber {
		grid-area: seek;
		width: 100%;
		min-width: 0;
		margin: 0;
		accent-color: var(--ink-primary);
	}

	/* Every digit the same width, so the numbers changing never nudge
	   the seek bar. */
	.time {
		grid-area: time;
		font-variant-numeric: tabular-nums;
		white-space: nowrap;
		text-align: right;
	}

	/* Popped out: the seek row says where the song went instead. */
	.away {
		grid-area: seek / seek / time / time;
		display: none;
		margin: 0;
	}

	&[data-state='popped'] {
		.scrubber,
		.time {
			visibility: hidden;
		}

		.away {
			display: block;
		}
	}

	.pop-out {
		grid-area: pop-out;
		justify-self: end;
		display: flex;
		align-items: center;
		justify-content: center;
		width: var(--toggle-size);
		height: var(--toggle-size);
		/* The drawing lines up with the time's right edge under it. */
		margin-right: calc((var(--toggle-size) - var(--pop-out-drawing)) / -2);
		color: var(--ink-primary);

		svg {
			width: var(--pop-out-drawing);
			height: var(--pop-out-drawing);
		}

		/* Its drawing already says it opens elsewhere, so it skips the
		   ↗ every targeted link wears (setup.css). */
		&::before,
		&::after {
			content: none;
		}
	}

	/* Focus: the site's control ring, for the keyboard only. */
	.toggle,
	.scrubber,
	.pop-out {
		&:focus-visible {
			outline: var(--control-focus-ring);
			outline-offset: var(--control-focus-offset);
		}
	}

	/* No script: our controls would do nothing, so the browser's own take
	   their place. */
	@media (scripting: none) {
		display: block;

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

		.toggle,
		.scrubber,
		.time,
		.away,
		.pop-out {
			display: none;
		}
	}
}
