/* ==========================================================================
   BASE — Reset, typography defaults, layout primitives.
   All values come from tokens.css.
   ========================================================================== */

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

/* Remove default margins */
html, body, h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd {
	margin: 0;
}

/* Smooth scroll, but respect reduced motion */
html {
	scroll-behavior: smooth;
	-webkit-text-size-adjust: 100%;
	text-rendering: optimizeLegibility;
}

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

body {
	min-height: 100vh;
	font-family: var(--apm-font-body);
	font-size: var(--apm-text-base);
	font-weight: var(--apm-weight-regular);
	line-height: var(--apm-leading-normal);
	color: var(--apm-color-text);
	background-color: var(--apm-color-bg);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

/* Media defaults */
img, picture, svg, video {
	display: block;
	max-width: 100%;
	height: auto;
}

/* Form defaults */
input, button, textarea, select {
	font: inherit;
	color: inherit;
}

button {
	cursor: pointer;
	background: none;
	border: 0;
	padding: 0;
}

/* Links */
a {
	color: var(--apm-color-link);
	text-decoration: underline;
	text-underline-offset: 0.15em;
	text-decoration-thickness: 1px;
	transition: color var(--apm-duration-fast) var(--apm-ease-out);
}
a:hover { color: var(--apm-color-link-hover); }

/* Focus — keyboard only */
:focus { outline: none; }
:focus-visible {
	outline: 2px solid var(--apm-primary-500);
	outline-offset: 2px;
	border-radius: var(--apm-radius-xs);
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
	font-family: var(--apm-font-display);
	font-weight: var(--apm-weight-bold);
	line-height: var(--apm-leading-tight);
	letter-spacing: var(--apm-tracking-tight);
	color: var(--apm-color-text);
	text-wrap: balance;
}

h1 { font-size: clamp(var(--apm-text-4xl), 5vw, var(--apm-text-6xl)); }
h2 { font-size: clamp(var(--apm-text-3xl), 4vw, var(--apm-text-5xl)); }
h3 { font-size: clamp(var(--apm-text-2xl), 3vw, var(--apm-text-4xl)); }
h4 { font-size: var(--apm-text-2xl); }
h5 { font-size: var(--apm-text-xl); }
h6 { font-size: var(--apm-text-lg); }

p { text-wrap: pretty; }

/* Long-form prose readability */
.apm-prose {
	max-width: 68ch;
	font-size: var(--apm-text-lg);
	line-height: var(--apm-leading-relaxed);
}
.apm-prose > * + * { margin-top: var(--apm-space-4); }
.apm-prose h2 { margin-top: var(--apm-space-12); margin-bottom: var(--apm-space-3); }
.apm-prose h3 { margin-top: var(--apm-space-10); margin-bottom: var(--apm-space-2); }

/* Lists default reset (override per-component as needed) */
ul, ol { padding-left: var(--apm-space-6); }
.apm-list-reset { list-style: none; padding: 0; margin: 0; }

/* Code */
code, pre {
	font-family: var(--apm-font-mono);
	font-size: 0.9em;
}
code {
	background: var(--apm-color-bg-muted);
	padding: 0.15em 0.35em;
	border-radius: var(--apm-radius-xs);
}

/* ==========================================================================
   LAYOUT PRIMITIVES
   ========================================================================== */

.apm-container {
	width: 100%;
	max-width: var(--apm-container-xl);
	margin-inline: auto;
	padding-inline: var(--apm-container-gutter);
}

.apm-container--narrow { max-width: var(--apm-container-md); }
.apm-container--wide   { max-width: var(--apm-container-2xl); }

.apm-section {
	padding-block: clamp(var(--apm-space-12), 8vw, var(--apm-space-24));
}

.apm-section--tight {
	padding-block: clamp(var(--apm-space-8), 5vw, var(--apm-space-16));
}

.apm-section--accent {
	background-color: var(--apm-color-bg-accent);
	color: var(--apm-color-text-inverse);
}
.apm-section--accent h1,
.apm-section--accent h2,
.apm-section--accent h3,
.apm-section--accent h4 {
	color: inherit;
}

.apm-section--dark {
	background-color: var(--apm-color-bg-inverse);
	color: var(--apm-color-text-inverse);
}
.apm-section--dark h1,
.apm-section--dark h2,
.apm-section--dark h3,
.apm-section--dark h4 {
	color: inherit;
}

.apm-section--subtle {
	background-color: var(--apm-color-bg-subtle);
}

/* Stack utility - vertical rhythm */
.apm-stack > * + * { margin-top: var(--apm-space-4); }
.apm-stack-sm > * + * { margin-top: var(--apm-space-2); }
.apm-stack-lg > * + * { margin-top: var(--apm-space-8); }

/* Cluster - horizontal group with wrapping */
.apm-cluster {
	display: flex;
	flex-wrap: wrap;
	gap: var(--apm-space-3);
	align-items: center;
}

/* Grid presets */
.apm-grid {
	display: grid;
	gap: var(--apm-space-6);
}
.apm-grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.apm-grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }

/* Skip link (accessibility) */
.skip-link {
	position: absolute;
	top: -100px;
	left: 0;
	background: var(--apm-color-bg-inverse);
	color: var(--apm-color-text-inverse);
	padding: var(--apm-space-3) var(--apm-space-4);
	z-index: var(--apm-z-toast);
	text-decoration: none;
}
.skip-link:focus-visible { top: 0; }

/* Screen-reader only */
.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;
}
