/* ==========================================================================
   Quran Ayah Player — design system
   --------------------------------------------------------------------------
   A cohesive, premium visual language: Fraunces (display) + Inter (UI), an
   emerald/teal core with a warm gold accent, layered depth, and calm motion.
   Theming is driven by CSS custom properties toggled via
   html[data-theme="light" | "dark"]. `color-scheme` is set per theme so the
   native <audio> controls, scrollbars, and focus rings match.
   ========================================================================== */

:root {
	--font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--font-display: "Fraunces", "Iowan Old Style", Georgia, "Times New Roman", serif;

	--radius-xl: 22px;
	--radius-lg: 16px;
	--radius-md: 12px;
	--radius-sm: 10px;

	--maxw: 720px;
	--ease: cubic-bezier(0.22, 0.61, 0.36, 1);
	--fast: 140ms var(--ease);
	--med: 240ms var(--ease);
}

/* ---- Light theme ---------------------------------------------------------- */
html[data-theme="light"] {
	color-scheme: light;
	--bg: #eef2f0;
	--bg-tint: rgba(16, 150, 130, 0.16);
	--bg-tint-2: rgba(183, 134, 43, 0.08);
	--surface: #ffffff;
	--surface-2: #f2f6f4;
	--surface-3: #e9efec;
	--border: #e2e8e5;
	--border-strong: #d0d9d4;
	--text: #12211d;
	--text-muted: #566a63;
	--text-faint: #8a988f;
	--accent: #0f766e;
	--accent-2: #14b8a6;
	--accent-ink: #ffffff;
	--accent-soft: rgba(15, 118, 110, 0.1);
	--gold: #a9781f;
	--danger: #c0392b;
	--danger-soft: rgba(192, 57, 43, 0.1);
	--ring: rgba(20, 184, 166, 0.4);
	--shadow-sm: 0 1px 2px rgba(16, 40, 34, 0.06), 0 1px 3px rgba(16, 40, 34, 0.07);
	--shadow-md: 0 6px 16px -6px rgba(16, 40, 34, 0.14), 0 2px 6px -2px rgba(16, 40, 34, 0.08);
	--shadow-lg: 0 28px 50px -20px rgba(16, 40, 34, 0.28);
	--hairline: rgba(255, 255, 255, 0.7);
}

/* ---- Dark theme ----------------------------------------------------------- */
html[data-theme="dark"] {
	color-scheme: dark;
	--bg: #080d0b;
	--bg-tint: rgba(45, 212, 191, 0.12);
	--bg-tint-2: rgba(226, 192, 105, 0.06);
	--surface: #111a16;
	--surface-2: #16211c;
	--surface-3: #1d2a24;
	--border: #253128;
	--border-strong: #35473d;
	--text: #e7f0ec;
	--text-muted: #97a89f;
	--text-faint: #66766d;
	--accent: #2dd4bf;
	--accent-2: #5eead4;
	--accent-ink: #04231e;
	--accent-soft: rgba(45, 212, 191, 0.14);
	--gold: #e2c069;
	--danger: #ff7a6d;
	--danger-soft: rgba(255, 122, 109, 0.14);
	--ring: rgba(45, 212, 191, 0.45);
	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
	--shadow-md: 0 8px 22px -8px rgba(0, 0, 0, 0.6);
	--shadow-lg: 0 30px 60px -24px rgba(0, 0, 0, 0.75);
	--hairline: rgba(255, 255, 255, 0.06);
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	padding: 0;
}

body {
	min-height: 100vh;
	background: var(--bg);
	color: var(--text);
	font-family: var(--font-sans);
	font-size: 16px;
	line-height: 1.55;
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
}

/* Ambient light — a soft glow that grounds the layout without a hard edge. */
body::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	background:
		radial-gradient(1100px 560px at 50% -8%, var(--bg-tint), transparent 62%),
		radial-gradient(760px 400px at 88% 4%, var(--bg-tint-2), transparent 60%);
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* ---- Shell ---------------------------------------------------------------- */

.app {
	position: relative;
	z-index: 1;
	max-width: var(--maxw);
	margin: 0 auto;
	padding: clamp(20px, 5vw, 44px) clamp(16px, 4vw, 28px) 40px;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	gap: clamp(18px, 3vw, 26px);
}

/* ---- Header --------------------------------------------------------------- */

.app-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
}

.brand {
	display: flex;
	align-items: center;
	gap: 14px;
	min-width: 0;
}

