:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e232b;
  --border: #2a303a;
  --text: #e6e9ee;
  --muted: #8b93a1;
  --accent: #4f8cff;
  --user-bubble: #2b3038;
  --bubble: #1e232b;
  --code-bg: #0b0d11;
  --active-bg: #2a3038;
  --active-text: #ffffff;
  /* per-chat Lagrange Colorful accents; overridden in JS when a chat opens.
     The dark defaults are grayscale so the monochrome (non-patrick) scheme and
     the no-chat state stay neutral rather than tinted by the app blue. */
  --chat-accent: #c9d0d8;
  --chat-accent-soft: #9aa4af;
  --chat-bubble: #1e232b;
  --chat-bg: #0f1115;
  --composer-bg: #14171d;
  --chat-bubble-text: #e6e9ee;
  --chat-muted: #8b93a1;
  --chat-border: #3a414b;
  --chat-shadow-rgb: 0, 0, 0;
  --chat-code-bg: #0b0d11;
  /* page body: darker variant of the chat pane, set per-chat in JS */
  --body-bg: #0a0c0f;
  /* subtle gaussian noise texture (SVG feTurbulence), tiled */
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --panel-2: #eef1f5;
    --border: #d7dce3;
    --text: #1a1d23;
    --muted: #5b6470;
    --accent: #2f6fed;
    --user-bubble: #dbe7ff;
    --bubble: #eef1f5;
    --code-bg: #f0f2f5;
    --active-bg: #cfe0ff;
    --active-text: #0d1b2e;
    --body-bg: #e8eaee;
    /* scheme-aware chat defaults: in light mode un-themed contexts must use dark
       text (never the dark scheme's near-white), for consistent enhanced contrast */
    --chat-accent: #2f6fed;
    --chat-accent-soft: #7fb0ff;
    --chat-bubble: #ffffff;
    --chat-bg: #f4f5f7;
    --composer-bg: #f8f9fa;
    --chat-bubble-text: #1a1d23;
    --chat-muted: #5b6470;
    --chat-border: #d7dce3;
    --chat-code-bg: #eef1f5;
  }
}


* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  /* never allow a horizontal scrollbar (e.g. the off-canvas sidebar or wide
     bubbles/composer on a phone); content that must overflow scrolls inside
     its own container instead */
  overflow-x: hidden;
  background-color: var(--body-bg, var(--bg));
  background-image: var(--noise);
  background-size: 160px 160px;
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; /* no rubber-banding/bounce on the page itself */
}

#app {
  display: flex;
  /* 100dvh is the visible viewport on mobile (accounts for the iOS URL bar /
     standalone PWA chrome); 100vh is the fallback for browsers without it */
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
  overflow-x: hidden;
  padding: 10px;
  gap: 10px;
}

/* ── Sidebar ─────────────────────────────── */
#sidebar {
  width: 300px;
  min-width: 240px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* layered, chat-tinted drop shadow so the panel lifts off the page */
  box-shadow:
    0 1px 2px rgba(var(--chat-shadow-rgb), .10),
    0 3px 8px -1px rgba(var(--chat-shadow-rgb), .08),
    0 12px 24px -8px rgba(var(--chat-shadow-rgb), .06);
}
.sidebar-head {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.new-chat { flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 9px 0; border-radius: 8px; cursor: pointer; font-weight: 600; }
.new-chat:hover { background: var(--border); }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; cursor: pointer; }
.ghost:hover { color: var(--text); }

#chat-list { flex: 1; overflow-y: auto; padding: 6px; overscroll-behavior: contain; }
.group-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 12px 8px 4px; cursor: pointer; user-select: none; display: flex; align-items: center; gap: 4px; }
.group-label::before { content: "▾"; color: var(--muted); font-size: 9px; }
.group.collapsed .group-label::before { content: "▸"; }
.group-label:hover { color: var(--text); }
.group.collapsed .chat-item { display: none; }
.search-row { padding: 6px 12px 2px; }
#chat-search { width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
#chat-search:focus { outline: none; border-color: var(--accent); }
.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 13px;
  padding: 5px 8px;
  margin-bottom: 1px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.chat-item > span { overflow: hidden; text-overflow: ellipsis; }
