/* ==============================================
   TYPOGRAPHY
   ============================================== */

@font-face {
    font-family: "Inter";
    src: url("../../fonts/inter/InterVariable.woff2") format("woff2");
    font-style: normal;
    font-weight: 300 600;
    font-display: swap;
}

@font-face {
    font-family: "Space Mono";
    src: url("../../fonts/space-mono/SpaceMono-Regular.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Space Mono";
    src: url("../../fonts/space-mono/SpaceMono-Bold.woff2") format("woff2");
    font-style: normal;
    font-weight: 700;
    font-display: swap;
}

@font-face {
    font-family: "Space Mono";
    src: url("../../fonts/space-mono/SpaceMono-Italic.woff2") format("woff2");
    font-style: italic;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Space Mono";
    src: url("../../fonts/space-mono/SpaceMono-BoldItalic.woff2") format("woff2");
    font-style: italic;
    font-weight: 700;
    font-display: swap;
}

* {
    font-family: var(--font-primary, "Inter", sans-serif);
    font-optical-sizing: auto;
}

body {
    font-family: var(--font-primary, "Inter", sans-serif);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    line-height: 1.2;
}

/* Shared optical text contract for reusable copy and controls.
   Components opt in either through the utility classes or their shared selectors. */
:is(.text-optical, .text-optical-control, .page-title, .section-title, .section-description, .card-optical-crop, .card-panel__title, .exercise-snacks-tracker-card__title, .card-panel__title-button, .exercise-snacks-tracker-card__title-button, .milestones-skill-title, .exercise-history-card-name, .exercise-name, .workout-card__title, .card-panel__body, .exercise-snacks-tracker-card__body, .driver-popover-title, .driver-popover-description, .smart-tooltip__title, .form-input, .modern-input, .auth-input, .form-control, .form-search-input, .considerations-input, .form-textarea-shell, .finish-notes-textarea, .card-control, .card-control--icon, .exercise-snacks-date-controls__arrow) {
    --text-optical-phi: 1.618034;
    --text-optical-phi-sq: 2.618034;
    --text-optical-sqrt-phi: 1.27202;
    --text-optical-cap-ratio: 0.73;
    --text-optical-x-ratio: 0.53;
    --text-optical-ascender-ratio: 0.80;
    --text-optical-descender-ratio: 0.20;
    --text-optical-line-height: var(--line-height-normal);
    --text-optical-half-leading: calc((var(--text-optical-line-height) - 1) / 2 * 1em);
    --text-optical-ghost-top: calc(var(--text-optical-half-leading) + (var(--text-optical-ascender-ratio) - var(--text-optical-cap-ratio)) * 1em);
    --text-optical-ghost-bottom: calc(var(--text-optical-half-leading) + var(--text-optical-descender-ratio) * 1em);
    --text-optical-ghost-delta: calc(var(--text-optical-ghost-bottom) - var(--text-optical-ghost-top));
    --text-optical-base-pad-v: calc((var(--text-optical-sqrt-phi) / var(--text-optical-phi-sq)) * 1em);
    --text-optical-pad-top: calc(var(--text-optical-base-pad-v) + var(--text-optical-ghost-delta) / 2);
    --text-optical-pad-bottom: calc(var(--text-optical-base-pad-v) - var(--text-optical-ghost-delta) / 2);
    --text-optical-pad-x: 1em;

    /* Legacy aliases kept for existing reusable consumers. */
    --phi: var(--text-optical-phi);
    --phi-sq: var(--text-optical-phi-sq);
    --sqrt-phi: var(--text-optical-sqrt-phi);
    --font-cap-ratio: var(--text-optical-cap-ratio);
    --font-x-ratio: var(--text-optical-x-ratio);
    --font-ascender-ratio: var(--text-optical-ascender-ratio);
    --font-descender-ratio: var(--text-optical-descender-ratio);
}

:is(.text-optical--top, .text-optical--both, .page-title, .section-title, .card-optical-crop--top, .card-panel__title, .exercise-snacks-tracker-card__title, .card-panel__title-button, .exercise-snacks-tracker-card__title-button, .milestones-skill-title, .exercise-history-card-name, .exercise-name, .workout-card__title, .driver-popover-title, .smart-tooltip__title)::before {
    content: '';
    display: table;
    margin-bottom: calc(-1 * var(--text-optical-ghost-top));
}

:is(.text-optical--bottom, .text-optical--both, .section-description, .card-optical-crop--bottom, .card-panel__body, .exercise-snacks-tracker-card__body, .driver-popover-description)::after {
    content: '';
    display: table;
    margin-top: calc(-1 * var(--text-optical-ghost-bottom));
}

:is(.text-optical-control, .form-input, .modern-input, .auth-input, .form-control, .form-search-input, .card-control) {
    padding: var(--text-optical-pad-top) var(--text-optical-pad-x) var(--text-optical-pad-bottom) var(--text-optical-pad-x);
}

/* Global section-level typography utilities */
.section-title {
    --text-optical-line-height: 1.2;

    font-family: var(--font-primary);
    font-weight: var(--font-weight-regular);
    font-size: var(--text-xl);
    color: var(--text-primary);
    margin: 0;
    line-height: var(--text-optical-line-height);
    padding-left: var(--space-sm);
}

.page-title {
    --text-optical-line-height: 1.2;

    font-family: var(--font-primary);
    font-weight: var(--font-weight-regular);
    font-size: var(--text-xl);
    color: var(--text-primary);
    margin: 0;
    line-height: var(--text-optical-line-height);
}

.section-description {
    --text-optical-line-height: var(--line-height-normal);

    font-family: var(--font-primary);
    font-weight: var(--font-weight-regular);
    font-size: var(--text-base);
    color: var(--text-muted);
    margin: 0;
    line-height: var(--text-optical-line-height);
}

/* Reusable label for input fields inside modals and forms (overline/tag style).
   Apply class="form-field-label" to any <label> or <p> above an input.
   Component CSS may override margin if needed (e.g. centered column headers). */
.form-field-label {
    font-family: var(--font-primary);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-regular);
    color: var(--text-muted);
    margin: 0 0 var(--space-sm) var(--space-sm);
    display: block;
}
