:root {
    --bg: #0f1115;
    --panel: #15181e;
    --card: #1a1e26;
    --border: rgba(255, 255, 255, 0.08);
    --text: #e8eaed;
    --muted: #9aa0a6;
    --accent: #8ab4f8;
    --sidebar-w: 16rem;
    --font: "Google Sans Flex", "Google Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-weight: 400;          /* normal text */
    line-height: 1.6;
}

.topbar,
.scrim {
    display: none;
}

/* every title is weight 500 */
h1, h2, h3, h4, .brand {
    font-family: var(--font);
    font-weight: 500;
    line-height: 1.2;
    margin: 0 0 0.75rem;
}

/* ---------- sidebar ---------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    background: var(--panel);
    border-right: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.25rem 0.75rem;
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    color: var(--text);
    text-decoration: none;
}

.brand-icon {
    width: 2rem;
    height: 2rem;
    flex: none;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav a,
.sidebar-footer a {
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    color: var(--muted);
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease;
}

.nav a:hover,
.sidebar-footer a:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}

.nav a.active {
    background: rgba(138, 180, 248, 0.14);
    color: var(--accent);
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
}

.account {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: auto;          /* pushes the chip to the bottom of the sidebar */
    padding: 0.6rem 0.75rem;
    border-radius: 14px;
    transition: background 0.2s ease;
}

.account:hover {
    background: rgba(255, 255, 255, 0.06);
}

.avatar {
    width: 2.4rem;
    height: 2.4rem;
    flex: none;
    object-fit: cover;         /* fills the circle without stretching the photo */
    border-radius: 50%;
    border: 1px solid var(--border);
}

.account-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.account-name {
    font-weight: 500;
    color: var(--text);
}

