/* Phone layout for the text chat page (templates/chat.html, body.chat-page).

   Up to 600px wide the chat is laid out like a messaging app instead of a
   box on a scrolling page: a slim header, the transcript filling whatever
   height is left, and the composer on the bottom edge. On an iPhone the old
   layout spent the top 300px on header and a full-width New Chat button,
   showed a fixed 432px transcript, and left the message field below the
   fold (measured in the iOS simulator, 2026-11-12).

   Plain CSS, loaded after output.css and only by chat.html, so it needs no
   Tailwind build. Selectors carry #main-chat-container / body.chat-page so
   they outrank the component rules in input.css whatever the order.

   static/chat_viewport.js keeps --chat-vh at window.visualViewport's height,
   so the column ends at the top of the on-screen keyboard; that file
   explains how the changes are timed to stay smooth. */

@media (max-width: 600px) {
  html:has(> body.chat-page) {
    height: 100%;
    overflow: hidden;
    /* No rubber-band of the whole page when a drag starts on the header. */
    overscroll-behavior: none;
  }

  /* An ordinary block as tall as the visible area (--chat-vh, kept by
     chat_viewport.js), not a fixed box: iOS Safari re-positions fixed boxes
     only well after its keyboard slide has ended, which showed as the header
     returning a second late. */
  /* The page behind the white chat sheet is white too: iPhone Safari tints
     the strips around its status bar and its bottom toolbar with the page's
     background, which showed the site's lavender gradient above the header
     and under the footnote (owner, 2026-11-17). */
  body.chat-page {
    background: #ffffff;
  }

  /* Separate: a browser without :has() drops only this rule. */
  html:has(> body.chat-page) {
    background: #ffffff;
  }

  body.chat-page {
    /* For the ☰ toggle, which is positioned against it (below), and for
       --chat-vt: however far the browser has moved the page to bring a
       field above the keyboard (Safari's page scroll, until the script
       takes it back; Chrome's visual viewport pan), so the column stays
       on the visible area (chat_viewport.js placeColumn). */
    position: relative;
    top: var(--chat-vt, 0px);
    width: 100%;
    height: var(--chat-vh, 100dvh);
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    /* A column of two: the chat container, and the Disclaimer link as a
       footnote line under it (it used to sit below the container, reached
       by scrolling the page; the page no longer scrolls). */
    display: flex;
    flex-direction: column;
  }

  /* Keyboard closing: the column grows back over the keyboard's own
     duration, so the composer rides it down (chat_viewport.js adds the
     class for that long). Only the height: --chat-vt (top) must land at
     once, to stay with the browser's scroll or pan in the same frame. */
  html.chat-kb-closing > body.chat-page {
    transition: height 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
  }

  /* The one time the top glides: the keyboard is leaving and Safari is
     taking back a page scroll it had held while the keys were up (16 to
     38px on the onboarding's name and scenario steps). It reports nothing
     until the slide is over, so the column's top returns over the same time
     (chat_viewport.js onPageScroll). */
  html.chat-top-gliding > body.chat-page {
    transition: height 0.3s cubic-bezier(0.25, 0.1, 0.25, 1),
                top 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
  }

  body.chat-page #main-chat-container {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    /* Safety valve. Normally everything fits and nothing scrolls. When a
       tall notice (a blocked-scenario message with its buttons) or the
       persona/name forms need more room than the screen has, the column
       scrolls instead of pushing the composer off an unscrollable page. */
    overflow-y: auto;
    margin: 0;
    --chat-side-padding: 10px;
    padding: 0 var(--chat-side-padding) 6px;
    border-radius: 0;
    box-shadow: none;
  }

  /* The iPhone's home indicator under the page when it is opened from the
     home screen (0 in a browser tab; components/standalone_viewport_fit.html
     makes iOS report it). While the keyboard is up the page ends at the
     keyboard, not at the indicator. */
  html {
    --chat-safe-bottom: env(safe-area-inset-bottom, 0px);
  }

  html.chat-kb-up {
    --chat-safe-bottom: 0px;
  }

  body.chat-page > .disclaimer-link {
    flex: none;
    max-height: calc(20px + var(--chat-safe-bottom));
    margin: 0;
    padding-bottom: calc(4px + var(--chat-safe-bottom));
    overflow: hidden;
    font-size: 11px;
    line-height: 16px;
    background: #fff; /* the chat container's own colour, so the two read as one sheet */
    transition: max-height 0.2s ease, padding-bottom 0.2s ease, opacity 0.2s ease;
  }

  /* While a field in the chat column has focus (keyboard open) the footnote
     gives its line back to the transcript: it folds away rather than
     vanishing, so the composer does not jump by a line at the tap. */
  body.chat-page:has(#main-chat-container textarea:focus, #main-chat-container input:focus) > .disclaimer-link {
    max-height: 0;
    padding-bottom: 0;
    opacity: 0;
  }

  /* ---- Header: one 48px row (menu or login · title · New Chat) and a thin
     row of links. The title and links are moved to the top with `order`;
     everything else keeps its place in the document. ---- */

  /* align-self keeps the heading's box as wide as its text, so the corner
     controls sit beside it, not on top of an invisible full-width box. */
  body.chat-page #main-chat-container .chat-title {
    order: -2;
    flex: none;
    align-self: center;
    height: 44px;
    margin: 0;
    font-size: 18px;
    line-height: 44px;
    letter-spacing: -0.2px;
    white-space: nowrap;
  }

  body.chat-page #main-chat-container .chat-tagline {
    display: none;
  }

  body.chat-page #main-chat-container .patreon-link {
    order: -1;
    position: static;
    transform: none;
    display: flex;
    flex: none;
    /* One line where it fits; the donor thank-you is longer and wraps to a
       second centred line on small phones rather than running off-screen. */
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 12px;
    width: auto;
    max-width: none;
    margin: 0;
    padding-bottom: 8px;
  }

  body.chat-page #main-chat-container .patreon-link a {
    margin-left: 0;
    font-size: 13px;
    line-height: 20px;
    white-space: nowrap;
  }

  /* Signed out: Login/Register sits in the title row's left corner. (Signed
     in, input.css hides this block and the ☰ sidebar carries the links.) */
  body.chat-page #main-chat-container:not(.has-sidebar) .login-section {
    position: absolute;
    top: 0;
    left: 10px;
    display: flex;
    align-items: center;
    height: 44px;
  }

  body.chat-page #main-chat-container:not(.has-sidebar) .login-section a {
    font-size: 13px;
  }

  /* Signed in: the ☰ toggle takes the same corner. */
  /* Positioned against the body, which is exactly the visible area, rather
     than fixed to the screen: iOS moves fixed boxes late after a keyboard
     slide (see the body rule above). */
  body.chat-page .sidebar-toggle {
    position: absolute;
    top: 3px;
    left: 8px;
    width: 38px;
    height: 38px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  }

  /* New Chat: a small pill in the title row's right corner instead of a
     full-width bar above the transcript. Scripts toggle its inline display. */
  body.chat-page #main-chat-container #new-chat-button {
    position: absolute;
    top: 5px;
    right: 10px;
    width: auto;
    margin: 0;
    padding: 7px 12px;
    border-radius: 17px;
    font-size: 13px;
    line-height: 20px;
  }

  /* The keyboard slide carries the header off the top; when the column is
     fitted afterwards it eases back in (chat_viewport.js, html.chat-header-in). */
  html.chat-header-in > body.chat-page #main-chat-container .chat-title,
  html.chat-header-in > body.chat-page #main-chat-container .patreon-link,
  html.chat-header-in > body.chat-page #main-chat-container .login-section,
  html.chat-header-in > body.chat-page #main-chat-container #new-chat-button,
  html.chat-header-in > body.chat-page .sidebar-toggle {
    animation: chat-header-in 0.2s ease-out both;
  }

  /* .chat-kb-room (utils/preview_switch.py, CHAT_KEYBOARD_ROOM_ENABLED):
     while the keyboard is up (html.chat-kb-up, kept by chat_viewport.js) the
     header gives its two rows, 72px, to the transcript, which on an iPhone
     otherwise has about 235px between header and composer (measured
     2026-11-15). Nothing in the header is needed while typing; it returns
     when the keyboard closes. The two rows in the page flow fold; the corner
     controls, which are positioned over the title row, are hidden with them.
     The header easing back in after Safari's slide (html.chat-header-in)
     would un-hide them for its 0.2s, so it is switched off here. */
  body.chat-page.chat-kb-room #main-chat-container .chat-title,
  body.chat-page.chat-kb-room #main-chat-container .patreon-link {
    overflow: hidden;
    transition: height 0.2s ease, padding-bottom 0.2s ease, opacity 0.2s ease;
  }

  /* The corner controls come back only once the rows have reopened (0.2s),
     then fade in: returning at once, they sat on top of the transcript while
     the title row was still opening, the menu button most visibly. */
  body.chat-page.chat-kb-room #main-chat-container .login-section {
    transition: visibility 0s linear 0.2s, opacity 0.12s ease 0.2s;
  }

  /* New Chat and the menu button keep the transitions they have for
     everything else (the tap lift and shadow; the menu button's own 0.3s). */
  body.chat-page.chat-kb-room #main-chat-container #new-chat-button {
    transition: all 0.3s ease, visibility 0s linear 0.2s, opacity 0.12s ease 0.2s;
  }

  body.chat-page.chat-kb-room .sidebar-toggle {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.2s, opacity 0.12s ease 0.2s;
  }

  /* A fit after Safari's slide lands at once (chat_viewport.js
     fitAfterSlide): the header is off the screen by then, and animating the
     fold showed it again for a frame. */
  html.chat-kb-snap > body.chat-page.chat-kb-room #main-chat-container .chat-title,
  html.chat-kb-snap > body.chat-page.chat-kb-room #main-chat-container .patreon-link {
    transition: none;
  }

  html.chat-kb-up > body.chat-page.chat-kb-room #main-chat-container .chat-title {
    height: 0;
    opacity: 0;
    animation: none;
  }

  /* The links row has no fixed height (the donor thank-you wraps on small
     phones), and a height cannot animate from `auto`. chat_viewport.js
     (foldHeaderRows) gives the row its measured height inline just before
     this class goes on and takes it away again once the row has reopened, so
     it folds and unfolds in step with the title row. !important: to beat
     that inline height. (An earlier version animated max-height from a
     generous cap: nothing moved for most of the 0.2s, then the row collapsed
     at the end.) */
  html.chat-kb-up > body.chat-page.chat-kb-room #main-chat-container .patreon-link {
    height: 0 !important;
    padding-bottom: 0;
    opacity: 0;
    animation: none;
  }

  html.chat-kb-up > body.chat-page.chat-kb-room #main-chat-container .login-section,
  html.chat-kb-up > body.chat-page.chat-kb-room #main-chat-container #new-chat-button,
  html.chat-kb-up > body.chat-page.chat-kb-room .sidebar-toggle {
    visibility: hidden;
    opacity: 0;
    animation: none;
    /* Gone at once: the menu button transitions `all` over 0.3s, visibility
       included, and would float over the folded header for that long. */
    transition: none;
  }

  /* With the header folded the transcript starts at the top of the screen:
     the hairline that separated it from the header has nothing above it. */
  html.chat-kb-up > body.chat-page.chat-kb-room.chat-flat #main-chat-container .chat-box-wrapper {
    border-top-color: transparent;
  }

  /* ---- Transcript: all the height that is left. ---- */

  /* Never squeezed below a few lines: past that the column scrolls. The
     floor is 120px, less on a very short visible area (a 320x568 phone with
     the keyboard up has about 244px in all). */
  body.chat-page #main-chat-container .chat-box-wrapper {
    flex: 1 1 0;
    min-height: min(120px, calc(var(--chat-vh, 100dvh) * 0.3));
    margin-bottom: 8px;
  }

  body.chat-page #main-chat-container #chat-box {
    height: 100%;
    padding: 10px;
    overscroll-behavior: contain;
    /* Not the smooth scrolling the box has elsewhere. On Send the page
       scrolls to the new message while the "is typing" bubble still has its
       placeholder height; a frame later the bubble is its real size and the
       transcript starts growing as the keyboard leaves. Safari kept
       animating toward the stale target, past the end of the content: the
       sent message sat at the top over blank space for 0.4s, then snapped
       under the previous reply. Instant scrolls land where the layout is,
       and stay in step with the keyboard. */
    scroll-behavior: auto;
  }

  /* .chat-flat (utils/preview_switch.py, CHAT_FLAT_TRANSCRIPT_ENABLED): the
     transcript without its box. The border and the 10px of padding inside it
     cost every bubble 21px of text width on a 390px screen (301px -> 322px,
     measured 2026-11-15), and drew a frame inside a frame. The box also
     marked where the transcript scrolls, so a hairline across the full width
     above and below it takes that job (without one, a bubble scrolled half
     out of view just stops in mid-air over the composer). */
  body.chat-page.chat-flat #main-chat-container .chat-box-wrapper {
    margin-left: -10px;
    margin-right: -10px;
    padding: 0 10px;
    border-top: 1px solid #ece6f3;
    border-bottom: 1px solid #ece6f3;
  }

  body.chat-page.chat-flat #main-chat-container #chat-box {
    padding-left: 0;
    padding-right: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    /* A new user bubble slides in from 20px to the right; with no padding to
       absorb it the transcript would be scrollable sideways for that moment. */
    overflow-x: hidden;
  }

  /* Positioned against the wrapper, which now reaches the screen edges:
     the jump buttons keep their old distance from the edge of the screen, and
     the loading shimmer sits on the hairlines, edge to edge (it was inset by
     the box's corner radius). */
  body.chat-page.chat-flat #main-chat-container .scrollback-jumps {
    right: 30px;
  }

  body.chat-page.chat-flat #main-chat-container .chat-box-wrapper::before,
  body.chat-page.chat-flat #main-chat-container .chat-box-wrapper::after {
    left: 0;
    right: 0;
  }

  body.chat-page.chat-flat #main-chat-container .chat-box-wrapper::before {
    top: 0;
  }

  body.chat-page.chat-flat #main-chat-container .chat-box-wrapper::after {
    bottom: 0;
  }

  body.chat-page #main-chat-container .persona-section,
  body.chat-page #main-chat-container .name-section,
  body.chat-page #main-chat-container #read-only-notice {
    flex: none;
  }

  body.chat-page #main-chat-container #read-only-notice {
    margin: 0 0 8px;
  }

  body.chat-page #main-chat-container #ai-conversation-controls {
    flex: none;
    margin: 0 0 8px;
  }

  /* ---- Composer: the field with Send in its corner, and Continue by voice
     beside it, on one row; the field grows with
     the text up to about five lines (four at the Larger text size), then
     scrolls. 16px text keeps iOS
     Safari from zooming the page when the field takes focus. Scripts set
     the section's inline display to block/none, hence the attribute test
     and !important. ---- */

  body.chat-page #main-chat-container #message-input-section:not([style*="none"]) {
    display: flex !important;
    flex: none;
    align-items: flex-end;
    gap: 8px;
  }

  body.chat-page #main-chat-container #message-input {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 44px;
    max-height: 132px;
    margin: 0;
    padding: 10px 14px;
    border-radius: 22px;
    font-size: 16px;
    line-height: 1.4;
    /* The field grows a line at a time over a tenth of a second, and the
       transcript glides up with it (chat.html sets the height, and turns
       overflow-y to auto once the text passes max-height). */
    overflow-y: hidden;
    transition: height 0.12s ease-out, border-color 0.3s, box-shadow 0.3s;
  }

  /* Every other field on this page a phone can focus that was under 16px:
     the edit-message form, the name and persona fields, the sidebar's
     search and rename fields, onboarding's history search. iOS Safari
     zooms the page into a focused field whose text is under 16px, and a
     zoomed page neither fits the column nor is re-fitted (chat_viewport.js
     leaves a zoomed page alone), so the keyboard covered the composer. */
  body.chat-page #main-chat-container textarea,
  body.chat-page #main-chat-container select,
  body.chat-page #main-chat-container input,
  body.chat-page #chat-sidebar input,
  body.chat-page #onboarding-history-search {
    font-size: 16px;
  }

  body.chat-page #main-chat-container .input-controls {
    flex: none;
    gap: 6px;
    margin: 0;
  }

  /* Send sits inside the field's bottom-right corner as a round arrow, so
     the field and Send read as one card and the field gets the width the
     "Send" pill took (owner's option A, 2026-11-18; Continue by voice stays
     outside, beside the card). The button keeps its "Send" text (script.js
     enableSendButton resets it; it is the accessible name): the text is
     hidden and the arrow is a separate layer, because dark.css restyles
     the chat buttons' backgrounds. The field's right padding leaves room
     for the button (5px + 34px + 1px of air beyond the 14px padding). */
  body.chat-page #main-chat-container #message-input {
    padding-right: 54px;
  }

  /* Send's containing block: the controls box holds only Continue by voice
     (44px wide, or 0 when it is hidden: a fresh or read-only chat, AI
     Theater's Steer, before script.js shows it). right: calc(100% + 13px)
     clears that and the row's 8px gap and sits 5px inside the field's edge
     either way. */
  body.chat-page #main-chat-container .input-controls {
    position: relative;
  }

  body.chat-page #main-chat-container #send-button {
    position: absolute;
    right: calc(100% + 13px);
    bottom: 5px;
    z-index: 1;
    width: 34px;
    min-width: 0;
    height: 34px;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    font-size: 0;
    color: transparent;
    /* Not the chat buttons' `transition: all`: Send would glide across the
       field when Continue by voice appears; and no hover lift, which sticks
       after a tap on a phone and sets the circle off-centre in the field. */
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
    transform: none;
  }

  /* A 44px tap target around the 34px circle, still inside the field. */
  body.chat-page #main-chat-container #send-button::after {
    content: "";
    position: absolute;
    inset: -5px;
  }

  body.chat-page #main-chat-container #send-button::before {
    content: "";
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5'/%3E%3Cpath d='M5 12l7-7 7 7'/%3E%3C/svg%3E") center / 19px 19px no-repeat;
    pointer-events: none;
  }

  /* High-contrast modes drop the purple and could leave a white arrow on a
     light button: show the word instead. */
  @media (forced-colors: active) {
    body.chat-page #main-chat-container #send-button {
      width: auto;
      padding: 0 12px;
      border-radius: 18px;
      font-size: 15px;
      color: ButtonText;
    }

    body.chat-page #main-chat-container #message-input {
      padding-right: 72px;
    }

    body.chat-page #main-chat-container #send-button::before {
      display: none;
    }
  }

  body.chat-page #main-chat-container .voice-switch-button {
    width: 44px;
    height: 44px;
  }
}