.chat-item:hover, .chat-item:focus-visible { background: var(--panel-2); outline: none; }
.chat-item.active { background: var(--chat-bubble, var(--active-bg)); color: var(--chat-bubble-text, var(--active-text)); box-shadow: inset 0 0 0 1px var(--chat-border, var(--border)); }
.chat-del { background: none; border: 0; color: inherit; cursor: pointer; padding: 0 2px; opacity: 0; flex: none; }
.chat-item:hover .chat-del, .chat-item.active .chat-del, .chat-del:focus-visible { opacity: .7; }
.chat-del:hover { opacity: 1; }
.sort-row { display: flex; align-items: center; gap: 10px; padding: 6px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.sort-label { text-transform: uppercase; letter-spacing: .05em; }
.segmented { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; }
.seg { position: relative; cursor: pointer; padding: 3px 12px; border-radius: 6px; font-size: 12px; color: var(--muted); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg:hover { color: var(--text); }
.seg:has(input:checked) { background: var(--bg); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--border); }
/* hidden by default so non-admins never see it (not even a flash on load);
   shown only for the admin account via JS */
#admin-link { display: none; font-size: 12px; color: var(--muted); text-decoration: none; }
#admin-link:hover { color: var(--text); }
.footer-link { background: none; border: 0; color: var(--muted); font-size: 12px; cursor: pointer; padding: 2px 0; }
.footer-link:hover { color: var(--text); }
.chat-item.editing { background: var(--panel-2); padding: 2px; }
.title-edit { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--accent); color: var(--text); border-radius: 6px; padding: 4px 6px; font-size: 13px; }
.regen { flex: none; background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 15px; padding: 0 4px; }
.regen:hover { color: var(--text); }
.regen:disabled { opacity: .4; cursor: not-allowed; }

/* ── Chat area ───────────────────────────── */
#chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--panel); border: 2px solid color-mix(in srgb, var(--chat-border, var(--border)) 60%, var(--border)); border-radius: 12px; overflow: hidden; /* layered, chat-tinted drop shadow for depth on the page */ box-shadow: 0 1px 2px rgba(var(--chat-shadow-rgb), .12), 0 4px 10px -1px rgba(var(--chat-shadow-rgb), .10), 0 16px 32px -12px rgba(var(--chat-shadow-rgb), .07); }
#messages { flex: 1; overflow-y: auto; padding: 24px 20px; background-color: var(--chat-bg, var(--bg)); background-image: var(--noise); background-size: 160px 160px; overscroll-behavior: contain; }
.chat-title { font-size: 20px; font-weight: 700; margin: 0 0 18px; }

.chat-title-wrap { margin: 4px 0 18px; }
.chat-title-row { display: flex; align-items: center; gap: 8px; margin: 0; }
.chat-date { font-size: 12px; color: var(--chat-muted, var(--muted)); text-align: center; margin-top: 6px; }
.chat-title-input { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; color: var(--chat-bubble-text, var(--text)); font-size: 20px; font-weight: 600; border-radius: 8px; padding: 4px 8px; }
.chat-title-input:hover { border-color: var(--border); }
.chat-title-input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.chat-regen { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; opacity: 0; padding: 4px; }
.chat-title-row:hover .chat-regen, .chat-regen:focus-visible, .chat-title-input:focus + .chat-regen { opacity: 1; }
.chat-regen:hover { color: var(--accent); }

.msg { display: flex; margin-bottom: 18px; }
.msg .bubble { max-width: 78%; padding: 10px 14px 6px; border-radius: 12px; white-space: normal; overflow-wrap: anywhere; border: 1px solid var(--chat-border, transparent); box-shadow: 0 1px 2px rgba(var(--chat-shadow-rgb), .08), 0 3px 6px -1px rgba(var(--chat-shadow-rgb), .06), 0 8px 14px -4px rgba(var(--chat-shadow-rgb), .05); }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--chat-bubble, var(--user-bubble)); color: var(--chat-bubble-text, var(--text)); }
.msg.assistant { justify-content: flex-start; }
.msg.assistant .bubble { background: var(--chat-bubble, var(--bubble)); color: var(--chat-bubble-text, var(--text)); }
.msg .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--chat-muted, var(--muted)); margin-bottom: 6px; }
.msg-actions { display: inline-flex; align-items: center; gap: 8px; opacity: 0; transition: opacity .12s; }
.msg:hover .msg-actions, .msg.selected .msg-actions { opacity: 1; }
.msg-actions button { background: none; border: 0; color: var(--chat-muted, var(--muted)); cursor: pointer; padding: 0; font-size: 24px; line-height: 1; }
.msg-actions button:hover { color: var(--chat-bubble-text, var(--text)); }
.copied { font-size: 11px; color: var(--chat-accent, var(--accent)); margin-right: 2px; }

