  :root {
    --bg-base:     #0C0C0F;
    --bg-surface:  #141418;
    --bg-elevated: #1A1A20;
    --bg-overlay:  #1E1E26;
    --bg-sheet:    #17171D;
    --bg-sidebar:  #0F0F13;
    --accent:      #4A9EFF;
    --accent-dim:  rgba(74, 158, 255, .13);
    --accent-glow: rgba(74, 158, 255, .07);
    --text-primary:   #DCDCDC;
    --text-secondary: #888896;
    --text-muted:     #48484E;
    --border:         rgba(255, 255, 255, .06);
    --border-accent:  rgba(74, 158, 255, .22);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --font-sans: 'Syne', sans-serif;
    --font-mono: 'DM Mono', monospace;
    --tr: .22s cubic-bezier(.4, 0, .2, 1);
  
    --app-max-width: 480px;
    --sidebar-width: 288px;
    --chat-padding-x: 16px;
    --input-padding-x: 14px;
  }
  
  @media (min-width: 768px) {
    :root {
      --app-max-width: 720px;
      --sidebar-width: 300px;
      --chat-padding-x: 28px;
      --input-padding-x: 20px;
    }
  }
  
  @media (min-width: 1024px) {
    :root {
      --app-max-width: 820px;
      --sidebar-width: 320px;
      --chat-padding-x: 40px;
      --input-padding-x: 28px;
    }
  }
  
  @media (min-width: 1280px) {
    :root {
      --app-max-width: 900px;
      --sidebar-width: 340px;
    }
  }
  
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  html, body {
    height: 100%;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
  }
  
  body {
    display: flex;
    justify-content: center;
    align-items: stretch;
  }
  
  #app {
    width: 100%;
    max-width: var(--app-max-width);
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-base);
    overflow: hidden;
    transition: max-width var(--tr);
  }
  
  
  /* Modal */
  
  @keyframes oIn {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
  
  @keyframes modalIn {
    from { opacity: 0; transform: scale(.94) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
  }
  
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .75);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(10px);
    animation: oIn .2s ease;
  }
  
  .modal-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .7);
    animation: modalIn .22s cubic-bezier(.34, 1.2, .64, 1);
    max-height: 90vh;
    overflow-y: auto;
    scrollbar-width: thin;
  }
  
  @media (min-width: 768px) {
    .modal-card {
      max-width: 480px;
      padding: 32px;
    }
  }
  
  .modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -.02em;
  }
  
  @media (min-width: 768px) {
    .modal-title { font-size: 18px; }
  }
  
  .modal-sub {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    margin-bottom: 20px;
    line-height: 1.6;
  }
  
  .modal-label {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    margin-bottom: 5px;
    display: block;
    text-transform: uppercase;
    letter-spacing: .07em;
  }
  
  .modal-row2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  
  .modal-input {
    width: 100%;
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 13px;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--tr);
    margin-bottom: 14px;
  }
  
  @media (min-width: 768px) {
    .modal-input { font-size: 14px; padding: 12px 15px; }
  }
  
  .modal-input:focus         { border-color: var(--border-accent); }
  .modal-input::placeholder  { color: var(--text-muted); }
  
  .modal-api-hint {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    margin-top: 5px;
    margin-bottom: 16px;
    line-height: 1.5;
  }
  
  .modal-api-hint a       { color: var(--accent); text-decoration: none; }
  .modal-api-hint a:hover { text-decoration: underline; }
  
  .modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 4px;
  }
  
  .modal-btn {
    padding: 9px 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 13px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--tr);
  }
  
  @media (min-width: 768px) {
    .modal-btn { padding: 10px 24px; font-size: 14px; }
  }
  
  .modal-btn.cancel {
    background: var(--bg-overlay);
    color: var(--text-secondary);
    border: 1px solid var(--border);
  }
  
  .modal-btn.cancel:hover   { color: var(--text-primary); }
  
  .modal-btn.confirm {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
  }
  
  .modal-btn.confirm:hover  { box-shadow: 0 0 16px rgba(74, 158, 255, .4); }
  
  .modal-btn.danger-btn {
    background: rgba(255, 107, 107, .15);
    color: #FF6B6B;
    border: 1px solid rgba(255, 107, 107, .2);
  }
  
  .modal-btn.danger-btn:hover { background: rgba(255, 107, 107, .25); }
  
  
  /* Sidebar */
  
  @keyframes sbIn {
    from { transform: translateX(-100%); }
    to   { transform: translateX(0); }
  }
  
  .sb-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    z-index: 40;
    backdrop-filter: blur(4px);
    animation: oIn .2s ease;
  }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    z-index: 41;
    display: flex;
    flex-direction: column;
    animation: sbIn .26s cubic-bezier(.34, 1.1, .64, 1);
    overflow: hidden;
  }
  
  .sb-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 14px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  
  @media (min-width: 768px) {
    .sb-head { padding: 18px 16px 14px; }
  }
  
  .sb-search {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 7px 12px;
    transition: border-color var(--tr);
  }
  
  .sb-search:focus-within { border-color: var(--border-accent); }
  
  .sb-search i {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
  }
  
  .sb-search input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
  }
  
  .sb-search input::placeholder { color: var(--text-muted); }
  
  .sb-new-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all var(--tr);
    flex-shrink: 0;
  }
  
  .sb-new-btn:hover {
    color: var(--accent);
    border-color: var(--border-accent);
    background: var(--accent-glow);
  }
  
  .sb-menu {
    padding: 10px 10px 0;
    flex-shrink: 0;
  }
  
  .sb-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--tr);
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: var(--font-sans);
  }
  
  .sb-menu-item:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
  }
  
  .sb-menu-item i {
    width: 16px;
    font-size: 12px;
    opacity: .7;
  }
  
  .sb-hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 10px 14px 8px;
  }
  
  .sb-hist-label {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 0 14px 8px;
  }
  
  .sb-hist {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-overlay) transparent;
  }
  
  .sb-hist::-webkit-scrollbar       { width: 3px; }
  .sb-hist::-webkit-scrollbar-thumb { background: var(--bg-overlay); border-radius: 99px; }
  
  .sb-hist-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--tr);
    position: relative;
  }
  
  .sb-hist-item:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
  }
  
  .sb-hist-item.active {
    color: var(--text-primary);
    background: var(--accent-dim);
  }
  
  .hi-pin  { font-size: 9px; color: var(--accent); opacity: .7; flex-shrink: 0; }
  .hi-icon { font-size: 10px; opacity: .5; flex-shrink: 0; }
  
  .hi-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .hi-time {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    flex-shrink: 0;
  }
  
  .hi-actions {
    display: none;
    gap: 2px;
    align-items: center;
  }
  
  .sb-hist-item:hover .hi-actions { display: flex; }
  
  /* Touch device: always show actions */
  @media (hover: none) {
    .hi-actions { display: flex; }
    .hi-time    { display: none; }
  }
  
  .hi-act-btn {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    transition: all var(--tr);
  }
  
  .hi-act-btn:hover {
    color: var(--accent);
    background: var(--accent-glow);
  }
  
  .sb-empty-hist {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 20px;
    text-align: center;
    gap: 12px;
  }
  
  .em-title { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
  .em-sub   { font-size: 11px; font-family: var(--font-mono); color: var(--text-muted); line-height: 1.6; }
  
  .sb-bottom {
    padding: 12px 10px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    flex-shrink: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  
  .sb-account {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--tr);
  }
  
  .sb-account:hover { background: var(--bg-elevated); }
  
  .sb-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #0060CC);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    text-transform: uppercase;
  }
  
  @media (min-width: 768px) {
    .sb-avatar { width: 34px; height: 34px; font-size: 12px; }
  }
  
  .sb-acct-info  { flex: 1; min-width: 0; }
  
  .sb-acct-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .sb-acct-sub {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
  }
  
  .sb-reset-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
    transition: all var(--tr);
    flex-shrink: 0;
  }
  
  .sb-reset-btn:hover { color: #FF6B6B; }
  
  
  /* Top bar */
  
  .top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    pointer-events: none;
  }
  
  @media (min-width: 768px) {
    .top-bar { padding: 18px 24px; }
  }
  
  .top-bar > * { pointer-events: all; }
  
  .btn-hamburger {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: rgba(18, 18, 22, .92);
    backdrop-filter: blur(18px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    transition: all var(--tr);
  }
  
  .btn-hamburger:hover {
    color: var(--text-primary);
    border-color: var(--border-accent);
  }
  
  .pill-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    background: rgba(18, 18, 22, .92);
    backdrop-filter: blur(18px);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 5px 6px 5px 12px;
    position: relative;
  }
  
  .pill-nav.incognito {
    border-color: rgba(255, 200, 74, .3);
    background: rgba(18, 15, 6, .92);
  }
  
  .pill-incognito-icon {
    font-size: 12px;
    color: #FFC84A;
    padding: 4px 8px 4px 2px;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  
  .pill-incognito-label { font-size: 11px; color: #FFC84A; font-weight: 500; }
  
  .pill-lock-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFC84A;
    font-size: 14px;
    cursor: pointer;
  }
  
  .pill-new-chat {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 6px 4px 2px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color var(--tr);
    font-family: var(--font-sans);
  }
  
  .pill-new-chat:hover { color: var(--text-primary); }
  
  .pill-div {
    width: 1px;
    height: 14px;
    background: var(--border);
    margin: 0 4px;
  }
  
  .pill-kebab {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all var(--tr);
  }
  
  .pill-kebab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, .05);
  }
  
  @keyframes ddIn {
    from { opacity: 0; transform: scale(.9) translateY(-6px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
  }
  
  .kebab-dd {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    min-width: 186px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .65);
    transform-origin: top right;
    animation: ddIn .17s cubic-bezier(.34, 1.56, .64, 1);
    z-index: 30;
  }
  
  .kitem {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--tr);
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: var(--font-sans);
  }
  
  @media (min-width: 768px) {
    .kitem { padding: 11px 16px; font-size: 14px; }
  }
  
  .kitem:hover {
    color: var(--text-primary);
    background: var(--bg-overlay);
  }
  
  .kitem.danger       { color: #FF6B6B; }
  .kitem.danger:hover { background: rgba(255, 107, 107, .07); }
  
  .kitem i {
    width: 14px;
    font-size: 12px;
    opacity: .75;
  }
  
  
  /* Chat area */
  
  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  
  @keyframes msgIn {
    from { opacity: 0; transform: translateY(8px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
  }
  
  .chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 78px var(--chat-padding-x) 8px;
    display: flex;
    flex-direction: column;
    gap: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-overlay) transparent;
  }
  
  @media (min-width: 768px) {
    .chat-area { padding-top: 90px; }
  }
  
  .chat-area::-webkit-scrollbar       { width: 3px; }
  .chat-area::-webkit-scrollbar-thumb { background: var(--bg-overlay); border-radius: 99px; }
  
  .chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 40px 20px;
    text-align: center;
    animation: fadeUp .5s ease;
  }
  
  @media (min-width: 768px) {
    .chat-empty { gap: 18px; padding: 60px 40px; }
  }
  
  .empty-icon  { width: 50px; height: 50px; opacity: .35; }
  
  @media (min-width: 768px) {
    .empty-icon { width: 60px; height: 60px; }
  }
  
  .empty-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -.02em;
  }
  
  @media (min-width: 768px) {
    .empty-title { font-size: 28px; }
  }
  
  .empty-sub {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    line-height: 1.7;
    max-width: 240px;
  }
  
  @media (min-width: 768px) {
    .empty-sub { font-size: 13px; max-width: 320px; }
  }
  
  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    justify-content: center;
    margin-top: 6px;
  }
  
  .chip {
    padding: 6px 13px;
    border-radius: 99px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 11px;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all var(--tr);
    white-space: nowrap;
  }
  
  @media (min-width: 768px) {
    .chip { font-size: 12px; padding: 7px 15px; }
  }
  
  .chip:hover {
    border-color: var(--border-accent);
    color: var(--accent);
    background: var(--accent-glow);
  }
  
  .msg-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 14px;
    animation: msgIn .27s cubic-bezier(.34, 1.56, .64, 1);
  }
  
  .msg-row.user { align-items: flex-end; }
  .msg-row.ai   { align-items: flex-start; }
  
  .msg-bubble {
    max-width: 84%;
    padding: 11px 14px;
    border-radius: var(--radius-lg);
    line-height: 1.65;
    font-size: 14px;
    position: relative;
    word-break: break-word;
  }
  
  @media (min-width: 768px) {
    .msg-bubble {
      max-width: 78%;
      padding: 13px 18px;
      font-size: 15px;
    }
  }
  
  @media (min-width: 1024px) {
    .msg-bubble { max-width: 72%; }
  }
  
  .msg-row.user .msg-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
    display: inline-block;
    align-self: flex-end;
    min-width: 0;
    width: fit-content;
  }
  
  .msg-row.ai .msg-bubble {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    max-width: 96%;
  }
  
  @media (min-width: 768px) {
    .msg-row.ai .msg-bubble { max-width: 90%; }
  }
  
  .msg-bubble img.att-img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin-top: 0;
    display: block;
  }
  
  .msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 3px;
  }
  
  .msg-time {
    font-size: 10px;
    color: var(--text-muted);
    font-family: var(--font-mono);
  }
  
  .msg-tools {
    display: flex;
    gap: 1px;
    opacity: 0;
    transition: opacity var(--tr);
  }
  
  .msg-row:hover .msg-tools { opacity: 1; }
  
  /* Touch: always visible */
  @media (hover: none) {
    .msg-tools { opacity: 1; }
  }
  
  .tool-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 11px;
    transition: all var(--tr);
  }
  
  /* Bigger tap target on touch */
  @media (hover: none) {
    .tool-btn { width: 34px; height: 34px; font-size: 13px; }
  }
  
  .tool-btn:hover {
    color: var(--accent);
    background: var(--accent-glow);
  }
  
  .ai-text { animation: fadeUp .3s ease forwards; }
  
  .ai-text strong  { color: #7EC8FF; font-weight: 600; }
  .ai-text em      { color: var(--text-secondary); font-style: italic; }
  .ai-text del     { opacity: .45; text-decoration: line-through; }
  .ai-text ul      { padding-left: 20px; margin: 6px 0; list-style: disc; }
  .ai-text ol      { padding-left: 20px; margin: 6px 0; list-style: decimal; }
  .ai-text li      { margin: 3px 0; padding-left: 6px; line-height: 1.6; }
  
  .ai-text h1, .ai-text h2, .ai-text h3 {
    font-family: var(--font-sans);
    font-weight: 600;
    margin: 14px 0 6px;
    color: var(--text-primary);
    letter-spacing: -.01em;
  }
  
  .ai-text h1 { font-size: 18px; }
  .ai-text h2 { font-size: 16px; }
  .ai-text h3 { font-size: 14px; color: var(--text-secondary); }
  
  @media (min-width: 768px) {
    .ai-text h1 { font-size: 20px; }
    .ai-text h2 { font-size: 17px; }
    .ai-text h3 { font-size: 15px; }
  }
  
  .ai-text blockquote {
    border-left: 2px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
    font-style: italic;
  }
  
  .ai-text a  { color: var(--accent); text-decoration: underline; }
  .ai-text p  { margin: 5px 0; line-height: 1.7; }
  .ai-text hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
  
  .ai-text code {
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--bg-overlay);
    padding: 2px 6px;
    border-radius: 4px;
    color: #A8D4FF;
    border: 1px solid rgba(74, 158, 255, .13);
  }
  
  .ai-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
    overflow-x: auto;
    display: block;
    -webkit-overflow-scrolling: touch;
  }
  
  .ai-text th {
    background: var(--bg-overlay);
    color: var(--text-secondary);
    padding: 8px 10px;
    text-align: left;
    border: 1px solid var(--border);
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: nowrap;
  }
  
  .ai-text td {
    padding: 7px 10px;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: top;
    line-height: 1.5;
  }
  
  .ai-text tr:nth-child(even) td { background: rgba(255, 255, 255, .02); }
  
  
  /* Artifact block */
  
  .artifact-block {
    background: #0D1117;
    border: 1px solid rgba(74, 158, 255, .14);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin: 10px 0;
    font-size: 13px;
  }
  
  .artifact-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    background: rgba(255, 255, 255, .025);
    border-bottom: 1px solid rgba(255, 255, 255, .05);
    gap: 8px;
  }
  
  .artifact-head-left {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    flex: 1;
  }
  
  .artifact-lang-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .artifact-lang-icon img,
  .artifact-lang-icon svg {
    width: 16px;
    height: 16px;
    object-fit: contain;
  }
  
  .artifact-fname {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .artifact-type-badge {
    font-size: 9px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 1px 7px;
    border-radius: 99px;
    text-transform: uppercase;
    flex-shrink: 0;
  }
  
  .artifact-head-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }
  
  .artifact-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 11px;
    transition: all var(--tr);
  }
  
  /* Bigger tap targets on touch */
  @media (hover: none) {
    .artifact-btn { width: 34px; height: 34px; font-size: 13px; }
  }
  
  .artifact-btn:hover {
    color: var(--accent);
    background: var(--accent-glow);
  }
  
  .artifact-code-wrap {
    overflow: hidden;
    position: relative;
  }
  
  .artifact-code-wrap.collapsed { max-height: 130px; }
  
  .artifact-code-wrap.collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 52px;
    background: linear-gradient(to top, #0D1117, transparent);
    pointer-events: none;
  }
  
  .artifact-code-wrap pre {
    margin: 0;
    padding: 14px;
    overflow-x: auto;
    background: transparent;
    -webkit-overflow-scrolling: touch;
  }
  
  .artifact-code-wrap pre code {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    background: none;
    border: none;
    padding: 0;
    color: inherit;
  }
  
  @media (min-width: 768px) {
    .artifact-code-wrap pre code { font-size: 13px; }
  }
  
  .artifact-expand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid rgba(255, 255, 255, .05);
    cursor: pointer;
    transition: background var(--tr);
  }
  
  .artifact-expand:hover         { background: rgba(255, 255, 255, .02); }
  .artifact-expand span          { font-size: 11px; font-family: var(--font-mono); color: var(--text-muted); }
  .artifact-expand i             { font-size: 10px; color: var(--text-muted); transition: transform var(--tr); }
  
  @keyframes artifactPulse {
    0%, 100% { opacity: .5; }
    50%       { opacity: 1; }
  }
  
  .artifact-lottie-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 28px 16px;
    background: #0D1117;
    border: 1px solid rgba(74, 158, 255, .14);
    border-radius: var(--radius-md);
    margin: 10px 0;
    animation: artifactPulse 1.4s ease-in-out infinite;
  }
  
  .artifact-lottie-spinner svg  { width: 32px; height: 32px; flex-shrink: 0; }
  
  .artifact-lottie-spinner span {
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-muted);
  }
  
  /* Artifact edit mode */
  .artifact-edit-area {
    background: #0D1117;
    border-top: 1px solid rgba(255, 255, 255, .06);
  }
  
  .artifact-edit-ta {
    width: 100%;
    min-height: 180px;
    max-height: 420px;
    background: transparent;
    border: none;
    outline: none;
    padding: 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    color: #cdd6f4;
    resize: vertical;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }
  
  @media (min-width: 768px) {
    .artifact-edit-ta { font-size: 13px; min-height: 220px; }
  }
  
  .artifact-edit-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid rgba(255, 255, 255, .05);
  }
  
  .artifact-edit-save {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 11px;
    font-family: var(--font-sans);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--tr);
  }
  
  .artifact-edit-save:hover { box-shadow: 0 0 14px rgba(74, 158, 255, .4); }
  
  .artifact-edit-cancel {
    padding: 7px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 11px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--tr);
  }
  
  .artifact-edit-cancel:hover { color: var(--text-primary); border-color: var(--border-accent); }
  
  
  /* File viewer block */
  .file-viewer-block {
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 8px;
  }
  
  .file-viewer-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    background: rgba(255, 255, 255, .025);
    cursor: pointer;
  }
  
  .file-viewer-name {
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .file-viewer-size {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    flex-shrink: 0;
  }
  
  .file-viewer-toggle {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color var(--tr);
  }
  
  .file-viewer-toggle:hover { color: var(--accent); }
  
  .file-viewer-body { border-top: 1px solid var(--border); }
  
  .file-viewer-text {
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 260px;
    overflow-y: auto;
    scrollbar-width: thin;
    background: #0D1117;
    -webkit-overflow-scrolling: touch;
  }
  
  @media (min-width: 768px) {
    .file-viewer-text { max-height: 360px; font-size: 12px; }
  }
  
  .file-viewer-pdf { width: 100%; height: 300px; background: #fff; }
  
  @media (min-width: 768px) {
    .file-viewer-pdf { height: 480px; }
  }
  
  .pdf-embed { width: 100%; height: 100%; display: block; border: none; }
  
  
  /* URL preview */
  
  .url-preview-block {
    background: var(--bg-elevated);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin: 8px 0;
  }
  
  .url-steps {
    padding: 12px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  
  .url-step            { display: flex; align-items: flex-start; gap: 8px; }
  .url-step-icon       { flex-shrink: 0; margin-top: 1px; width: 14px; }
  
  .url-step-text {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    line-height: 1.5;
  }
  
  .url-step-text b     { color: var(--text-primary); }
  .url-iframe-area     { position: relative; background: #fff; }
  .url-iframe          { width: 100%; height: 240px; border: none; display: block; }
  
  @media (min-width: 768px) {
    .url-iframe { height: 380px; }
  }
  
  .url-iframe-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--bg-overlay);
    border-top: 1px solid var(--border);
  }
  
  .url-iframe-label {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 8px;
  }
  
  .url-fullscreen-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all var(--tr);
    flex-shrink: 0;
  }
  
  .url-fullscreen-btn:hover {
    color: var(--accent);
    border-color: var(--border-accent);
  }
  
  .url-analysis {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    border-top: 1px solid var(--border);
  }
  
  
  /* Fullscreen view */
  
  .fullscreen-view {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 100;
    display: flex;
    flex-direction: column;
    animation: oIn .18s ease;
  }
  
  .fullscreen-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(10, 10, 14, .97);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 10px;
  }
  
  @media (min-width: 768px) {
    .fullscreen-bar { padding: 10px 20px; }
  }
  
  .fullscreen-bar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
  }
  
  .fullscreen-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, .06);
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--tr);
    flex-shrink: 0;
  }
  
  .fullscreen-close:hover { background: rgba(255, 255, 255, .12); }
  
  .fullscreen-title {
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .fullscreen-bar-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }
  
  .fs-tab-group {
    display: flex;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
    margin-right: 6px;
  }
  
  .fs-tab {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--tr);
  }
  
  .fs-tab.active {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--border-accent);
  }
  
  .fs-tab:not(.active):hover { color: var(--text-primary); background: rgba(255,255,255,.04); }
  
  .fs-tab i    { font-size: 10px; }
  .fs-tab span { font-size: 11px; }
  
  /* Hide label on very small screens */
  @media (max-width: 360px) {
    .fs-tab span { display: none; }
    .fs-tab      { padding: 5px 8px; }
  }
  
  .fs-action-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--tr);
  }
  
  .fs-action-btn:hover {
    color: var(--accent);
    border-color: var(--border-accent);
    background: var(--accent-glow);
  }
  
  .fullscreen-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: #fff;
  }
  
  .fullscreen-code-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #0D1117;
  }
  
  .fs-code-textarea {
    flex: 1;
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    outline: none;
    padding: 20px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.7;
    color: #cdd6f4;
    resize: none;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-overlay) transparent;
    -webkit-overflow-scrolling: touch;
  }
  
  @media (min-width: 768px) {
    .fs-code-textarea { font-size: 14px; padding: 28px; }
  }
  
  
  /* Thinking bubble */
  
  @keyframes tdBounce {
    0%, 80%, 100% { transform: scale(.5); opacity: .3; }
    40%           { transform: scale(1.1); opacity: 1; }
  }
  
  .thinking-bubble {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    width: fit-content;
  }
  
  .tdots            { display: inline-flex; gap: 5px; }
  
  .tdots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: tdBounce 1.3s infinite ease-in-out;
  }
  
  .tdots span:nth-child(2) { animation-delay: .18s; }
  .tdots span:nth-child(3) { animation-delay: .36s; }
  
  
  /* Input bar */
  
  @keyframes pulseRec {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 74, 74, .35); }
    50%       { box-shadow: 0 0 0 8px rgba(255, 74, 74, 0); }
  }
  
  .input-bar {
    flex-shrink: 0;
    padding: 6px var(--input-padding-x) 0;
    background: linear-gradient(to top, var(--bg-base) 75%, transparent);
  }
  
  .model-row   { text-align: center; margin-bottom: 5px; }
  
  .model-badge {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    padding: 3px 10px;
    border-radius: 99px;
    border: 1px solid var(--border);
    display: inline-block;
  }
  
  .input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 10px 10px 10px 14px;
    transition: border-color var(--tr), box-shadow var(--tr);
  }
  
  @media (min-width: 768px) {
    .input-wrapper { padding: 12px 12px 12px 18px; }
  }
  
  .input-wrapper:focus-within {
    border-color: var(--border-accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
  }
  
  .input-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  
  .input-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 8px;
  }
  
  .att-prev {
    position: relative;
    display: inline-flex;
  }
  
  .att-prev img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
  }
  
  @media (min-width: 768px) {
    .att-prev img { width: 64px; height: 64px; }
  }
  
  .att-file-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    max-width: 145px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .remove-att {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .input-row {
    display: flex;
    align-items: center;
    gap: 6px;
  }
  
  .btn-attach {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 15px;
    transition: all var(--tr);
    flex-shrink: 0;
  }
  
  .btn-attach:hover { color: var(--accent); }
  
  textarea#prompt {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    min-height: 22px;
    max-height: 120px;
    overflow-y: auto;
    scrollbar-width: none;
    padding: 3px 0;
  }
  
  @media (min-width: 768px) {
    textarea#prompt { font-size: 15px; max-height: 160px; }
  }
  
  textarea#prompt::-webkit-scrollbar { display: none; }
  textarea#prompt::placeholder        { color: var(--text-muted); }
  
  .btn-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all var(--tr);
    flex-shrink: 0;
  }
  
  @media (min-width: 768px) {
    .btn-send { width: 40px; height: 40px; font-size: 15px; }
  }
  
  .btn-send.mic {
    background: var(--bg-overlay);
    color: var(--text-secondary);
    border: 1px solid var(--border);
  }
  
  .btn-send.mic:hover {
    color: var(--accent);
    border-color: var(--border-accent);
  }
  
  .btn-send.send {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 18px rgba(74, 158, 255, .28);
  }
  
  .btn-send.send:hover   { transform: scale(1.06); }
  
  .btn-send.recording {
    background: #FF4A4A;
    color: #fff;
    animation: pulseRec 1s infinite;
  }
  
  
  /* Footer */
  
  .bottom-footer {
    padding: 8px 16px 14px;
    text-align: center;
    border-top: 1px solid var(--border);
    margin-top: 4px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  
  .footer-copy {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
  }
  
  .footer-copy a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--tr);
  }
  
  .footer-copy a:hover { color: var(--accent); }
  
  
  /* Bottom sheet */
  
  @keyframes sheetUp {
    from { transform: translateX(-50%) translateY(100%); }
    to   { transform: translateX(-50%) translateY(0); }
  }
  
  .sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 50;
    backdrop-filter: blur(4px);
    animation: oIn .2s ease;
  }
  
  .bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--app-max-width);
    background: var(--bg-sheet);
    border-top-left-radius: 22px;
    border-top-right-radius: 22px;
    border-top: 1px solid var(--border);
    z-index: 51;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    animation: sheetUp .28s cubic-bezier(.34, 1.2, .64, 1);
  }
  
  @media (min-width: 768px) {
    .bottom-sheet {
      border-left: 1px solid var(--border);
      border-right: 1px solid var(--border);
    }
  }
  
  .sheet-handle {
    width: 34px;
    height: 4px;
    background: var(--border);
    border-radius: 99px;
    margin: 12px auto 18px;
  }
  
  .sheet-sec {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .09em;
    padding: 0 18px 10px;
  }
  
  .sheet-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 0 16px 16px;
  }
  
  @media (min-width: 768px) {
    .sheet-grid { gap: 14px; padding: 0 20px 20px; }
  }
  
  .sgbtn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--tr);
    font-family: var(--font-sans);
  }
  
  .sgbtn:hover {
    border-color: var(--border-accent);
    background: var(--accent-glow);
  }
  
  .sgbtn i    { font-size: 17px; color: var(--accent); }
  
  .sgbtn span {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.3;
  }
  
  @media (min-width: 768px) {
    .sgbtn        { padding: 18px 10px; }
    .sgbtn i      { font-size: 20px; }
    .sgbtn span   { font-size: 12px; }
  }
  
  .sheet-hr { border: none; border-top: 1px solid var(--border); margin: 0 16px 16px; }
  
  .cfg-grp  { padding: 0 16px 12px; }
  
  @media (min-width: 768px) {
    .cfg-grp { padding: 0 20px 16px; }
  }
  
  .cfg-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
  }
  
  .cfg-label { font-size: 13px; color: var(--text-secondary); }
  
  @media (min-width: 768px) {
    .cfg-label { font-size: 14px; }
  }
  
  .toggle-sw {
    width: 38px;
    height: 22px;
    border-radius: 99px;
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    cursor: pointer;
    position: relative;
    transition: all var(--tr);
    flex-shrink: 0;
  }
  
  .toggle-sw.on {
    background: var(--accent);
    border-color: var(--accent);
  }
  
  .toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all var(--tr);
  }
  
  .toggle-sw.on .toggle-knob {
    left: 18px;
    background: #fff;
  }
  
  .speech-style-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px 3px 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    transition: all var(--tr);
  }
  
  .speech-style-btn:hover   { border-color: var(--border-accent); }
  .speech-style-val         { font-size: 11px; font-family: var(--font-mono); color: var(--accent); }
  .speech-style-arrow       { font-size: 9px; color: var(--text-muted); }
  
  .speech-style-dd {
    position: absolute;
    right: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    min-width: 160px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .7);
    z-index: 200;
    animation: ddIn .15s ease;
  }
  
  .ss-item {
    padding: 9px 14px;
    font-size: 13px;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--tr);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  .ss-item:hover      { color: var(--text-primary); background: var(--bg-overlay); }
  .ss-item.active     { color: var(--accent); }
  .ss-item-check      { font-size: 10px; color: var(--accent); }
  
  
  /* Memory sheet */
  
  .mem-sheet {
    max-height: 92vh;
    overflow-y: auto;
    scrollbar-width: thin;
  }
  
  .mem-sheet::-webkit-scrollbar       { width: 3px; }
  .mem-sheet::-webkit-scrollbar-thumb { background: var(--bg-overlay); }
  
  .mem-section   { padding: 0 16px 14px; }
  
  @media (min-width: 768px) {
    .mem-section { padding: 0 20px 18px; }
  }
  
  .mem-row2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  
  .mem-col { display: flex; flex-direction: column; }
  
  .mem-label {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: 6px;
    display: block;
  }
  
  .mem-input {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--tr);
    margin-bottom: 10px;
  }
  
  @media (min-width: 768px) {
    .mem-input { font-size: 14px; padding: 11px 14px; }
  }
  
  .mem-input:focus        { border-color: var(--border-accent); }
  .mem-input::placeholder { color: var(--text-muted); }
  
  .mem-textarea {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
    outline: none;
    resize: none;
    line-height: 1.6;
    transition: border-color var(--tr);
    min-height: 90px;
  }
  
  .mem-textarea:focus        { border-color: var(--border-accent); }
  .mem-textarea::placeholder { color: var(--text-muted); }
  
  .mem-save-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--tr);
    width: 100%;
    margin-bottom: 4px;
    font-family: var(--font-sans);
  }
  
  .mem-save-btn:hover { box-shadow: 0 0 18px rgba(74, 158, 255, .4); }
  
  .mem-dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--tr);
  }
  
  .mem-dropdown-toggle:hover { border-color: var(--border-accent); }
  
  .mem-dropdown-toggle span {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
  }
  
  .mem-dropdown-toggle i {
    font-size: 11px;
    color: var(--text-muted);
    transition: transform var(--tr);
  }
  
  .mem-dropdown-toggle i.open { transform: rotate(180deg); }
  
  .mem-dropdown-body {
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    padding: 12px;
  }
  
  .mem-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
  }
  
  .mem-loading .ldots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block;
    animation: tdBounce 1.3s infinite ease-in-out;
    margin: 0 2px;
  }
  
  .mem-loading .ldots span:nth-child(2) { animation-delay: .18s; }
  .mem-loading .ldots span:nth-child(3) { animation-delay: .36s; }
  
  .mem-content {
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  
  /* Toast */
  
  .toast {
    position: fixed;
    bottom: 78px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 12px;
    font-family: var(--font-mono);
    padding: 8px 16px;
    border-radius: 99px;
    opacity: 0;
    transition: all .22s ease;
    pointer-events: none;
    white-space: nowrap;
    z-index: 200;
  }
  
  .toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  
  input[type="file"] { display: none; }
  
  
  /* Desktop border */
  @media (min-width: 640px) {
    #app          { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
    .bottom-sheet { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  }
  
  /* iOS safe area */
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    .input-bar     { padding-bottom: env(safe-area-inset-bottom); }
    .bottom-footer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
    .bottom-sheet  { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
    .sb-bottom     { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  }
  
  /* Prevent text size inflation on iOS */
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  
  /* Smooth scrolling on iOS */
  .chat-area,
  .sb-hist,
  .mem-sheet,
  .modal-card {
    -webkit-overflow-scrolling: touch;
  }