/* Smaller phones: tighter links, so the usual three fit one line down to
   320px and the longer donor thank-you fits one line from 360px up. */
@media (max-width: 389px) {
  body.chat-page #main-chat-container .patreon-link {
    gap: 0 10px;
  }

  body.chat-page #main-chat-container .patreon-link a {
    font-size: 12px;
  }
}

/* The narrowest phones (320px): tighter title row so Login/Register, the
   title and New Chat still fit on one line. */
@media (max-width: 359px) {
  body.chat-page #main-chat-container .chat-title {
    font-size: 16px;
  }

  body.chat-page #main-chat-container:not(.has-sidebar) .login-section a {
    font-size: 12px;
  }

  body.chat-page #main-chat-container #new-chat-button {
    padding: 7px 10px;
    font-size: 12px;
  }
}

@keyframes chat-header-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* Reduced motion drops the one decorative movement, the header easing in.
   The others stay: the column growing as the keyboard leaves, the composer
   growing by a line and the footnote folding follow something that is
   already moving (the keyboard, the text) and replace a jump, not stillness. */
@media (prefers-reduced-motion: reduce) {
  html.chat-header-in > body.chat-page #main-chat-container .chat-title,
  html.chat-header-in > body.chat-page #main-chat-container .patreon-link,
  html.chat-header-in > body.chat-page #main-chat-container .login-section,
  html.chat-header-in > body.chat-page #main-chat-container #new-chat-button,
  html.chat-header-in > body.chat-page .sidebar-toggle {
    animation: none;
  }
}

