html {
    scroll-behavior: smooth;
}

:root {
    --body-text: #1e293b;
    --font-heading: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-body: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, .font-heading {
    font-family: var(--font-heading);
    letter-spacing: 0;
    text-wrap: balance;
    overflow-wrap: break-word;
    word-break: break-word;
}

::selection {
    background-color: #2563eb;
    color: #ffffff;
}

/* Keep landing-page gutters and line lengths consistent between breakpoints. */
.landing-page .container {
    width: 100%;
    max-width: 96rem;
    padding-inline: clamp(1rem, 3vw, 2rem);
}

/* The full menu fits from 640px; smaller screens use an in-flow disclosure. */
.nav-layout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.nav-links {
    display: flex;
    flex: 0 0 100%;
    flex-direction: column;
    gap: 0.25rem;
    padding-top: 0.75rem;
    border-top: 1px solid #5274b1;
}

.nav-links a {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    padding-inline: 0.75rem;
}

.nav-links[hidden] {
    display: none;
}

.nav-layout .nav-toggle {
    display: none;
}

@media (max-width: 639px) {
    .nav-layout .nav-toggle {
        display: flex;
    }
}

@media (min-width: 640px) {
    .nav-layout {
        flex-wrap: nowrap;
        gap: 1.5rem;
    }

    .nav-links {
        flex: 0 0 auto;
        flex-direction: row;
        gap: 1.5rem;
        padding-top: 0;
        border-top: 0;
        white-space: nowrap;
    }

    .nav-links a {
        padding-inline: 0;
        font-size: 0.875rem;
    }
}

.hero-title {
    font-size: clamp(1.75rem, calc(1.25rem + 2vw), 3rem);
    line-height: 1.25;
}

.studio-preview {
    container-type: inline-size;
}

/* Split the preview only when the component itself has enough space. */
@container (min-width: 32rem) {
    .studio-preview .studio-workspace {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .studio-preview .studio-player {
        aspect-ratio: auto;
    }
}

.landing-page .site-footer a {
    min-height: 2.75rem;
    overflow-wrap: anywhere;
}

@media (min-width: 768px) {
    .landing-page .site-footer .footer-compact-links a {
        min-height: 2rem;
    }
}

/* Shared footer palette for all pages. */
.site-footer {
    --footer-background: #f8fafc;
    --footer-text: var(--body-text);
    --footer-heading: #17365d;
    --footer-accent: #1d4ed8;
    --footer-hover: #1e40af;
    --footer-focus: #2563eb;
    --footer-border: #e2e8f0;
    --footer-divider: #cbd5e1;
    background-color: var(--footer-background);
    color: var(--footer-text);
}

.site-footer .footer-heading,
.site-footer a[aria-current="page"] {
    color: var(--footer-heading);
}

.site-footer a[aria-current="page"] {
    font-weight: 600;
}

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

.site-footer .footer-link:hover {
    color: var(--footer-hover);
}

.site-footer a:focus-visible {
    outline: 2px solid var(--footer-focus);
    outline-offset: 3px;
}

.site-footer .footer-border,
.site-footer.footer-border {
    border-color: var(--footer-border);
}

.site-footer .footer-divider {
    background-color: var(--footer-divider);
}

.site-footer .footer-line-icon {
    background-color: currentColor;
    -webkit-mask: url('../assets/line-icon.svg') center / contain no-repeat;
    mask: url('../assets/line-icon.svg') center / contain no-repeat;
}

/* Skip link visible on keyboard focus */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: 1rem;
    max-width: calc(100% - 2rem);
    background: #ffffff;
    color: #1e3a8a;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    box-shadow: 0 2px 8px rgba(2, 6, 23, 0.12);
    z-index: 60;
    /* Keep the target in the viewport while revealing it only on keyboard focus. */
    clip-path: inset(50%);
}

.skip-link:focus,
.skip-link:active {
    clip-path: none;
}

#main-content:target,
#main-content:focus {
    scroll-margin-block: 1rem;
}

#preview-motion-toggle:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 3px;
}

/* WCAG: make focus visible for keyboard users */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid #0b67ff;
    outline-offset: 2px;
}

/* Ensure buttons have visible focus when not using :focus-visible capable browsers */
:where(button):focus {
    outline: 3px solid #0b67ff;
    outline-offset: 2px;
}

.motion-paused *,
.motion-paused *::before,
.motion-paused *::after {
    animation-play-state: paused !important;
}

/* Respect user preference to reduce motion */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* Terminal cursor blinking animation */
@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.animate-cursor-blink {
    animation: cursor-blink 1s steps(2, start) infinite;
}

/* Back button styling */
.back-button {
    display: inline-flex;
    align-items: center;
    color: var(--body-text);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.back-button:hover {
    color: #0b67ff;
    background-color: #f1f5f9;
}

/* Basic markdown content styling */
#markdown-content {
    font-family: 'Sarabun', sans-serif;
}

@media (max-width: 640px) {
    #markdown-content {
        line-height: 1.6;
    }
}

#markdown-content li {
    margin-bottom: 0.25em;
}

#markdown-content blockquote {
    margin: 1em 0;
    padding: 0 1em;
    color: var(--body-text);
    border-left: 0.25em solid #d1d5db;
}

#markdown-content code {
    background-color: #f3f4f6;
    padding: 0.125em 0.25em;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

#markdown-content pre {
    background-color: #1f2937;
    color: #f9fafb;
    padding: 1em;
    border-radius: 0.5em;
    overflow-x: auto;
}

#markdown-content pre code {
    background-color: transparent;
    padding: 0;
}

#markdown-content a {
    color: #2563eb;
    text-decoration: underline;
}

#markdown-content strong {
    font-weight: 600;
}

#markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 1em;
    display: block;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

#markdown-content th,
#markdown-content td {
    border: 1px solid #d1d5db;
    padding: 0.5em;
    text-align: left;
}

#markdown-content th {
    background-color: #f9fafb;
    font-weight: 600;
}
