/* --------------------------------------------------------------------------
   Design tokens
   -------------------------------------------------------------------------- */
:root {
	--app-bg: #eef1f6;
	--app-bg-subtle: linear-gradient(160deg, #eef1f6 0%, #e4e9f2 100%);
	--app-surface: #ffffff;
	--app-surface-muted: #f8fafc;
	--app-accent: #2563eb;
	--app-accent-hover: #1d4ed8;
	--app-accent-soft: rgba(37, 99, 235, 0.12);
	--app-game-panel: linear-gradient(145deg, #1e40af 0%, #2563eb 45%, #3b82f6 100%);
	--app-game-panel-shadow: 0 1rem 2.5rem rgba(30, 64, 175, 0.28);
	--app-text: #1e293b;
	--app-text-muted: #64748b;
	--app-border: rgba(15, 23, 42, 0.08);
	--app-border-strong: rgba(15, 23, 42, 0.14);
	--app-radius: 0.875rem;
	--app-radius-sm: 0.5rem;
	--app-shadow: 0 0.25rem 1rem rgba(15, 23, 42, 0.06);
	--app-shadow-lg: 0 1rem 2rem rgba(15, 23, 42, 0.1);
	--app-nav-bg: #0f172a;
	--app-success: #16a34a;
	--app-danger: #dc2626;
	--app-warning: #d97706;
	--app-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--app-transition: 0.2s ease;
}

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

body {
	background: var(--app-bg-subtle);
	background-color: var(--app-bg);
	color: var(--app-text);
	font-family: var(--app-font);
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

main.page-main {
	flex: 1 0 auto;
}

a {
	transition: color var(--app-transition);
}

kbd {
	background: var(--app-surface);
	border: 1px solid var(--app-border-strong);
	border-bottom-width: 2px;
	border-radius: 0.35rem;
	box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
	color: var(--app-text);
	display: inline-block;
	font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
	font-size: 0.82em;
	font-weight: 600;
	line-height: 1.25;
	margin: 0 0.1em;
	padding: 0.12rem 0.5rem;
	vertical-align: baseline;
	white-space: nowrap;
}

.game-panel kbd {
	background: rgba(255, 255, 255, 0.96);
	border-color: rgba(255, 255, 255, 0.35);
	box-shadow: inset 0 -2px 0 rgba(15, 23, 42, 0.12), 0 1px 2px rgba(15, 23, 42, 0.18);
	color: var(--app-text);
}

/* --------------------------------------------------------------------------
   Navigation
   -------------------------------------------------------------------------- */
.site-nav {
	background: var(--app-nav-bg) !important;
	border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.site-nav .navbar-brand {
	font-weight: 700;
	letter-spacing: -0.02em;
	max-width: min(100%, 14rem);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.site-nav .nav-link {
	border-radius: var(--app-radius-sm);
	color: rgba(255, 255, 255, 0.78) !important;
	font-size: 0.925rem;
	padding: 0.45rem 0.75rem !important;
	transition: background var(--app-transition), color var(--app-transition);
}

.site-nav .nav-link:hover,
.site-nav .nav-link:focus {
	background: rgba(255, 255, 255, 0.08);
	color: #fff !important;
}

.site-nav .nav-link.active {
	background: rgba(255, 255, 255, 0.14);
	color: #fff !important;
	font-weight: 600;
}

.site-nav .nav-link .nav-icon {
	opacity: 0.85;
	width: 1.1em;
}

.site-nav .nav-link.active .nav-icon {
	opacity: 1;
}

.lang-picker .lang-flag {
	border-radius: 3px;
	cursor: pointer;
	margin: 0 0.12rem;
	transition: transform var(--app-transition), box-shadow var(--app-transition);
}

.lang-picker .lang-flag:hover,
.lang-picker .lang-flag.active {
	box-shadow: 0 0 0 2px var(--app-accent), 0 0 0 4px rgba(37, 99, 235, 0.35);
	transform: scale(1.12);
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.site-footer {
	background: var(--app-surface);
	border-top: 1px solid var(--app-border);
	flex-shrink: 0;
}

.donate-link {
	color: var(--app-text-muted);
	font-weight: 500;
	transition: color var(--app-transition);
}

.donate-link:hover {
	color: var(--app-accent);
}

/* --------------------------------------------------------------------------
   Home page
   -------------------------------------------------------------------------- */
.hero-section {
	padding: 2.75rem 0 1.75rem;
}

.hero-section h1 {
	color: var(--app-text);
	font-weight: 800;
	letter-spacing: -0.03em;
	line-height: 1.15;
}

.hero-section .lead {
	color: var(--app-text-muted);
	max-width: 42rem;
	margin-left: auto;
	margin-right: auto;
}

.game-card {
	background: var(--app-surface);
	border: 1px solid var(--app-border);
	border-radius: var(--app-radius);
	box-shadow: var(--app-shadow);
	height: 100%;
	overflow: hidden;
	position: relative;
	transition: transform var(--app-transition), box-shadow var(--app-transition), border-color var(--app-transition);
}

.game-card::before {
	background: var(--card-accent, var(--app-accent));
	content: "";
	height: 4px;
	left: 0;
	position: absolute;
	right: 0;
	top: 0;
}

.game-card:hover {
	border-color: var(--app-border-strong);
	box-shadow: var(--app-shadow-lg);
	transform: translateY(-5px);
}

.game-card .card-body {
	padding: 1.5rem 1.35rem 1.35rem;
}

.game-card .card-icon {
	align-items: center;
	background: var(--app-accent-soft);
	border-radius: 0.75rem;
	color: var(--card-accent, var(--app-accent));
	display: inline-flex;
	font-size: 1.35rem;
	height: 2.75rem;
	justify-content: center;
	margin-bottom: 0.85rem;
	width: 2.75rem;
}

.game-card--digitation { --card-accent: #2563eb; }
.game-card--digitation .card-icon { background: rgba(37, 99, 235, 0.12); }

.game-card--mic { --card-accent: #16a34a; }
.game-card--mic .card-icon { background: rgba(22, 163, 74, 0.12); }

.game-card--bass { --card-accent: #0891b2; }
.game-card--bass .card-icon { background: rgba(8, 145, 178, 0.12); }

.game-card--sequencer { --card-accent: #d97706; }
.game-card--sequencer .card-icon { background: rgba(217, 119, 6, 0.12); }

.game-card h2 {
	color: var(--app-text);
	font-weight: 700;
}

.game-card .btn {
	border-radius: var(--app-radius-sm);
	font-weight: 600;
}

/* --------------------------------------------------------------------------
   Game layout (shared across game pages)
   -------------------------------------------------------------------------- */
.sidebar-card {
	background: var(--app-surface);
	border: 1px solid var(--app-border);
	border-radius: var(--app-radius);
	box-shadow: var(--app-shadow);
}

.sidebar-card h2,
.sidebar-card h3 {
	color: var(--app-text);
}

.sidebar-card h2 {
	font-weight: 700;
	letter-spacing: -0.02em;
}

.sidebar-card h3 {
	color: var(--app-text-muted);
	font-size: 0.8rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	margin-top: 1.25rem;
	text-transform: uppercase;
}

.sidebar-card .form-label {
	color: var(--app-text);
	font-size: 0.875rem;
	font-weight: 600;
	margin-bottom: 0.35rem;
}

.sidebar-card .form-select,
.sidebar-card .btn {
	border-radius: var(--app-radius-sm);
}

.sidebar-card .btn-group .btn {
	font-weight: 600;
}

.game-panel {
	background: var(--app-game-panel);
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: var(--app-radius);
	box-shadow: var(--app-game-panel-shadow);
	color: #fff;
	padding: 1.25rem;
}

.game-panel .btn-outline-light {
	border-color: rgba(255, 255, 255, 0.45);
	font-weight: 600;
}

.game-panel .btn-outline-light:hover {
	background: rgba(255, 255, 255, 0.12);
	border-color: #fff;
}

.panel-inset {
	background: var(--app-surface);
	border: 1px solid var(--app-border);
	border-radius: var(--app-radius-sm);
	box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
	color: var(--app-text);
	padding: 1rem;
}

.panel-inset--muted {
	background: var(--app-surface-muted);
}

.game-timer {
	font-size: 1.05rem;
	font-variant-numeric: tabular-nums;
	font-weight: 600;
	letter-spacing: 0.02em;
}

.stat-card p {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	justify-content: space-between;
	margin-bottom: 0.55rem;
}

.stat-card p:last-child {
	margin-bottom: 0;
}

.stat-card .badge {
	font-size: 0.8rem;
	font-weight: 600;
	min-width: 2.5rem;
}

.score-table {
	--bs-table-color: rgba(255, 255, 255, 0.92);
	--bs-table-bg: transparent;
	font-size: 0.95rem;
}

.score-table td {
	padding: 0.35rem 0;
	vertical-align: middle;
}

.score-table td:last-child {
	font-variant-numeric: tabular-nums;
	font-weight: 700;
}

.feedback-panel {
	min-height: 4.5rem;
	position: relative;
}

.feedback-icon {
	display: none;
	font-size: 2.25rem;
	line-height: 1;
	position: absolute;
	right: 0.85rem;
	top: 0.75rem;
}

.feedback-icon.feedback-bad {
	color: var(--app-danger);
}

.feedback-icon.feedback-good {
	color: var(--app-success);
}

#result {
	font-size: 0.925rem;
	line-height: 1.55;
	padding-right: 2.5rem;
}

/* Notation / score canvas */
.notation-canvas {
	align-items: center;
	display: flex;
	justify-content: center;
	min-height: 150px;
	overflow-x: auto;
}

.notation-canvas canvas {
	display: block;
	max-width: 100%;
}

/* Digitation trumpet */
#trumpet {
	height: 140px;
	margin: 0 auto;
	max-width: 100%;
	position: relative;
	width: 295px;
}

#trumpet img,
.score img {
	position: absolute;
}

#piston_1 { top: 26px; left: 93px; }
#piston_2 { top: 26px; left: 120px; }
#piston_3 { top: 26px; left: 147px; }

.score {
	position: relative;
}

/* Reference panel (digitation) */
.reference_div {
	display: none;
}

.reference_div .panel-inset--muted {
	overflow-x: auto;
}

/* Game visibility toggles */
#reset_game,
#stop_game {
	display: none;
}

.game_div {
	display: none;
}

.game_div.active {
	display: block;
}

/* --------------------------------------------------------------------------
   Mic / pitch detector
   -------------------------------------------------------------------------- */
.pitch-detector {
	border: 1px solid var(--app-border);
	border-radius: var(--app-radius-sm);
	max-width: 100%;
	padding: 0.85rem 1rem;
	text-align: center;
	width: 100%;
}

.pitch-detector.vague {
	color: var(--app-text-muted);
}

.pitch-detector.confident {
	color: var(--app-text);
}

.pitch-detector .note {
	font-size: 1.75rem;
	font-weight: 700;
	line-height: 1.2;
}

.pitch-detector .pitch {
	color: var(--app-text-muted);
	font-size: 0.85rem;
}

.pitch-detector .progress {
	background: var(--app-surface-muted);
	border-radius: 999px;
	height: 0.45rem;
	overflow: hidden;
}

.pitch-detector #output {
	display: block;
	margin: 0.5rem auto 0;
	max-width: 100%;
}

#flat { display: none; }
#sharp { display: none; }
.flat #flat { display: inline; }
.sharp #sharp { display: inline; }

/* Legacy id selector kept for pitchdetect.js */
#detector {
	border: 1px solid var(--app-border);
	border-radius: var(--app-radius-sm);
	max-width: 100%;
	padding: 0.85rem 1rem;
	text-align: center;
	width: 100%;
}

.pitch-detector.panel-inset,
#detector.panel-inset {
	border: none;
	padding: 1rem;
}
#detector.confident { color: var(--app-text); }
#note { font-size: 1.75rem; font-weight: 700; }

/* --------------------------------------------------------------------------
   Sequencer
   -------------------------------------------------------------------------- */
#sequencer .beat {
	background: var(--app-surface-muted);
	cursor: default;
	font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
	font-size: 0.9rem;
	font-weight: 600;
	padding: 0.65rem 0.25rem !important;
	text-align: center;
	transition: background var(--app-transition), color var(--app-transition);
	user-select: none;
	vertical-align: middle;
	width: 6.25%;
}

#sequencer .beat.active-beat {
	background: var(--app-danger) !important;
	color: #fff !important;
}

.sequencer-wrap {
	background: var(--app-surface);
	border-radius: var(--app-radius-sm);
	padding: 0.75rem;
}

/* --------------------------------------------------------------------------
   Utilities & focus
   -------------------------------------------------------------------------- */
:focus-visible {
	outline: 2px solid var(--app-accent);
	outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
	.site-nav .navbar-brand {
		max-width: 11rem;
	}

	.game-panel {
		padding: 1rem;
	}
}

@media (max-width: 767.98px) {
	.hero-section {
		padding: 1.75rem 0 1.25rem;
	}

	.hero-section h1 {
		font-size: calc(1.35rem + 1.5vw);
	}

	.sidebar-card {
		margin-bottom: 0.25rem;
	}

	.sidebar-card .btn-group {
		flex-direction: column;
	}

	.sidebar-card .btn-group .btn {
		border-radius: var(--app-radius-sm) !important;
		width: 100%;
	}

	#trumpet {
		transform: scale(0.92);
		transform-origin: top center;
	}

	.notation-canvas {
		min-height: 130px;
	}
}

/* --------------------------------------------------------------------------
   Landing page (martinferes.cl home)
   -------------------------------------------------------------------------- */
.landing-main {
	padding-top: 1rem;
}

.landing-bio {
	background: var(--app-surface);
	border: 1px solid var(--app-border);
	border-radius: var(--app-radius);
	box-shadow: var(--app-shadow);
	margin: 0 auto;
	max-width: 42rem;
	padding: 2.25rem 2rem;
}

.landing-bio-header {
	margin-bottom: 1.5rem;
}

.landing-eyebrow {
	color: var(--app-text-muted);
	font-size: 0.8125rem;
	font-weight: 600;
	letter-spacing: 0.14em;
	margin-bottom: 0.5rem;
	text-transform: uppercase;
}

.landing-title {
	color: var(--app-text);
	font-weight: 800;
	letter-spacing: -0.03em;
	margin-bottom: 0.35rem;
}

.landing-tagline {
	color: var(--app-accent);
	font-weight: 600;
	margin-bottom: 0;
}

.landing-bio-body p {
	color: var(--app-text);
	font-size: 1.0625rem;
	line-height: 1.7;
	margin-bottom: 1rem;
}

.landing-bio-body p:last-child {
	margin-bottom: 0;
}

.landing-bio-sections {
	border-top: 1px solid var(--app-border);
	margin-top: 1.75rem;
	padding-top: 1.75rem;
}

.landing-links-heading {
	color: var(--app-text);
	font-weight: 700;
	margin-bottom: 0.75rem;
}

.landing-link-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.landing-link-list li + li {
	margin-top: 0.5rem;
}

.landing-link-list a {
	color: var(--app-accent);
	font-weight: 500;
	text-decoration: none;
}

.landing-link-list a:hover {
	color: var(--app-accent-hover);
	text-decoration: underline;
}

.landing-lang-switch {
	font-size: 0.875rem;
	font-weight: 600;
}

.landing-lang-link {
	color: rgba(255, 255, 255, 0.65);
	padding: 0.25rem 0.35rem;
	text-decoration: none;
}

.landing-lang-link:hover {
	color: #fff;
}

.landing-lang-link.active {
	color: #fff;
}

@media (max-width: 767.98px) {
	.landing-bio {
		padding: 1.5rem 1.25rem;
	}
}

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

	.game-card:hover {
		transform: none;
	}
}
