/*
 * Site-wide element and component styles. Values come from tokens.css; add new tokens there
 * rather than hard-coding colours or sizes here. Pages should only need these shared classes.
 */

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

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: var(--leading);
}

main {
    flex: 1;
}

h1, h2, h3 {
    font-family: var(--font-display);
    line-height: 1.15;
    margin: 0 0 var(--space-3);
}

h1 { font-size: var(--text-hero); }
h2 { font-size: var(--text-xl); }

p {
    margin: 0 0 var(--space-3);
}

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

img {
    max-width: 100%;
    display: block;
}

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

h1:focus {
    outline: none;
}

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

.container {
    width: min(100% - 2 * var(--space-4), var(--container-width));
    margin-inline: auto;
}

.page-body {
    padding-block: var(--space-5) var(--space-6);
}

.split {
    display: grid;
    gap: var(--space-5);
    align-items: center;
}

@media (min-width: 48rem) {
    .split {
        grid-template-columns: 1fr 1fr;
    }
}

.split--reverse > :first-child {
    order: 2;
}

@media (max-width: 47.99rem) {
    .split--reverse > :first-child {
        order: 0;
    }
}

.stack > * + * {
    margin-top: var(--space-2);
}

.plain-list {
    list-style: none;
    margin: 0 0 var(--space-3);
    padding: 0;
}

.skip-link {
    position: absolute;
    left: var(--space-3);
    top: -100%;
    z-index: 10;
    padding: var(--space-2) var(--space-3);
    background: var(--color-surface);
}

.skip-link:focus {
    top: var(--space-2);
}

/* ---------- Text ---------- */

.lead {
    font-size: var(--text-lg);
    max-width: 40rem;
}

/* Read by screen readers and search engines, not shown. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

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

.eyebrow {
    color: var(--color-accent);
    font-size: var(--text-sm);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ---------- Header and footer ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--color-header-bg);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--color-border);
}

.site-header__inner {
    min-height: var(--header-height);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 700;
    text-decoration: none;
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    margin-inline-end: auto;
}

.site-nav a {
    color: var(--color-text);
    text-decoration: none;
    padding-block: var(--space-1);
    border-bottom: 2px solid transparent;
    transition: border-color var(--transition);
}

.site-nav a:hover,
.site-nav a.active {
    border-bottom-color: var(--color-accent);
}

.site-header__tools {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.site-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding-block: var(--space-5);
    font-size: var(--text-sm);
}

.site-footer__inner {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

.site-footer a {
    color: var(--color-text);
}

/* Keep stacked footer links at least 24px tall (WCAG 2.5.8 target size). */
.site-footer li a {
    display: inline-block;
    padding-block: 0.2rem;
}

/* ---------- Mobile menu ---------- */

.mobile-menu {
    position: relative;
    display: none;
}

.mobile-menu summary {
    cursor: pointer;
    list-style: none;
}

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

.mobile-menu__panel {
    position: absolute;
    right: 0;
    top: calc(100% + var(--space-2));
    min-width: 14rem;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-raised);
    box-shadow: var(--shadow-card);
}

.mobile-menu__panel .plain-list {
    margin: 0;
}

.mobile-menu__panel a {
    display: block;
    padding-block: var(--space-2);
    color: var(--color-text);
    text-decoration: none;
}

.mobile-menu__panel a.active {
    color: var(--color-accent);
    font-weight: 600;
}

/* Below the nav breakpoint (--nav-breakpoint) the menu moves into the disclosure. */
@media (max-width: 55.99rem) {
    .site-nav { display: none; }
    .mobile-menu { display: block; }
    .site-header__tools { margin-inline-start: auto; }
}

/* ---------- Language and theme switches ---------- */

.language-switch {
    display: flex;
    gap: var(--space-2);
}

.language-switch__flag {
    border-radius: var(--radius-sm);
    opacity: 0.55;
    transition: opacity var(--transition);
}

.language-switch__flag img {
    border-radius: 3px;
    box-shadow: 0 0 0 1px var(--color-border);
}

.language-switch__flag:hover,
.language-switch__flag[aria-current="true"] {
    opacity: 1;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
}

