/* Global Styles
 *
 * Single source of truth for design tokens, base element styles, and shared
 * patterns. Components and page styles reference these tokens instead of
 * hard-coding colors, so every section supports both themes.
 *
 * Theme: data-theme="light|dark" on <html>, set before first paint by
 * components/theme-init.js.
 *
 * Breakpoints (custom properties cannot be used inside media queries):
 *   48rem (768px)  - tablet
 *   64rem (1024px) - desktop; the header switches to its desktop nav here
 * Write page styles mobile-first with min-width queries at these values.
 */

/* ---------- Tokens ---------- */

:root {
    /* Palette: raw brand colors. Prefer the semantic tokens below; use these
       directly only for surfaces that ignore the theme (e.g. the overlay header). */
    --palette-navy: #20435a;
    --palette-navy-raised: #2a5470;
    --palette-navy-deep: #162f3f; /* dark-mode header and footer */
    --palette-slate: #36566b; /* dark-mode page sections */
    --palette-steel: #4f6778; /* muted blue-gray band, light mode */
    --palette-steel-deep: #26404f; /* muted blue-gray band, dark mode */
    --palette-gold: #d7c098;
    --palette-gold-light: #e6d7bb;
    --palette-sun: #fbcb2c; /* bright accent for highlights on dark surfaces */
    --palette-cream: #e9e8e0;
    --palette-cream-muted: #c3ccd2;
    --palette-cream-divider: rgba(233, 232, 224, 0.14);
    --palette-paper: #f7f6f1;
    --palette-stone: #deddd9; /* light panels in dark mode */
    --palette-mist: #eef2f5; /* very pale blue-gray panel, light mode */
    --palette-mist-deep: #d3dbe1; /* the same panel inside a dark page */
    --palette-parchment: #f4eada; /* light-mode header and footer */
    --palette-white: #ffffff;
    --palette-ink: #1c1c1c;
    --palette-ink-muted: #595959;
    --palette-ink-divider: rgba(20, 20, 20, 0.1);
    --palette-black: #141414;
}

/* Theme: light (default). .surface-light re-declares these on an element so a
   light panel keeps light-theme colors even when the page is in dark mode. */
:root,
.surface-light,
.section--alt,
.section--standard {
    --color-bg: var(--palette-white);
    --color-surface: var(--palette-paper);
    --color-text: var(--palette-ink);
    --color-text-muted: var(--palette-ink-muted);
    --color-heading: var(--palette-navy);
    --color-border: var(--palette-ink-divider);
    --color-accent: var(--palette-navy);
    --color-accent-hover: var(--palette-navy-raised);
    --color-on-accent: var(--palette-white);
    --color-link: var(--palette-navy);
    --color-link-hover: var(--palette-navy-raised);
    --color-focus: var(--palette-navy);
    --color-band: var(--palette-steel);
    --color-on-band: var(--palette-cream);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.1);
}

:root {
    /* Typography */
    --font-sans: 'Lato', 'Helvetica Neue', Arial, sans-serif;
    --font-serif: Georgia, 'Times New Roman', Times, serif; /* system serif for names and accents; nothing to download */
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-h1: clamp(2rem, 1.5rem + 2.5vw, 3rem);
    --font-size-h2: clamp(1.625rem, 1.3rem + 1.6vw, 2.25rem);
    --font-size-h3: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
    --font-size-h4: 1.125rem;
    --line-height-body: 1.6;
    --line-height-heading: 1.2;
    --measure: 70ch;

    /* Spacing */
    --space-2xs: 0.25rem;
    --space-xs: 0.5rem;
    --space-sm: 0.75rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;
    --section-space: clamp(3rem, 2rem + 5vw, 6rem);

    /* Layout: container widths and gutters match the header and footer */
    --container-max: 82.5rem;
    --container-narrow: 45rem;
    --container-pad: 1rem;
    --scroll-offset: 5.5rem; /* keeps anchor targets clear of the fixed header */

    /* Shape & motion */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --border-width: 1px;
    --ease-out: cubic-bezier(0, 0, 0.5, 1);
    --duration-fast: 150ms;
    --duration-base: 300ms;
}

