:root {
    --ink: #3d2a22;
    --ink-deep: #251712;
    --oak: #b77336;
    --oak-mid: #c4844a;
    --oak-light: #d4a06a;
    --olive: #8a8530;
    --linen: #f8f6f2;
    --linen-dark: #efeae5;
    --stone: #e2ddd9;
    --muted: #5a5450;
    --cream: #f7f1e8;
    --white: #ffffff;
    --code-bg: #1f1612;
    --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-sans: 'Source Sans 3', 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
    --measure: 72rem;
    --docs-sidebar: 15.5rem;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --topbar-h: 4rem;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    color: var(--ink);
    background:
        radial-gradient(ellipse 80% 50% at 10% 0%, rgba(183, 115, 54, 0.08), transparent 55%),
        radial-gradient(ellipse 60% 40% at 90% 20%, rgba(138, 133, 48, 0.06), transparent 50%),
        linear-gradient(180deg, var(--linen) 0%, var(--cream) 48%, var(--linen-dark) 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; height: auto; }
code, .mono { font-family: var(--font-mono); }
p a, .prose a {
    color: var(--oak);
    text-decoration: underline;
    text-underline-offset: 0.15em;
}
p a:hover, .prose a:hover { color: var(--ink-deep); }

.shell {
    width: min(100% - 2.5rem, var(--measure));
    margin-inline: auto;
}

/* —— Topbar —— */
.topbar {
    position: relative;
    z-index: 20;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(61, 42, 34, 0.1);
    background: rgba(248, 246, 242, 0.92);
    backdrop-filter: blur(10px);
}

.topbar--over-hero {
    position: absolute;
    inset: 0 0 auto;
    border-bottom-color: transparent;
    background: transparent;
    backdrop-filter: none;
}

.topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: min(100% - 2.5rem, var(--measure));
    margin-inline: auto;
}

.topbar__brand {
    font-family: var(--font-display);
    font-size: 1.05rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-deep);
    white-space: nowrap;
}

.topbar--over-hero .topbar__brand { color: var(--linen); }

.topbar__links {
    display: flex;
    align-items: center;
    gap: 1.35rem;
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--muted);
}

.topbar--over-hero .topbar__links { color: rgba(248, 246, 242, 0.82); }

.topbar__links a {
    transition: color 0.25s var(--ease);
}

.topbar__links a:hover,
.topbar__links a.is-active { color: var(--oak); }

.topbar--over-hero .topbar__links a:hover,
.topbar--over-hero .topbar__links a.is-active { color: var(--oak-light); }

.topbar__cta {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.9rem;
    border-radius: 0.3rem;
    background: var(--oak);
    color: var(--white) !important;
    font-weight: 600;
    font-size: 0.88rem;
}

.topbar__cta:hover { background: var(--oak-mid); color: var(--white) !important; }

.topbar--over-hero .topbar__cta {
    background: var(--oak);
    color: var(--white) !important;
}

@media (max-width: 720px) {
    .topbar__links { gap: 0.85rem; font-size: 0.85rem; }
    .topbar__links .hide-sm { display: none; }
}

/* —— Buttons —— */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1.35rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 0.35rem;
    border: 1px solid transparent;
    transition: background 0.25s var(--ease), color 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.25s var(--ease);
    cursor: pointer;
}

.btn:hover { transform: translateY(-1px); }
.btn--primary { background: var(--oak); color: var(--white); }
.btn--primary:hover { background: var(--oak-mid); }
.btn--ghost {
    background: transparent;
    border-color: rgba(248, 246, 242, 0.45);
    color: var(--linen);
}
.btn--ghost:hover {
    border-color: var(--linen);
    background: rgba(248, 246, 242, 0.08);
}
.btn--ink { background: var(--ink-deep); color: var(--linen); }
.btn--ink:hover { background: var(--ink); }
.btn--line {
    background: transparent;
    border-color: rgba(61, 42, 34, 0.28);
    color: var(--ink);
}
.btn--line:hover { border-color: var(--oak); color: var(--oak); }
.btn--sm { padding: 0.55rem 0.95rem; font-size: 0.88rem; }

