/* Self-hosted — keeps the page fully offline. DM Serif Display
   is currently unused (the wordmark moved to DM Sans 800); kept
   declared in case the serif treatment is wanted again. */
@font-face {
    font-family: "DM Serif Display";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("assets/fonts/dm-serif-display-latin-400.woff2") format("woff2");
}
/* Variable face — one file covers the 300–700 weights the page
   uses (lede 400, hero 700, hero em 300). */
@font-face {
    font-family: "DM Sans";
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url("assets/fonts/dm-sans-latin-var.woff2") format("woff2");
}
/* Extra-bold (800) is outside the variable file's 300–700 range,
   so the wordmark gets its own static 800 face. */
@font-face {
    font-family: "DM Sans";
    font-style: normal;
    font-weight: 800;
    font-display: swap;
    src: url("assets/fonts/dm-sans-800.woff2") format("woff2");
}

:root {
    --ink: oklch(96% 0.01 95);
    --ink-dim: oklch(82% 0.02 95 / 0.78);
    --ink-dark: oklch(50% 0.01 95);
    --rule: oklch(96% 0.01 95 / 0.34);
    --accent: oklch(0.458969 0.080686 185.4988);

    --text-kicker: clamp(0.72rem, 0.66rem + 0.3vw, 0.85rem);
    --text-hero: clamp(2.9rem, 1rem + 9.2vw, 8.5rem);
    --text-sub: clamp(1rem, 0.92rem + 0.45vw, 1.3rem);

    --space-edge: clamp(1.5rem, 0.8rem + 3.5vw, 5rem);

    --duration-slow: 1200ms;
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html,
body {
    height: 100%;
    overflow: hidden; /* non-scroll: the page is exactly one screen */
}

body {
    position: relative;
    min-height: 100svh;
    background: #11130f; /* shows before the shader paints */
    color: #000;
    font-family:
        "DM Sans",
        system-ui,
        -apple-system,
        sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Cel-shaded media, full-bleed behind everything. */
#cel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 0;
}

/* CSS fallback so the page is never blank if WebGL is unavailable. */
.bg-fallback {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: #11130f url("assets/mountain.jpg") center / cover no-repeat;
    opacity: 0;
    transition: opacity var(--duration-slow) var(--ease-out-expo);
}
body.gl-failed .bg-fallback {
    opacity: 1;
}
body.gl-failed #cel {
    display: none;
}

/* Legibility scrim — anchored to the text edges, not a flat wash, so the
   cel-shaded art stays readable as art. */
.scrim {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        linear-gradient(
            105deg,
            oklch(8% 0.02 95 / 0.74) 0%,
            oklch(8% 0.02 95 / 0.36) 38%,
            transparent 64%
        ),
        linear-gradient(to top, oklch(8% 0.02 95 / 0.66) 0%, transparent 40%);
}

.stage {
    position: relative;
    z-index: 2;
    min-height: 100svh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    /* Smaller top inset pulls the header toward the top edge;
       sides and bottom keep the full edge margin. */
    padding: clamp(1rem, 0.6rem + 1.2vw, 2rem) var(--space-edge)
        var(--space-edge);
}

/* ---- Top bar ---- */
.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}
.wordmark {
    font-family:
        "DM Sans",
        system-ui,
        -apple-system,
        sans-serif;
    font-weight: 800; /* extra bold — real 800 face */
    font-size: clamp(1.35rem, 1rem + 1.6vw, 2.25rem);
    text-transform: lowercase;
    letter-spacing: 0.03em;
    line-height: 1;
    color: #000;
}
.meta {
    font-size: var(--text-kicker);
    /*text-transform: uppercase;*/
    color: var(--ink-dark);
}
/* Layout-only: positions the contact section in the upper right.
   Type styling is inherited from .meta so no colors, fonts, or
   letter-spacing change. */
.contact {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.4rem;
    text-align: right;
}
.contact a {
    color: inherit;
    text-decoration: none;
}

/* ---- Middle row: hero and demo sit side by side, packed left ---- */
.middle {
    align-self: start;
    margin-top: clamp(2.5rem, 1.5rem + 5vw, 6rem);
    display: grid;
    /* Hero sized to its own content (capped at 48ch) so the demo sits
       right beside it rather than floating to the far right edge. The
       gap keeps a decent margin between the two. */
    grid-template-columns: minmax(0, 48ch) minmax(360px, 460px);
    gap: clamp(2rem, 1.5rem + 4vw, 6rem);
    justify-content: start;
    align-items: start;
}

