:root,
[data-theme="light"] {
    --bg: #f4f5f8;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --border: #dde1ea;
    --text: #1a1f2e;
    --text-muted: #5c6578;
    --prose-text: #2e3648;
    --accent: #dc382d;
    --accent-soft: rgba(220, 56, 45, 0.1);
    --link: #c62828;
    --eyebrow-text: #b71c1c;
    --callout-strong: #a31515;
    --code-bg: rgba(26, 31, 46, 0.06);
    --header-bg: rgba(255, 255, 255, 0.92);
    --mobile-nav-bg: rgba(255, 255, 255, 0.98);
    --mobile-nav-shadow: 0 12px 32px rgba(26, 31, 46, 0.12);
    --body-gradient-1: rgba(220, 56, 45, 0.08);
    --body-gradient-2: rgba(88, 101, 242, 0.05);
    --radius: 12px;
    --max-width: 920px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --header-h: 3.25rem;
    --header-offset: calc(env(safe-area-inset-top, 0px) + var(--header-h) + 1rem + 1px);
    --page-pad-x: 1rem;
}

[data-theme="dark"] {
    --bg: #0f1117;
    --bg-elevated: #171a22;
    --bg-card: #1c2030;
    --border: #2a3042;
    --text: #e8ecf4;
    --text-muted: #9aa3b8;
    --prose-text: #d5dbe8;
    --accent: #dc382d;
    --accent-soft: rgba(220, 56, 45, 0.14);
    --link: #ff6b61;
    --eyebrow-text: #ffb4ae;
    --callout-strong: #ffc1bb;
    --code-bg: rgba(255, 255, 255, 0.06);
    --header-bg: rgba(15, 17, 23, 0.92);
    --mobile-nav-bg: rgba(15, 17, 23, 0.98);
    --mobile-nav-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    --body-gradient-1: rgba(220, 56, 45, 0.12);
    --body-gradient-2: rgba(88, 101, 242, 0.08);
}

* { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    scroll-padding-top: var(--header-offset);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    background: radial-gradient(1200px 600px at 10% -10%, var(--body-gradient-1), transparent 60%),
                radial-gradient(900px 500px at 100% 0%, var(--body-gradient-2), transparent 55%),
                var(--bg);
    color: var(--text);
    line-height: 1.65;
    overflow-x: hidden;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

a {
    color: var(--link);
    text-decoration: none;
}

a:hover { text-decoration: underline; }

.container {
    width: min(100% - 2 * var(--page-pad-x), var(--max-width));
    margin: 0 auto;
}

/* —— Header —— */

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    overflow: visible;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: var(--header-h);
    padding: 0.5rem 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--text);
    font-weight: 700;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: block;
    flex-shrink: 0;
    object-fit: cover;
    box-shadow: 0 4px 14px rgba(220, 56, 45, 0.28);
}

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-elevated);
    cursor: pointer;
    flex-shrink: 0;
}

.nav-toggle-bar {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--text);
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.site-header.nav-open .nav-toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.site-header.nav-open .nav-toggle-bar:nth-child(2) {
    opacity: 0;
}

.site-header.nav-open .nav-toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem 1rem;
    flex-wrap: wrap;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1rem;
    align-items: center;
}

.nav a {
    color: var(--text-muted);
    font-size: 0.95rem;
    padding: 0.35rem 0.15rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.nav a.active,
.nav a:hover {
    color: var(--text);
    text-decoration: none;
}

.lang-switch {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bg-elevated);
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 11px 11px;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 0.82rem;
    line-height: 1.2;
    padding: 0.28rem 1.55rem 0.28rem 0.55rem;
    min-width: 6.75rem;
    height: 1.6rem;
    box-sizing: border-box;
}

[data-theme="light"] .lang-switch {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235c6578' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
}

[data-theme="dark"] .lang-switch {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239aa3b8' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
}

.lang-switch:hover {
    border-color: var(--text-muted);
}

.lang-switch:focus {
    outline: 2px solid var(--accent-soft);
    outline-offset: 2px;
}

/* —— Home —— */

.hero {
    padding: 4.5rem 0 3rem;
}

.hero-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 2rem;
    align-items: center;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--eyebrow-text);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

h1, h2, h3 {
    line-height: 1.25;
    letter-spacing: -0.02em;
}

h1 {
    font-size: clamp(1.75rem, 5vw, 3rem);
    margin: 0 0 1rem;
    overflow-wrap: anywhere;
}