.icon-button svg {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

/* ---------- Day / night ---------- */

/* Elements that exist in a day and a night variant (images, the theme switch). The theme
   cookie decides when set; otherwise the OS setting does. !important so component display
   rules never resurrect the hidden variant. */
:root[data-theme="light"] .night-only,
:root[data-theme="dark"] .day-only {
    display: none !important;
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme]) .night-only { display: none !important; }
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .day-only { display: none !important; }
}

/* ---------- Scene banner (day / night illustration) ---------- */

.scene {
    --scene: var(--scene-day);
    position: relative;
    display: flex;
    align-items: flex-end;
    min-height: 18rem;
    padding-block: var(--space-6) var(--space-5);
    color: var(--color-scene-text);
    background: var(--scene) center bottom / cover no-repeat;
}

.scene::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, var(--color-scene-veil) 15%, transparent 75%);
}

.scene__content {
    position: relative;
    text-shadow: 0 1px 12px var(--color-scene-veil);
}

.scene--hero {
    min-height: min(80vh, 40rem);
}

:root[data-theme="dark"] .scene {
    --scene: var(--scene-night);
}

/* System theme: the same override when no theme cookie is set and the OS is dark. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .scene { --scene: var(--scene-night); }
}

/* ---------- Content sections ---------- */

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

.section + .section,
.card-grid + .section {
    border-top: 1px solid var(--color-border);
}

.prose {
    max-width: 44rem;
}

.feature-grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: feature;
}

.feature {
    counter-increment: feature;
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-raised);
}

.feature::before {
    content: counter(feature, decimal-leading-zero);
    display: block;
    margin-bottom: var(--space-2);
    color: var(--color-accent);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 700;
}

.feature h3,
.timeline__item h3,
.person h3 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-2);
}

.feature p,
.timeline__item p {
    margin: 0;
    color: var(--color-text-muted);
}

/* Term/description list (FactsBlock): term in a narrow column on wide screens. */
.facts {
    display: grid;
    gap: var(--space-3);
    margin: 0;
}

.facts__row {
    display: grid;
    gap: var(--space-1) var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

@media (min-width: 48rem) {
    .facts__row {
        grid-template-columns: 12rem 1fr;
    }
}

.facts dt {
    font-weight: 600;
}

.facts dd {
    margin: 0;
    color: var(--color-text-muted);
}

.facts dd p {
    margin: 0;
}

code {
    padding: 0.1em 0.35em;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-raised);
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.timeline {
    position: relative;
    margin: 0;
    padding: 0 0 0 var(--space-5);
    list-style: none;
    max-width: 44rem;
}

.timeline::before {
    content: "";
    position: absolute;
    inset: var(--space-2) auto var(--space-2) var(--space-2);
    width: 2px;
    background: var(--color-border);
}

.timeline__item {
    position: relative;
    padding-bottom: var(--space-4);
}

.timeline__item::before {
    content: "";
    position: absolute;
    left: calc(-1 * var(--space-5) + var(--space-2) - 5px);
    top: 0.45em;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 0 0 4px var(--color-bg);
}

.timeline__label {
    display: block;
    color: var(--color-accent);
    font-weight: 700;
    font-size: var(--text-sm);
    letter-spacing: 0.06em;
}

.people {
    display: grid;
    gap: var(--space-5);
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
}

.person {
    display: grid;
    grid-template-columns: 8rem 1fr;
    gap: var(--space-4);
    align-items: start;
}

.person__portrait {
    width: 8rem;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
}

.spec-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-1) var(--space-4);
    margin: 0 0 var(--space-4);
}

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

.spec-list dd {
    margin: 0;
    font-weight: 600;
}

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

.narrow {
    max-width: 36rem;
}

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

.form {
    display: grid;
    gap: var(--space-3);
}

.field {
    display: grid;
    gap: var(--space-1);
}

.field label {
    font-weight: 600;
}

.field input,
.field textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-sm);
    background: var(--color-input-bg);
    color: var(--color-text);
    font: inherit;
}

.field .invalid {
    border-color: var(--color-danger);
}

.field__error {
    margin: 0;
    color: var(--color-danger);
    font-size: var(--text-sm);
}

.form .button {
    justify-self: start;
    cursor: pointer;
}