:root[data-theme="dark"] {
    --color-bg: var(--palette-slate);
    --color-surface: var(--palette-slate); /* every section, shaded or not, defaults to slate in dark mode */
    --color-text: var(--palette-cream);
    --color-text-muted: var(--palette-cream-muted);
    --color-heading: var(--palette-cream);
    --color-border: var(--palette-cream-divider);
    --color-accent: var(--palette-gold);
    --color-accent-hover: var(--palette-gold-light);
    --color-on-accent: var(--palette-navy);
    --color-link: var(--palette-gold-light); /* plain gold is under 4.5:1 on slate */
    --color-link-hover: var(--palette-cream);
    --color-focus: var(--palette-cream);
    --color-band: var(--palette-steel-deep);
    --color-on-band: var(--palette-cream);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (min-width: 48rem) {
    :root {
        --container-pad: 1.5rem;
    }
}

@media (min-width: 64rem) {
    :root {
        --container-pad: 1.25rem;
        --scroll-offset: 7.5rem;
    }
}

/* ---------- Base ---------- */

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

* {
    margin: 0;
    padding: 0;
}

html {
    color-scheme: light;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* Column layout keeps the footer at the bottom of short pages */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: var(--line-height-body);
    color: var(--color-text);
    background-color: var(--color-bg);
    overflow-wrap: break-word;
}

main {
    flex: 1 0 auto;
}

main:focus {
    outline: none;
}

[id] {
    scroll-margin-top: var(--scroll-offset);
}

h1, h2, h3, h4, h5, h6 {
    margin-bottom: 0.5em;
    font-family: var(--font-sans);
    font-weight: 700;
    line-height: var(--line-height-heading);
    color: var(--color-heading);
    text-wrap: balance;
}

h1 { font-size: var(--font-size-h1); }
h2 { font-size: var(--font-size-h2); }
h3 { font-size: var(--font-size-h3); }
h4 { font-size: var(--font-size-h4); }

p {
    margin-bottom: 1em;
}

p:last-child {
    margin-bottom: 0;
}

a {
    color: var(--color-link);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-out);
}

a:hover {
    color: var(--color-link-hover);
}

/* Links inside running text are underlined so they don't rely on color alone */
:where(main) :where(p, li, dd, blockquote) a {
    text-decoration: underline;
    text-decoration-thickness: from-font;
    text-underline-offset: 0.15em;
}

img,
picture,
video,
svg {
    max-width: 100%;
    height: auto;
}

img,
picture,
video {
    display: block;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

/* ---------- Layout ---------- */

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

.container--narrow {
    max-width: calc(var(--container-narrow) + 2 * var(--container-pad));
}

.section {
    padding-block: var(--section-space);
}

.section--surface {
    background-color: var(--color-surface);
}

.section__header {
    max-width: var(--measure);
    margin-bottom: var(--space-xl);
}

/* Centered section heading with generous space before the content */
.section__title {
    margin-bottom: clamp(var(--space-xl), 1.5rem + 2vw, var(--space-3xl));
    text-align: center;
}

/* Adds a short decorative rule under the heading */
.section__title--rule {
    margin-bottom: var(--space-xl);
}

.section__title--rule::after {
    content: "";
    display: block;
    width: 5rem;
    height: calc(var(--border-width) * 2);
    margin: var(--space-lg) auto 0;
    background-color: var(--color-band);
}

.text-muted {
    color: var(--color-text-muted);
}

/* Light panel in either theme; pairs with the token block at the top.
   .section--alt and .section--standard are light panels too, so they need no
   extra class. */
.surface-light,
.section--alt,
.section--standard {
    color: var(--color-text);
    color-scheme: light;
}

/* Inside a dark page the panel uses a slightly dimmer light shade */
:root[data-theme="dark"] .surface-light,
:root[data-theme="dark"] .section--alt,
:root[data-theme="dark"] .section--standard {
    --color-surface: var(--palette-stone);
}

/* The section right after .page-title: white in light mode, stone grey in dark
   mode, with light-theme (dark) text in both. It sets --color-surface so a
   .wave-top on it draws in the same color. */
.section--alt {
    --color-surface: var(--palette-white);
    --color-heading: var(--palette-slate);
    background-color: var(--color-surface);
}

/* Default content section: white with slate headings in light mode, stone grey
   (matching .section--alt) in dark mode. */
.section--standard {
    --color-surface: var(--palette-white);
    --color-heading: var(--palette-slate);
    background-color: var(--color-surface);
}

/* ---------- Page title ---------- */

/* Standard first section on every inner page: a centered h1 and a one-sentence
   intro, followed by the wave transition into a .section--alt section:
     <section class="section section--surface page-title wave-above">
       <div class="container container--narrow">
         <h1 class="page-title__heading">…</h1>
         <p class="page-title__text">…</p>
       </div>
     </section>
     <section class="section section--alt wave-top">…</section>
   Later sections use .section--standard. */
.page-title {
    /* Thinner than a normal section; .section and .wave-above both read this */
    --section-space: clamp(2rem, 1.5rem + 2.5vw, 3.5rem);
    /* Slate in both themes (used by .section--surface) with cream text on it */
    --color-surface: var(--palette-slate);
    --color-heading: var(--palette-cream);
    --color-text: var(--palette-cream);
    /* Links, buttons and focus rings need the light-on-dark colors here, since
       the navy light-mode defaults disappear on slate */
    --color-link: var(--palette-gold-light);
    --color-link-hover: var(--palette-cream);
    --color-accent: var(--palette-gold);
    --color-accent-hover: var(--palette-gold-light);
    --color-on-accent: var(--palette-navy);
    --color-focus: var(--palette-cream);

    color: var(--color-text);
    text-align: center;
}

.page-title__heading {
    margin-bottom: var(--space-md);
}

.page-title__text {
    font-size: clamp(var(--font-size-base), 0.95rem + 0.4vw, 1.25rem);
    line-height: 1.6;
}

/* ---------- Section transition (wave) ---------- */

/* Default transition between two sections (as used on the homepage after
   "What is the Biblical Gospel?" and "Hear the Word Preached").
   Usage: put .wave-above on the upper section and .wave-top on the lower one,
   which should be a surface section, e.g.
     <section class="section wave-above">…</section>
     <section class="section section--surface surface-light wave-top">…</section>
   A wave in the lower section's surface color (so it matches in both themes)
   rises out of its top edge into the section above. ::after is the solid wave;
   ::before is a faint, offset wave behind it for depth. .wave-above adds
   matching bottom padding so the wave never crowds that section's content. */
.wave-top,
.wave-above {
    --wave-height: clamp(2rem, 1rem + 4vw, 4.5rem);
}

.wave-above {
    padding-bottom: calc(var(--section-space) + var(--wave-height));
}

.wave-top {
    position: relative;
}

.wave-top::before,
.wave-top::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% - 1px); /* 1px overlap avoids a hairline seam */
    height: var(--wave-height);
    background-color: var(--color-surface);
    pointer-events: none;
    -webkit-mask: var(--wave-shape) center bottom / 100% 100% no-repeat;
    mask: var(--wave-shape) center bottom / 100% 100% no-repeat;
}

