
    /* ===== Design Tokens ===== */
    :root {
      --bg: #f8fafc;
      --surface: #ffffff;
      --surface-soft: #f1f5f9;
      --surface-hover: #e2e8f0;
      --text: #1e293b;
      --text-secondary: #64748b;
      --muted: #94a3b8;
      --border: #e2e8f0;
      --border-hover: #cbd5e1;
      --accent: #6366f1;
      --accent-soft: #e0e7ff;
      --user-bg: #6366f1;
      --user-text: #ffffff;
      --user-border: transparent;
      --assistant-border: transparent;
      --danger: #ef4444;
      --danger-bg: #fee2e2;
      --danger-border: #fecaca;
      --success: #10b981;
      --success-soft: #ecfdf5;
      --warning: #f59e0b;
      --warning-soft: #fffbeb;
      --radius: 12px;
      --radius-lg: 16px;
      --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
      --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
      --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
      --topbar-h: 64px;
      --composer-h: 240px;
      --font: "Inter", system-ui, -apple-system, sans-serif;
      --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
    }

    @media (prefers-color-scheme: dark) {
      :root {
        --bg: #0f172a;
        --surface: #1e293b;
        --surface-soft: #334155;
        --surface-hover: #475569;
        --text: #f1f5f9;
        --text-secondary: #94a3b8;
        --muted: #64748b;
        --border: #334155;
        --border-hover: #475569;
        --accent: #818cf8;
        --accent-soft: #312e81;
        --user-bg: #818cf8;
        --user-text: #ffffff;
        --user-border: transparent;
        --assistant-border: transparent;
        --danger: #f87171;
        --danger-bg: #450a0a;
        --danger-border: #7f1d1d;
        --success: #34d399;
        --success-soft: #064e3b;
        --warning: #fbbf24;
        --warning-soft: #451a03;
      }
    }

    /* ===== Reset ===== */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    html {
      height: 100%;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      -webkit-text-size-adjust: 100%;
      text-size-adjust: 100%;
    }

    body {
      min-height: 100%;
      color: var(--text);
      font-family: var(--font);
      font-size: 16px;
      line-height: 1.6;
      background: var(--bg);
      overscroll-behavior: none;
      -webkit-overflow-scrolling: touch;
    }

    /* ===== App Shell ===== */
    .app-shell {
      width: 100%;
      min-height: 100vh;
      min-height: 100dvh;
      display: flex;
      flex-direction: column;
      max-width: 800px;
      margin: 0 auto;
      background: var(--bg);
    }

    /* ===== Top Bar ===== */
    .topbar {
      position: sticky;
      top: 0;
      z-index: 100;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      min-height: var(--topbar-h);
      padding: 0 20px;
      padding-top: max(0px, env(safe-area-inset-top));
      background: rgba(255, 255, 255, 0.8);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      border-bottom: 1px solid rgba(226, 232, 240, 0.5);
    }

    @media (prefers-color-scheme: dark) {
      .topbar {
        background: rgba(30, 41, 59, 0.8);
        border-bottom-color: rgba(51, 65, 85, 0.5);
      }
    }

    .brand h1 {
      font-size: 1.125rem;
      font-weight: 700;
      color: var(--text);
      letter-spacing: -0.02em;
    }

    .brand p {
      margin-top: 2px;
      color: var(--text-secondary);
      font-size: 0.75rem;
      font-weight: 500;
    }

    .toolbar {
      display: flex;
      gap: 8px;
      align-items: center;
    }

    /* ===== Identity Badge ===== */
    .identity-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      height: 32px;
      padding: 0 12px;
      border-radius: 20px;
      font-size: 0.75rem;
      font-weight: 600;
      cursor: pointer;
      background: var(--surface-soft);
      color: var(--text-secondary);
      transition: all 0.2s;
      border: 1px solid transparent;
    }
    .identity-badge:hover {
      background: var(--surface-hover);
      color: var(--text);
    }
    .identity-badge.has-code {
      color: var(--accent);
      background: var(--accent-soft);
    }

    /* ===== Buttons ===== */
    button, select, textarea { font: inherit; }

    button {
      border: none;
      cursor: pointer;
      transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
      -webkit-tap-highlight-color: transparent;
      user-select: none;
      display: inline-flex;
      align-items: center;
      justify-content: center;
    }
    button:active:not(:disabled) { transform: scale(0.96); }
    button:disabled { cursor: not-allowed; opacity: 0.5; }

    .icon-btn, .ghost-btn {
      height: 40px;
      padding: 0 16px;
      border-radius: var(--radius);
      background: var(--surface-soft);
      color: var(--text);
      font-size: 0.875rem;
      font-weight: 600;
    }
    .icon-btn:hover:not(:disabled), .ghost-btn:hover:not(:disabled) {
      background: var(--surface-hover);
    }

    .icon-btn { width: 40px; padding: 0; }

    .primary-btn {
      height: 44px;
      padding: 0 24px;
      border-radius: var(--radius);
      color: var(--user-text);
      background: var(--accent);
      font-weight: 600;
      font-size: 0.9375rem;
      box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    }
    .primary-btn:hover:not(:disabled) {
      transform: translateY(-1px);
      box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
    }

    .primary-btn.is-sending {
      background: var(--muted);
      box-shadow: none;
      pointer-events: none;
    }

    /* ===== Chat Area ===== */
    .chat-wrap {
      flex: 1;
      min-height: 0;
      padding: 8px 12px calc(var(--composer-h) + env(safe-area-inset-bottom, 0px) + 8px);
    }

    #chat {
      min-height: calc(100dvh - var(--topbar-h) - var(--composer-h) - 16px);
      padding: 8px 4px 12px;
    }

    /* ===== Empty State ===== */
    .empty-state {
      min-height: calc(100dvh - var(--topbar-h) - var(--composer-h) - 40px);
      display: flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      padding: 32px 20px;
    }

    .empty-state-inner { max-width: 320px; }

    .empty-state-icon {
      width: 48px;
      height: 48px;
      margin: 0 auto 16px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--muted);
    }
    .empty-state-icon svg { width: 36px; height: 36px; }

    .empty-state strong {
      display: block;
      margin-bottom: 6px;
      color: var(--text);
      font-size: 1rem;
      font-weight: 600;
    }

    .empty-state p {
      color: var(--text-secondary);
      font-size: 0.875rem;
      line-height: 1.7;
    }

    .empty-state-hints {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      justify-content: center;
      margin-top: 16px;
    }

    .empty-state-hint {
      padding: 6px 12px;
      border-radius: var(--radius);
      background: var(--surface-soft);
      border: 1px solid var(--border);
      font-size: 0.8125rem;
      color: var(--text-secondary);
      cursor: default;
    }

    /* ===== Messages ===== */
    .message {
      width: fit-content;
      max-width: min(90%, 700px);
      margin-bottom: 20px;
      padding: 16px 20px;
      border-radius: var(--radius-lg);
      animation: msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
      box-shadow: var(--shadow-sm);
    }
    @keyframes msg-in {
      from { opacity: 0; transform: translateY(8px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .message.user {
      margin-left: auto;
      background: var(--user-bg);
      color: var(--user-text);
      border-bottom-right-radius: 4px;
      box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
    }

    .message.assistant {
      margin-right: auto;
      background: var(--surface);
      border: 1px solid var(--border);
      border-bottom-left-radius: 4px;
      box-shadow: var(--shadow);
    }

    .message.error {
      background: var(--danger-bg);
      border: 1px solid var(--danger-border);
      color: var(--danger);
    }

    .message-header {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      align-items: center;
      margin-bottom: 10px;
      opacity: 0.8;
    }

    .role-label {
      font-size: 0.75rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--muted);
    }
    .message.user .role-label { color: rgba(255, 255, 255, 0.8); }

    .meta-group {
      display: inline-flex;
      align-items: center;
      gap: 8px;
    }

    .time-label, .duration-label {
      font-size: 0.6875rem;
      font-weight: 500;
    }
    .message.user .time-label { color: rgba(255, 255, 255, 0.7); }
    .message.assistant .time-label { color: var(--muted); }
    .duration-label { color: var(--accent); }

    .message-content {
      word-break: break-word;
      line-height: 1.75;
      font-size: 0.9375rem;
    }
    .message.user .message-content { color: var(--user-text); }
    
    .message-content p, .message-content ul, .message-content ol,
    .message-content pre, .message-content blockquote { margin-bottom: 12px; }
    .message-content p:last-child, .message-content ul:last-child,
    .message-content ol:last-child, .message-content pre:last-child,
    .message-content blockquote:last-child { margin-bottom: 0; }

    .message-content pre {
      overflow-x: auto;
      padding: 16px;
      border-radius: var(--radius);
      background: var(--surface-soft);
      border: 1px solid var(--border);
      color: var(--text);
      font-size: 0.875em;
    }
    @media (prefers-color-scheme: dark) {
      .message-content pre { background: rgba(15, 23, 42, 0.5); }
    }
    .message-content code {
      font-family: var(--font-mono);
      font-size: 0.875em;
      font-weight: 500;
    }
    .message-content :not(pre) > code {
      background: var(--accent-soft);
      padding: 2px 6px;
      border-radius: 4px;
      color: var(--accent);
    }
    .message.user :not(pre) > code {
      background: rgba(255, 255, 255, 0.2);
      color: #ffffff;
    }
    .message-content blockquote {
      border-left: 4px solid var(--accent);
      padding: 4px 0 4px 16px;
      color: var(--text-secondary);
      background: var(--surface-soft);
      border-radius: 0 var(--radius) var(--radius) 0;
    }
    .message-content img { max-width: 100%; border-radius: var(--radius); }
    .message-content a { color: var(--accent); text-decoration: none; font-weight: 600; }
    .message-content a:hover { text-decoration: underline; }
    .message-content table {
      border-collapse: separate;
      border-spacing: 0;
      width: 100%;
      margin-bottom: 12px;
      border: 1px solid var(--border);
      border-radius: var(--radius);
      overflow: hidden;
    }
    .message-content th, .message-content td {
      border-bottom: 1px solid var(--border);
      border-right: 1px solid var(--border);
      padding: 10px 14px;
      text-align: left;
    }
    .message-content th:last-child, .message-content td:last-child { border-right: none; }
    .message-content tr:last-child th, .message-content tr:last-child td { border-bottom: none; }
    .message-content th { background: var(--surface-soft); font-weight: 700; color: var(--text); }
    .message-content ul, .message-content ol { padding-left: 24px; }
    .message-content li { margin-bottom: 4px; }

    /* ===== Streaming Cursor ===== */
    .streaming-cursor .message-content::after {
      content: "";
      display: inline-block;
      width: 8px;
      height: 1.2em;
      background: var(--accent);
      margin-left: 4px;
      vertical-align: middle;
      animation: cursor-blink 0.8s infinite;
      border-radius: 1px;
    }
    @keyframes cursor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

    /* ===== Loading Spinner ===== */
    .message.loading .message-content {
      min-height: 24px;
      display: flex;
      align-items: center;
      gap: 12px;
    }
    .message.loading .message-content::before {
      content: "";
      width: 18px;
      height: 18px;
      border: 3px solid var(--accent-soft);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }
    .message.loading .message-content::after {
      content: "AI 正在思考...";
      color: var(--text-secondary);
      font-size: 0.875rem;
      font-weight: 500;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* ===== Error ===== */
    .error-header { font-weight: 600; color: var(--danger); margin-bottom: 4px; }
    .error-suggestion {
      color: var(--text-secondary);
      white-space: pre-wrap;
      font-size: 0.875em;
    }

    /* ===== Composer ===== */
    .composer {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 90;
      padding: 16px 20px calc(20px + env(safe-area-inset-bottom, 0px));
      background: linear-gradient(to top, var(--bg) 60%, transparent);
      pointer-events: none;
    }
    .composer-inner {
      max-width: 800px;
      margin: 0 auto;
      padding: 12px;
      border-radius: var(--radius-lg);
      background: rgba(255, 255, 255, 0.9);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      border: 1px solid rgba(226, 232, 240, 0.8);
      box-shadow: var(--shadow-lg);
      pointer-events: auto;
      transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .composer-inner:focus-within {
      transform: translateY(-2px);
      box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
      border-color: var(--accent);
    }

    @media (prefers-color-scheme: dark) {
      .composer-inner {
        background: rgba(30, 41, 59, 0.9);
        border-color: rgba(51, 65, 85, 0.8);
      }
    }

    .composer-top {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      align-items: center;
      margin-bottom: 10px;
      padding: 0 4px;
    }

    .current-model {
      font-size: 0.75rem;
      color: var(--text-secondary);
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .current-model::before {
      content: "";
      width: 6px;
      height: 6px;
      background: var(--success);
      border-radius: 50%;
    }
    .current-model strong { color: var(--text); font-weight: 700; }

    .composer-top-actions { display: flex; gap: 8px; }

    textarea {
      width: 100%;
      min-height: 48px;
      max-height: 200px;
      padding: 12px 14px;
      resize: none;
      border-radius: var(--radius);
      border: 1px solid var(--surface-soft);
      background: var(--surface-soft);
      color: var(--text);
      line-height: 1.6;
      font-size: 1rem;
      transition: all 0.2s;
    }
    textarea:focus {
      outline: none;
      background: var(--surface);
      border-color: var(--accent-soft);
    }

    .composer-actions {
      display: flex;
      gap: 12px;
      margin-top: 12px;
    }
    .composer-actions .ghost-btn {
      height: 44px;
      background: transparent;
      border: 1px solid var(--border);
    }
    .composer-actions .primary-btn { flex: 1; }

    /* ===== Sheet / Modal ===== */
    .sheet, .modal {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 200;
      background: rgba(15, 23, 42, 0);
      backdrop-filter: blur(0px);
      transition: background 0.4s ease, backdrop-filter 0.4s ease;
      padding: 20px;
      pointer-events: none;
    }
    .sheet.is-open, .modal.is-open {
      display: flex;
      background: rgba(15, 23, 42, 0.4);
      backdrop-filter: blur(8px);
      pointer-events: auto;
    }

    .sheet { align-items: flex-end; justify-content: center; padding: 0; }

    .sheet-panel, .modal-content {
      width: min(560px, 100%);
      background: var(--surface);
      border: 1px solid var(--border);
      box-shadow: var(--shadow-lg);
      opacity: 0;
      transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    .sheet-panel {
      border-radius: var(--radius-lg) var(--radius-lg) 0 0;
      padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0px));
      transform: translateY(100%);
    }
    .sheet.is-open .sheet-panel {
      opacity: 1;
      transform: translateY(0);
    }

    .modal { align-items: center; justify-content: center; }
    .modal-content {
      max-height: min(85vh, 640px);
      overflow-y: auto;
      border-radius: var(--radius-lg);
      padding: 28px;
      transform: scale(0.9) translateY(20px);
    }
    .modal.is-open .modal-content {
      opacity: 1;
      transform: scale(1) translateY(0);
    }
    .modal-content::-webkit-scrollbar { width: 6px; }
    .modal-content::-webkit-scrollbar-thumb {
      background: var(--border); border-radius: 3px;
    }

    /* ===== Form Controls ===== */
    .sheet-header, .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      gap: 16px;
      margin-bottom: 24px;
    }
    .sheet-header h2, .modal-header h2 { font-size: 1.25rem; font-weight: 700; color: var(--text); }
    .sheet-header p, .modal-header p {
      color: var(--text-secondary); font-size: 0.875rem; line-height: 1.5; margin-top: 4px;
    }

    .form-group { margin-bottom: 20px; }
    .form-label {
      display: block; margin-bottom: 8px;
      color: var(--text); font-size: 0.875rem;
      font-weight: 600;
    }

    select {
      width: 100%; height: 48px; padding: 0 16px;
      border-radius: var(--radius); border: 1px solid var(--border);
      background: var(--surface-soft); color: var(--text); font-size: 1rem;
      appearance: none;
      -webkit-appearance: none;
      -moz-appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
      background-repeat: no-repeat; background-position: right 16px center;
      cursor: pointer; transition: all 0.2s;
    }
    select:focus { outline: none; border-color: var(--accent); background: var(--surface); }
    select:disabled { opacity: 0.5; cursor: not-allowed; }

    .sheet-actions { display: flex; gap: 12px; margin-top: 24px; }
    .sheet-actions button { flex: 1; }

    /* ===== Identity Modal ===== */
    .identity-modal-content { max-width: 420px !important; }
    .identity-body { padding: 8px 0; }

    .identity-info {
      font-size: 0.9375rem;
      color: var(--text-secondary);
      line-height: 1.6;
      margin-bottom: 20px;
    }

    .identity-input {
      width: 100%;
      height: 56px;
      padding: 0 16px;
      border-radius: var(--radius);
      border: 2px solid var(--border);
      background: var(--surface-soft);
      color: var(--text);
      font-size: 1.25rem;
      font-weight: 700;
      letter-spacing: 0.2em;
      text-align: center;
      text-transform: uppercase;
      font-family: var(--font-mono);
      transition: all 0.2s;
    }
    .identity-input:focus {
      outline: none;
      border-color: var(--accent);
      background: var(--surface);
    }

    .identity-actions {
      display: flex;
      gap: 12px;
      margin-top: 20px;
    }
    .identity-actions button { flex: 1; }

    .identity-feedback {
      margin-top: 16px;
      padding: 12px 16px;
      border-radius: var(--radius);
      font-size: 0.875rem;
      font-weight: 500;
      display: none;
    }
    .identity-feedback.show { display: block; }
    .identity-feedback.success {
      background: var(--success-soft);
      color: var(--success);
      border: 1px solid var(--success);
    }
    .identity-feedback.error {
      background: var(--danger-bg);
      color: var(--danger);
      border: 1px solid var(--danger-border);
    }

    .identity-code-display {
      text-align: center;
      padding: 24px;
      margin: 16px 0;
      border-radius: var(--radius);
      background: var(--accent-soft);
      border: 2px dashed var(--accent);
    }
    .identity-code-display .code {
      font-family: var(--font-mono);
      font-size: 1.75rem;
      font-weight: 800;
      letter-spacing: 0.15em;
      color: var(--accent);
      user-select: all;
    }
    .identity-code-display .hint {
      font-size: 0.8125rem;
      color: var(--warning);
      margin-top: 12px;
      font-weight: 600;
    }

    .identity-footer-text {
      margin-top: 20px;
      font-size: 0.8125rem;
      color: var(--muted);
      text-align: center;
      line-height: 1.6;
    }

    /* ===== History List ===== */
    .history-list { display: grid; gap: 12px; }

    .history-item {
      padding: 16px;
      border: 1px solid var(--border);
      border-radius: var(--radius);
      background: var(--surface);
      cursor: pointer;
      transition: all 0.2s;
    }
    .history-item:hover {
      background: var(--surface-soft);
      border-color: var(--accent);
      transform: translateX(4px);
    }

    .history-item-title { font-weight: 700; margin-bottom: 4px; font-size: 1rem; color: var(--text); }
    .history-item-meta { font-size: 0.8125rem; color: var(--text-secondary); }

    /* ===== Empty State ===== */
    .empty-state {
      min-height: calc(100dvh - var(--topbar-h) - var(--composer-h) - 80px);
      display: flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      padding: 40px 24px;
    }
    .empty-state-inner { max-width: 400px; }
    .empty-state-icon {
      width: 64px; height: 64px;
      margin: 0 auto 24px;
      color: var(--accent);
      opacity: 0.2;
    }
    .empty-state strong { font-size: 1.25rem; font-weight: 800; color: var(--text); margin-bottom: 12px; display: block; }
    .empty-state p { color: var(--text-secondary); line-height: 1.6; }

    /* ===== Responsive ===== */
    @media (max-width: 768px) {
      .app-shell { max-width: 100%; }
      .message { max-width: 92%; }
      .composer { padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
      .composer-inner { border-radius: 20px; }
    }

    @media (max-width: 480px) {
      :root { --topbar-h: 60px; }
      .topbar { padding: 0 16px; }
      .brand p { display: none; }
      .modal { padding: 0; align-items: flex-end; }
      .modal-content { border-radius: var(--radius-lg) var(--radius-lg) 0 0; width: 100%; max-height: 90vh; }
    }