/* —— Hero —— */
.hero {
    position: relative;
    min-height: min(92vh, 42rem);
    display: flex;
    align-items: flex-end;
    overflow: hidden;
    color: var(--linen);
}

.hero--page {
    min-height: min(42vh, 22rem);
    align-items: flex-end;
}

.hero__media {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 40%;
    transform: scale(1.06);
    animation: hero-drift 18s var(--ease) infinite alternate;
}

.hero__shade {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(105deg, rgba(37, 23, 18, 0.88) 0%, rgba(37, 23, 18, 0.62) 42%, rgba(37, 23, 18, 0.28) 100%),
        linear-gradient(0deg, rgba(37, 23, 18, 0.72) 0%, transparent 48%);
}

.hero__content {
    position: relative;
    z-index: 2;
    padding: 7.5rem 0 4.5rem;
    max-width: 36rem;
}

.hero--page .hero__content {
    padding: 6.5rem 0 3rem;
    max-width: 40rem;
}

.hero__brand {
    font-family: var(--font-display);
    font-size: clamp(2.6rem, 7vw, 4.75rem);
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.02;
    margin-bottom: 0.85rem;
    opacity: 0;
    transform: translateY(1.25rem);
    animation: rise 0.9s var(--ease) 0.15s forwards;
}

.hero--page .hero__brand {
    font-size: clamp(2rem, 5vw, 3.25rem);
}

.hero__lead {
    font-size: clamp(1.05rem, 2.2vw, 1.25rem);
    color: rgba(248, 246, 242, 0.88);
    max-width: 28rem;
    margin-bottom: 1.75rem;
    opacity: 0;
    transform: translateY(1.25rem);
    animation: rise 0.9s var(--ease) 0.32s forwards;
}

.hero--page .hero__lead { margin-bottom: 0; }

.hero__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    opacity: 0;
    transform: translateY(1.25rem);
    animation: rise 0.9s var(--ease) 0.48s forwards;
}

/* —— Sections —— */
.band { padding: clamp(3.5rem, 7vw, 5.5rem) 0; }

.section-head {
    max-width: 34rem;
    margin-bottom: 2.25rem;
}

.section-head h2 {
    font-family: var(--font-display);
    font-size: clamp(1.85rem, 3.5vw, 2.55rem);
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink-deep);
    margin-bottom: 0.65rem;
    line-height: 1.15;
}

.section-head p {
    color: var(--muted);
    font-size: 1.05rem;
}

.base {
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.55), rgba(248, 246, 242, 0.2)),
        repeating-linear-gradient(
            -12deg,
            transparent,
            transparent 11px,
            rgba(183, 115, 54, 0.035) 11px,
            rgba(183, 115, 54, 0.035) 12px
        );
    border-block: 1px solid rgba(61, 42, 34, 0.08);
}

.base__panel {
    display: grid;
    gap: 1.5rem;
}

@media (min-width: 800px) {
    .base__panel {
        grid-template-columns: 1.2fr 1fr;
        align-items: end;
        gap: 2.5rem;
    }
}

.base__label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--oak);
    margin-bottom: 0.65rem;
}

.base__code {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.15rem;
    background: var(--code-bg);
    color: #f0e6da;
    border-radius: 0.4rem;
    font-size: clamp(0.85rem, 2vw, 1rem);
    overflow-x: auto;
}

.base__code button {
    flex-shrink: 0;
    border: 0;
    background: rgba(255, 255, 255, 0.08);
    color: var(--oak-light);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0.45rem 0.7rem;
    border-radius: 0.25rem;
    cursor: pointer;
}

.base__code button:hover { background: rgba(255, 255, 255, 0.14); }
.base__note { color: var(--muted); font-size: 0.98rem; }
.base__note strong { color: var(--ink); font-weight: 600; }

.endpoints__list {
    display: flex;
    flex-direction: column;
    border-top: 1px solid rgba(61, 42, 34, 0.12);
}

.endpoint {
    display: grid;
    gap: 0.35rem 1.25rem;
    padding: 1.15rem 0;
    border-bottom: 1px solid rgba(61, 42, 34, 0.12);
    transition: background 0.25s var(--ease), padding-left 0.25s var(--ease);
}

