/*
 * Applet sizing + control styling.
 *
 * .applet-fit  — responsive wrapper. Set --applet-w and --applet-h on the
 *                element to its native pixel dimensions; the wrapper scales
 *                to 100% container width and preserves the aspect ratio.
 *
 * .applet-controls — overlay panel (slider + labels + buttons) positioned at
 *                    the bottom-center of an applet, dark background, orange-
 *                    bordered slider, small Reset-style button.
 */

.applet-fit {
	display: block;
	position: relative;
	width: 100%;
	aspect-ratio: var(--applet-w) / var(--applet-h);
	margin: 0 auto 2em;
}
.applet-fit > * {
	display: block;
	width: 100%;
	height: 100%;
}
.applet-fit canvas {
	width: 100% !important;
	height: 100% !important;
	display: block;
}

.applet-controls {
	position: absolute;
	left: 50%;
	bottom: 14px;
	transform: translateX(-50%);
	width: auto !important;
	height: auto !important;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	z-index: 10;
	color: #fff;
	font-size: 12px;
	padding: 6px 12px;
	background: rgba(0, 0, 0, 0.55);
	border-radius: 6px;
}
.applet-controls .ac-row {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
}
.applet-controls b {
	color: #fff;
	font-weight: 700;
}
.applet-controls input[type=range] {
	-webkit-appearance: none;
	appearance: none;
	width: 200px;
	height: 10px;
	background: #1a1a1a;
	border: 2px solid #ff9600;
	border-radius: 0;
	margin: 0;
	padding: 0;
	outline: none;
}
.applet-controls input[type=range]::-webkit-slider-runnable-track {
	background: #1a1a1a;
	height: 100%;
	border: none;
}
.applet-controls input[type=range]::-moz-range-track {
	background: #1a1a1a;
	height: 100%;
	border: none;
}
.applet-controls input[type=range]::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 8px;
	height: 14px;
	background: #ccc;
	border: 1px solid #555;
	border-radius: 2px;
	cursor: pointer;
	margin-top: -3px;
}
.applet-controls input[type=range]::-moz-range-thumb {
	width: 8px;
	height: 14px;
	background: #ccc;
	border: 1px solid #555;
	border-radius: 2px;
	cursor: pointer;
}
.applet-controls button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: #1a1a1a;
	color: #fff;
	border: 1px solid #ff9600;
	border-radius: 4px;
	padding: 4px 12px;
	height: 24px;
	font-size: 12px;
	font-weight: 600;
	font-family: inherit;
	line-height: 1;
	cursor: pointer;
}
.applet-controls button:hover { background: #333; }

/* Square icon button (cassette-style transport controls). Larger than the
   regular text buttons so the unicode glyphs read clearly. Uses a system
   symbol font stack to keep the optical centering of the play/pause glyphs
   consistent across browsers (the default font often renders ▶ /⏸ with
   different baselines, which makes them look off-center). */
.applet-controls button.ac-icon {
	display: inline-grid;
	place-items: center;
	box-sizing: border-box;
	flex: 0 0 34px;
	width: 34px;
	min-width: 34px;
	max-width: 34px;
	height: 34px;
	aspect-ratio: 1 / 1;
	/* The unicode transport glyphs (⏸ ▶ ◀ ▶❙) ship with extra ascent
	   above the visual mark, so place-items: center puts them ~2 px
	   higher than the optical center. Padding-top inside a border-box
	   shrinks the grid content area and shifts the center down without
	   changing the button's outer 34 × 34 footprint. */
	padding: 3px 0 0 0;
	font-family: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols2",
	             "DejaVu Sans", sans-serif;
	font-size: 16px;
	font-weight: normal;
	line-height: 1;
	text-align: center;
}

/* Controls pinned to the top instead of the bottom. Add the `top` class to the
   .applet-controls element. */
.applet-controls.top {
	top: 14px;
	bottom: auto;
}

/* Controls pinned to the upper-left corner. Useful when a second panel needs
   to coexist with the main bottom/top control bar. Rows stretch to the panel's
   width so all inputs line up at the right edge with a uniform fixed width —
   labels float on the left, inputs in a clean column. */
.applet-controls.left {
	left: 14px;
	top: 14px;
	bottom: auto;
	transform: none;
	align-items: stretch;
}
.applet-controls.left .ac-row {
	justify-content: space-between;
	gap: 12px;
}
.applet-controls.left input[type=number] {
	width: 80px;
	box-sizing: border-box;
}

/* Mirror of .left, but pinned to the upper-right corner. */
.applet-controls.right {
	right: 14px;
	top: 14px;
	left: auto;
	bottom: auto;
	transform: none;
	align-items: stretch;
}
.applet-controls.right .ac-row {
	justify-content: space-between;
	gap: 12px;
}
.applet-controls.right input[type=number] {
	width: 80px;
	box-sizing: border-box;
}

/* Icon-only panel pinned to the upper-left corner — transparent, no padding.
   Used by every applet for the fullscreen toggle (and the gear in applets that
   have one). Stays visible even when controls-overflow hides the main bar so
   fullscreen remains reachable on narrow viewports. */
.applet-fit .applet-controls.corner-tl {
	top: 14px;
	left: 14px;
	right: auto;
	bottom: auto;
	transform: none;
	background: transparent;
	padding: 0;
	z-index: 11;
}
.applet-fit.controls-overflow .applet-controls.corner-tl {
	visibility: visible;
	pointer-events: auto;
}

/* Hide the controls bar when its natural content width exceeds the applet
   width (toggled by fitControls() in applet.js). visibility instead of
   display:none so the layout box remains measurable. */
.applet-fit.controls-overflow .applet-controls {
	visibility: hidden;
	pointer-events: none;
}

/* Fullscreen: letterbox the applet inside a viewport-sized black wrapper,
   preserving --applet-w / --applet-h aspect ratio on any screen shape. */
.applet-fit:fullscreen,
.applet-fit:-webkit-full-screen {
	width: 100vw;
	height: 100vh;
	max-width: none;
	aspect-ratio: auto;
	background: #000;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0;
}
.applet-fit:fullscreen > *,
.applet-fit:-webkit-full-screen > * {
	width: min(100vw, 100vh * var(--applet-w) / var(--applet-h));
	height: min(100vh, 100vw * var(--applet-h) / var(--applet-w));
	position: relative;
}

/* Number input (matches the slider/button border style). */
.applet-controls input[type=number] {
	width: 56px;
	background: #1a1a1a;
	color: #fff;
	border: 1px solid #ff9600;
	border-radius: 3px;
	padding: 1px 3px;
	font: inherit;
	font-size: 11px;
}

/* Select / combo box — matches the button style. Native arrow replaced by a
   custom chevron so the control reads as part of the control bar across
   browsers (Firefox/Chromium/WebKit render the native arrow very differently). */
.applet-controls select {
	display: inline-flex;
	align-items: center;
	background: #1a1a1a;
	color: #fff;
	border: 1px solid #ff9600;
	border-radius: 4px;
	padding: 0 22px 0 8px;
	min-width: 64px;
	height: 24px;
	font-size: 12px;
	font-weight: 600;
	font-family: inherit;
	line-height: 1;
	cursor: pointer;
	appearance: none;
	-webkit-appearance: none;
	-moz-appearance: none;
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'><path fill='%23ff9600' d='M0 0l5 6 5-6z'/></svg>");
	background-repeat: no-repeat;
	background-position: right 6px center;
	background-size: 8px 5px;
}
.applet-controls select:hover { background-color: #333; }
.applet-controls select option {
	background: #1a1a1a;
	color: #fff;
}

/* Prevent labels and label bolds from wrapping mid-text. */
.applet-controls b {
	white-space: nowrap;
}
.applet-controls label {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	cursor: pointer;
	margin: 0;
	padding: 0;
	line-height: 1;
	font-weight: inherit;
	color: inherit;
	white-space: nowrap;
}
.applet-controls label b {
	line-height: 1;
	white-space: nowrap;
}

/* Custom checkbox styling — overrides the site-wide hidden-checkbox pattern in
   main.css (opacity:0 + z-index:-1) that relies on a sibling label's :before. */
.applet-controls input[type=checkbox] {
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	display: inline-block;
	float: none;
	opacity: 1;
	z-index: auto;
	width: 16px;
	height: 16px;
	background: #1a1a1a;
	border: 1px solid #ff9600;
	border-radius: 3px;
	cursor: pointer;
	margin: 0;
	padding: 0;
	position: relative;
	flex: none;
	vertical-align: middle;
}
.applet-controls input[type=checkbox] + label,
.applet-controls label > input[type=checkbox] + b {
	padding: 0 !important;
}
.applet-controls input[type=checkbox] + label:before,
.applet-controls input[type=checkbox] + b:before {
	display: none !important;
	content: none !important;
}
.applet-controls input[type=checkbox]:checked {
	background: #ff9600;
}
.applet-controls input[type=checkbox]:checked::after {
	content: '';
	position: absolute;
	left: 4px;
	top: 0px;
	width: 4px;
	height: 9px;
	border: solid #1a1a1a;
	border-width: 0 2px 2px 0;
	transform: rotate(45deg);
}

/* Parameter description table rendered below an applet. */
.applet-params {
	width: 100%;
	border-collapse: collapse;
	margin: 0 0 2em;
	font-size: 0.95em;
}
.applet-params th, .applet-params td {
	border: 1px solid #ddd;
	padding: 0.5em 0.75em;
	vertical-align: top;
	text-align: left;
}
.applet-params th {
	background: #f4f4f4;
	white-space: nowrap;
}
.applet-params td:first-child {
	font-weight: 600;
	white-space: nowrap;
	width: 1%;
}
