/* Text-only pages: index.html and builds.html. Separate from styles.css on purpose. */
:root {
    --bg: #FAFAF8;
    --text: #1B1B19;
    --muted: #5E5E58;
    --muted-soft: #6E6E67;
    --line: #E3E1D9;
    --column: 540px;
    --gutter: 1.5rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #141413;
        --text: #EDEBE4;
        --muted: #A4A298;
        --muted-soft: #8E8C83;
        --line: #2E2D2A;
    }

    /* The logo is black artwork and the palm a mid gray; invert both so they stay visible on the dark background. */
    .logo,
    .palm {
        filter: invert(1);
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Newsreader', Georgia, serif;
    font-size: 21px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Narrow column sitting a little left of center on wide screens. */
main {
    max-width: var(--column);
    margin: 0 var(--gutter) 0 max(var(--gutter), calc(50vw - var(--column) / 2 - 8vw));
    padding: clamp(2.5rem, 9vh, 6rem) 0 4rem;
}

p {
    margin: 0;
}

main p + p {
    margin-top: 1rem;
}

a {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 5px;
}

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

/* Spans the full page width so the links sit in the corner, outside the text column. */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem var(--gutter);
    font-size: 19px;
}

.topbar nav {
    display: flex;
    gap: 1.5rem;
    margin-left: auto;
}

.topbar a {
    padding: 0.5rem 0;
    text-decoration: none;
}

/* The leading "/" marks these as links, so they skip the underline until hover. Muted by default;
   the current page's item is full strength, which doubles as the "you are here" marker. */
.topbar nav a {
    padding: 0.75rem 0;
    color: var(--muted);
    white-space: nowrap;
}

.topbar nav a[aria-current="page"],
.topbar nav a:hover,
.topbar nav a:focus-visible {
    color: var(--text);
}

.topbar a:hover,
.topbar a:focus-visible {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 5px;
}

/* The logo already contains the wordmark, so there is no separate text name. */
.logo {
    display: block;
    height: 52px;
    width: auto;
    /* Pure black next to the softer headline looked harsh, but 0.7 washed it out to gray and blurred the
       small wordmark. 0.9 lands on the headline's own tone (#1B1B19 on the page background). */
    opacity: 0.9;
}

h1 {
    margin: 4.5rem 0 1.5rem;
    font-size: clamp(2.75rem, 11vw, 4.5rem);
    font-weight: 400;
    line-height: 1.04;
    letter-spacing: -0.02em;
    text-wrap: balance;
}

h1 em {
    font-style: italic;
    color: var(--muted);
}

/* The headline opens the chat. An underline on text this size looks heavy (and splits across the
   smaller digits), so it fades on hover instead; "/say aloha" in the navbar is the other path. */
.headline-link {
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

/* :active also gives a tap on a phone, which has no hover, some feedback. */
.headline-link:hover,
.headline-link:active {
    opacity: 0.7;
}

/* Binary "01010101" stands in for the headline's period (and for AI). Sits on the baseline,
   nowrap so it never detaches from "more" when the headline wraps. */
.bits {
    font-family: ui-monospace, 'SF Mono', Consolas, 'Liberation Mono', monospace;
    font-size: 0.3em;
    letter-spacing: 0.08em;
    white-space: nowrap;
    color: var(--text);
    margin-left: 0.15em;
}

/* js/bits.js types the digits in, then keeps flipping them. visibility (not display) holds their width. */
.bit-pending {
    visibility: hidden;
}

/* Homepage: the body is one screen tall (navbar included), main takes the rest.
   The slogan sits in the middle and the footer is pinned to the bottom. */
body:has(.home) {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100svh;
}

.home {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

.home h1 {
    margin: auto 0;
}

.home .footnote {
    margin-top: 2rem;
}

/* Homepage palm sketch: faint, pinned to the bottom right and behind the text. Hidden while the chat
   is open so it never sits under the conversation. */
.palm {
    position: fixed;
    right: max(0px, calc(50vw - 640px));
    bottom: 0;
    z-index: -1;
    width: min(32vw, 360px);
    height: auto;
    opacity: 0.5;
    pointer-events: none;
}

body.chat-open .palm {
    display: none;
}

@media (prefers-reduced-motion: no-preference) {
    .home > * {
        animation: rise 0.7s ease both;
    }

    .home > :nth-child(2) { animation-delay: 0.08s; }
}

@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
}

h2 {
    margin: 0;
    font-size: 26px;
    font-weight: 500;
    line-height: 1.2;
}

.links {
    margin-top: 2.5rem;
}

.muted {
    color: var(--muted);
}

.intro {
    margin-top: 2rem;
}

/* Builds page: one section per pipeline stage, each an index of one-line rows. */
.stage {
    margin-top: 3rem;
}

/* Ideas page: each offer is a short heading over a paragraph, separated by a hairline. */
.offer {
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--line);
}

.offer p {
    margin-top: 0.5rem;
}

.offer-note {
    font-size: 17px;
    color: var(--muted);
}

.ledger {
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
    border-bottom: 1px solid var(--line);
}