.account-sub {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.new-chat {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
    padding: 0.6rem 0.75rem;
    font-family: var(--font);
    font-weight: 400;
    font-size: 1rem;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.new-chat:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* ---------- content ---------- */
.content {
    margin-left: var(--sidebar-w);
    padding: 0 3rem;
}

.content section {
    max-width: 52rem;
    padding: 5rem 0;
    scroll-margin-top: 1rem;
}

h1 { font-size: clamp(2.2rem, 4vw, 3.4rem); }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.2rem; }

.lead {
    font-size: 1.25rem;
    color: var(--muted);
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: 1rem;
}

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

.card p { margin: 0; color: var(--muted); }

/* ---------- small screens: the sidebar becomes a top bar ---------- */
@media (max-width: 800px) {
    .content { margin-left: 0; padding: 0 1.25rem; }
    .content section { padding: 3rem 0; }
}

/* ---------- home: centered heading and search bar ---------- */
.content .chat-view {
    max-width: none;
    min-height: 100vh;
    padding: 2rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.content .chat-view h1 {
    font-size: clamp(1rem, 4vw, 3rem);
    margin-bottom: 2rem;
}

.search {
    position: relative;
    width: min(44rem, 100%);
}

.search input {
    width: 100%;
    padding: 1.1rem 4rem 1.1rem 1.5rem;
    font-family: var(--font);
    font-weight: 400;
    font-size: 1.1rem;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search input::placeholder {
    color: var(--muted);
}

.search input:focus {
    border-color: rgba(138, 180, 248, 0.5);
    box-shadow: 0 0 0 4px rgba(138, 180, 248, 0.12);
}

.search button {
    position: absolute;
    top: 50%;
    right: 0.6rem;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    color: var(--bg);
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.search button:hover {
    opacity: 0.85;
}

.disclaimer {
    flex: none;
    width: min(44rem, 100%);
    margin: 0.75rem 0 0;
    font-size: 0.8rem;
    line-height: 1.4;
    text-align: center;
    color: var(--muted);
    opacity: 0.85;
}

.content .chat-view { min-height: calc(100dvh - 4rem); }

/* ---------- tabs ---------- */
.content section.view:not(.active) {
    display: none !important;
}

.nav a[target="_blank"]::after {
    content: " ↗";
    opacity: 0.45;
}

/* ---------- chat ---------- */
.content .chat-view > h1 {
    transition: opacity 0.3s ease, transform 0.3s ease;
    font-size: clamp(2.4rem, 5.5vw, 4.2rem);
}

.content .chat-view.leaving > h1 {
    opacity: 0;
    transform: translateY(-8px);
}

.content .chat-view.chatting > h1 {
    display: none;
}

.chat {
    display: none;
}

.content .chat-view.chatting {
    height: 100vh;
    min-height: 0;
    justify-content: flex-start;
}

.content .chat-view.chatting .chat {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    flex: 1;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    padding: 1rem max(0.25rem, calc((100% - 52rem) / 2)); /* keeps the text in a 52rem column */
    text-align: left;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* the conversation sits at the bottom, just above the input bar, and grows upward */
.chat > :first-child {
    margin-top: auto;
}

.content .chat-view.chatting .search {
    flex: none;
    margin-top: 1rem;
}

/* the visitor's message */
.bubble.user {
    align-self: flex-end;
    max-width: 75%;
    padding: 0.8rem 1.2rem;
    background: rgba(138, 180, 248, 0.16);
    border-radius: 22px 22px 6px 22px;
    overflow-wrap: anywhere;
}

/* the three pulsing dots */
.thinking {
    display: flex;
    gap: 0.35rem;
    padding: 0.5rem 0;
}

.thinking span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--muted);
    animation: pulse 1s ease-in-out infinite;
}

.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
    0%, 80%, 100% { opacity: 0.25; }
    40%           { opacity: 1; }
}

/* ---------- reply: written out word by word ---------- */

/* nothing takes up space until its first word has appeared, so the reply grows as it is written */
.reply :is(p, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, blockquote):not(.shown) {
    display: none;
}

.reply .w:not(.in) {
    display: none;
}

.reply .w.in {
    animation: wordin 0.6s ease both;
}

.reply img:not(.in) {
    display: none;
}

.reply img.in {
    display: block;
    max-width: min(100%, 28rem);
    height: auto;
    margin: 0 0 1rem;
    border-radius: 18px;
    animation: wordin 0.8s ease both;
}

/* the Projects answer is already written out: show everything immediately */
.reply.static :is(p, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, blockquote):not(.shown) {
    display: revert;
}

.reply.static img {
    display: block;
    max-width: min(100%, 28rem);
    height: auto;
    margin: 0 0 1rem;
    border-radius: 18px;
}

@keyframes wordin {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.reply p {
    margin: 0 0 1rem;
    line-height: 1.7;
}

/* markdown elements */
.reply h1, .reply h2, .reply h3 {
    margin: 1.2rem 0 0.5rem;
}

.reply h1 { font-size: 2.4rem; }
.reply h2 { font-size: 1.8rem; }
.reply h3 { font-size: 1.4rem; }

.reply strong { font-weight: 500; }

.reply ul,
.reply ol {
    margin: 0 0 1rem;
    padding-left: 1.5rem;
    list-style: none;
}

.reply ol { counter-reset: item; }

.reply li {
    position: relative;
    margin-bottom: 0.3rem;
}

.reply li::before {
    position: absolute;
    left: -1.3rem;
    color: var(--muted);
}

.reply ul > li::before { content: "•"; }

.reply ol > li::before {
    counter-increment: item;
    content: counter(item) ".";
}

.reply li.shown::before {
    animation: wordin 0.6s ease both;
}

.reply a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.reply code {
    padding: 0.15rem 0.4rem;
    font-size: 0.9em;
    background: var(--card);
    border-radius: 6px;
}

.reply pre {
    margin: 0 0 1rem;
    padding: 1rem;
    overflow-x: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.reply pre code {
    padding: 0;
    background: none;
}

.reply blockquote {
    margin: 0 0 1rem;
    padding-left: 1rem;
    color: var(--muted);
    border-left: 3px solid var(--border);
}

.reply hr {
    margin: 1.2rem 0;
    border: none;
    border-top: 1px solid var(--border);
}

@media (prefers-reduced-motion: reduce) {
    .reply .w.in,
    .reply li.shown::before { animation: none; }
}

@media (max-width: 800px) {
    .content .chat-view.chatting { height: calc(100dvh - 4rem); }
}

@media (max-width: 800px) {
    /* the Home screen before a chat starts: heading in the middle, search bar at the bottom */
    .content .chat-view:not(.chatting) {
        justify-content: flex-start;
        min-height: calc(100dvh - 4rem);   /* the screen minus the top bar */
        padding: 1rem 0;
    }

    .content .chat-view:not(.chatting) > h1 {
        margin: auto 0;                    /* soaks up the free space above and below it, centering it */
    }
}

@media (max-width: 800px) {
    /* ---------- top bar: same colour as the page ---------- */
    .topbar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 4rem;
        align-items: center;
        gap: 0.4rem;
        padding: 0 0.75rem;
        background: var(--bg);
        z-index: 20;
    }

    .menu-btn {
        display: grid;
        place-items: center;
        width: 2.6rem;
        height: 2.6rem;
        color: var(--text);
        background: none;
        border: none;
        border-radius: 10px;
        cursor: pointer;
    }

    .menu-btn:active { background: rgba(255, 255, 255, 0.08); }

    .topbar-brand {
        font-weight: 500;
        font-size: 1.25rem;
        color: var(--text);
        text-decoration: none;
    }

    .content {
        margin-left: 0;                 /* the drawer overlays the page, so nothing needs to make room for it */
        padding: 4rem 1.25rem 0;        /* room for the top bar, and side padding */
    }

    /* ---------- the sidebar becomes a drawer ---------- */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        width: min(18rem, 82vw);
        height: auto;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 1.5rem 1rem;
        overflow-x: hidden;
        overflow-y: auto;
        border-right: 1px solid var(--border);
        border-bottom: none;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 40;
    }

    body.nav-open .sidebar { transform: none; }

    .brand { margin: 0 0 1rem; white-space: normal; }
    .nav { flex-direction: column; }
    .nav a { white-space: normal; }
    .new-chat { margin: 0 0 1rem; }
    .account { display: flex; }   /* it fits in the drawer */

    /* ---------- everything to the right of the drawer ---------- */
    .scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: 30;
    }

    body.nav-open .scrim {
        opacity: 1;
        pointer-events: auto;
    }

    body.nav-open { overflow: hidden; }
}

@media (max-width: 800px) and (prefers-reduced-motion: reduce) {
    .sidebar, .scrim { transition: none; }
}

/* ---------- suggestions ---------- */
.suggestions {
    display: none;
    flex: none;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    width: min(44rem, 100%);
    margin-top: 0.75rem;
}

.chat-view.introduced .suggestions {
    display: flex;
    animation: chipsin 0.5s ease both;
}

@keyframes chipsin {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

.chip {
    padding: 0.55rem 1rem;
    font-family: var(--font);
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.chip:hover {
    background: rgba(138, 180, 248, 0.12);
    border-color: rgba(138, 180, 248, 0.4);
}

/* ---------- invalid input: shake, red glow, message ---------- */
.search.shake {
    animation: shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shake {
    10%, 90%         { transform: translateX(-2px); }
    20%, 80%         { transform: translateX(4px); }
    30%, 50%, 70%    { transform: translateX(-8px); }
    40%, 60%         { transform: translateX(8px); }
}

.search.invalid input,
.search.invalid input:focus {
    border-color: #ff5a5f;
    box-shadow: 0 0 0 4px rgba(255, 90, 95, 0.18), 0 0 26px rgba(255, 90, 95, 0.45);
}

.form-error {
    display: none;
    flex: none;
    width: min(44rem, 100%);
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: center;
    color: #ff7b80;
}

.chat-view.has-error .form-error { display: block; }
.chat-view.has-error .disclaimer { display: none; }   /* the error takes the disclaimer's place */

@media (max-width: 800px) {
    /* chips scroll sideways on phones instead of stacking */
    .suggestions {
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .chip { flex: none; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
    .search.shake,
    .chat-view.introduced .suggestions { animation: none; }
}

/* ---------- out of tokens ---------- */
.token-notice {
    display: none;
    flex: none;
    width: min(44rem, 100%);
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: center;
    color: var(--muted);
}

.chat-view.locked .token-notice { display: block; }

.chat-view.locked .search { opacity: 0.45; }

.chat-view.locked .search input {
    cursor: not-allowed;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.04);
}

.chat-view.locked .search button {
    cursor: not-allowed;
    background: var(--muted);
}

.chat-view.locked .search button:hover { opacity: 1; }