/* ---- Hero ---- */
.hero {
    max-width: 48ch;
}
.hero h1 {
    font-size: var(--text-hero);
    line-height: 0.92;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-wrap: balance;
}
.hero h1 em {
    font-style: italic;
    font-weight: 300;
    color: var(--ink-dark);
}
.hero p {
    font-size: clamp(2.4rem, 1rem + 9.2vw, 1.5rem);
    font-weight: 400;
}

/* ---- Demo: chat surface with bottom composer ---- */
.demo {
    --demo-bg: oklch(20% 0 0 / 0.7);
    --demo-surface-1: oklch(20% 0 0 / 0.9);
    --demo-surface-2: oklch(35% 0 0);
    --demo-popover-bg: oklch(20% 0 0 / 0.9);
    --demo-border: oklch(100% 0 0 / 0.1);
    --demo-border-soft: oklch(96% 0.01 95 / 0.06);

    color: var(--ink);
    font-size: 0.92rem;
    line-height: 1.5;
    background: var(--demo-bg);
    backdrop-filter: blur(1px) saturate(0%);
    -webkit-backdrop-filter: blur(1px) saturate(0%);
    border: 1px solid var(--demo-border);
    /*outline: 1px solid oklch(0% 0 0 / 0.7);*/
    border-radius: 8px;
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    /*height: min(70svh, 460px);*/
    height: 460px;
}

.demo-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.25rem 0.35rem;
    /* Top fade so content scrolls out of view gracefully. */
    /*mask-image: linear-gradient(
        to bottom,
        transparent 0px,
        #000 16px,
        #000 100%
    );
    -webkit-mask-image: linear-gradient(
        to bottom,
        transparent 0px,
        #000 16px,
        #000 100%
    );*/
    scrollbar-width: thin;
    scrollbar-color: oklch(96% 0.01 95 / 0.18) transparent;
}
.demo-thread::-webkit-scrollbar {
    width: 6px;
}
.demo-thread::-webkit-scrollbar-thumb {
    background: oklch(96% 0.01 95 / 0.18);
    border-radius: 999px;
}
.demo-thread::-webkit-scrollbar-track {
    background: transparent;
}
/* Messages flow top-down: the user bubble lands at the top of the
   thread when it appears, the assistant message extends below it,
   and scroll kicks in once the answer outgrows the thread. */

.msg {
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(8px);
    transition:
        opacity 360ms var(--ease-out-expo),
        transform 360ms var(--ease-out-expo);
}
.demo.phase-sent .msg-user,
.demo.phase-tools .msg-user,
.demo.phase-answer .msg-user,
.demo.phase-done .msg-user {
    opacity: 1;
    transform: none;
}
.demo.phase-tools .msg-assistant,
.demo.phase-answer .msg-assistant,
.demo.phase-done .msg-assistant {
    opacity: 1;
    transform: none;
}

/* ---- User message: rounded bubble, right-aligned ---- */
.msg-user {
    align-items: flex-end;
}
.bubble {
    background: var(--demo-surface-1);
    color: var(--ink);
    padding: 0.7rem 0.95rem;
    border-radius: 8px;
    border-bottom-right-radius: 6px;
    max-width: 92%;
    font-size: 0.9rem;
    line-height: 1.45;
}
.composer-text-static {
    white-space: pre-wrap;
}
.msg-meta {
    margin-top: 0.4rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    color: var(--ink-dim);
}
.msg-meta .copy-icon {
    width: 12px;
    height: 12px;
    opacity: 0.7;
}

/* ---- Assistant message: no bubble, plain text ---- */
.msg-assistant {
    align-items: stretch;
}
.tools-used {
    background: none;
    border: none;
    padding: 0;
    margin: 0 0 0.55rem;
    color: var(--ink-dim);
    font-family: inherit;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    cursor: default;
    width: fit-content;
    opacity: 0;
    transform: translateY(4px);
    transition:
        opacity 280ms var(--ease-out-expo),
        transform 280ms var(--ease-out-expo);
}
.demo.phase-tools .tools-used,
.demo.phase-answer .tools-used,
.demo.phase-done .tools-used {
    opacity: 1;
    transform: none;
}
.tools-used .chev {
    width: 10px;
    height: 10px;
    opacity: 0.7;
}
.answer-content {
    color: var(--ink);
    font-size: 0.92rem;
    line-height: 1.55;
    min-height: 1.55em;
}
/* Hidden blocks are removed from layout so the thread grows
   progressively as each block reveals (rather than reserving the full
   final answer height up front and scrolling past the first ~100
   transparent blocks). When .is-revealed flips them back into flow,
   a keyframe animation fades them in. */
