/**
 * VDO.Ninja SDK - Shared site stylesheet
 * Copyright (c) 2025-2026 Steve Seguin
 * SPDX-License-Identifier: MIT
 *
 * Design tokens and components shared by the landing page, guides, and demos.
 * The VDO.Ninja SDK core remains separately licensed under MPL-2.0; see LICENSE.
 */

:root {
    color-scheme: dark;

    --bg: #0b1120;
    --bg-alt: #0f172a;
    --surface: #131c2e;
    --surface-2: #1a2438;
    --surface-3: #222e45;
    --border: #253049;
    --border-strong: #34405a;

    --text: #e5e9f2;
    --text-muted: #9aa5ba;
    --text-faint: #6c7790;

    --accent: #6366f1;
    --accent-hover: #575ae6;
    --accent-text: #a5b4fc;
    --accent-soft: rgba(99, 102, 241, 0.12);
    --accent-border: rgba(129, 140, 248, 0.38);

    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.12);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.12);
    --danger: #f87171;
    --danger-strong: #dc2626;
    --danger-soft: rgba(248, 113, 113, 0.12);

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.25);
    --header-h: 60px;
    --container: 1180px;
    --gutter: 24px;
}

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

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

html {
    -webkit-text-size-adjust: 100%;
    scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
    margin: 0 0 0.5em;
    line-height: 1.25;
    color: #fff;
    font-weight: 650;
    letter-spacing: -0.015em;
}

h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); letter-spacing: -0.025em; }
h2 { font-size: clamp(1.4rem, 3vw, 1.85rem); }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

p { margin: 0 0 1em; }