/* version pager for multi-fork conversations: a slim bar sandwiched between
   the message pane and the composer, shown only when a lineage has >1 version */
#version-bar {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--composer-bg, var(--panel));
  border-top: 1px solid var(--chat-border, var(--border));
}
#version-bar:not(:empty) { display: flex; }
.vp-btn { background: none; border: 0; color: var(--chat-accent, var(--accent)); font-size: 14px; cursor: pointer; padding: 2px 8px; }
.vp-btn:hover:not(:disabled) { color: var(--text); }
.vp-btn:disabled { opacity: .35; cursor: default; }
.vp-label { font-size: 12px; color: var(--chat-muted, var(--muted)); white-space: nowrap; }

/* editing a user message: the target turn gets a dashed border and every
   later turn is muted to show it will be replaced when re-submitted */
.msg.editing .bubble { border: 2px dashed var(--chat-accent, var(--accent)); }
.msg.muted { opacity: .4; filter: grayscale(.7); }
#composer.editing #input { border-color: var(--chat-accent, var(--accent)); }
/* while a message is being edited: show cancel in place of edit in its actions */
.msg-actions .cancelmsg { display: none; }
.msg.editing .cancelmsg { display: inline-block; }
.msg.editing .editmsg { display: none; }
/* composer cancel button, only visible while editing; given the same solid
   colourful treatment as Send so the two actions sit together */
/* Cancel is a compact circular ✕ keeping the previous Send look (bubble
   background, normal text); only the Send/Send edit button uses the inverted
   solid colourful fill */
#cancel-edit { display: none; width: 46px; min-width: 46px; height: 46px; padding: 0; background: var(--chat-bubble, var(--accent)); border: 1px solid var(--chat-border, var(--border)); color: var(--chat-bubble-text, var(--text)); border-radius: 12px; cursor: pointer; font-size: 18px; line-height: 1; align-items: center; justify-content: center; }
#cancel-edit:hover:not(:disabled) { filter: brightness(1.08); }
#composer.editing #cancel-edit { display: inline-flex; }

/* muted title notice injected at the start of a conversation */
.msg.system { justify-content: center; }
.title-notice { font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 4px 12px; max-width: 80%; text-align: center; }

/* reasoning: muted, smaller, expanded by default, separated by an hr */
.reasoning { font-size: 12.5px; color: var(--chat-muted, var(--muted)); }
.reasoning summary { cursor: pointer; font-style: italic; font-size: 12px; }
.reasoning-body { margin-top: 6px; }
.reasoning-body p { margin: 4px 0; }
.reasoning-body pre, .reasoning-body code { font-size: 12px; }
.reason-hr { border: 0; border-top: 1px solid var(--chat-border, var(--border)); margin: 10px 0; }
.content { white-space: pre-wrap; }

/* markdown */
.bubble pre { background: var(--chat-code-bg, var(--code-bg)); padding: 10px; border-radius: 8px; overflow-x: auto; }
.bubble code { background: var(--chat-code-bg, var(--code-bg)); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble pre code { padding: 0; background: none; }
.bubble a { color: var(--chat-accent, var(--accent)); }
.bubble hr { border: 0; border-top: 1px solid var(--chat-border, var(--border)); margin: 10px 0; }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 24px; }
.bubble li { margin: 2px 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 { font-weight: 600; line-height: 1.3; margin: 12px 0 6px; color: var(--chat-bubble-text, var(--text)); }
.bubble h1 { font-size: 1.3em; }
.bubble h2 { font-size: 1.16em; }
.bubble h3 { font-size: 1.07em; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 1em; }
.bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  /* make wide tables scroll horizontally inside the bubble instead of
     blowing the bubble past the viewport */
  display: block;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
  min-width: 2em;
  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;
}
.bubble th { background: color-mix(in srgb, var(--chat-bubble, var(--panel-2)) 88%, var(--border)); color: var(--chat-bubble-text, var(--text)); font-weight: 600; }