/* ==========================================================================
   .chat-menu (utils/preview_switch.py, CHAT_HEADER_MENU_ENABLED): on phones
   the header is ONE row, and everything else is in one menu panel.

   Header row (80px): menu button, then a short Support link (signed in) or
   Log in (signed out), the portrait of who you are talking to
   (static/chat_menu.js fills #chat-portrait; no name: it is on every
   message), then, signed out, the Support link, and New Chat as an icon in
   the right corner.
   Menu panel: the chat-history sidebar (signed in) or the guest panel
   (signed out), restyled: the site's name and a close button, Story
   Generator and Updates, the chats as one portrait + title row each, and
   the account links pinned to the bottom.

   The page's <h1> and tagline stay in the document for search engines and
   screen readers; the heading is only moved out of sight.
   Desktop is unchanged: everything the menu adds is hidden above 600px.
   ========================================================================== */
@media (min-width: 601px) {
  .chat-menu-only,
  .support-short,
  .login-short,
  .conv-portrait {
    display: none !important;
  }
}

@media (max-width: 600px) {
  /* ---- Header row ---- */

  /* Still the page's heading; not shown (the name is in the menu). */
  body.chat-page.chat-menu #main-chat-container .chat-title {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  body.chat-page.chat-menu #main-chat-container .chat-portrait {
    order: -2;
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    height: 80px;
  }

  body.chat-page.chat-menu .chat-portrait > img,
  body.chat-page.chat-menu .chat-portrait > .portrait-crop,
  body.chat-page.chat-menu .chat-portrait .chat-portrait-initial {
    box-sizing: border-box;
    width: 68px;
    height: 68px;
    /* 64px of picture: the owner found 36px too small to hold the centre
       of the row, then asked for larger than 46px and chose 64 from
       rendered sizes (2026-11-16). The gap between picture and ring is a
       border in the header's own colour, which the dark scheme remaps (a
       white box-shadow it would not, leaving a bright halo). */
    border: 2px solid #ffffff;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 0 1.5px #c9b1f3;
  }

  /* A face crop (chat_menu.js CROPS): the round box clips, and the
     picture inside is enlarged and placed by inline percentages. */
  body.chat-page.chat-menu .portrait-crop {
    position: relative;
    display: block;
    overflow: hidden;
  }

  body.chat-page.chat-menu .portrait-crop > img {
    position: absolute;
    display: block;
    max-width: none;
    height: auto;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  /* Every portrait in the header positioned alike, so they paint in DOM
     order: the second overlaps the first even when only one is a crop
     (a positioned crop would otherwise paint above a plain picture). */
  body.chat-page.chat-menu .chat-portrait > * {
    position: relative;
  }

  /* Two characters in one chat (AI Theater, three-way): overlapped. */
  body.chat-page.chat-menu .chat-portrait > * + * {
    margin-left: -10px;
  }

  body.chat-page.chat-menu .chat-portrait-initial,
  body.chat-page.chat-menu .conv-portrait-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e9ddfb;
    color: #6b21a8;
    font-weight: 700;
    font-size: 15px;
  }

  /* The header's letter, for a character with no picture, sized to its
     64px circle (the rows' 36px circles have 15px). */
  body.chat-page.chat-menu .chat-portrait .chat-portrait-initial {
    font-size: 26px;
  }

  /* The links row: only the short Support link, in the header row: beside
     New Chat for guests, beside the menu button signed in (below). Story
     Generator and Updates are in the menu. */
  body.chat-page.chat-menu #main-chat-container .patreon-link {
    position: absolute;
    top: 0;
    /* Guests: 14px clear of the New Chat button's box (12 + 44 + 14). */
    right: 70px;
    left: auto;
    transform: none;
    flex-wrap: nowrap;
    align-items: center;
    width: auto;
    max-width: none;
    height: 80px;
    padding: 0;
  }

  body.chat-page.chat-menu #main-chat-container .patreon-link a {
    display: none;
  }

  body.chat-page.chat-menu #main-chat-container .patreon-link a.support-short {
    display: inline;
    font-size: 14px;
    font-weight: 600;
  }

  /* Signed in, "Support us" sits beside the menu button (where Log in is
     for guests), so New Chat stands alone in the right corner, where chat
     apps put it (owner's choice B, 2026-11-17). 14px clear of the button's
     box, so it does not read as the menu's label. Guests keep it on the
     right: their left already holds Log in. */
  body.chat-page.chat-menu #main-chat-container.has-sidebar .patreon-link {
    right: auto;
    left: 60px;
  }

  /* Signed out: Log in sits beside the menu button. */
  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .login-section {
    left: 52px;
    height: 80px;
  }

  body.chat-page.chat-menu #main-chat-container .login-section a.login-long {
    display: none;
  }

  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .login-section a.login-short {
    font-size: 14px;
    font-weight: 600;
  }

  /* The menu button: three bars, no box. */
  body.chat-page.chat-menu .sidebar-toggle,
  body.chat-page.chat-menu .sidebar-toggle:hover {
    top: 21px;
    /* The 26px icon's edge 14px from the screen's. */
    left: 8px;
    width: 38px;
    height: 38px;
    border: 0;
    background: transparent;
    box-shadow: none;
    color: #6b21a8;
  }

  body.chat-page.chat-menu .sidebar-toggle .toggle-icon {
    display: none;
  }

  /* 26px, near New Chat's 28-30px, so the two corners read as a pair (the
     owner, 2026-11-17; it was 22px). */
  body.chat-page.chat-menu .sidebar-toggle::before {
    content: "";
    width: 26px;
    height: 26px;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16'/%3E%3C/svg%3E") center / contain no-repeat;
  }

  /* A new Update is announced by a dot on the menu button (the Updates link
     itself is inside the menu; html.has-new-update is set in chat.html). */
  html.has-new-update body.chat-page.chat-menu .sidebar-toggle::after {
    content: "";
    position: absolute;
    /* Clear of the 26px icon's top bar. */
    top: 2px;
    right: 0;
    width: 9px;
    height: 9px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: #e11d48;
  }

  /* The panel has its own close button. */
  /* At once: the button's own transitions (0.3s, and the keyboard fold's
     delayed visibility) left the bars drawn over the panel as it slid in. */
  body.sidebar-open.chat-page.chat-menu .sidebar-toggle {
    visibility: hidden;
    transition: none;
  }

  /* New Chat: a quiet icon in the right corner, an outline in the site's
     purple with no filled box (the filled one crowded Support beside it,
     the owner's call 2026-11-16). Its label stays for screen readers: the
     text is only made invisible. A 44px tap target. Sizes the owner chose
     from rendered options (2026-11-17): for guests a 28px icon, its edge
     20px from the screen's; signed in, alone in the corner, 30px and 24px
     in (below). */
  body.chat-page.chat-menu #main-chat-container #new-chat-button,
  body.chat-page.chat-menu #main-chat-container #new-chat-button:hover,
  body.chat-page.chat-menu #main-chat-container #new-chat-button:active {
    top: 18px;
    right: 12px;
    width: 44px;
    min-width: 0;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 11px;
    background: transparent;
    box-shadow: none;
    color: #6b21a8;
    font-size: 0;
    line-height: 0;
    transform: none;
  }

  body.chat-page.chat-menu #main-chat-container #new-chat-button::before {
    content: "";
    display: block;
    width: 28px;
    height: 28px;
    margin: auto;
    /* The button's text colour, which the dark scheme remaps with it. */
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-6'/%3E%3Cpath d='M17.5 3.5a2.1 2.1 0 0 1 3 3L12 15l-4 1 1-4z'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-6'/%3E%3Cpath d='M17.5 3.5a2.1 2.1 0 0 1 3 3L12 15l-4 1 1-4z'/%3E%3C/svg%3E") center / contain no-repeat;
  }

  body.chat-page.chat-menu #main-chat-container.has-sidebar #new-chat-button,
  body.chat-page.chat-menu #main-chat-container.has-sidebar #new-chat-button:hover,
  body.chat-page.chat-menu #main-chat-container.has-sidebar #new-chat-button:active {
    right: 17px;
  }

  body.chat-page.chat-menu #main-chat-container.has-sidebar #new-chat-button::before {
    width: 30px;
    height: 30px;
  }

  /* ---- Picture off (body.chat-portrait-off, utils/chat_portrait.py) ----
     The visitor turned the header's character picture off in the menu: the
     middle stays empty and the row is 56px instead of 80px. #chat-portrait
     stays in the flow (empty, chat_menu.js) as the row's height: it is what
     keeps the transcript below the absolutely placed controls. */
  body.chat-page.chat-menu.chat-portrait-off #main-chat-container .chat-portrait {
    height: 56px;
  }

  body.chat-page.chat-menu.chat-portrait-off #main-chat-container .patreon-link,
  body.chat-page.chat-menu.chat-portrait-off #main-chat-container:not(.has-sidebar) .login-section {
    height: 56px;
  }

  body.chat-page.chat-menu.chat-portrait-off .sidebar-toggle,
  body.chat-page.chat-menu.chat-portrait-off .sidebar-toggle:hover {
    top: 9px;
  }

  body.chat-page.chat-menu.chat-portrait-off #main-chat-container #new-chat-button,
  body.chat-page.chat-menu.chat-portrait-off #main-chat-container #new-chat-button:hover,
  body.chat-page.chat-menu.chat-portrait-off #main-chat-container #new-chat-button:active {
    top: 6px;
  }

  /* Tapping the portrait offers to hide it (static/chat_menu.js). */
  body.chat-page.chat-menu #main-chat-container .chat-portrait > * {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  body.chat-page.chat-menu #main-chat-container .chat-portrait > [role="button"]:focus-visible {
    outline: 2px solid #7e22ce;
    outline-offset: 3px;
  }

  /* The "Hide picture" bubble under the portrait; placed by chat_menu.js. */
  body.chat-page.chat-menu .chat-portrait-bubble {
    position: fixed;
    z-index: 60;
    transform: translateX(-50%);
  }

  body.chat-page.chat-menu .chat-portrait-bubble::before {
    content: "";
    position: absolute;
    top: -6px;
    left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top: 0;
    border-bottom-color: #2b1d42;
  }

  body.chat-page.chat-menu .chat-portrait-bubble button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 40px;
    padding: 0 14px;
    border: 0;
    border-radius: 10px;
    background: #2b1d42;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
  }

  /* After hiding: a short message just above the message box, with Undo. */
  body.chat-page.chat-menu .chat-portrait-toast {
    position: fixed;
    z-index: 60;
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 10px 10px 14px;
    border-radius: 12px;
    background: #2b1d42;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    color: #ffffff;
    font-size: 14px;
    line-height: 1.35;
  }

  body.chat-page.chat-menu .chat-portrait-toast span {
    flex: 1 1 auto;
  }

  body.chat-page.chat-menu .chat-portrait-toast button {
    flex: none;
    min-height: 36px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #d8b4fe;
    font-size: 14px;
    font-weight: 700;
  }

  /* The way back, in the menu panel: shown only while the picture is hidden
     (components/chat_menu_show_picture.html). */
  body.chat-page.chat-menu .chat-menu-show-picture {
    display: none;
  }

  body.chat-page.chat-menu.chat-portrait-off .chat-menu-show-picture {
    display: block;
    flex: none;
    width: 100%;
    padding: 10px 0 2px;
    border: 0;
    border-top: 1px solid #ece4f8;
    background: transparent;
    color: #7e22ce;
    font-size: 13px;
    text-align: center;
  }

  body.chat-page.chat-menu.chat-portrait-off .chat-menu-show-picture + .chat-menu-foot {
    border-top: 0;
    padding-top: 2px;
  }


  /* ---- Header and the keyboard (.chat-kb-room): the portrait row folds as
     the title row did; Support, a corner control now, goes and returns with
     the other corner controls. ---- */
  html.chat-header-in > body.chat-page.chat-menu #main-chat-container .chat-portrait {
    animation: chat-header-in 0.2s ease-out both;
  }

  body.chat-page.chat-kb-room.chat-menu #main-chat-container .chat-portrait {
    overflow: hidden;
    transition: height 0.2s ease, opacity 0.2s ease;
  }

  html.chat-kb-snap > body.chat-page.chat-kb-room.chat-menu #main-chat-container .chat-portrait {
    transition: none;
  }

  html.chat-kb-up > body.chat-page.chat-kb-room.chat-menu #main-chat-container .chat-portrait {
    height: 0;
    opacity: 0;
    animation: none;
  }

  body.chat-page.chat-kb-room.chat-menu #main-chat-container .patreon-link {
    overflow: visible;
    transition: visibility 0s linear 0.2s, opacity 0.12s ease 0.2s;
  }

  /* !important: the two-row header's rule folds this row to height 0 with
     !important, and chat_viewport.js gives it an inline height. */
  html.chat-kb-up > body.chat-page.chat-kb-room.chat-menu #main-chat-container .patreon-link {
    height: 80px !important;
    visibility: hidden;
    opacity: 0;
    transition: none;
  }

  html.chat-kb-up > body.chat-page.chat-kb-room.chat-menu.chat-portrait-off #main-chat-container .patreon-link {
    height: 56px !important;
  }

  /* The link itself too: its own transition (`all 0.3s`, input.css) kept it
     visible, and tappable, for 0.3s after its row had hidden. */
  html.chat-kb-up > body.chat-page.chat-kb-room.chat-menu #main-chat-container .patreon-link a.support-short {
    visibility: hidden;
    transition: none;
  }

  /* ---- The menu panel ---- */
  body.chat-page.chat-menu .chat-sidebar {
    width: min(86vw, 320px);
    max-width: none;
    background: #fbf8ff;
  }

  body.chat-page.chat-menu .chat-sidebar.collapsed {
    transform: translateX(-105%);
  }

  body.chat-page.chat-menu .chat-sidebar .sidebar-content {
    padding: 0 14px 8px;
  }

  body.chat-page.chat-menu .chat-sidebar .sidebar-top {
    margin: 0 -14px;
    padding: 14px 14px 2px;
    background: #fbf8ff;
  }

  body.chat-page.chat-menu .chat-guest-menu .sidebar-content {
    padding-top: 14px;
  }

  body.chat-page.chat-menu .chat-sidebar .sidebar-header,
  body.chat-page.chat-menu .chat-sidebar .sidebar-top .sidebar-account {
    display: none;
  }

  body.chat-page.chat-menu .chat-menu-brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
  }

  body.chat-page.chat-menu .chat-menu-brand {
    color: #7e22ce;
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.01em;
  }

  body.chat-page.chat-menu .chat-menu-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: -4px -8px -4px 0;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    box-shadow: none;
    color: #6b7280;
    cursor: pointer;
  }

  body.chat-page.chat-menu .chat-menu-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 8px;
    border-radius: 10px;
    color: #3b2a57;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
  }

  body.chat-page.chat-menu .chat-menu-nav svg {
    flex: none;
    color: #7e22ce;
  }

  body.chat-page.chat-menu .chat-menu-badge {
    display: none;
    margin-left: auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e11d48;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
  }

  html.has-new-update body.chat-page.chat-menu .chat-menu-badge {
    display: inline;
  }

  body.chat-page.chat-menu .chat-menu-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin: 8px 2px;
    padding-top: 10px;
    border-top: 1px solid #e9e0f7;
    color: #8b7aa8;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  /* "Archived ›" at the label's right: the label's colour, not its capitals. */
  body.chat-page.chat-menu .chat-menu-label .history-archived-link {
    /* A finger-sized target (the menu's rows are 44px) that looks no bigger. */
    margin: -12px 0;
    padding: 12px 0 12px 16px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
  }

  body.chat-page.chat-menu .chat-sidebar .sidebar-search input {
    margin-bottom: 8px;
  }

  /* One row per chat: portrait, title (up to two lines), and at the right
     the time with the options button under it, all centred on the row's
     middle (they sat high, with the space under them: the owner chose
     option A, 2026-11-17: 36px portraits, 15px titles). The row's inner
     wrappers (.conversation-content, .meta) dissolve so their children can
     be placed on the row's grid. */
  body.chat-page.chat-menu .chat-sidebar .conversation-list {
    gap: 2px;
  }

  body.chat-page.chat-menu .chat-sidebar .conversation-item,
  body.chat-page.chat-menu .chat-sidebar .conversation-item:hover {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    column-gap: 11px;
    align-items: center;
    padding: 9px 8px;
    border: 0;
    background: transparent;
    box-shadow: none;
    transform: none;
  }

  body.chat-page.chat-menu .chat-sidebar .conversation-item.active {
    border: 0;
    background: #efe5ff;
  }

  body.chat-page.chat-menu .chat-sidebar .conversation-content,
  body.chat-page.chat-menu .chat-sidebar .conversation-item .meta {
    display: contents;
  }

  body.chat-page.chat-menu .chat-sidebar .conv-portrait {
    grid-column: 1;
    grid-row: 1 / span 2;
  }

  body.chat-page.chat-menu .chat-sidebar .conv-portrait > img,
  body.chat-page.chat-menu .chat-sidebar .conv-portrait > .portrait-crop,
  body.chat-page.chat-menu .chat-sidebar .conv-portrait-initial {
    display: block;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
  }

  body.chat-page.chat-menu .chat-sidebar .conv-portrait-initial {
    display: flex;
    font-size: 15px;
  }

  body.chat-page.chat-menu .chat-sidebar .conversation-item .title {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: -webkit-box;
    margin: 0;
    padding-right: 0;
    overflow: hidden;
    white-space: normal;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.3;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  /* While a title is being renamed its box holds the field and buttons. */
  body.chat-page.chat-menu .chat-sidebar .conversation-item .title:has(.title-edit-input) {
    display: block;
    overflow: visible;
  }

  body.chat-page.chat-menu .chat-sidebar .conversation-item .preview,
  body.chat-page.chat-menu .chat-sidebar .conversation-item .persona-badge,
  body.chat-page.chat-menu .chat-sidebar .conversation-item .mode-indicator {
    display: none;
  }

  body.chat-page.chat-menu .chat-sidebar .conversation-item .date {
    grid-column: 3;
    grid-row: 1;
    align-self: end;
    justify-self: end;
    color: #8b8b99;
    font-size: 12px;
    white-space: nowrap;
  }

  body.chat-page.chat-menu .chat-sidebar .conversation-item .conversation-actions {
    position: relative;
    top: auto;
    right: auto;
    grid-column: 3;
    grid-row: 2;
    align-self: start;
    justify-self: end;
  }

  /* Signed out: a log-in card where the chats would be. */
  body.chat-page.chat-menu .chat-menu-guest {
    padding: 14px 12px;
    border: 1px dashed #cdb9ee;
    border-radius: 12px;
    background: #ffffff;
    text-align: center;
  }

  body.chat-page.chat-menu .chat-menu-guest b {
    display: block;
    margin-bottom: 4px;
    color: #2b1d42;
    font-size: 15px;
  }

  body.chat-page.chat-menu .chat-menu-guest span {
    display: block;
    margin-bottom: 12px;
    color: #6b7280;
    font-size: 13px;
  }

  body.chat-page.chat-menu .chat-menu-guest-btn {
    display: block;
    padding: 11px 15px;
    border-radius: 999px;
    background: linear-gradient(135deg, #8a3cc8 0%, #6b2fa0 100%);
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
  }

  /* (Every foot always holds Settings since 2026-11-18, guests' too, so the
     rules for an empty guest foot in the installed app were removed.) */

  /* The account links, pinned under the list. */
  body.chat-page.chat-menu .chat-menu-foot {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0 10px;
    padding: 4px 12px calc(6px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #e9e0f7;
  }
}

/* Narrow phones (up to 374px) with two characters in the chat: the pair
   overlaps a little more, each is smaller, and the link is a size smaller,
   so "Log in", the pair and "Support us" all fit (chat_menu.js fitHeader()
   handles the rest; at 360px two full-size portraits left 6px, measured
   2026-11-17). Elsewhere fitHeader()'s small shift keeps them clear. */
@media (max-width: 374px) {
  body.chat-page.chat-menu .chat-portrait > * + * {
    /* -28px: a guest's 320px header left 7px at -24px (measured
       2026-11-17). */
    margin-left: -28px;
  }

  /* 56px boxes (52px pictures) instead of 68px. */
  body.chat-page.chat-menu .chat-portrait:has(> * + *) > img,
  body.chat-page.chat-menu .chat-portrait:has(> * + *) > .portrait-crop,
  body.chat-page.chat-menu .chat-portrait:has(> * + *) .chat-portrait-initial {
    width: 56px;
    height: 56px;
  }

  body.chat-page.chat-menu #main-chat-container:has(.chat-portrait > * + *) .patreon-link a.support-short {
    font-size: 12px;
  }
}

/* Guests, whose right side holds both "Support us" and New Chat (28px icon,
   20px in), need the smaller pair up to 389px, and smaller still below
   360px (measured 2026-11-17: 3px at 320 and 6px at 375 without). */
@media (max-width: 389px) {
  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .chat-portrait > * + * {
    margin-left: -28px;
  }

  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .chat-portrait:has(> * + *) > img,
  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .chat-portrait:has(> * + *) > .portrait-crop,
  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .chat-portrait:has(> * + *) .chat-portrait-initial {
    width: 56px;
    height: 56px;
  }

  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar):has(.chat-portrait > * + *) .patreon-link a.support-short {
    font-size: 12px;
  }
}