.lead {
    font-size: clamp(1rem, 2.5vw, 1.1rem);
    color: var(--text-muted);
    max-width: 58ch;
}

.hero-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.hero-card ul {
    margin: 0;
    padding-left: 1.1rem;
    color: var(--text-muted);
}

.cta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.1rem;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--border);
    color: var(--text);
    background: var(--bg-elevated);
    font-weight: 600;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #ff5a4f, #c62828);
    border-color: transparent;
    color: white;
}

.section {
    padding: 2.5rem 0;
}

.section-title {
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    margin-bottom: 1rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.grid-features {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
    gap: 1rem;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
}

.card h3 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
}

.card p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.card .feature-list {
    margin: 0.75rem 0 0;
    padding-left: 1.1rem;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.card .feature-list li {
    margin: 0.35rem 0;
}

.card .feature-list strong {
    color: var(--text);
    font-weight: 600;
}

.feature-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 1.35rem;
}

.feature-section h2 {
    margin: 0 0 0.5rem;
    font-size: clamp(1.2rem, 3vw, 1.45rem);
}

.feature-section .feature-lead {
    margin: 0 0 1.25rem;
    color: var(--text-muted);
    font-size: 0.98rem;
    max-width: 72ch;
}

.feature-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem 1.25rem;
}

.feature-block h3 {
    margin: 0 0 0.4rem;
    font-size: 1rem;
    color: var(--text);
}