.wave-top::before {
    --wave-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 100' preserveAspectRatio='none'%3E%3Cpath d='M0 40C220 0 420 10 640 45s460 50 800-20V100H0Z'/%3E%3C/svg%3E");
    opacity: 0.45;
}

.wave-top::after {
    --wave-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 100' preserveAspectRatio='none'%3E%3Cpath d='M0 70C260 20 520 25 760 60s460 35 680-10V100H0Z'/%3E%3C/svg%3E");
}

/* ---------- Scripture references ---------- */

/* Wrapped by the Bible Link plugin (bible-link.globalrize.org). Its default
   blue fails contrast in dark mode, so use theme colors and an underline so
   references don't rely on color alone. */
.bible-link {
    color: var(--color-link);
    text-decoration: underline;
    text-decoration-thickness: from-font;
    text-underline-offset: 0.15em;
    cursor: pointer;
}

/* ---------- Buttons ---------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    min-height: 2.75rem;
    padding: var(--space-sm) var(--space-lg);
    border: 2px solid var(--color-accent);
    border-radius: var(--radius-sm);
    background-color: var(--color-accent);
    color: var(--color-on-accent);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.03em;
    text-align: center;
    text-decoration: none;
    transition:
        background-color var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out),
        color var(--duration-fast) var(--ease-out);
}

.button:hover {
    border-color: var(--color-accent-hover);
    background-color: var(--color-accent-hover);
    color: var(--color-on-accent);
}

.button--secondary {
    background-color: transparent;
    color: var(--color-accent);
}

.button--secondary:hover {
    border-color: var(--color-accent);
    background-color: var(--color-accent);
    color: var(--color-on-accent);
}

/* ---------- Forms ---------- */

/* One labeled control per .form-field:
     <div class="form-field">
       <label class="form-field__label" for="x">Name</label>
       <input class="form-field__control" id="x" …>
     </div>
   Control borders use the muted text color so they meet the 3:1 contrast
   needed for input boundaries (the divider border color is too faint). */
.form-field {
    display: grid;
    gap: var(--space-xs);
    min-width: 0;
}

.form-field__label {
    font-weight: 700;
    color: var(--color-text);
}

.form-field__hint {
    font-size: var(--font-size-sm);
    font-weight: 400;
    color: var(--color-text-muted);
}

.form-field__control {
    width: 100%;
    min-height: 2.75rem;
    padding: var(--space-sm) var(--space-md);
    border: var(--border-width) solid var(--color-text-muted);
    border-radius: var(--radius-sm);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.4;
    transition: border-color var(--duration-fast) var(--ease-out);
}

.form-field__control:hover {
    border-color: var(--color-text);
}

.form-field__control:focus-visible {
    border-color: var(--color-focus);
    outline-offset: 1px;
}

.form-field__control--multiline {
    min-height: 10rem;
    resize: vertical;
}

/* ---------- Accessibility ---------- */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: var(--space-xs);
    left: var(--space-xs);
    z-index: 1100;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    background-color: var(--color-accent);
    color: var(--color-on-accent);
    font-weight: 700;
    transform: translateY(-200%);
}

.skip-link:focus {
    transform: none;
    color: var(--color-on-accent);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important; /* honor the user's setting over component motion */
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