@media (max-width: 359px) {
  /* Log in 2px nearer the menu button (still 10px from its drawn icon):
     at 320px a portrait has no room for 8px each side otherwise (7.5px
     measured 2026-11-17). */
  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .login-section {
    left: 50px;
  }

  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .chat-portrait:has(> * + *) > img,
  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .chat-portrait:has(> * + *) > .portrait-crop,
  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .chat-portrait:has(> * + *) .chat-portrait-initial {
    width: 50px;
    height: 50px;
  }
}

/* Narrower than any phone the layout is drawn for (320px): only a large
   browser zoom gets here (Android Chrome's Accessibility "Default zoom" at
   140% on a 412px phone is 294px). "Support us" ran into the portrait, so
   the row keeps the menu button, the portrait and New Chat; Log in and
   Support are both in the menu panel (owner, 2026-11-18). The message box's
   placeholder stays on one line instead of wrapping half out of view. */
@media (max-width: 319.98px) {
  body.chat-page.chat-menu #main-chat-container .patreon-link,
  body.chat-page.chat-menu #main-chat-container:not(.has-sidebar) .login-section {
    display: none;
  }

  body.chat-page #main-chat-container #message-input::placeholder {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Support goes into the menu panel instead (templates/chat.html). */
  body.chat-page.chat-menu .chat-menu-foot a.chat-menu-support {
    display: inline-flex; /* as its .sidebar-account-link siblings */
  }
}

