/* multilayer.app — shared site chrome
 * Header (.topbar), nav (.nav-link, .tutorial-menu), theme switch, footer,
 * skip-link, theme tokens. Page-specific CSS stays inline per page. */

:root {
    color-scheme: dark light;
    --radius: 8px;
    --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Theme tokens. Apply on either <html> or <body> so static pages
 * (html[data-theme]) and the calculator (body[data-theme]) both work. */
html[data-theme="dark"],
body[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101011;
    --surface: #18191b;
    --surface2: #222326;
    --surface3: #2d2f33;
    --border: #3a3d42;
    --border-strong: #676c74;
    --accent: #2aa198;
    --accent2: #cc6677;
    --accent-soft: rgba(42, 161, 152, 0.18);
    --text: #f4f4f2;
    --text-dim: #c9cbc7;
    --text-soft: #969a9f;
    --shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
    --chart-bg: #121315;
    --grid: #33363a;
    --axis: #f4f4f2;
    --metric-a: #d55e00;
    --metric-t: #56b4e9;
    --metric-r: #009e73;
    --metric-bare: #cc6677;
    --metric-ideal: #d55e00;
    --field-main: #cc79a7;
    --field-s: #56b4e9;
    --field-p: #f0e442;
    --layer-boundary: #b7bab6;
    --incident-boundary: #b7bab6;
    --substrate-boundary: #8b5cf6;
    --danger: #d55e00;
    --warning: #e69f00;
    --success: #009e73;
    --select-active: #2aa198;
    --select-active-text: #ffffff;
}

html[data-theme="light"],
body[data-theme="light"] {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface2: #edf0f2;
    --surface3: #dde4e7;
    --border: #d0d5d8;
    --border-strong: #8b969d;
    --accent: #007f79;
    --accent2: #cc6677;
    --accent-soft: rgba(0, 127, 121, 0.12);
    --text: #171716;
    --text-dim: #50575a;
    --text-soft: #717a80;
    --shadow: 0 12px 28px rgba(17, 17, 17, 0.07);
    --chart-bg: #ffffff;
    --grid: #d7dde0;
    --axis: #171716;
    --metric-a: #d55e00;
    --metric-t: #0072b2;
    --metric-r: #009e73;
    --metric-bare: #cc6677;
    --metric-ideal: #d55e00;
    --field-main: #cc79a7;
    --field-s: #0072b2;
    --field-p: #8f7600;
    --layer-boundary: #687179;
    --incident-boundary: #687179;
    --substrate-boundary: #5b45c6;
    --danger: #d55e00;
    --warning: #e69f00;
    --success: #009e73;
    --select-active: #007f79;
    --select-active-text: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 10px;
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
}

/* Page container. Modifiers control max-width:
 *   .shell                — default (1220px) for tutorials and validation
 *   .shell--wide          — 1520px for the calculator
 *   .shell--narrow        — 960px for prose pages (about) */
.shell {
    width: min(1220px, 100%);
    margin: 0 auto;
}
.shell--wide {
    max-width: 1520px;
    width: 100%;
}
.shell--narrow {
    width: min(960px, 100%);
}

/* Skip-link for keyboard users — first focusable element on the page. */
.skip-link {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 100;
    padding: 6px 10px;
    border-radius: 6px;
    background: var(--accent);
    color: var(--select-active-text, #ffffff);
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
    transform: translateY(-150%);
    transition: transform 0.12s ease;
}
.skip-link:focus {
    transform: translateY(0);
    outline: 2px solid var(--text);
    outline-offset: 2px;
}

/* Topbar / header */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
    padding: 4px 2px;
}

/* The brand area is now a single anchor wrapping logo + title.
 * Clicking the logo or the title takes the user to the calculator. */
.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    border-radius: 12px;
}
.app-brand:hover,
.app-brand:focus,
.app-brand:focus-visible {
    text-decoration: none;
}
.app-brand:hover .app-title,
.app-brand:focus-visible .app-title {
    color: var(--accent);
}
.app-brand:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

.app-icon {
    width: 42px;
    height: 42px;
    display: block;
    flex: 0 0 auto;
    border-radius: 12px;
    box-shadow: 0 10px 22px rgba(16, 16, 17, 0.16);
}

.app-brand-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.app-title {
    display: block;
    margin: 0;
    color: var(--text);
    font-size: 0.94rem;
    font-weight: 750;
    line-height: 1.2;
    letter-spacing: 0;
    transition: color 0.12s ease;
}

.app-subtitle {
    display: block;
    min-width: 0;
    color: var(--text-soft);
    font-size: 0.74rem;
    font-weight: 400;
    line-height: 1.25;
}

.deployment-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    color: var(--text-soft);
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.2;
}

.deployment-status-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--success);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 46%, transparent);
    animation: service-pulse 3.2s ease-in-out infinite;
}

.deployment-status.is-warning .deployment-status-dot {
    background: var(--warning);
    box-shadow: none;
    animation: none;
}

