/* Esquires — colour themes, fonts, and text sizes */

/* --------------------------------------------------------------------------
   Font stacks (system only — no external CDN, CSP-safe)
   -------------------------------------------------------------------------- */

html[data-font="system"],
html:not([data-font]) {
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-font="humanist"] {
    --font-sans: "Trebuchet MS", Verdana, "Segoe UI", sans-serif;
}

html[data-font="serif"] {
    --font-sans: Georgia, "Times New Roman", Times, serif;
}

html[data-font="rounded"] {
    --font-sans: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

/* --------------------------------------------------------------------------
   Text size scale
   -------------------------------------------------------------------------- */

html[data-text-size="sm"] {
    --text-scale: 0.9;
}

html[data-text-size="md"],
html:not([data-text-size]) {
    --text-scale: 1;
}

html[data-text-size="lg"] {
    --text-scale: 1.125;
}

html[data-text-size="xl"] {
    --text-scale: 1.25;
}

html {
    font-size: calc(16px * var(--text-scale, 1));
}

/* --------------------------------------------------------------------------
   Classic (default)
   -------------------------------------------------------------------------- */

html[data-theme="classic"],
html:not([data-theme]) {
    --color-cream: #F8F4EF;
    --color-espresso: #3B2F2F;
    --color-green: #2D5A3D;
    --color-green-light: #3d7352;
    --color-white: #ffffff;
    --color-muted: #6b5e5e;
    --color-border: #e8dfd4;
    --color-surface: #ffffff;
    --color-surface-alt: #F8F4EF;
    --color-hero-gradient-end: #eef5f0;
    --color-footer-bg: #3B2F2F;
    --color-footer-text: rgba(255, 255, 255, 0.75);
    --color-footer-link: rgba(255, 255, 255, 0.85);
    --color-link: #2D5A3D;
    --color-link-hover: #3d7352;
    --color-focus: #2D5A3D;
    --shadow-sm: 0 1px 3px rgba(59, 47, 47, 0.08);
    --shadow-md: 0 4px 16px rgba(59, 47, 47, 0.1);
}

/* --------------------------------------------------------------------------
   Dark Roast
   -------------------------------------------------------------------------- */

html[data-theme="dark"] {
    --color-cream: #1a1714;
    --color-espresso: #f2ebe3;
    --color-green: #6fcf97;
    --color-green-light: #8fe0ae;
    --color-white: #24201c;
    --color-muted: #b8aea3;
    --color-border: #3d3630;
    --color-surface: #24201c;
    --color-surface-alt: #1f1b18;
    --color-hero-gradient-end: #1a2420;
    --color-footer-bg: #12100e;
    --color-footer-text: rgba(242, 235, 227, 0.72);
    --color-footer-link: rgba(242, 235, 227, 0.9);
    --color-link: #6fcf97;
    --color-link-hover: #8fe0ae;
    --color-focus: #6fcf97;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* --------------------------------------------------------------------------
   Forest Green
   -------------------------------------------------------------------------- */

html[data-theme="forest"] {
    --color-cream: #edf4ef;
    --color-espresso: #1f3328;
    --color-green: #1b5e3b;
    --color-green-light: #247a4d;
    --color-white: #ffffff;
    --color-muted: #4d6356;
    --color-border: #c8d9ce;
    --color-surface: #ffffff;
    --color-surface-alt: #e4efe8;
    --color-hero-gradient-end: #d8e8dc;
    --color-footer-bg: #1b5e3b;
    --color-footer-text: rgba(255, 255, 255, 0.78);
    --color-footer-link: rgba(255, 255, 255, 0.92);
    --color-link: #1b5e3b;
    --color-link-hover: #247a4d;
    --color-focus: #1b5e3b;
    --shadow-sm: 0 1px 3px rgba(27, 94, 59, 0.1);
    --shadow-md: 0 4px 16px rgba(27, 94, 59, 0.14);
}

/* --------------------------------------------------------------------------
   Warm Espresso
   -------------------------------------------------------------------------- */

html[data-theme="espresso"] {
    --color-cream: #f6efe8;
    --color-espresso: #3d2914;
    --color-green: #8b5a2b;
    --color-green-light: #a56d36;
    --color-white: #fffaf5;
    --color-muted: #7a6350;
    --color-border: #e5d4c3;
    --color-surface: #fffaf5;
    --color-surface-alt: #f0e4d8;
    --color-hero-gradient-end: #ead9c8;
    --color-footer-bg: #3d2914;
    --color-footer-text: rgba(255, 250, 245, 0.75);
    --color-footer-link: rgba(255, 250, 245, 0.9);
    --color-link: #8b5a2b;
    --color-link-hover: #a56d36;
    --color-focus: #8b5a2b;
    --shadow-sm: 0 1px 3px rgba(61, 41, 20, 0.1);
    --shadow-md: 0 4px 16px rgba(61, 41, 20, 0.14);
}

/* --------------------------------------------------------------------------
   High Contrast (accessibility)
   -------------------------------------------------------------------------- */

html[data-theme="high-contrast"] {
    --color-cream: #ffffff;
    --color-espresso: #000000;
    --color-green: #004d00;
    --color-green-light: #006600;
    --color-white: #ffffff;
    --color-muted: #1a1a1a;
    --color-border: #000000;
    --color-surface: #ffffff;
    --color-surface-alt: #f0f0f0;
    --color-hero-gradient-end: #e8e8e8;
    --color-footer-bg: #000000;
    --color-footer-text: #ffffff;
    --color-footer-link: #ffffff;
    --color-link: #004d00;
    --color-link-hover: #006600;
    --color-focus: #000000;
    --shadow-sm: none;
    --shadow-md: 0 0 0 2px #000000;
}

html[data-theme="high-contrast"] a {
    text-decoration: underline;
    text-underline-offset: 3px;
}

html[data-theme="high-contrast"] .site-header,
html[data-theme="high-contrast"] .step-card,
html[data-theme="high-contrast"] .benefit-card,
html[data-theme="high-contrast"] .hero-card,
html[data-theme="high-contrast"] .theme-panel-inner {
    border-width: 2px;
}

/* --------------------------------------------------------------------------
   Theme panel swatch previews
   -------------------------------------------------------------------------- */

.theme-swatch {
    display: block;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    flex-shrink: 0;
}

.theme-swatch--classic {
    background: linear-gradient(135deg, #F8F4EF 50%, #2D5A3D 50%);
}

.theme-swatch--dark {
    background: linear-gradient(135deg, #1a1714 50%, #6fcf97 50%);
}

.theme-swatch--forest {
    background: linear-gradient(135deg, #edf4ef 50%, #1b5e3b 50%);
}

.theme-swatch--espresso {
    background: linear-gradient(135deg, #f6efe8 50%, #8b5a2b 50%);
}

.theme-swatch--high-contrast {
    background: linear-gradient(135deg, #ffffff 50%, #000000 50%);
}

/* --------------------------------------------------------------------------
   Theme panel UI
   -------------------------------------------------------------------------- */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-muted);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    color: var(--color-green);
    border-color: var(--color-green);
    outline: none;
}

.theme-toggle:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-focus) 35%, transparent);
}

.theme-toggle-icon {
    width: 1.1rem;
    height: 1.1rem;
}

.theme-panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0, 0, 0, 0.45);
}