.form .button:disabled {
    opacity: 0.6;
    cursor: progress;
}

/* ---------- Configurator ---------- */

.configurator {
    display: grid;
    gap: var(--space-5);
    align-items: start;
}

@media (min-width: 60rem) {
    .configurator {
        grid-template-columns: minmax(0, 3fr) minmax(16rem, 2fr);
    }

    .configurator__summary {
        position: sticky;
        top: calc(var(--header-height) + var(--space-3));
    }
}

.configurator__summary {
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-raised);
    box-shadow: var(--shadow-card);
}

.summary__title {
    margin-top: var(--space-3);
}

/* Until the configurator is interactive, its prerendered controls would do nothing. */
.configurator:not([data-interactive]) .configurator__choices {
    opacity: 0.6;
    pointer-events: none;
}

.choice-group {
    margin: 0 0 var(--space-4);
    padding: 0;
    border: 0;
}

.choice-group legend {
    margin-bottom: var(--space-2);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 700;
}

.choice-grid {
    display: grid;
    gap: var(--space-2);
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
}

.choice {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0 var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-raised);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.choice:has(input:checked) {
    border-color: var(--color-accent);
    background: var(--color-selected-bg);
}

.choice:has(input:disabled) {
    cursor: default;
}

.choice input {
    grid-row: span 2;
    margin-top: 0.3em;
    accent-color: var(--color-accent);
}

.choice__title {
    font-weight: 600;
}

.choice__body {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}

.tag {
    display: inline-block;
    margin-inline-start: var(--space-1);
    padding: 0 var(--space-2);
    border-radius: 999px;
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    font-size: 0.75rem;
    font-weight: 600;
    vertical-align: middle;
}

.swatch-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.swatch-choice {
    display: grid;
    justify-items: center;
    gap: var(--space-1);
    font-size: var(--text-sm);
    cursor: pointer;
}

/* The radio stays focusable for keyboards but is drawn as the swatch ring. */
.swatch-choice input {
    position: absolute;
    opacity: 0;
}

.swatch {
    display: inline-block;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: var(--swatch);
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15);
}

.swatch-choice input:checked + .swatch {
    outline: 3px solid var(--color-accent);
    outline-offset: 3px;
}

.swatch-choice input:focus-visible + .swatch {
    outline: 3px solid var(--color-focus);
    outline-offset: 3px;
}

.swatch--small {
    width: 0.9rem;
    height: 0.9rem;
    vertical-align: -0.1em;
}

.spec-list--compact {
    margin: 0;
    font-size: var(--text-sm);
}

/* ---------- Admin ---------- */

.admin-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: var(--space-3);
}

.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.data-table th,
.data-table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    text-align: start;
    vertical-align: top;
}

.data-table__message {
    max-width: 20rem;
    white-space: pre-wrap;
}

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

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.button {
    display: inline-block;
    padding: var(--space-2) var(--space-4);
    border: 2px solid var(--color-accent);
    border-radius: 999px;
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    font-weight: 600;
    text-decoration: none;
    transition: filter var(--transition);
}

.button:hover {
    filter: brightness(1.1);
}

.button--ghost {
    background: transparent;
    color: var(--color-text);
}

/* ---------- Cards ---------- */

.card-grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
}

.card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-raised);
    box-shadow: var(--shadow-card);
}

.card__image {
    aspect-ratio: 3 / 2;
    width: 100%;
    object-fit: cover;
    background: var(--color-bg);
}

/* Photographer credit under an image adapted from someone else's photo (ThemedImage). */
.credited-image {
    margin: 0;
}

.image-credit {
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

/* Fixed ratio so the space is reserved before the image loads (no layout shift). */
.rounded-image {
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: cover;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

.card__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: var(--space-4);
}

.card__body > .button {
    margin-top: auto;
    align-self: flex-start;
}

.card__title {
    margin-bottom: var(--space-1);
}

/* ---------- Blazor ---------- */

.blazor-error-boundary {
    padding: var(--space-3);
    background: var(--color-danger);
    color: #fff;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1000;
    padding: var(--space-2) var(--space-4);
    background: var(--color-danger);
    color: #fff;
}

#blazor-error-ui .dismiss {
    float: right;
    cursor: pointer;
}