@media (min-width: 720px) {
    .endpoint {
        grid-template-columns: 5.5rem minmax(0, 1fr) auto;
        align-items: baseline;
    }
}

.endpoint:hover {
    background: rgba(183, 115, 54, 0.05);
    padding-left: 0.65rem;
}

.method {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--olive);
}

.method--post { color: var(--oak); }
.method--auth { color: #9a5b2f; }

.path {
    font-family: var(--font-mono);
    font-size: 0.92rem;
    color: var(--ink-deep);
    word-break: break-all;
}

.path a:hover { color: var(--oak); }
.desc { font-size: 0.92rem; color: var(--muted); }

.group-label {
    margin-top: 2.5rem;
    margin-bottom: 0.35rem;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--oak);
}

.group-label:first-of-type { margin-top: 0; }

.auth-band {
    background: linear-gradient(160deg, var(--ink-deep) 0%, #3a241c 55%, #4a3126 100%);
    color: var(--linen);
}

.auth-band .section-head h2 { color: var(--linen); }
.auth-band .section-head p { color: rgba(248, 246, 242, 0.72); }

.auth__grid {
    display: grid;
    gap: 2rem;
}

@media (min-width: 800px) {
    .auth__grid { grid-template-columns: 1fr 1fr; gap: 3rem; }
}

.auth__block h3 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    margin-bottom: 0.55rem;
}

.auth__block p {
    color: rgba(248, 246, 242, 0.75);
    margin-bottom: 1rem;
    max-width: 28rem;
}

.auth__code {
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(248, 246, 242, 0.12);
    border-radius: 0.4rem;
    padding: 1rem 1.1rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.65;
    color: #f0e6da;
    overflow-x: auto;
    white-space: pre;
}

.token { color: var(--oak-light); }
.key { color: #c8d48a; }

.apps__row {
    display: grid;
    gap: 2rem;
}

@media (min-width: 720px) {
    .apps__row {
        grid-template-columns: 1fr 1fr;
        gap: 3rem;
    }
}

.app-link h3 {
    font-family: var(--font-display);
    font-size: 1.55rem;
    margin-bottom: 0.4rem;
    color: var(--ink-deep);
}

.app-link p {
    color: var(--muted);
    margin-bottom: 1.1rem;
    max-width: 26rem;
}

.app-link__meta {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--oak);
    margin-bottom: 1rem;
}

.site-footer {
    margin-top: auto;
    width: 100%;
    border-top: 1px solid rgba(61, 42, 34, 0.1);
    background: rgba(255, 255, 255, 0.72);
}

.site-footer__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1.5rem;
    padding: 1.75rem 0 2.15rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.site-footer strong {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--ink);
    letter-spacing: 0.06em;
}

@media (max-width: 520px) {
    .site-footer__inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }
}

/* —— Docs shell —— */
.docs-shell {
    display: grid;
    flex: 1 0 auto;
    width: 100%;
}

@media (min-width: 900px) {
    .docs-shell {
        grid-template-columns: var(--docs-sidebar) minmax(0, 1fr);
    }
}

.docs-nav {
    padding: 1.75rem 1.25rem 2.5rem;
    border-bottom: 1px solid rgba(61, 42, 34, 0.1);
    background: rgba(255, 255, 255, 0.35);
}

@media (min-width: 900px) {
    .docs-nav {
        border-bottom: 0;
        border-right: 1px solid rgba(61, 42, 34, 0.1);
        position: sticky;
        top: 0;
        align-self: start;
        max-height: calc(100vh - var(--topbar-h));
        overflow-y: auto;
    }
}

.docs-nav__label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--oak);
    margin: 1.35rem 0 0.55rem;
}

.docs-nav__label:first-child { margin-top: 0; }

.docs-nav a {
    display: block;
    padding: 0.4rem 0.55rem;
    border-radius: 0.3rem;
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.2s ease, color 0.2s ease;
}

.docs-nav a:hover { color: var(--ink); background: rgba(183, 115, 54, 0.08); }
.docs-nav a.is-active {
    color: var(--ink-deep);
    background: rgba(183, 115, 54, 0.12);
    font-weight: 600;
}