.feature-block p,
.feature-block ul {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.feature-block ul {
    margin-top: 0.35rem;
    padding-left: 1.1rem;
}

.feature-block li { margin: 0.25rem 0; }

@media (max-width: 820px) {
    .feature-grid-2 { grid-template-columns: 1fr; }
}

/* —— Content pages —— */

.page {
    padding: 2rem 0 3rem;
    padding-bottom: calc(3rem + env(safe-area-inset-bottom));
}

.page h1 {
    font-size: clamp(1.5rem, 4vw, 2.4rem);
    margin-bottom: 0.35rem;
    overflow-wrap: anywhere;
}

.meta {
    color: var(--text-muted);
    font-size: 0.92rem;
    margin-bottom: 1.5rem;
}

.prose {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.prose h2 {
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    font-size: clamp(1.1rem, 3vw, 1.25rem);
}

.prose h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 1.05rem;
}

.prose p,
.prose li {
    color: var(--prose-text);
}

.prose ul,
.prose ol {
    padding-left: 1.25rem;
}

.prose li { margin: 0.35rem 0; }

/* —— User guide sidebar —— */

.guide-layout {
    display: grid;
    grid-template-columns: minmax(10.5rem, 13.5rem) minmax(0, 1fr);
    gap: 2.5rem;
    width: min(100% - 2 * var(--page-pad-x), 72rem);
    margin: 0 auto;
    align-items: start;
}

.guide-sidebar {
    position: sticky;
    top: var(--header-offset);
    z-index: 5;
    max-height: calc(100vh - var(--header-offset) - 1.5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: 1rem;
    scrollbar-width: thin;
}

.guide-sidebar .toc {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.85rem 0.65rem;
    margin: 0;
}

.guide-sidebar .toc-title {
    margin: 0 0 0.5rem;
    padding: 0 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.guide-sidebar .toc ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

.guide-sidebar .toc li {
    margin: 0.1rem 0;
}

.guide-sidebar .toc a {
    display: block;
    padding: 0.38rem 0.55rem;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.86rem;
    line-height: 1.35;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.guide-sidebar .toc a:hover {
    background: var(--code-bg);
    color: var(--text);
    text-decoration: none;
}

.guide-sidebar .toc a.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.guide-main {
    min-width: 0;
}

.guide-sidebar .toc-select {
    display: none;
}

@media (max-width: 1023px) {
    .guide-layout {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .guide-sidebar {
        top: var(--header-offset);
        max-height: none;
        overflow: visible;
        margin: 0 calc(-1 * var(--page-pad-x)) 1.25rem;
        padding: 0.65rem var(--page-pad-x) 0.75rem;
        background: color-mix(in srgb, var(--bg) 92%, transparent);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border);
    }

    html:has(.page--guide) {
        scroll-padding-top: calc(var(--header-offset) + var(--guide-mobile-toc-offset, 3.5rem));
    }

    .page--guide .guide-main h2[id] {
        scroll-margin-top: calc(var(--header-offset) + var(--guide-mobile-toc-offset, 3.5rem));
    }

    .guide-sidebar .toc {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        padding: 0;
        border: none;
        background: transparent;
        border-radius: 0;
    }

    .guide-sidebar .toc-title {
        margin: 0;
        padding: 0;
        font-size: 0.85rem;
        font-weight: 600;
        text-transform: none;
        letter-spacing: normal;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .guide-sidebar .toc ol {
        display: none;
    }

    .guide-sidebar .toc-select {
        display: block;
        flex: 1;
        min-width: 0;
        width: auto;
        appearance: none;
        -webkit-appearance: none;
        min-height: 44px;
        padding: 0.55rem 2rem 0.55rem 0.75rem;
        border: 1px solid var(--border);
        border-radius: 10px;
        background-color: var(--bg-elevated);
        background-repeat: no-repeat;
        background-position: right 0.75rem center;
        background-size: 12px 12px;
        color: var(--text);
        font: inherit;
        font-size: 0.92rem;
        line-height: 1.35;
        cursor: pointer;
    }

    [data-theme="light"] .guide-sidebar .toc-select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235c6578' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
    }

    [data-theme="dark"] .guide-sidebar .toc-select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239aa3b8' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
    }

    .guide-sidebar .toc-select:hover {
        border-color: var(--text-muted);
    }

    .guide-sidebar .toc-select:focus {
        outline: 2px solid var(--accent-soft);
        outline-offset: 2px;
    }
}

.callout {
    background: var(--accent-soft);
    border: 1px solid rgba(220, 56, 45, 0.35);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    margin: 1.25rem 0;
}

.callout strong { color: var(--callout-strong); }

code, .mono {
    font-family: var(--mono);
    font-size: 0.92em;
    background: var(--code-bg);
    padding: 0.1rem 0.35rem;
    border-radius: 6px;
    overflow-wrap: anywhere;
    word-break: break-all;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.table-scroll table {
    margin: 0;
    min-width: 36rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

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

th {
    background: var(--bg-elevated);
}

.site-footer {
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    color: var(--text-muted);
    font-size: 0.92rem;
}

.footer-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 2rem;
    justify-content: space-between;
    align-items: flex-start;
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.5rem;
    align-items: center;
    line-height: 1.8;
}

.site-footer--center {
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding-left: var(--page-pad-x);
    padding-right: var(--page-pad-x);
}

/* Language visibility — html[lang] is set early by js/init.js */
[class*="lang-"] { display: none; }
html[lang="en"] .lang-en,
html[lang="zh"] .lang-zh,
html[lang="ru"] .lang-ru,
html[lang="fr"] .lang-fr,
html[lang="es"] .lang-es,
html[lang="pt"] .lang-pt { display: revert; }

/* —— Tablet —— */

@media (max-width: 820px) {
    .hero-grid { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
    .hero { padding: 2.5rem 0 2rem; }
}

/* —— Mobile —— */

@media (max-width: 768px) {
    :root {
        --page-pad-x: 1rem;
    }

    .nav-toggle {
        display: flex;
    }

    .header-nav {
        display: none;
        position: absolute;
        left: 0;
        right: 0;
        top: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 0.75rem var(--page-pad-x) 1rem;
        background: var(--mobile-nav-bg);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--mobile-nav-shadow);
    }

    .site-header {
        position: sticky;
    }

    .site-header .container.header-inner {
        position: relative;
    }

    .site-header.nav-open .header-nav {
        display: flex;
    }

    .nav {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 0;
    }

    .nav a {
        padding: 0.75rem 0.5rem;
        border-bottom: 1px solid var(--border);
        min-height: 48px;
    }

    .nav a:last-child {
        border-bottom: none;
    }

    .lang-switch {
        width: 100%;
        margin-top: 0.75rem;
        height: auto;
        min-height: 44px;
        padding: 0.5rem 1.75rem 0.5rem 0.65rem;
        font-size: 0.85rem;
    }

    .cta-row {
        flex-direction: column;
    }

    .cta-row .btn {
        width: 100%;
    }

    .footer-grid {
        flex-direction: column;
    }

    .footer-links {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .footer-links .sep {
        display: none;
    }

    .page {
        padding-top: 1.5rem;
    }

    .prose h2 {
        margin-top: 1.5rem;
    }

    th, td {
        padding: 0.55rem 0.6rem;
        font-size: 0.88rem;
    }
}

@media (max-width: 380px) {
    :root {
        --page-pad-x: 0.75rem;
    }

    .brand span:not(.brand-mark) {
        font-size: 0.95rem;
    }
}