/* The menu panels' Support link exists for the narrow case above only. */
body.chat-page .chat-menu-foot a.chat-menu-support {
  display: none;
}

/* Guests' Settings link is for the desktop header row. On phones the menu
   panel's foot has it; the classic two-row phone header (the menu switched
   off) has no room for it beside Login/Register under the title. */
@media (max-width: 600px) {
  body.chat-page #main-chat-container .login-section a.guest-settings-link {
    display: none;
  }
}

/* Text size (Settings, utils/text_size.py): the chat's messages and the
   message box, at every width; the header and buttons keep their sizes.
   Default is 16px; line heights are ratios, so they scale along. */
body.chat-page.text-size-large #chat-box .ai-message,
body.chat-page.text-size-large #chat-box .user-message,
body.chat-page.text-size-large #chat-box .edit-textarea,
body.chat-page.text-size-large #main-chat-container #message-input {
  font-size: 18px;
}

body.chat-page.text-size-larger #chat-box .ai-message,
body.chat-page.text-size-larger #chat-box .user-message,
body.chat-page.text-size-larger #chat-box .edit-textarea,
body.chat-page.text-size-larger #main-chat-container #message-input {
  font-size: 20px;
}

@media (prefers-reduced-motion: reduce) {
  html.chat-header-in > body.chat-page.chat-menu #main-chat-container .chat-portrait {
    animation: none;
  }
}

