  :root {
    /* Apple-inspired dark palette */
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --surface-3: #3a3a3c;
    --separator: rgba(84, 84, 88, 0.55);
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --accent: #0a84ff;
    --accent-press: #0974e0;
    --red: #ff453a;
    --green: #30d158;
    --orange: #ff9f0a;
    --bubble-other: #2c2c2e;
    --bubble-mine: #0a84ff;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    --spring: cubic-bezier(0.32, 0.72, 0, 1);
  }

  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { margin: 0; background: var(--bg); color: var(--label);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro",
          "Segoe UI", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none; letter-spacing: -0.01em; }
  body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
  body, button, input, textarea { font-family: inherit; }
  button { color: inherit; }

  /* HEADER (translucent vibrancy) */
  header { display: flex; align-items: center; gap: 8px;
    padding: 10px 16px;
    padding-top: calc(10px + var(--safe-top));
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    background: rgba(28, 28, 30, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--separator);
    flex-shrink: 0; position: sticky; top: 0; z-index: 10; }
  header .title { flex: 1; font-weight: 600; font-size: 17px;
    letter-spacing: -0.02em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  header button { background: transparent; border: none; color: var(--label);
    width: 36px; height: 36px; padding: 0; border-radius: 50%; cursor: pointer;
    font-size: 18px; display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.2s var(--spring), transform 0.15s var(--spring); }
  header button:hover { background: var(--surface-2); }
  header button:active { background: var(--surface-3); transform: scale(0.92); }

  .status { font-size: 13px; color: var(--label-2); display: inline-flex;
    align-items: center; gap: 6px; }
  .status::before { content: ""; width: 8px; height: 8px; border-radius: 50%;
    background: var(--label-3); transition: background-color 0.3s var(--spring); }
  .status.ok { color: var(--green); }
  .status.ok::before { background: var(--green); box-shadow: 0 0 6px rgba(48,209,88,0.6); }
  .status.err { color: var(--red); }
  .status.err::before { background: var(--red); box-shadow: 0 0 6px rgba(255,69,58,0.6); }

  /* MAIN — chat scroll */
  main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 12px 16px;
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    width: 100%; }
  .messages-inner { max-width: 1080px; margin: 0 auto;
    display: flex; flex-direction: column; gap: 4px;
    padding-bottom: 12px; }
  .thinking { align-self: flex-start; display: inline-flex; gap: 5px;
    padding: 12px 16px; background: var(--surface);
    border-radius: 20px; border-bottom-left-radius: 6px;
    animation: pop 0.25s var(--spring); }
  .thinking span { width: 7px; height: 7px; border-radius: 50%;
    background: var(--label-2);
    animation: thinking-pulse 1.4s ease-in-out infinite; }
  .thinking span:nth-child(2) { animation-delay: 0.2s; }
  .thinking span:nth-child(3) { animation-delay: 0.4s; }
  @keyframes thinking-pulse {
    0%, 80%, 100% { opacity: 0.25; transform: scale(0.7); }
    40% { opacity: 1; transform: scale(1); }
  }

  /* iMessage-style bubbles */
  .msg { padding: 9px 14px; border-radius: 20px;
    word-wrap: break-word; overflow-wrap: anywhere;
    max-width: 80%; line-height: 1.35; font-size: 16px;
    animation: pop 0.25s var(--spring); }
  @keyframes pop { from { opacity: 0; transform: translateY(4px) scale(0.98); }
                   to   { opacity: 1; transform: none; } }
  .msg .role { display: none; }
  .msg.user { background: var(--bubble-mine); color: #fff;
    align-self: flex-end; border-bottom-right-radius: 6px; }
  .msg.user .body a { color: #fff; text-decoration: underline; }
  .msg.assistant { background: var(--bubble-other); color: var(--label);
    align-self: flex-start; border-bottom-left-radius: 6px; }
  .msg.error { background: rgba(255,69,58,0.18); color: var(--red);
    align-self: stretch; max-width: 100%; font-size: 14px; }
  .msg .body { word-wrap: break-word; overflow-wrap: anywhere; }
  .msg .body pre { background: rgba(0,0,0,0.35); padding: 10px 12px;
    border-radius: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch;
    font-size: 13.5px; margin: 8px 0; }
  .msg.user .body pre { background: rgba(255,255,255,0.18); }
  .msg .body code { font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.92em; }
  .msg .body p:first-child { margin-top: 0; }
  .msg .body p:last-child { margin-bottom: 0; }
  .msg .body img { max-width: 100%; height: auto; border-radius: 12px; margin-top: 4px; }

  /* tool inline pill */
  .msg-wrap { display: contents; }
  .tool-line { align-self: flex-start; display: inline-flex; align-items: center;
    gap: 8px; padding: 5px 12px; margin: 2px 0; border-radius: 999px;
    background: var(--surface); color: var(--label-2);
    font-size: 13px; max-width: 80%;
    animation: pop 0.25s var(--spring); }
  .tool-line .tool-name { color: var(--label); white-space: nowrap; font-weight: 500;
    display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
  .tool-line .tool-summary { overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px; }

  /* FOOTER (composer) */
  footer { padding: 10px 16px;
    padding-bottom: calc(10px + var(--safe-bottom));
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    background: rgba(28, 28, 30, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--separator);
    flex-shrink: 0; }
  .composer { display: flex; flex-direction: column; gap: 8px;
    max-width: 1080px; margin: 0 auto; }
  .hint { font-size: 13px; color: var(--label-2); padding: 0 4px;
    text-align: center; }

  .chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px; }
  .chip { display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-2); color: var(--label);
    border: none; border-radius: 999px;
    padding: 5px 6px 5px 12px; font-size: 13px; max-width: 100%; }
  .chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 220px; }
  .chip-x { background: var(--surface-3); border: none; color: var(--label);
    width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
    font-size: 13px; line-height: 1; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    transition: transform 0.15s var(--spring), background-color 0.15s var(--spring); }
  .chip-x:active { transform: scale(0.85); background: var(--red); color: #fff; }

  .attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
  .chip-static { padding: 4px 12px; cursor: default;
    background: rgba(255,255,255,0.18); }
  .msg.assistant .chip-static { background: var(--surface-3); }

  textarea { width: 100%; background: var(--surface); color: var(--label);
    border: 0.5px solid var(--separator);
    border-radius: 18px; padding: 11px 14px;
    font-size: 17px; line-height: 1.35;
    resize: none; min-height: 110px; max-height: 320px;
    outline: none; vertical-align: top;
    transition: border-color 0.2s var(--spring), background-color 0.2s var(--spring); }
  textarea::placeholder { color: var(--label-3); }
  textarea:focus { border-color: var(--accent); background: var(--surface-2); }

  .composer-row { display: flex; gap: 8px; align-items: center; }
  .composer-row .spacer { flex: 1; }
  .composer-row .ico { background: var(--surface); border: none; color: var(--label);
    width: 40px; height: 40px; padding: 0; border-radius: 50%; cursor: pointer;
    font-size: 19px; display: inline-flex;
    align-items: center; justify-content: center; flex-shrink: 0;
    transition: background-color 0.2s var(--spring), transform 0.15s var(--spring); }
  .composer-row .ico:hover { background: var(--surface-2); }
  .composer-row .ico:active { background: var(--surface-3); transform: scale(0.9); }
  .composer-row .ico.recording { background: var(--red); color: #fff;
    animation: rec-pulse 1.4s ease-in-out infinite; }
  .composer-row .ico.recording:hover { background: var(--red); }
  .composer-row .ico.busy { opacity: 0.7; cursor: progress; }
  .rec-time { font-size: 13px; color: var(--red); font-variant-numeric: tabular-nums;
    min-width: 32px; }
  @keyframes rec-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,69,58,0.55); }
                         50% { box-shadow: 0 0 0 8px rgba(255,69,58,0); } }

  .send { background: var(--accent); border: none; color: #fff;
    width: 40px; height: 40px; padding: 0; border-radius: 50%;
    cursor: pointer; font-size: 18px; display: inline-flex;
    align-items: center; justify-content: center; flex-shrink: 0;
    transition: background-color 0.15s var(--spring),
                transform 0.12s var(--spring), opacity 0.2s var(--spring); }
  .send:disabled { background: var(--surface-2); color: var(--label-3);
    cursor: not-allowed; }
  .send:not(:disabled):hover { background: var(--accent-press); }
  .send:not(:disabled):active { transform: scale(0.88); }
  .send.stop { background: #c0392b; }
  .send.stop:hover { background: #a93324; }

  .drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 20; }
  .drawer { position: fixed; top: 0; left: 0; bottom: 0; z-index: 21;
    width: 300px; max-width: 86vw; background: var(--surface);
    display: flex; flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.25s var(--spring);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 4px 0 20px rgba(0,0,0,0.4); }
  .drawer.open { transform: none; }
  .drawer-head { display: flex; align-items: center; justify-content: space-between;
    padding: 16px 14px 8px; font-weight: 600; font-size: 17px;
    letter-spacing: -0.02em; }
  .drawer-head .ico { background: var(--surface-2); border: none; color: var(--label);
    width: 32px; height: 32px; padding: 0; border-radius: 50%; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background-color 0.15s var(--spring), transform 0.12s var(--spring); }
  .drawer-head .ico:hover { background: var(--surface-3); }
  .drawer-head .ico:active { transform: scale(0.9); }
  .thread-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px;
    display: flex; flex-direction: column; gap: 2px; }
  .thread-item { display: flex; align-items: center; gap: 4px;
    padding: 8px 8px; border-radius: 10px; cursor: pointer;
    transition: background-color 0.15s var(--spring); }
  .thread-item:hover { background: var(--surface-2); }
  .thread-item.active { background: var(--surface-3); }
  .thread-title { flex: 1; min-width: 0; background: transparent; border: none;
    color: var(--label); font: inherit; font-size: 14.5px; padding: 4px 4px;
    outline: none; cursor: pointer; text-overflow: ellipsis; }
  .thread-title:focus { background: var(--surface); border-radius: 6px; cursor: text; }
  .thread-del { background: transparent; border: none; color: var(--label-2);
    width: 28px; height: 28px; padding: 0; border-radius: 50%; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.15s var(--spring), background-color 0.15s var(--spring); }
  .thread-item:hover .thread-del, .thread-item.active .thread-del { opacity: 1; }
  .thread-del:hover { background: var(--surface); color: var(--red); }
  .thread-empty { color: var(--label-2); font-size: 14px; text-align: center;
    padding: 24px 16px; }

  .jump-bottom { position: fixed; right: 14px; z-index: 10;
    bottom: calc(env(safe-area-inset-bottom) + 140px);
    width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer;
    background: var(--surface-2); color: var(--label);
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
    transition: transform 0.15s var(--spring), background-color 0.15s var(--spring); }
  .jump-bottom:hover { background: var(--surface-3); }
  .jump-bottom:active { transform: scale(0.9); }

  /* MODAL */
  .modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 16px;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
    animation: fade 0.25s var(--spring); }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
  .modal-card { background: var(--surface); border: none;
    border-radius: 18px; padding: 20px 22px;
    width: min(420px, 100%); max-height: 100%; overflow: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: rise 0.3s var(--spring); }
  @keyframes rise { from { opacity: 0; transform: translateY(20px) scale(0.96); }
                    to   { opacity: 1; transform: none; } }
  .modal-card h3 { margin: 0 0 12px; font-size: 19px; font-weight: 600;
    letter-spacing: -0.02em; }
  .modal-card label { display: block; margin: 14px 0 6px; font-size: 13px;
    color: var(--label-2); font-weight: 500; }
  .modal-card input[type=text], .modal-card input[type=password] {
    width: 100%; background: var(--surface-2); color: var(--label);
    border: none; border-radius: 12px;
    padding: 12px 14px; font-size: 17px; outline: none;
    transition: background-color 0.2s var(--spring); }
  .modal-card input:focus { background: var(--surface-3); }
  .modal-card .actions { margin-top: 20px; display: flex; gap: 8px;
    flex-wrap: wrap; justify-content: flex-end; }
  .modal-card button { background: var(--surface-2); border: none;
    color: var(--label); padding: 10px 18px; border-radius: 999px; cursor: pointer;
    font-size: 15px; font-weight: 500; min-height: 40px;
    transition: transform 0.12s var(--spring), background-color 0.2s var(--spring); }
  .modal-card button:active { transform: scale(0.96); }
  .modal-card button.primary { background: var(--accent); color: #fff; }
  .modal-card button.primary:active { background: var(--accent-press); }
  .modal-card button.danger { background: rgba(255,69,58,0.15); color: var(--red); }
  .modal-card button.danger:active { background: rgba(255,69,58,0.3); }
  .modal-card button.full { width: 100%; background: var(--accent); color: #fff;
    margin-bottom: 8px; }
  .modal-card button.full:active { background: var(--accent-press); }
  .modal-card button:disabled { opacity: 0.4; cursor: not-allowed; }
  .model-row { display: flex; align-items: center; gap: 12px; margin: 0 0 14px;
    padding: 10px 12px; background: var(--surface-2); border-radius: 12px; }
  .model-row > span { font-size: 14px; color: var(--label-2); }
  .model-row select { flex: 1; background: var(--surface-3); color: var(--label);
    border: none; border-radius: 8px; padding: 8px 10px; font-size: 14px;
    font-family: inherit; }
  .hint-block { margin-top: 12px; }
  .hint-block p { font-size: 13px; color: var(--label-2); margin: 0 0 8px; }
  .copy-row { display: flex; gap: 8px; align-items: center; }
  .copy-row code { flex: 1; background: var(--surface-2); padding: 8px 12px;
    border-radius: 8px; font-size: 12px; word-break: break-all;
    font-family: ui-monospace, "SF Mono", Menlo, monospace; }
  .copy-row button { padding: 8px 14px !important; min-height: 36px !important;
    flex-shrink: 0; }

  /* FILES */
  .file-row { display: flex; align-items: stretch; gap: 4px; min-height: 48px; }
  .file-main { flex: 1; display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 12px; cursor: pointer;
    overflow: hidden;
    transition: background-color 0.15s var(--spring); }
  .file-main:hover { background: var(--surface-2); }
  .file-main:active { background: var(--surface-3); }
  .file-row .icon { width: 22px; flex-shrink: 0; font-size: 20px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--label-2); }
  .file-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; font-size: 15px; }
  .file-row .size { font-size: 12px; color: var(--label-2); flex-shrink: 0; }
  .file-del { background: transparent; border: none; color: var(--label-2);
    width: 40px; padding: 0; border-radius: 12px; cursor: pointer;
    font-size: 18px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background-color 0.15s var(--spring), color 0.15s var(--spring); }
  .file-del:hover { color: var(--red); background: rgba(255,69,58,0.12); }
  .file-del:active { background: rgba(255,69,58,0.25); }
  .breadcrumb { font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 13px; color: var(--label-2); margin-bottom: 8px;
    word-break: break-all; }

  /* MOBILE */
  @media (max-width: 600px) {
    main { padding: 8px 12px; }
    .messages-inner { gap: 3px; }
    .status .status-text { display: none; }
    .msg { max-width: 86%; }
    .modal-card { border-radius: 18px 18px 0 0;
      align-self: flex-end; max-height: 90%; padding: 18px 20px; }
    .modal { align-items: flex-end; padding: 0; }
    header { padding: 8px 12px;
      padding-top: calc(8px + var(--safe-top)); }
    header .title { font-size: 16px; }
    header button { width: 34px; height: 34px; font-size: 17px; }
    textarea { font-size: 16px; min-height: 96px; }
    .composer-row .ico, .send { width: 38px; height: 38px; font-size: 17px; }
  }
  @media (max-width: 360px) {
    header .title { font-size: 14px; }
    header button { width: 32px; height: 32px; }
  }

  /* scrollbar */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
  ::-webkit-scrollbar-track { background: transparent; }

  [x-cloak] { display: none !important; }

  /* SVG icons — flat, SF-Symbols-style, color via currentColor */
  .icon-svg { width: 1em; height: 1em; display: inline-block;
    stroke: currentColor; fill: none; stroke-width: 1.7;
    stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
  .send .icon-svg { stroke-width: 2.2; }