.brand__mark {
	flex: none;
	width: 48px;
	height: 48px;
	display: grid;
	place-items: center;
	font-size: 1.4rem;
	border-radius: 15px;
	background: linear-gradient(140deg, var(--accent), var(--accent-2));
	box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.app-title {
	margin: 0;
	font-family: var(--font-display);
	font-weight: 600;
	font-size: clamp(1.45rem, 4.6vw, 2.05rem);
	line-height: 1.04;
	letter-spacing: -0.015em;
	color: var(--text);
}

.app-subtitle {
	margin: 2px 0 0;
	font-size: 0.85rem;
	color: var(--text-muted);
	letter-spacing: 0.01em;
}

.theme-toggle {
	flex: none;
	width: 46px;
	height: 46px;
	border-radius: 50%;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
	display: grid;
	place-items: center;
	box-shadow: var(--shadow-sm);
	transition:
		background var(--fast),
		border-color var(--fast),
		transform var(--fast);
}

.theme-toggle:hover {
	border-color: var(--border-strong);
	transform: translateY(-1px);
}

.theme-toggle:active {
	transform: translateY(0) scale(0.96);
}

.theme-toggle__icon {
	font-size: 1.15rem;
	line-height: 1;
	transition: transform var(--med);
}

.theme-toggle:hover .theme-toggle__icon {
	transform: rotate(18deg);
}

.theme-toggle__icon::before {
	content: "🌙";
}

html[data-theme="dark"] .theme-toggle__icon::before {
	content: "☀️";
}

/* ---- Cards ---------------------------------------------------------------- */

.app-main {
	display: flex;
	flex-direction: column;
	gap: clamp(16px, 2.6vw, 22px);
}

.card {
	position: relative;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-xl);
	box-shadow: var(--shadow-md);
	overflow: hidden;
	transition:
		border-color var(--med),
		box-shadow var(--med);
}

/* Brand hairline along the very top of the single card. */
.card::before {
	content: "";
	position: absolute;
	inset: 0 0 auto;
	height: 3px;
	background: linear-gradient(90deg, var(--accent), var(--accent-2), transparent);
	opacity: 0.9;
	z-index: 1;
}

.card:focus-within {
	border-color: var(--border-strong);
}

/* Each area inside the single card, separated by a hairline. */
.card__section {
	padding: clamp(18px, 3.4vw, 26px);
}

.card__section + .card__section {
	border-top: 1px solid var(--border);
}

.card__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 16px;
}

.card__hint {
	margin: 0;
	font-size: 0.82rem;
	color: var(--text-faint);
}

.card__hint em {
	font-style: normal;
	color: var(--text-muted);
	font-weight: 600;
}

.eyebrow {
	display: inline-flex;
	align-items: center;
	gap: 0.55em;
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.15em;
	text-transform: uppercase;
	color: var(--text-faint);
}

.eyebrow::before {
	content: "";
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: linear-gradient(var(--accent), var(--accent-2));
	box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---- Inputs --------------------------------------------------------------- */

.input,
.select {
	width: 100%;
	font: inherit;
	font-size: 0.98rem;
	color: var(--text);
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 11px 13px;
	transition:
		border-color var(--fast),
		background var(--fast),
		box-shadow var(--fast);
}

.input::placeholder {
	color: var(--text-faint);
}

.input:hover,
.select:hover {
	border-color: var(--border-strong);
}

.input:focus,
.select:focus,
.btn:focus-visible,
.ctrl:focus-visible,
.row__remove:focus-visible,
.theme-toggle:focus-visible {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 4px var(--ring);
}

/* Hide number spinners for a cleaner field. */
.input[type="number"] {
	-moz-appearance: textfield;
	appearance: textfield;
}
.input[type="number"]::-webkit-outer-spin-button,
.input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

/* Custom select with a drawn chevron. */
.select-wrap {
	position: relative;
}

.select {
	appearance: none;
	padding-right: 40px;
	cursor: pointer;
}

.select-wrap::after {
	content: "";
	position: absolute;
	right: 16px;
	top: 50%;
	width: 8px;
	height: 8px;
	border-right: 2px solid var(--text-muted);
	border-bottom: 2px solid var(--text-muted);
	transform: translateY(-65%) rotate(45deg);
	pointer-events: none;
	transition: border-color var(--fast);
}

.select-wrap:hover::after {
	border-color: var(--accent);
}

/* ---- Rows ----------------------------------------------------------------- */

.rows__head,
.row {
	display: grid;
	grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.05fr) minmax(0, 0.78fr) 42px;
	gap: 12px;
}