.theme-panel {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 400;
    width: min(100%, 22rem);
    height: 100%;
    overflow-y: auto;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
}

.theme-panel-inner {
    padding: 1.5rem;
}

.theme-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.theme-panel-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-espresso);
}

.theme-panel-intro {
    margin: 0 0 1.25rem;
    font-size: 0.875rem;
    color: var(--color-muted);
}

.theme-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--color-muted);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
}

.theme-panel-close:hover,
.theme-panel-close:focus-visible {
    color: var(--color-espresso);
    border-color: var(--color-green);
    outline: none;
}

.theme-fieldset {
    margin: 0 0 1.25rem;
    padding: 0;
    border: 0;
}

.theme-fieldset legend {
    margin-bottom: 0.65rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--color-muted);
}

.theme-options {
    display: grid;
    gap: 0.5rem;
}

.theme-options--colors {
    grid-template-columns: 1fr;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-alt);
    cursor: pointer;
}

.theme-option--compact {
    padding: 0.55rem 0.75rem;
}

.theme-option:has(input:checked) {
    border-color: var(--color-green);
    box-shadow: inset 0 0 0 1px var(--color-green);
}

.theme-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.theme-option-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-espresso);
}

.theme-form-actions {
    margin-top: 0.5rem;
}

.theme-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1rem;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
}

.theme-btn--ghost {
    color: var(--color-muted);
    background: transparent;
    border: 1px solid var(--color-border);
}

.theme-btn--ghost:hover,
.theme-btn--ghost:focus-visible {
    color: var(--color-espresso);
    border-color: var(--color-green);
    outline: none;
}

body.theme-panel-open {
    overflow: hidden;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .theme-panel,
    .theme-panel-backdrop {
        transition: none;
    }
}

@media (min-width: 640px) {
    .theme-options--colors {
        grid-template-columns: repeat(2, 1fr);
    }
}
