/* Base styling */
:root {
    --primary: #02041c;
    --chrome-background: #101838;
    --secondary: #aac9e2;
    --link: #285d82;
    --surface: #faf9f7;
    --border: #dce1e5;
    --row-alternate: #eef1f3;
    --text-light: #ffffff;
    --text-dark: #303740;
    --text-muted: #cccccc;
    --bg-overlay: rgba(2, 4, 28, 0.9);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body,
html {
    min-height: 100%;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--text-dark);
}

body {
    min-height: 100vh;
    background-color: var(--surface);
    font-size: clamp(1.0625rem, 1rem + 0.25vw, 1.125rem);
    line-height: 1.65;
    display: flex;
    flex-direction: column;
}

body.home { background-color: var(--primary); }
body.home { min-height: 100dvh; }
.home footer {
    margin-top: auto;
    position: relative;
    z-index: 1;
}
body.modal-open { overflow: hidden; }
[hidden] { display: none !important; }

:focus-visible {
    outline: 3px solid var(--link);
    outline-offset: 4px;
}

.navbar :focus-visible,
.popup :focus-visible { outline-color: var(--secondary); }

.skip-link {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    padding: 0.75rem;
    background: white;
    color: var(--text-dark);
    transform: translateY(-200%);
    z-index: 40;
}
.skip-link:focus { transform: translateY(0); }

/* Full-page background image */
.background-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url("../images/race-bg.webp") no-repeat center center;
    background-size: cover;
    z-index: 0;
}

/* Background image for vertical mobile orientation */
@media (max-aspect-ratio: 1/1) {
    .background-image {
        background: url("../images/race-bg-vertical.webp") no-repeat center
            center;
        background-size: cover;
    }
}

/* Background image for 1:1 aspect ratio (square) */
@media (min-aspect-ratio: 1/1) and (max-aspect-ratio: 16/9) {
    .background-image {
        background: url("../images/race-bg-square.webp") no-repeat center center;
        background-size: cover;
    }
}

/* Navbar */
#header { position: sticky; top: 0; z-index: 10; }
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    position: relative;
    width: 100%;
    background-color: var(--chrome-background);
    z-index: 10;
    transition: background-color 0.2s ease;
}

.navbar.scrolled {
    background-color: var(--chrome-background);
}

.logo-container {
    background: transparent;
    height: 30px;
}

.logo {
    background: transparent;
    height: 100%;
    width: auto;
    display: block;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 1.5rem;
}

.nav-links li a {
    text-decoration: none;
    color: var(--text-light);
    font-weight: 700;
    font-size: 1rem;
    transition: color 0.2s ease;
    padding: 0.5rem 0;
    position: relative;
}

.nav-links li a:hover,
.nav-links li a[aria-current="page"] {
    color: var(--secondary);
}

.nav-links li a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background-color: var(--secondary);
    transition: width 0.3s ease;
}

.nav-links li a:hover::after,
.nav-links li a:focus-visible::after,
.nav-links li a[aria-current="page"]::after {
    width: 100%;
}

/* Hamburger menu for mobile */
.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    z-index: 20;
}

.hamburger-line {
    display: block;
    width: 25px;
    height: 3px;
    background-color: #ffffff;
    margin: 5px 0;
    transition: all 0.3s ease;
}

.hamburger.active .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translate(5px, 6px);
}

.hamburger.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.hamburger.active .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

/* Without JavaScript, mobile navigation stays visible in normal flow. */
@media (max-width: 768px) {
    .navbar { padding: 1rem; flex-wrap: wrap; gap: 1rem; }
    .nav-links { width: 100%; flex-direction: column; gap: 1rem; }
    .enhanced .hamburger { display: block; }
    .enhanced .nav-links {
        position: absolute;
        top: 100%;
        right: 0;
        width: min(100%, 320px);
        max-height: calc(100dvh - 80px);
        overflow-y: auto;
        background-color: var(--primary);
        padding: 1.5rem;
    }
    .nav-links li a { display: block; overflow-wrap: anywhere; }
}

main {
    width: 100%;
    max-width: 76ch;
    padding: clamp(2rem, 4vw, 3.5rem) 1.5rem 4rem;
    margin: 0 auto;
    flex: 1;
    line-height: 1.65;
    overflow-wrap: anywhere;
    scroll-margin-top: 100px;
}

/* Typography */
h1,
h2 {
    color: var(--primary);
    font-weight: 650;
    letter-spacing: -0.025em;
    text-wrap: balance;
}

h1 {
    font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem);
    margin-bottom: 2rem;
    line-height: 1.15;
}

h2 {
    font-size: clamp(1.4rem, 1.2rem + 0.75vw, 1.75rem);
    margin: 0 0 1rem;
    line-height: 1.25;
}

main section + section { margin-top: 3rem; }

p {
    font-size: inherit;
    line-height: 1.65;
    margin-bottom: 1.25rem;
    color: var(--text-dark);
}

main a:not(.inline-gallery-item) {
    color: var(--link);
    text-underline-offset: 0.2em;
    text-decoration-thickness: 1px;
}

main a:not(.inline-gallery-item):hover { text-decoration-thickness: 2px; }

.specifications {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

.specifications th,
.specifications td {
    padding: 0.9rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.specifications th { width: 50%; font-weight: 600; }
.specifications td { text-align: right; font-variant-numeric: tabular-nums; }
.specifications tbody tr:nth-child(even) { background-color: var(--row-alternate); }

/* Footer follows the document content. */
footer {
    width: 100%;
    background-color: var(--chrome-background);
    text-align: center;
    padding: 1.25rem 1rem;
    color: #d5dce5;
}

footer p {
    color: inherit;
    font-size: 0.875rem;
    margin: 0;
}

/* Pienet esikatselukuvat tekstin seassa */
.inline-gallery-item {
    display: block;
    cursor: pointer;
    margin: 1.5rem auto;
    max-width: 600px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(2, 4, 28, 0.08);
    transition: box-shadow 0.2s ease;
}

.inline-gallery-item:hover {
    box-shadow: 0 3px 12px rgba(2, 4, 28, 0.14);
}

.inline-gallery-img {
    width: 100%;
    height: auto;
    display: block;
}

/* Popup-ikkuna */
.popup:not([open]) { display: none; }

.popup {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border: 0;
    padding: 4rem 1rem 1rem;
    background: rgba(0, 0, 0, 0.95);
    color: var(--text-light);
    overflow: auto;
}

.popup::backdrop { background: rgba(0, 0, 0, 0.8); }

.popup-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 75dvh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.close-popup {
    border: 0;
    position: absolute;
    top: 20px;
    right: 30px;
    color: var(--text-light);
    font-size: 42px;
    font-weight: bold;
    transition: color 0.2s ease;
    cursor: pointer;
    line-height: 1;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
}

.close-popup:hover {
    color: var(--secondary);
}

#popup-caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: var(--text-muted);
    padding: 15px 0;
    font-size: 1rem;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition: none !important; }
}