/* Common Latin text uses the smaller subset. Other supported characters
   use the full face. Browsers fetch these faces only for a theme that uses them. */
@font-face {
  font-family: "Literata";
  src: url("../fonts/literata/literata-roman.woff2") format("woff2");
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("../fonts/literata/literata-roman-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122;
}
@font-face {
  font-family: "Literata";
  src: url("../fonts/literata/literata-italic.woff2") format("woff2");
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("../fonts/literata/literata-italic-latin.woff2") format("woff2");
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122;
}

body.chat-page.chat-paper {
  --chat-nav: #514b43;
  --chat-desk: #eee8de;
  --chat-sheet: #fbf8ef;
  --chat-ink: #342e30;
  --chat-muted: #71636c;
  --chat-line: #ccc0bf;
  --chat-reply: #f0e9dc;
  --chat-user: #ece0e7;
  --chat-second: #e2e9e4;
  --chat-accent: #70445e;
  --chat-button: #70445e;
  --chat-button-hover: #593249;
}

body.chat-page.chat-dressing-table {
  --chat-nav: #79425c;
  --chat-desk: #f1d9d3;
  --chat-sheet: #fcf8f1;
  --chat-ink: #382725;
  --chat-muted: #735850;
  --chat-line: #cebab0;
  --chat-reply: #f2eada;
  --chat-user: #f4d9dd;
  --chat-second: #e6e4d3;
  --chat-accent: #803451;
  --chat-button: #84344e;
  --chat-button-hover: #69263d;
}

/* Kitchen, calmer than the first Kitchen Table (owner, 2026-11-27): a brick-red bar
   and buttons, oatmeal replies instead of yellow. */
body.chat-page.chat-kitchen-table {
  --chat-nav: #8b3a35;
  --chat-desk: #efe8dc;
  --chat-sheet: #fffcf6;
  --chat-ink: #39291b;
  --chat-muted: #715c4c;
  --chat-line: #d2bca4;
  --chat-reply: #f0e7d9;
  --chat-user: #f5ddd6;
  --chat-second: #e1ead7;
  --chat-accent: #9c2f37;
  --chat-button: #a3343a;
  --chat-button-hover: #872a31;
}

body.chat-page.chat-themed {
  --chat-nav-ink: #fff8ef;
  --chat-nav-line: color-mix(in srgb, var(--chat-nav-ink) 35%, var(--chat-nav));
  --chat-nav-hover: color-mix(in srgb, var(--chat-nav-ink) 12%, var(--chat-nav));
  background: var(--chat-desk);
}

.chat-nav-band {
  display: contents;
}

body.chat-page.chat-themed #main-chat-container .chat-title {
  color: var(--chat-ink);
  font-weight: 600;
}