a { color: var(--accent-text); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { color: #c7d0fe; }

img, svg, video, canvas { max-width: 100%; }

code, kbd, pre, samp { font-family: var(--mono); font-variant-ligatures: none; }

code {
    font-size: 0.875em;
    padding: 0.12em 0.35em;
    border-radius: 4px;
    background: var(--surface-2);
    overflow-wrap: anywhere;
}

pre {
    margin: 0 0 1rem;
    padding: 16px 18px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.6;
    -webkit-overflow-scrolling: touch;
}

pre code {
    padding: 0;
    background: none;
    font-size: inherit;
    overflow-wrap: normal;
    white-space: pre;
}

hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

::selection { background: rgba(99, 102, 241, 0.45); color: #fff; }

:focus-visible {
    outline: 2px solid var(--accent-text);
    outline-offset: 2px;
}

.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: 16px; top: -100px; z-index: 1001;
    padding: 8px 14px; border-radius: var(--radius-sm);
    background: var(--surface-2); color: #fff;
}
.skip-link:focus { top: 10px; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

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

.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.stack > * + * { margin-top: 1rem; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row-between { justify-content: space-between; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 0.875rem; }
.mono { font-family: var(--mono); }

/* ---------- Site header ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(11, 17, 32, 0.86);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    backdrop-filter: saturate(140%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.site-header-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    min-height: var(--header-h);
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 650;
    font-size: 1rem;
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: -0.01em;
}
.brand:hover { color: #fff; }
.brand img { width: 26px; height: 26px; border-radius: 6px; }

.site-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.site-nav a {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.925rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s, background-color 0.15s;
}
.site-nav a:hover { color: #fff; background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: #fff; background: var(--surface-2); }

.site-header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

@media (max-width: 820px) {
    .site-header-inner { flex-wrap: wrap; gap: 0 16px; padding-top: 10px; }
    .site-nav {
        order: 3;
        flex-basis: 100%;
        margin: 6px calc(var(--gutter) * -1) 0;
        padding: 0 calc(var(--gutter) - 12px) 8px;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
        mask-image: linear-gradient(to right, #000 88%, transparent);
    }
    .site-nav::-webkit-scrollbar { display: none; }
    html { scroll-padding-top: 116px; }
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 8px;
    font: inherit;
    font-size: 0.925rem;
    font-weight: 550;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

.btn-secondary { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-3); border-color: #45516d; color: #fff; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: #fff; }

.btn-danger { background: transparent; border-color: rgba(248, 113, 113, 0.45); color: #fca5a5; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: #fecaca; }

.btn-success { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; color: #fff; }

.btn-sm { min-height: 32px; padding: 0 12px; font-size: 0.85rem; border-radius: 7px; }
.btn-lg { min-height: 48px; padding: 0 24px; font-size: 1rem; }
.btn-block { width: 100%; }

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

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

label { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }

input[type="text"], input[type="password"], input[type="url"], input[type="number"],
input[type="search"], input[type="email"], input:not([type]), select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    background: var(--bg-alt);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 0.925rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
select { cursor: pointer; }

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

input:disabled, select:disabled, textarea:disabled { opacity: 0.55; cursor: not-allowed; }

input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.9rem; cursor: pointer; }

.input-group { display: flex; gap: 8px; }
.input-group > input, .input-group > textarea { flex: 1; min-width: 0; }

/* ---------- Cards and panels ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    min-width: 0;
}

a.card {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s, background-color 0.15s;
}
a.card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.card h3 { margin-bottom: 6px; }
.card p { color: var(--text-muted); font-size: 0.925rem; margin-bottom: 0; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    min-width: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.panel-header h2, .panel-header h3 { margin: 0; font-size: 1rem; }

.panel-body { padding: 18px; }
.panel-body > :last-child { margin-bottom: 0; }

.panel-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
}

/* ---------- Badges, tags, status ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 550;
    line-height: 1.6;
    white-space: nowrap;
}
.badge-accent { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent-text); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }

.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 3px 11px 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 550;
    white-space: nowrap;
}
.status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
    flex-shrink: 0;
}
.status[data-state="connecting"]::before,
.status[data-state="waiting"]::before { background: var(--warning); animation: status-pulse 1.4s ease-in-out infinite; }
.status[data-state="connecting"], .status[data-state="waiting"] { color: #fde68a; border-color: rgba(251, 191, 36, 0.35); }
.status[data-state="live"]::before { background: var(--success); }
.status[data-state="live"] { color: #a7f3d0; border-color: rgba(52, 211, 153, 0.4); background: var(--success-soft); }
.status[data-state="error"]::before { background: var(--danger); }
.status[data-state="error"] { color: #fecaca; border-color: rgba(248, 113, 113, 0.45); background: var(--danger-soft); }

@keyframes status-pulse { 50% { opacity: 0.35; } }

/* ---------- Callouts ---------- */

.callout {
    padding: 14px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.925rem;
}
.callout > :last-child { margin-bottom: 0; }
.callout strong { color: var(--text); }
.callout-info { border-color: var(--accent-border); background: var(--accent-soft); }
.callout-warning { border-color: rgba(251, 191, 36, 0.35); background: var(--warning-soft); }
.callout-danger { border-color: rgba(248, 113, 113, 0.4); background: var(--danger-soft); }
.callout-success { border-color: rgba(52, 211, 153, 0.35); background: var(--success-soft); }

/* ---------- Details / disclosure ---------- */

details.disclosure {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
details.disclosure > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    list-style: none;
    font-weight: 550;
    font-size: 0.925rem;
    color: var(--text);
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(-45deg);
    transition: transform 0.15s;
    flex-shrink: 0;
}
details.disclosure[open] > summary::before { transform: rotate(45deg); }
details.disclosure > .disclosure-body { padding: 0 16px 16px; }
details.disclosure > .disclosure-body > :last-child { margin-bottom: 0; }

/* ---------- Event log ---------- */

.log {
    height: 220px;
    overflow-y: auto;
    padding: 10px 12px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 0.78rem;
    line-height: 1.55;
    color: var(--text-muted);
}
.log-entry { display: flex; gap: 10px; padding: 2px 0; overflow-wrap: anywhere; }
.log-time { color: var(--text-faint); flex-shrink: 0; }
.log-entry.success, .log-entry.received { color: #a7f3d0; }
.log-entry.error { color: #fca5a5; }
.log-entry.warning { color: #fde68a; }
.log-entry.sent, .log-entry.info { color: #c7d2fe; }
.log-entry.system { color: var(--text-muted); }

/* ---------- Chat ---------- */

.chat {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 240px;
    overflow-y: auto;
    padding: 14px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.chat-empty { margin: auto; color: var(--text-faint); font-size: 0.875rem; text-align: center; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 85%; }
.msg-meta { display: flex; gap: 8px; font-size: 0.72rem; color: var(--text-faint); margin-bottom: 3px; }
.msg-sender { color: var(--text-muted); font-weight: 600; overflow-wrap: anywhere; }
.msg-body {
    padding: 8px 12px;
    border-radius: 12px 12px 12px 4px;
    background: var(--surface-3);
    color: var(--text);
    font-size: 0.925rem;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.msg.self { align-self: flex-end; align-items: flex-end; }
.msg.self .msg-meta { flex-direction: row-reverse; }
.msg.self .msg-body { background: var(--accent); color: #fff; border-radius: 12px 12px 4px 12px; }
.msg.system { align-self: center; align-items: center; max-width: 100%; }
.msg.system .msg-body { background: transparent; color: var(--text-faint); font-size: 0.78rem; padding: 0; }

/* ---------- Media ---------- */

.video-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #05080f;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.video-frame > video, .video-frame > canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #05080f;
}
.video-label {
    position: absolute;
    left: 10px;
    top: 10px;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(5, 8, 15, 0.75);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 550;
}

/* ---------- Stats ---------- */

.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.stat {
    padding: 10px 12px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.stat-label { display: block; font-size: 0.72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { display: block; font-size: 1.15rem; font-weight: 650; color: #fff; font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */

.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table-wrap th, .table-wrap td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-wrap th { background: var(--surface-2); color: #fff; font-weight: 600; font-size: 0.85rem; }
.table-wrap tbody tr:last-child td { border-bottom: 0; }

/* ---------- Demo pages ---------- */

.demo-page { padding: 32px 0 64px; }

.demo-head { margin-bottom: 24px; }
.demo-head h1 { margin-bottom: 8px; }
.demo-head .lead { max-width: 72ch; color: var(--text-muted); font-size: 1.05rem; margin-bottom: 0; }

.crumb {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-decoration: none;
}
.crumb:hover { color: #fff; }

.steps {
    counter-reset: step;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    margin: 0 0 24px;
    padding: 0;
    list-style: none;
}
.steps > li {
    counter-increment: step;
    position: relative;
    padding: 12px 14px 12px 50px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}
.steps > li::before {
    content: counter(step);
    position: absolute;
    left: 14px;
    top: 11px;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    color: var(--accent-text);
    font-size: 0.78rem;
    font-weight: 700;
}
.steps > li strong { color: var(--text); }
.steps > li.done::before { content: '✓'; background: var(--success-soft); border-color: rgba(52, 211, 153, 0.45); color: var(--success); }

.share-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-bottom: 24px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--text-muted);
}
.share-bar code { color: var(--text); }
.share-bar .row { margin-left: auto; }

.section-label {
    margin: 0 0 10px;
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}

/* ---------- Site footer ---------- */

.site-footer {
    margin-top: 48px;
    padding: 28px 0;
    border-top: 1px solid var(--border);
    color: var(--text-faint);
    font-size: 0.875rem;
}
.site-footer .container { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: #fff; }

@media (max-width: 640px) {
    :root { --gutter: 16px; }
    .card { padding: 18px; }
    .panel-body { padding: 16px; }
    .panel-header { padding: 12px 16px; }
    .demo-page { padding-top: 24px; }
    .share-bar .row { margin-left: 0; }
}