.rows__head {
	padding: 0 6px 10px;
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--text-faint);
}

.rows__list {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin-bottom: 14px;
}

.row {
	align-items: center;
	padding: 14px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	animation: row-in var(--med) both;
}

@keyframes row-in {
	from {
		opacity: 0;
		transform: translateY(-6px);
	}
}

.row .input {
	background: var(--surface);
}

.row__field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	min-width: 0;
}

.row__label {
	display: none;
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	color: var(--text-faint);
}

.row__remove {
	width: 42px;
	height: 42px;
	display: grid;
	place-items: center;
	font-size: 0.9rem;
	color: var(--text-faint);
	background: transparent;
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	cursor: pointer;
	transition:
		color var(--fast),
		background var(--fast),
		border-color var(--fast),
		transform var(--fast);
}

.row__remove:hover {
	color: var(--danger);
	background: var(--danger-soft);
	border-color: var(--danger);
}

.row__remove:active {
	transform: scale(0.92);
}

/* ---- Buttons -------------------------------------------------------------- */

.btn {
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	border-radius: var(--radius-md);
	border: 1px solid transparent;
	padding: 12px 18px;
	transition:
		background var(--fast),
		border-color var(--fast),
		color var(--fast),
		transform var(--fast);
}

.btn:active {
	transform: scale(0.985);
}

.btn--ghost {
	width: 100%;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	color: var(--accent);
	background: transparent;
	border: 1.5px dashed var(--border-strong);
}

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

.btn__plus {
	font-size: 1.1rem;
	line-height: 1;
}

/* ---- Player --------------------------------------------------------------- */

.player {
	display: flex;
	flex-direction: column;
	gap: 18px;
}

.player__meta {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.now-playing {
	font-size: clamp(1.05rem, 3vw, 1.28rem);
	font-weight: 600;
	line-height: 1.35;
	color: var(--text);
	min-height: 1.4em;
}

.now-playing:empty::before {
	content: "Nothing queued yet";
	color: var(--text-faint);
	font-weight: 500;
}

.player__audio {
	width: 100%;
	height: 42px;
	border-radius: var(--radius-md);
}

.player__nav {
	display: flex;
	gap: 12px;
}

.ctrl {
	flex: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 9px;
	font: inherit;
	font-weight: 600;
	color: var(--text);
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: 12px 16px;
	cursor: pointer;
	transition:
		background var(--fast),
		border-color var(--fast),
		color var(--fast),
		transform var(--fast),
		box-shadow var(--fast);
}

.ctrl:hover:not(:disabled) {
	color: var(--accent);
	border-color: var(--accent);
	transform: translateY(-1px);
	box-shadow: var(--shadow-sm);
}

.ctrl:active:not(:disabled) {
	transform: translateY(0) scale(0.98);
}

.ctrl:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.ctrl__icon {
	font-size: 0.95rem;
	line-height: 1;
}

/* ---- Status --------------------------------------------------------------- */

.status {
	margin: 0;
	min-height: 1.35em;
	font-size: 0.88rem;
	color: var(--text-muted);
	transition: color var(--fast);
}

.status:not(:empty) {
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

.status--error {
	align-self: flex-start;
	color: var(--danger);
	background: var(--danger-soft);
	border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
	border-radius: 999px;
	padding: 7px 14px;
}

.status--loading::after {
	content: "";
	width: 0.85em;
	height: 0.85em;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: spin 0.7s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* ---- Footer --------------------------------------------------------------- */

.app-footer {
	margin-top: auto;
	padding-top: 8px;
	text-align: center;
	color: var(--text-faint);
	font-size: 0.82rem;
}

.app-footer a {
	color: var(--accent);
	text-decoration: none;
	border-bottom: 1px solid transparent;
	transition: border-color var(--fast);
}

.app-footer a:hover {
	border-color: var(--accent);
}

/* ---- Responsive ----------------------------------------------------------- */

@media (max-width: 560px) {
	.rows__head {
		display: none;
	}

	.row {
		grid-template-columns: 1fr 1fr;
		grid-template-areas:
			"surah ayah"
			"repeat remove";
		column-gap: 12px;
		row-gap: 14px;
		align-items: end;
	}

	.row > :nth-child(1) {
		grid-area: surah;
	}
	.row > :nth-child(2) {
		grid-area: ayah;
	}
	.row > :nth-child(3) {
		grid-area: repeat;
	}
	.row__remove {
		grid-area: remove;
		width: 100%;
	}

	.row__label {
		display: block;
	}
}

/* ---- Motion preferences --------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
	}
}