.docs-main {
    padding: 2rem 1.25rem 3.5rem;
}

@media (min-width: 900px) {
    .docs-main {
        padding: 2.5rem 2.5rem 4rem;
        max-width: 52rem;
    }
}

.docs-main h1 {
    font-family: var(--font-display);
    font-size: clamp(1.9rem, 3.5vw, 2.6rem);
    color: var(--ink-deep);
    line-height: 1.15;
    margin-bottom: 0.75rem;
}

.docs-lead {
    font-size: 1.1rem;
    color: var(--muted);
    max-width: 40rem;
    margin-bottom: 2rem;
}

.prose h2 {
    font-family: var(--font-display);
    font-size: 1.45rem;
    color: var(--ink-deep);
    margin: 2.25rem 0 0.7rem;
}

.prose h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink);
    margin: 1.5rem 0 0.5rem;
}

.prose p, .prose li {
    color: var(--muted);
    font-size: 1.02rem;
}

.prose p + p { margin-top: 0.85rem; }
.prose ul, .prose ol {
    margin: 0.75rem 0 1rem 1.25rem;
}
.prose li + li { margin-top: 0.35rem; }

.prose pre,
.code-block {
    margin: 1rem 0 1.35rem;
    padding: 1rem 1.1rem;
    background: var(--code-bg);
    color: #f0e6da;
    border-radius: 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.65;
    overflow-x: auto;
}

.prose code:not(pre code) {
    font-size: 0.88em;
    background: rgba(183, 115, 54, 0.1);
    color: var(--ink-deep);
    padding: 0.1em 0.35em;
    border-radius: 0.2rem;
}

.callout {
    margin: 1.5rem 0;
    padding: 1rem 1.15rem;
    border-left: 3px solid var(--oak);
    background: rgba(183, 115, 54, 0.08);
    color: var(--ink);
    border-radius: 0 0.35rem 0.35rem 0;
}

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

.tile-grid {
    display: grid;
    gap: 1rem;
    margin: 1.5rem 0 0.5rem;
}

@media (min-width: 640px) {
    .tile-grid { grid-template-columns: 1fr 1fr; }
}

.tile {
    display: block;
    padding: 1.15rem 1.2rem;
    border-top: 2px solid var(--oak);
    background: rgba(255, 255, 255, 0.45);
    transition: background 0.25s var(--ease), transform 0.25s var(--ease);
}

.tile:hover {
    background: rgba(255, 255, 255, 0.8);
    transform: translateY(-2px);
}

.tile h3 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--ink-deep);
    margin-bottom: 0.35rem;
}

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

.steps {
    counter-reset: step;
    list-style: none;
    margin: 1rem 0 0;
    padding: 0;
}

.steps li {
    position: relative;
    padding: 0 0 1.5rem 2.5rem;
    border-left: 1px solid rgba(61, 42, 34, 0.15);
    margin-left: 0.65rem;
}

.steps li:last-child {
    border-left-color: transparent;
    padding-bottom: 0;
}

.steps li::before {
    counter-increment: step;
    content: counter(step);
    position: absolute;
    left: -0.7rem;
    top: 0;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    background: var(--ink-deep);
    color: var(--linen);
    font-size: 0.75rem;
    font-weight: 700;
    display: grid;
    place-items: center;
}

.steps strong {
    display: block;
    color: var(--ink-deep);
    margin-bottom: 0.25rem;
}

/* —— Explorer —— */
body.is-explorer {
    background: var(--linen);
    overflow: hidden;
    height: 100vh;
}

.explorer-frame {
    height: calc(100vh - var(--topbar-h));
}

.explorer-frame #app,
.explorer-frame .scalar-app {
    height: 100%;
}

/* —— Motion —— */
@keyframes rise {
    to { opacity: 1; transform: translateY(0); }
}

@keyframes hero-drift {
    from { transform: scale(1.06) translate3d(0, 0, 0); }
    to { transform: scale(1.12) translate3d(-1.5%, -1%, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .hero__media { animation: none; transform: none; }
    .hero__brand, .hero__lead, .hero__actions {
        animation: none;
        opacity: 1;
        transform: none;
    }
    html { scroll-behavior: auto; }
}