.answer-content > * {
    display: none;
}
.answer-content > .is-revealed {
    display: block;
    animation: ans-fade-in 320ms var(--ease-out-expo);
}
@keyframes ans-fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}
.answer-content p {
    margin: 0 0 0.55rem;
}
.answer-content p:last-child {
    margin-bottom: 0;
}
.ans-h1 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0.9rem 0 0.6rem;
    color: var(--ink);
    letter-spacing: -0.01em;
}
.ans-h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0.85rem 0 0.55rem;
    color: var(--ink);
}
.ans-rule {
    border: 0;
    height: 1px;
    background: var(--demo-border-soft);
    margin: 0.95rem 0;
}
.ans-quote {
    border-left: 2px solid var(--demo-border);
    padding: 0.1rem 0 0.1rem 0.85rem;
    margin: 0.5rem 0 0.7rem;
    color: var(--ink-dim);
}
.ans-quote p {
    margin: 0 0 0.45rem;
    font-size: 0.88rem;
    line-height: 1.5;
}
.ans-quote p:last-child {
    margin-bottom: 0;
}
.ans-cite {
    color: var(--ink-dim);
    font-size: 0.82rem;
    margin-bottom: 0.95rem !important;
}
.ans-closing {
    margin-top: 0.95rem !important;
    color: var(--ink-dim);
}
.answer-content em {
    font-style: italic;
}
.answer-content strong {
    font-weight: 700;
    color: var(--ink);
}
@keyframes caret-blink {
    0%,
    49% {
        opacity: 1;
    }
    50%,
    100% {
        opacity: 0;
    }
}

/* ---- Composer ---- */
.composer {
    position: relative;
    background: var(--demo-surface-1);
    border: 1px solid var(--demo-border);
    border-radius: 8px;
    padding: 0.8rem 0.9rem 0.65rem;
    flex-shrink: 0;
}
.composer-input {
    color: var(--ink);
    font-size: 0.9rem;
    line-height: 1.45;
    position: relative;
}
.composer-placeholder {
    color: oklch(55% 0.005 95 / 0.8);
}
/* Idle cursor — blinks in the empty input before typing and after
   submit, matching real chat composer behavior. */
.composer-placeholder::before {
    content: "";
    display: inline-block;
    width: 1px;
    height: 1em;
    background: var(--ink);
    margin-right: 0px;
    vertical-align: -0.15em;
    animation: caret-blink 1.05s steps(1) infinite;
}
.composer-text {
    color: var(--ink);
    white-space: pre-wrap;
}
.composer-text.is-typing::after {
    content: "";
    display: inline-block;
    width: 2px;
    height: 0.95em;
    background: var(--ink);
    margin-left: 3px;
    vertical-align: -0.15em;
    /* Solid (no blink) while actively typing — feels like a real
       input cursor moving with the text. */
}
.demo.phase-typing .composer-placeholder,
.demo.phase-typed .composer-placeholder {
    display: none;
}
.composer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.composer-plus {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: inherit;
    color: var(--ink);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    padding: 0;
    transition:
        background 200ms var(--ease-out-expo),
        transform 200ms var(--ease-out-expo);
}
.composer-plus svg {
    width: 14px;
    height: 14px;
}
.demo.phase-popover .composer-plus {
    background: oklch(36% 0.005 95);
}
.composer-meta {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--ink-dim);
    font-size: 0.78rem;
}
.composer-meta .model-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--ink-dim);
}
.composer-meta .mic-icon,
.composer-meta .wave-icon {
    width: 16px;
    height: 16px;
    color: var(--ink-dark);
}

/* ---- Popover (over the + button) ---- */
.popover {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0.4rem;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px) scale(0.96);
    transform-origin: bottom left;
    transition:
        opacity 220ms var(--ease-out-expo),
        transform 220ms var(--ease-out-expo);
    z-index: 5;
}
.demo.phase-popover .popover,
.demo.phase-connecting .popover {
    opacity: 1;
    pointer-events: auto;
    transform: none;
}
.popover-main {
    background: var(--demo-popover-bg);
    border: 1px solid var(--demo-border);
    border-radius: 8px;
    padding: 0.35rem;
    min-width: 180px;
    box-shadow: 0 12px 28px oklch(0% 0 0 / 0.45);
}
.menu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 1px;
}
.menu-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    font-size: 0.82rem;
    color: var(--ink-dim);
}
.menu-row .menu-label {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
}
.menu-row svg {
    width: 14px;
    height: 14px;
    opacity: 0.85;
}
.menu-row .chev {
    width: 10px;
    height: 10px;
    opacity: 0.6;
}
.menu-row.is-divider {
    height: 1px;
    padding: 0;
    margin: 0.2rem 0.4rem;
    background: var(--demo-border);
}
.menu-row.is-active {
    background: var(--demo-surface-2);
    color: var(--ink);
}
.menu-row.is-muted {
    color: var(--ink-dark);
}