.deployment-status.is-offline .deployment-status-dot {
    background: var(--danger);
    box-shadow: none;
    animation: none;
}

@keyframes service-pulse {
    0%,
    100% {
        opacity: 0.55;
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 42%, transparent);
    }
    50% {
        opacity: 1;
        box-shadow: 0 0 0 6px color-mix(in srgb, var(--success) 0%, transparent);
    }
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* One nav button class for every text link in the header. */
.nav-link,
.feedback-btn,
.theme-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-dim);
    font-size: 1rem;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.nav-link {
    width: auto;
    min-width: 38px;
    padding: 0 11px;
    font-size: 0.72rem;
    letter-spacing: 0;
}

.feedback-btn {
    font-size: 1.24rem;
    line-height: 1;
}

.nav-link:hover,
.feedback-btn:hover,
.theme-switch:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.nav-link:focus-visible,
.feedback-btn:focus-visible,
.theme-switch:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Active page indicator — accent border + filled background. */
.nav-link[aria-current="page"] {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.tutorial-menu {
    position: relative;
    display: inline-flex;
}

.tutorial-menu summary {
    list-style: none;
}

.tutorial-menu summary::-webkit-details-marker {
    display: none;
}

.tutorial-menu[open] summary {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.tutorial-menu-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    display: grid;
    gap: 4px;
    min-width: 236px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.tutorial-menu-dropdown .nav-link {
    width: 100%;
    justify-content: flex-start;
    box-shadow: none;
}

/* Tooltip on hover for the icon-only buttons. */
.feedback-btn::after,
.theme-switch::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 20;
    min-width: max-content;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-3px);
    transition: opacity 0.08s ease, transform 0.08s ease;
    box-shadow: var(--shadow);
}

.feedback-btn:hover::after,
.feedback-btn:focus-visible::after,
.theme-switch:hover::after,
.theme-switch:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}

.theme-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Sun/moon glyph swap. Reads the theme from <html> or <body>. */
.theme-icon::before {
    content: "☾";
    color: currentColor;
    font-size: 1.05rem;
    line-height: 1;
}
html[data-theme="light"] .theme-icon::before,
body[data-theme="light"] .theme-icon::before {
    content: "☀";
}

.spectra-metric-tabs,
.polarization-tabs,
.angle-metric-tabs,
.angle-polarization-tabs,
.spectra-x-axis-tabs {
    display: flex;
    gap: 6px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface2);
}

.spectra-metric-tab,
.polarization-tab,
.angle-metric-tab,
.angle-polarization-tab,
.spectra-x-axis-tab {
    appearance: none;
    -webkit-appearance: none;
    min-width: 44px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
}

.spectra-metric-tab.active,
.polarization-tab.active,
.angle-metric-tab.active,
.angle-polarization-tab.active,
.spectra-x-axis-tab.active {
    border-color: var(--accent);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 32%, transparent);
}

.spectra-metric-tab:focus-visible,
.polarization-tab:focus-visible,
.angle-metric-tab:focus-visible,
.angle-polarization-tab:focus-visible,
.spectra-x-axis-tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.spectra-metric-tab[hidden] {
    display: none;
}

/* Labels that should only appear in exported PNG/SVG output, not the
 * on-screen display. The PNG export code removes the attribute on a
 * clone, so the label shows up in the saved figure but is hidden in
 * the live UI. */
[data-export-only="true"] {
    display: none;
}

.hover-readout .hover-wavelength,
.hover-readout .hover-value {
    background: #ffffff !important;
    color: #000000 !important;
}

/* Chart frame — shared by every tutorial's result plots. Matches the
 * .chart-frame styling inlined in index.html. */
.chart-frame {
    position: relative;
    width: 100%;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
}
.chart-frame > svg {
    display: block;
    width: 100%;
    height: auto;
    cursor: crosshair;
}

/* Footer — single shared one-line note. */
.site-footer {
    margin: 28px auto 0;
    padding: 14px 4px 6px;
    border-top: 1px solid var(--border);
    color: var(--text-soft);
    font-size: 0.72rem;
    line-height: 1.5;
    text-align: center;
}
.site-footer a {
    color: var(--text-dim);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.site-footer a:hover {
    color: var(--accent);
}

/* Responsive: compact topbar at narrow widths. */
@media (max-width: 960px) {
    .topbar {
        gap: 10px;
    }
    .app-brand {
        gap: 9px;
    }
    .app-icon {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }
    .app-title {
        font-size: 0.86rem;
    }
    .app-subtitle {
        font-size: 0.68rem;
    }
    .nav-link,
    .feedback-btn,
    .theme-switch {
        width: 34px;
        height: 32px;
    }
    .nav-link {
        width: auto;
        min-width: 34px;
        padding: 0 9px;
    }
    .tutorial-menu-dropdown {
        right: auto;
        left: 0;
    }
}