/* copy buttons on code blocks / tables / inline code */
.copy-wrap { position: relative; }
.copy-block { position: absolute; top: 6px; right: 6px; z-index: 2; background: var(--chat-code-bg, #0b0d11); color: var(--chat-muted, var(--muted)); border: 1px solid var(--chat-border, var(--border)); border-radius: 6px; padding: 1px 7px; font-size: 12px; line-height: 1.4; cursor: pointer; opacity: 0; transition: opacity .12s; }
.copy-wrap:hover .copy-block, .copy-block:focus-visible { opacity: 1; }
.copy-inline { display: inline-block; background: none; border: 0; color: var(--chat-muted, var(--muted)); font-size: 10px; line-height: 1; cursor: pointer; padding: 0 2px; opacity: 0; vertical-align: middle; transition: opacity .12s; }
.bubble code:hover + .copy-inline, .copy-inline:hover, .copy-inline:focus-visible { opacity: 1; }

/* ── Composer ────────────────────────────── */
#composer { position: relative; z-index: 1; display: flex; gap: 10px; padding: 14px; background: var(--composer-bg, var(--panel)); border-top: 1px solid var(--chat-border, var(--border)); /* gentle, wide, chat-tinted layered shadow cast up over the messages */
  box-shadow:
    0 -1px 2px rgba(var(--chat-shadow-rgb), .09),
    0 -3px 6px -1px rgba(var(--chat-shadow-rgb), .07),
    0 -9px 16px -4px rgba(var(--chat-shadow-rgb), .05),
    0 -24px 40px -12px rgba(var(--chat-shadow-rgb), .03);
}
#menu { display: none; background: var(--chat-bubble, var(--panel-2)); border: 1px solid var(--chat-border, var(--border)); color: var(--chat-bubble-text, var(--text)); border-radius: 10px; padding: 0 14px; font-size: 18px; cursor: pointer; align-items: center; justify-content: center; line-height: 1; }
#input { flex: 1; resize: none; background: var(--chat-bubble, var(--panel-2)); border: 1px solid var(--chat-border, var(--border)); color: var(--chat-bubble-text, var(--text)); border-radius: 10px; padding: 10px 12px; min-height: 80px; max-height: 200px; font-size: 15px; box-shadow: 0 1px 2px rgba(var(--chat-shadow-rgb), .07), 0 3px 8px -2px rgba(var(--chat-shadow-rgb), .05); }
#input::placeholder { color: var(--chat-muted, var(--muted)); opacity: 1; }
#input:focus { outline: none; border-color: var(--chat-border, var(--accent)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--chat-border, var(--accent)) 30%, transparent); }
#send { background: var(--chat-bubble, var(--accent)); border: 1px solid var(--chat-border, var(--border)); color: var(--chat-bubble-text, var(--text)); border-radius: 10px; padding: 0 18px; height: 46px; cursor: pointer; font-weight: 600; font-size: 15px; box-shadow: 0 1px 2px rgba(var(--chat-shadow-rgb), .10), 0 3px 6px -1px rgba(var(--chat-shadow-rgb), .08); }
/* colourful users get the inverted solid fill (background = border colour, text = the bubble colour) */
html.colorful #send { background: var(--chat-border, var(--accent)); color: var(--chat-bubble, var(--text)); }
#send:hover:not(:disabled) { filter: brightness(1.08); }
#send:disabled { opacity: .5; cursor: not-allowed; }
/* the Send/Cancel/New-chat buttons group, stacked into a column on narrow screens */
.composer-actions { display: flex; align-items: center; gap: 8px; }
#composer-new { width: 46px; min-width: 46px; height: 46px; padding: 0; background: var(--chat-bubble, var(--accent)); border: 1px solid var(--chat-border, var(--border)); color: var(--chat-bubble-text, var(--text)); border-radius: 12px; cursor: pointer; font-size: 24px; line-height: 1; align-items: center; justify-content: center; }
#composer-new:hover:not(:disabled) { filter: brightness(1.08); }

/* ── System prompt / memories modal ─────── */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card { width: 540px; max-width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 24px; color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.4); }
.modal-card h2 { margin: 0 0 8px; font-size: 20px; }
.modal-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
#prompt-input { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 12px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; box-sizing: border-box; }
#prompt-input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-actions button { border: 0; padding: 10px 18px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; }
#prompt-save { background: var(--accent); color: #fff; }
#prompt-save:hover:not(:disabled) { filter: brightness(1.1); }
#prompt-cancel { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
#prompt-result { min-height: 1.2em; margin-top: 10px; font-size: 13px; color: var(--muted); }
#prompt-result.err { color: #e5484d; }
#prompt-result.ok { color: #46a758; }