.popover-submenu {
    background: var(--demo-popover-bg);
    border: 1px solid var(--demo-border);
    border-radius: 8px;
    padding: 0.5rem 0.4rem;
    min-width: 220px;
    box-shadow: 0 12px 28px oklch(0% 0 0 / 0.45);
    opacity: 0;
    transform: translateX(-6px);
    transition:
        opacity 200ms var(--ease-out-expo),
        transform 200ms var(--ease-out-expo);
}
.demo.phase-connecting .popover-submenu {
    opacity: 1;
    transform: none;
}
.connectors-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 1px;
}
.connector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    font-size: 0.82rem;
    color: var(--ink);
}
.connector-name {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink);
}
.connector-name .globe {
    width: 14px;
    height: 14px;
    color: var(--ink-dim);
}
.toggle {
    width: 28px;
    height: 16px;
    border-radius: 999px;
    background: oklch(32% 0.005 95);
    position: relative;
    transition: background 240ms var(--ease-out-expo);
    flex-shrink: 0;
}
.toggle::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: oklch(94% 0.005 95);
    transition: transform 240ms var(--ease-out-expo);
}
.connector.is-on .toggle {
    background: var(--accent);
}
.connector.is-on .toggle::after {
    transform: translateX(12px);
}
.submenu-foot {
    list-style: none;
    margin: 0.35rem 0 0;
    padding: 0;
    border-top: 1px solid var(--demo-border);
    padding-top: 0.35rem;
    display: grid;
    gap: 1px;
}
.submenu-foot li {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.6rem;
    border-radius: 7px;
    font-size: 0.82rem;
    color: var(--ink-dim);
}
.submenu-foot li small {
    color: var(--ink-dark);
    font-size: 0.7rem;
    margin-left: auto;
}
.submenu-foot svg {
    width: 14px;
    height: 14px;
    opacity: 0.85;
}

/* ---- Footer: colophon, ported from layout/lower-left-contact.
   Uses main's existing tokens (--text-kicker, --ink-dark)
   so the font/letter-spacing stay unchanged. ---- */
.colophon {
    align-self: end;
    padding-top: 1rem;
    border-top: 1px solid var(--ink-dark);
    margin-top: 1rem;
    font-size: var(--text-kicker);
    color: var(--ink-dark);
}

/* ---- Entrance motion (compositor-only) ---- */
@media (prefers-reduced-motion: no-preference) {
    .reveal {
        opacity: 0;
        transform: translateY(18px);
        animation: reveal var(--duration-slow) var(--ease-out-expo) forwards;
    }
    .topbar.reveal {
        animation-delay: 120ms;
    }
    .hero.reveal {
        animation-delay: 260ms;
    }
    .demo.reveal {
        animation-delay: 400ms;
    }
    .colophon.reveal {
        animation-delay: 560ms;
    }
}
@keyframes reveal {
    to {
        opacity: 1;
        transform: none;
    }
}

@media (max-width: 900px) {
    /* Below 900px the demo stacks below the hero. The page can no longer
       fit one screen, so we allow vertical scroll. */
    html,
    body {
        overflow: auto;
    }
    .stage {
        grid-template-rows: auto auto auto;
    }
    .middle {
        grid-template-columns: 1fr;
        gap: clamp(2rem, 1.5rem + 2vw, 3rem);
    }
    .demo {
        width: 100%;
        max-width: 460px;
        justify-self: start;
    }
}

@media (max-height: 760px) {
    /* When the viewport is too short to fit the one-screen layout, the
       fixed (overflow: hidden) page would clip its bottom. Allow vertical
       scroll instead so the demo and footer stay reachable. */
    html,
    body {
        overflow: auto;
    }
    .stage {
        min-height: auto;
    }
}

@media (max-width: 640px) {
    .topbar {
        flex-direction: column;
        gap: 1.25rem;
    }
    .contact {
        align-items: flex-start;
        text-align: left;
    }
}

/* Reduced motion: skip animations, show end state immediately. */
@media (prefers-reduced-motion: reduce) {
    .msg,
    .tools-used {
        opacity: 1;
        transform: none;
    }
    .answer-content > .is-revealed {
        animation: none;
    }
    .composer-text.is-typing::after,
    .composer-placeholder::before {
        animation: none;
    }
    .connector .toggle,
    .connector .toggle::after,
    .popover,
    .popover-submenu {
        transition: none;
    }
}
