/* =====================================================================
   WAIFI — Reset & Base (reset.css)
   ---------------------------------------------------------------------
   Responsibility: normalize browser defaults + set GLOBAL element styles
   (box model, typography scale, link/list/blockquote/code, selection,
   focus, reduced-motion, skip-link). NOT for components or layout
   containers — those live in components.css / layout.css.
   Load order: 2nd, after variables.css. Token-driven; no raw hex/px.
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. BOX MODEL — modern box-sizing everywhere
   --------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

/* ---------------------------------------------------------------------
   2. ROOT / DOCUMENT
   --------------------------------------------------------------------- */
html {
    -webkit-text-size-adjust: 100%;          /* prevent iOS rotation resize */
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: var(--header-height); /* offset sticky header for anchors */
    tab-size: 4;
}

/* Reserve scrollbar gutter only on desktop-class viewports. On touch devices
   scrollbars overlay, so a stable gutter would waste horizontal space at 320px. */
@media (min-width: 48rem) and (pointer: fine) {
    html {
        scrollbar-gutter: stable;
    }
}

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

/* ---------------------------------------------------------------------
   3. TYPOGRAPHY — base element scale (matches DESIGN_SYSTEM.md §1.2)
   --------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    line-height: var(--line-height-tight);
    color: var(--color-heading);
    font-weight: var(--font-weight-bold);
    text-wrap: balance;                        /* nicer heading line breaks */
}

h1 {
    font-size: var(--font-size-h1);
    letter-spacing: var(--letter-spacing-tight);
}

h2 {
    font-size: var(--font-size-h2);
    letter-spacing: var(--letter-spacing-tight);
}

h3 {
    font-size: var(--font-size-h3);
    font-weight: var(--font-weight-semibold);
}

h4 {
    font-size: var(--font-size-h4);
    font-weight: var(--font-weight-semibold);
    line-height: 1.3;
}

p {
    line-height: var(--line-height-relaxed);
    text-wrap: pretty;                         /* avoid orphans in paragraphs */
    overflow-wrap: break-word;                 /* prevent long strings (email, URL, price) overflowing at 320px */
}

/* Defensive overflow guards: any text node breaks rather than causing horizontal scroll */
a, address, code, kbd, samp, td, th {
    overflow-wrap: break-word;
    word-break: break-word;
}

small {
    font-size: var(--font-size-sm);
}

strong, b {
    font-weight: var(--font-weight-semibold);
    color: var(--color-heading);
}

/* ---------------------------------------------------------------------
   4. LINKS — all 5 states (normal/hover/focus/visited/active)
   --------------------------------------------------------------------- */
a {
    color: var(--color-secondary-hover);       /* AA-safe green text link */
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-secondary);
    text-decoration: underline;
}

a:focus-visible {
    outline: 3px solid var(--color-focus-ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
    text-decoration: none;
}

a:visited {
    color: var(--color-secondary-hover);       /* keep brand colour; no purple */
}

a:active {
    color: var(--color-secondary);
}

/* Inherit colour/text-decoration for links that are purely navigational
   (styled as buttons/cards later). Resets the global link underline. */
a:not([href]) {
    color: inherit;
    text-decoration: none;
}

/* ---------------------------------------------------------------------
   5. LISTS
   --------------------------------------------------------------------- */
ul, ol {
    list-style: none;                          /* base list rebuilt per use */
}

/* Allow prose lists to opt back in via .prose utility (layout.css) */

/* ---------------------------------------------------------------------
   6. MEDIA — responsive by default
   --------------------------------------------------------------------- */
img, svg, video, canvas, picture, iframe {
    display: block;
    max-width: 100%;
    height: auto;
}

/* SVGs that are icons: fill currentColor unless overridden */
svg:not([width]) {
    height: 1em;
    width: 1em;
}

/* ---------------------------------------------------------------------
   7. FORM ELEMENT RESET
   --------------------------------------------------------------------- */
button,
input,
textarea,
select {
    font: inherit;
    color: inherit;
}

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

/* Re-enable cursor for non-disabled interactive controls */
[disabled] {
    cursor: not-allowed;
}

input,
button,
textarea,
select {
    border-radius: 0;                          /* reset iOS rounding; component sets radius */
}

textarea {
    resize: vertical;
}

/* Placeholder colour */
::placeholder {
    color: var(--color-gray-400);
    opacity: 1;
}

/* ---------------------------------------------------------------------
   8. TABLE — light base (used rarely; future-ready)
   --------------------------------------------------------------------- */
table {
    border-collapse: collapse;
    width: 100%;
}

/* ---------------------------------------------------------------------
   9. BLOCKQUOTE / CODE / HR — prose elements
   --------------------------------------------------------------------- */
blockquote {
    border-left: 4px solid var(--color-secondary);
    padding-left: var(--space-4);
    color: var(--color-muted);
    font-style: italic;
}

code,
kbd,
samp,
pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
}

code {
    background-color: var(--color-surface-alt);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-sm);
}

hr {
    border: none;
    border-top: var(--border);
    margin-block: var(--space-6);
}

/* ---------------------------------------------------------------------
   10. SELECTION — brand-tinted text selection
   --------------------------------------------------------------------- */
::selection {
    background-color: var(--color-primary);
    color: var(--color-text-on-primary);
}

/* ---------------------------------------------------------------------
   11. FOCUS — visible keyboard focus is mandatory (frontend.md §18)
   --------------------------------------------------------------------- */
:focus-visible {
    outline: 3px solid var(--color-focus-ring);
    outline-offset: 2px;
}

/* Remove mouse-focus ring but keep keyboard focus */
:focus:not(:focus-visible) {
    outline: none;
}

/* ---------------------------------------------------------------------
   12. ACCESSIBILITY — skip link
   Off-screen until focused; jumps to #main (frontend.md §18).
   --------------------------------------------------------------------- */
.skip-link {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: var(--z-skip-link);
    padding: var(--space-2) var(--space-4);
    background-color: var(--color-heading);
    color: var(--color-white);
    border-radius: var(--radius-md);
    font-weight: var(--font-weight-semibold);
    transform: translateY(-150%);
    transition: transform var(--transition-fast);
}

.skip-link:focus {
    transform: translateY(0);
    outline: 3px solid var(--color-focus-ring);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   13. REDUCED MOTION — hard guard (review R4)
   Disables smooth scroll + all transitions/animations regardless of
   what components set later. The !important here is intentional and
   the single sanctioned exception: a user health preference must win.
   --------------------------------------------------------------------- */
@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;
    }
}