/* ── Login ──────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; }
.auth-card {
  background: var(--chat-bubble, var(--panel));
  border: 1px solid var(--chat-border, var(--border));
  border-radius: 14px;
  padding: 32px;
  width: 340px;
  color: var(--chat-bubble-text, var(--text));
  box-shadow:
    0 1px 2px rgba(var(--chat-shadow-rgb), .10),
    0 3px 6px -1px rgba(var(--chat-shadow-rgb), .08),
    0 8px 14px -4px rgba(var(--chat-shadow-rgb), .06),
    0 20px 32px -12px rgba(var(--chat-shadow-rgb), .05);
}
.auth-card h1 { margin: 0 0 22px; font-size: 28px; font-weight: 700; color: var(--chat-bubble-text, var(--text)); }
.auth-error {
  background: color-mix(in srgb, var(--chat-accent, var(--accent)) 18%, transparent);
  color: var(--chat-bubble-text, var(--text));
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-form input {
  /* Keep the bubble's colour: tint over the (transparent) card so the hue
     shows through, just a touch lighter than the bubble. Dark mode stays a
     dark, coloured fill rather than a bright pale one. */
  background: color-mix(in srgb, var(--chat-bubble-text, var(--text)) 13%, transparent);
  border: 1px solid var(--chat-border, var(--border));
  color: var(--chat-bubble-text, var(--text));
  border-radius: 8px;
  padding: 10px 12px;
}
@media (prefers-color-scheme: light) {
  .auth-form input {
    background: color-mix(in srgb, var(--chat-bubble-text, var(--text)) 6%, transparent);
  }
}
.auth-form input::placeholder { color: var(--chat-muted, var(--muted)); }
.auth-form input:focus { outline: none; border-color: var(--chat-accent, var(--accent)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--chat-border, var(--accent)) 30%, transparent); }
.auth-form button {
  margin-top: 12px;
  background: var(--chat-accent, var(--accent));
  border: 1px solid var(--chat-border, var(--border));
  color: var(--chat-btn-text, var(--chat-bubble-text));
  padding: 11px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.auth-form button:hover { box-shadow: inset 0 0 0 100px rgba(0,0,0,.06); }

@media (max-width: 768px) {
  #app { padding: 0; gap: 0; }
  #sidebar {
    width: 240px;
    margin: 0;
    border-radius: 0;
  }
  #chat-area { border-radius: 0; border: 0; }
  #menu { display: inline-flex; }
  /* tighter chat pane but not edge-to-edge flush */
  #messages { padding: 12px 10px; }
  .msg { margin-bottom: 14px; }
  /* bubbles nearly full width, still pinned to their own side */
  .msg .bubble { max-width: 95%; }
  /* composer: tuck in, respect the home-indicator safe area, never overflow */
  #composer { padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); gap: 8px; }
  #input { font-size: 16px; } /* >=16px stops iOS auto-zoom on focus */
  /* compact circular up-arrow send to save width */
  #send { width: 46px; min-width: 46px; height: 46px; padding: 0; font-size: 0; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
  #send::after { content: "\2191"; font-size: 22px; line-height: 1; }
  .composer-actions { flex-direction: column; justify-content: center; gap: 6px; }
  .composer-actions #send { order: 1; }
  .composer-actions #composer-new { order: 2; }
  .composer-actions #cancel-edit { order: 3; }
  /* compact hamburger, hidden while the composer input is focused so the input
     gets the full width for typing; hidden entirely on touch screens where the
     left-edge swipe opens the sidebar instead */
  #menu { width: 46px; min-width: 46px; height: 46px; padding: 0; align-items: center; justify-content: center; }
  body.input-focus #menu { display: none; }
  body.touch #menu { display: none; }
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  body.sidebar-open #sidebar { transform: translateX(0); box-shadow: 0 0 30px rgba(0,0,0,.4); }
}


/* ── Superellipse corners (Blink) ────────────────────────
   Blink-based browsers support `corner-shape` with a `superellipse()` exponent;
   `border-radius` still supplies the size. Non-supporting browsers keep the
   plain border-radius above, so this is purely additive. */
@supports (corner-shape: superellipse(1)) {
  #sidebar, #chat-area, .msg .bubble, .title-notice, .auth-card,
  .new-chat, .ghost, #chat-search, .segmented, .seg, .title-edit,
  .chat-title-input, .bubble pre, .bubble code, .copy-block,
  #menu, #cancel-edit, #composer-new, #input, #send, .auth-error, .auth-form input, .auth-form button {
    corner-shape: superellipse(0.5);
  }
}