.ledger li {
    display: grid;
    grid-template-columns: 9rem 1fr auto;
    align-items: baseline;
    gap: 1.25rem;
    padding: 0.9rem 0;
    border-top: 1px solid var(--line);
}

.ledger-desc {
    font-size: 17px;
    line-height: 1.45;
    color: var(--muted);
}

.ledger-status {
    font-size: 15px;
    color: var(--muted-soft);
}

.footnote {
    margin-top: 5rem;
    font-size: 15px;
    color: var(--muted-soft);
}

.footnote p + p {
    margin-top: 0.25rem;
}

/* Chat (js/chat.js): takes the headline's place inside <main> when "Say aloha" is clicked.
   While open the page is exactly one screen tall so only the message log scrolls. */
body.chat-open {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body.chat-open .home {
    min-height: 0;
    padding-top: 0.5rem;
}

body.chat-open .footnote {
    display: none;
}

.chat {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    font-size: 19px;
}

.chat[hidden] {
    display: none;
}

.chat-back {
    align-self: flex-start;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 17px;
    cursor: pointer;
}

.chat-back:hover {
    color: var(--text);
}

.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* pre-line keeps the single line breaks the model puts in a list. */
.chat-msg p {
    white-space: pre-line;
}

.chat-msg a {
    overflow-wrap: anywhere; /* long URLs must not push the page wider than a phone */
}

.chat-msg p + p {
    margin-top: 0.6rem;
}

.chat-msg-bot {
    max-width: 94%;
    line-height: 1.5;
}

.chat-msg-user {
    align-self: flex-end;
    max-width: 85%;
    padding: 0.5rem 0.9rem;
    border-radius: 14px 14px 4px 14px;
    background: var(--line);
}

.chat-typing {
    color: var(--muted);
}

/* Same monospace as the headline digits; js/chat.js flickers them while a reply loads. */
.chat-typing-bits {
    font-family: ui-monospace, 'SF Mono', Consolas, 'Liberation Mono', monospace;
    font-size: 0.85em;
    letter-spacing: 0.15em;
}

.chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chat-chip {
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: none;
    color: inherit;
    font: inherit;
    font-size: 16px;
    cursor: pointer;
    min-height: 44px;
    touch-action: manipulation;
}

.chat-chip:hover {
    border-color: var(--muted-soft);
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
}

.chat-input {
    flex: 1;
    min-width: 0;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: none;
    color: inherit;
    font: inherit;
    /* 16px minimum: iOS Safari zooms the page when an input is smaller. */
    font-size: 16px;
    min-height: 44px;
}

.chat-send {
    padding: 0 1.1rem;
    border: 0;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    font: inherit;
    font-size: 16px;
    cursor: pointer;
    min-height: 44px;
    touch-action: manipulation;
}

/* Dimmed while a reply is on its way, so a tap that is ignored doesn't look broken. */
.chat-send:disabled {
    opacity: 0.45;
    cursor: default;
}

.chat-back:focus-visible,
.chat-chip:focus-visible,
.chat-send:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 2px;
}

.chat-input:focus-visible {
    outline: none;
    border-color: var(--text);
    box-shadow: 0 0 0 3px var(--line);
}

/* Before the first question the intro, buttons and input sit together in the middle of the page; a
   top-aligned intro with a bottom-aligned input left a big empty gap. */
@media (min-width: 769px) {
    /* Lifts the group a little above true center. Phones skip it: they need every pixel of height. */
    .chat-empty {
        padding-bottom: min(8vh, 4rem);
    }
}

/* flex-shrink and scrolling keep the input on screen on a short phone instead of pushing it off the bottom. */
.chat-empty .chat-log {
    flex: 0 1 auto;
    margin-top: auto;
}

.chat-empty .chat-form {
    margin-bottom: auto;
    border-top: 0;
}

/* Desktop: center the column and enlarge the slogan. The topbar shares the column so logo, slogan and link align. */
@media (min-width: 769px) {
    /* width: 100% because auto side margins stop flex children from stretching on the homepage. */
    .topbar,
    main {
        width: 100%;
        max-width: 720px;
        margin: 0 auto;
    }

    .topbar {
        padding-inline: 0;
    }

    .home h1 {
        font-size: clamp(4rem, 7vw, 6rem);
    }
}

@media (max-width: 768px) {
    body {
        font-size: 19px;
    }

    .logo {
        height: 44px;
    }

    .topbar nav {
        gap: 1rem;
        font-size: 17px;
    }

    /* Name and status share the first line; the description wraps below at full width. */
    .ledger li {
        grid-template-columns: 1fr auto;
        row-gap: 0.2rem;
    }

    .ledger-desc {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    /* "Build more" + the bits measure about 7.7em; dividing the width between the gutters by 8.2
       keeps them on one line, inside the gutters, down to 320px. */
    .home h1 {
        font-size: min(4rem, calc((100vw - 2 * var(--gutter)) / 8.2));
    }
}

/* The smallest phones: tighter gaps keep the logo and all three links on one line down to 320px. */
@media (max-width: 360px) {
    .topbar {
        gap: 1rem;
    }

    .topbar nav {
        gap: 0.75rem;
        font-size: 16px;
    }
}