body.chat-page.chat-kitchen-table #main-chat-container .chat-title {
  font-weight: 750;
}

body.chat-page.chat-themed:not(.chat-desk) #main-chat-container,
body.chat-page.chat-themed #main-chat-container .chat-desk-card,
body.chat-page.chat-themed #main-chat-container #chat-box {
  background-color: var(--chat-sheet);
}

body.chat-page.chat-paper .chat-title,
body.chat-page.chat-paper #chat-box :is(.ai-message, .user-message, .edit-textarea) {
  font-family: "Literata", Georgia, serif;
}

/* Match Paper's lowercase letters to the default chat at each text size. */
body.chat-page.chat-paper #chat-box :is(.ai-message, .user-message, .edit-textarea) {
  font-size-adjust: 0.53;
}

body.chat-page.chat-themed #chat-box .ai-message,
body.chat-page.chat-themed #chat-box .user-message {
  color: var(--chat-ink);
  line-height: 1.6;
  box-shadow: none;
}
body.chat-page.chat-themed #chat-box .ai-message {
  background-color: var(--chat-reply);
}
body.chat-page.chat-themed #chat-box .user-message {
  background-color: var(--chat-user);
}
body.chat-page.chat-themed #chat-box .ai-message.ai-second {
  background-color: var(--chat-second);
}

body.chat-page.chat-themed #main-chat-container #message-input,
body.chat-page.chat-themed #chat-box .edit-textarea {
  background-color: var(--chat-sheet);
  color: var(--chat-ink);
  border-color: var(--chat-line);
}
body.chat-page.chat-themed #main-chat-container #message-input:focus,
body.chat-page.chat-themed #chat-box .edit-textarea:focus {
  border-color: var(--chat-accent);
  outline: 1px solid var(--chat-accent);
  box-shadow: none;
}
body.chat-page.chat-themed #message-input::placeholder {
  color: var(--chat-muted);
}

body.chat-page.chat-themed #send-button,
body.chat-page.chat-themed .edit-actions .edit-save-btn {
  background: var(--chat-button);
  box-shadow: none;
}
body.chat-page.chat-themed #send-button:hover,
body.chat-page.chat-themed .edit-actions .edit-save-btn:hover {
  background: var(--chat-button-hover);
}
body.chat-page.chat-themed .voice-switch-button {
  background: var(--chat-sheet);
  color: var(--chat-accent);
  border-color: var(--chat-line);
  box-shadow: none;
}
body.chat-page.chat-themed .voice-switch-button:hover {
  background: var(--chat-user);
}
body.chat-page.chat-themed #chat-box .edit-btn,
body.chat-page.chat-themed #chat-box .regenerate-btn {
  color: var(--chat-muted);
}

@media (max-width: 600px) {
  /* The portrait shifts to clear the controls. The band stays put and
     follows its height when the portrait is hidden or the keyboard opens. */
  .chat-nav-band {
    order: -2;
    flex: none;
    display: block;
    margin-inline: calc(-1 * var(--chat-side-padding));
    overflow: hidden;
    background: var(--chat-nav);
  }
  body.chat-page.chat-themed,
  body.chat-page.chat-themed #main-chat-container,
  body.chat-page.chat-themed > .disclaimer-link {
    background: var(--chat-sheet);
  }
  body.chat-page.chat-themed.chat-flat #main-chat-container .chat-box-wrapper {
    border-color: var(--chat-line);
  }
  html.chat-kb-up > body.chat-page.chat-themed.chat-kb-room.chat-flat #main-chat-container .chat-box-wrapper {
    border-top-color: transparent;
  }
  body.chat-page.chat-themed.chat-menu .sidebar-toggle,
  body.chat-page.chat-themed.chat-menu .sidebar-toggle:hover,
  body.chat-page.chat-themed.chat-menu #main-chat-container #new-chat-button,
  body.chat-page.chat-themed.chat-menu #main-chat-container #new-chat-button:is(:hover, :active),
  body.chat-page.chat-themed.chat-menu #main-chat-container :is(.login-section, .patreon-link) a {
    color: var(--chat-nav-ink);
  }
  body.chat-page.chat-themed.chat-menu #main-chat-container #chat-portrait > [role="button"]:focus-visible {
    outline-color: var(--chat-nav-ink);
  }
  body.chat-page.chat-paper.chat-menu #chat-portrait > * {
    border-color: var(--chat-nav);
    box-shadow: 0 0 0 1.5px var(--chat-nav-line);
  }
}

@media (min-width: 601px) {
  body.chat-page.chat-themed #new-chat-button {
    background: var(--chat-button);
    box-shadow: none;
  }
  body.chat-page.chat-themed #new-chat-button:hover {
    background: var(--chat-button-hover);
  }
  body.chat-page.chat-themed.desk-bar :is(.chat-desk-bar, .chat-desk-more-menu, .sidebar-toggle) {
    background: var(--chat-nav);
    border-color: var(--chat-nav-line);
  }
  body.chat-page.chat-themed.desk-bar .sidebar-toggle,
  body.chat-page.chat-themed.desk-bar .chat-desk-bar .chat-desk-link,
  body.chat-page.chat-themed.desk-bar .chat-desk-bar .chat-desk-link:hover {
    color: var(--chat-nav-ink);
  }
  body.chat-page.chat-themed.desk-bar .chat-desk-link.is-current::after {
    background: var(--chat-nav-ink);
  }
  body.chat-page.chat-themed.desk-bar .chat-desk-bar .chat-desk-link:focus-visible {
    outline-color: var(--chat-nav-ink);
  }
  body.chat-page.chat-themed.desk-bar .chat-desk-bar .chat-desk-link:not(.is-current):hover {
    text-decoration: underline;
    text-underline-offset: 3px;
  }
  body.chat-page.chat-themed.desk-bar .sidebar-toggle:hover,
  body.chat-page.chat-themed.desk-bar .chat-desk-bar .chat-desk-more-menu .chat-desk-link:hover {
    background: var(--chat-nav-hover);
  }
}
