:root {
    --bg: #fdf6f0;
    --card: #ffffff;
    --pink-soft: #fce4ec;
    --pink-mid: #f8bbd0;
    --pink-deep: #e91e63;
    --pink-accent: #ff6b8a;
    --text: #3e2723;
    --text-light: #8d6e63;
    --text-muted: #bcaaa4;
    --ryo-bg: #fff8f0;
    --miao-bg: #fce4ec;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
    --radius: 18px;
    --sidebar-w: 280px;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    font-family: 'LXGW WenKai Screen', -apple-system, 'PingFang SC', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh; width: 100vw; max-width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* ===== Sidebar (always hidden by default) ===== */
  .sidebar {
    width: var(--sidebar-w);
    background: var(--card);
    border-right: 1px solid var(--pink-soft);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 20;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--pink-soft);
  }

  .sidebar-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--pink-deep);
  }

  .sidebar-new-btn {
    width: 32px; height: 32px;
    border: none;
    background: var(--pink-soft);
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    color: var(--pink-deep);
    transition: background 0.2s;
  }
  .sidebar-new-btn:hover { background: var(--pink-mid); }

  .sidebar-search {
    padding: 10px 16px;
    border-bottom: 1px solid var(--pink-soft);
  }
  .sidebar-search input {
    width: 100%;
    border: 1px solid var(--pink-soft);
    border-radius: 20px;
    padding: 7px 14px;
    font-family: inherit; font-size: 13px;
    color: var(--text); outline: none;
    background: var(--bg);
  }
  .sidebar-search input:focus { border-color: var(--pink-accent); }
  .sidebar-search input::placeholder { color: var(--text-muted); }

  .sidebar-list { flex: 1; overflow-y: auto; padding: 8px; }
  .sidebar-list::-webkit-scrollbar { width: 3px; }
  .sidebar-list::-webkit-scrollbar-thumb { background: var(--pink-mid); border-radius: 2px; }

  .conv-item {
    padding: 10px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 2px;
    position: relative;
  }
  .conv-item:hover { background: var(--pink-soft); }
  .conv-item.active { background: var(--pink-soft); }

  .conv-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--pink-soft), var(--pink-mid));
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0;
  }

  .conv-info { flex: 1; min-width: 0; }
  .conv-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .conv-preview { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
  .conv-time { font-size: 10px; color: var(--text-muted); flex-shrink: 0; align-self: flex-start; margin-top: 2px; }

  .conv-actions { display: none; position: absolute; right: 6px; bottom: 4px; gap: 2px; }
  .conv-item:hover .conv-actions { display: flex; }

  .conv-act-btn {
    width: 22px; height: 22px; border: none;
    background: rgba(233,30,99,0.1); border-radius: 50%;
    cursor: pointer; font-size: 10px;
    display: flex; align-items: center; justify-content: center;
    color: var(--pink-deep);
  }
  .conv-act-btn:hover { background: rgba(233,30,99,0.2); }

  .conv-name-input {
    width: 100%; border: 1px solid var(--pink-accent);
    border-radius: 6px; padding: 2px 6px;
    font-family: inherit; font-size: 13px; outline: none; background: white;
  }

  .sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--pink-soft);
    display: flex; align-items: center; gap: 8px;
  }
  .sidebar-footer-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    display: flex; align-items: center; justify-content: center; font-size: 12px;
  }
  .sidebar-footer-name { font-size: 12px; color: var(--text-light); flex: 1; }
  .sidebar-footer-btn {
    width: 28px; height: 28px; border: none; background: transparent;
    cursor: pointer; font-size: 14px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
  }
  .sidebar-footer-btn:hover { background: var(--pink-soft); }

  .sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.3); z-index: 19;
  }
  .sidebar-overlay.show { display: block; }

  /* ===== Main ===== */
  .main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }

  .header {
    background: var(--card);
    padding: 14px 20px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: var(--shadow); z-index: 10; flex-shrink: 0;
  }
  .header-menu {
    width: 36px; height: 36px; border: none;
    background: var(--pink-soft); border-radius: 50%;
    cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  }
  .header-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, var(--pink-soft), var(--pink-mid));
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0; overflow: hidden;
  }
  .header-avatar img { width: 100%; height: 100%; object-fit: cover; }
  .header-info { flex: 1; }
  .header-name { font-size: 16px; font-weight: 700; }
  .header-status { font-size: 11px; color: var(--text-muted); transition: color 0.3s; }
  .header-status.typing-status { color: var(--pink-accent); }

  .header-model-btn {
    padding: 4px 10px; border: 1px solid var(--pink-soft);
    border-radius: 12px; background: var(--bg);
    cursor: pointer; flex-shrink: 0; font-family: inherit;
    display: flex; align-items: center; gap: 4px;
    transition: all 0.15s;
  }
  .header-model-btn:hover { border-color: var(--pink-accent); }

  /* ===== Model Switch Panel ===== */
  .model-panel {
    display: none; position: fixed; top: 60px; right: 12px;
    background: var(--card); border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    z-index: 50; padding: 12px; min-width: 200px;
    animation: modalIn 0.2s ease;
  }
  .model-panel.show { display: block; }
  .model-panel-title { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; padding-left: 4px; }
  .model-option {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: 10px; cursor: pointer;
    font-family: inherit; font-size: 12px; color: var(--text);
    border: none; background: none; width: 100%; text-align: left;
    transition: background 0.15s;
  }
  .model-option:hover { background: var(--pink-soft); }
  .model-option.active { background: var(--pink-soft); color: var(--pink-deep); font-weight: 600; }
  .model-option-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
  .model-option-info { font-size: 10px; color: var(--text-muted); margin-left: auto; }

  /* ===== Chat ===== */
  .chat-area {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    
  }
  .chat-area::-webkit-scrollbar { width: 3px; }
  .chat-area::-webkit-scrollbar-thumb { background: var(--pink-mid); border-radius: 2px; }

  .msg-row { display: flex; gap: 8px; max-width: 85%; animation: msgIn 0.3s ease; }
  @keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
  .msg-row.ryo { align-self: flex-start; }
  .msg-row.miao { align-self: flex-end; flex-direction: row-reverse; }

  .msg-avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; margin-top: 4px;
  }
  .msg-row.ryo .msg-avatar {
    background: linear-gradient(135deg, var(--pink-soft), var(--pink-mid));
    overflow: hidden;
  }
  .msg-row.ryo .msg-avatar img {
    width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
  }
  .msg-row.miao .msg-avatar { background: linear-gradient(135deg, #e8f5e9, #c8e6c9); }

  .msg-bubble {
    padding: 10px 14px; border-radius: var(--radius);
    font-size: 14px; line-height: 1.7;
    word-break: break-word; white-space: pre-wrap;
  }
  .msg-row.ryo .msg-bubble { background: var(--ryo-bg); border-top-left-radius: 4px; box-shadow: var(--shadow); }
  .msg-row.miao .msg-bubble { background: var(--miao-bg); border-top-right-radius: 4px; box-shadow: var(--shadow); }

  .msg-footer { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
  .msg-time { font-size: 10px; color: var(--text-muted); }
  .msg-row.ryo .msg-footer { margin-left: 40px; }
  .msg-row.miao .msg-footer { justify-content: flex-end; margin-right: 40px; }

  .token-btn {
    width: 18px; height: 18px; border: none;
    background: rgba(233,30,99,0.08); border-radius: 50%;
    cursor: pointer; font-size: 9px;
    display: flex; align-items: center; justify-content: center;
    color: var(--pink-accent); flex-shrink: 0;
  }
  .token-btn:hover { background: rgba(233,30,99,0.18); }

  .token-detail {
    display: none; font-size: 10px; color: var(--text-muted);
    background: rgba(252,228,236,0.5); border-radius: 8px;
    padding: 4px 10px; margin-top: 3px; line-height: 1.6;
  }
  .token-detail.show { display: block; }
  .msg-row.ryo .token-detail { margin-left: 40px; }

  .debug-btn {
    width: 18px; height: 18px; border: none;
    background: rgba(139,195,74,0.15); border-radius: 50%;
    cursor: pointer; font-size: 9px;
    display: flex; align-items: center; justify-content: center;
    color: #689f38; flex-shrink: 0;
  }
  .debug-btn:hover { background: rgba(139,195,74,0.3); }

  .tts-btn {
    width: 18px; height: 18px; border: none;
    background: rgba(33,150,243,0.1); border-radius: 50%;
    cursor: pointer; font-size: 9px;
    display: flex; align-items: center; justify-content: center;
    color: #1976d2; flex-shrink: 0;
  }
  .tts-btn:hover { background: rgba(33,150,243,0.2); }
  .tts-btn.playing { background: rgba(233,30,99,0.15); color: var(--pink-deep); }

  .debug-detail {
    display: none; font-size: 10px; color: var(--text-muted);
    background: rgba(232,245,233,0.6); border-radius: 8px;
    padding: 8px 10px; margin-top: 3px; line-height: 1.6;
    white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto;
  }
  .debug-detail.show { display: block; }
  .msg-row.ryo .debug-detail { margin-left: 40px; }

  .typing-indicator {
    display: none; align-self: flex-start;
    gap: 8px; align-items: center;
    max-width: 85%; padding: 0 16px;
  }
  .typing-indicator.show { display: flex; }
  .typing-avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    overflow: hidden; margin-top: 4px;
    background: linear-gradient(135deg, var(--pink-soft), var(--pink-mid));
  }
  .typing-avatar img { width: 100%; height: 100%; object-fit: cover; }
  .typing-bubble {
    padding: 10px 16px; background: var(--ryo-bg);
    border-radius: var(--radius); border-top-left-radius: 4px;
    box-shadow: var(--shadow); display: flex; gap: 4px; align-items: center;
  }

  .typing-dot {
    width: 6px; height: 6px; background: var(--pink-accent);
    border-radius: 50%; animation: typingBounce 1.4s infinite;
  }
  .typing-dot:nth-child(2) { animation-delay: 0.2s; }
  .typing-dot:nth-child(3) { animation-delay: 0.4s; }
  @keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
  }

  /* ===== Input ===== */
  .input-toolbar {
    display: flex; gap: 10px; padding: 4px 16px;
    background: var(--card); flex-shrink: 0;
    border-top: 1px solid var(--pink-soft);
  }
  .input-area {
    max-width: 100%;
    background: var(--card); padding: 8px 16px 12px;
    display: flex; gap: 10px; align-items: flex-end;
    flex-shrink: 0;
  }
  .input-wrap {
    min-width: 0;
    flex: 1; background: var(--bg); border-radius: 20px;
    padding: 8px 16px; display: flex; align-items: flex-end;
  }
  .input-wrap textarea {
    flex: 1; border: none; outline: none; background: transparent;
    font-family: inherit; font-size: 14px; color: var(--text);
    resize: none; max-height: 120px; line-height: 1.5; overflow-y: auto;
  }
  .send-btn {
    width: 40px; height: 40px; border: none;
    background: linear-gradient(135deg, var(--pink-accent), var(--pink-deep));
    color: white; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s;
  }
  .newline-btn {
    width: 28px; height: 28px; border: none;
    background: transparent; color: var(--text-muted);
    border-radius: 50%; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: color 0.2s;
  }
  .newline-btn:hover { color: var(--pink-accent); }
  .send-btn:hover { transform: scale(1.05); }
  .send-btn:active { transform: scale(0.95); }
  .send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

  /* ===== Welcome ===== */
  .welcome {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center; padding: 40px; gap: 16px;
  }
  .welcome-icon { font-size: 48px; animation: float 3s ease-in-out infinite; }
  @keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
  .welcome h2 { font-size: 20px; color: var(--pink-deep); }
  .welcome p { font-size: 13px; color: var(--text-light); line-height: 1.8; }
  .welcome-btn {
    font-family: inherit; font-size: 14px; padding: 10px 24px;
    border-radius: 20px; border: none;
    background: linear-gradient(135deg, var(--pink-accent), var(--pink-deep));
    color: white; cursor: pointer; margin-top: 8px;
  }
  .welcome-btn:hover { transform: scale(1.05); }

  .date-sep { text-align: center; font-size: 11px; color: var(--text-muted); padding: 8px 0; }
  .date-sep span { background: var(--bg); padding: 2px 12px; border-radius: 10px; }

  /* ===== Modal (shared) ===== */
  .modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
    z-index: 100; justify-content: center; align-items: center; padding: 20px;
  }
  .modal-overlay.show { display: flex; }
  .modal {
    background: var(--card); border-radius: 20px; padding: 24px;
    max-width: 480px; width: 100%; max-height: 85vh;
    overflow-y: auto; box-shadow: 0 24px 80px rgba(0,0,0,0.15);
    animation: modalIn 0.3s ease;
  }
  .modal::-webkit-scrollbar { width: 3px; }
  .modal::-webkit-scrollbar-thumb { background: var(--pink-mid); border-radius: 2px; }
  @keyframes modalIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

  .modal h3 { font-size: 16px; color: var(--pink-deep); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
  .modal label { display: block; font-size: 12px; color: var(--text-light); margin-bottom: 4px; margin-top: 14px; }
  .modal input, .modal textarea, .modal select {
    width: 100%; border: 1px solid var(--pink-soft); border-radius: 10px;
    padding: 8px 12px; font-family: inherit; font-size: 13px;
    color: var(--text); outline: none;
  }
  .modal input:focus, .modal textarea:focus { border-color: var(--pink-accent); }
  .modal textarea { resize: vertical; min-height: 100px; }
  .modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
  .modal-btn {
    font-family: inherit; font-size: 13px; padding: 8px 20px;
    border-radius: 20px; border: none; cursor: pointer; transition: all 0.2s;
  }
  .modal-btn.cancel { background: var(--pink-soft); color: var(--text); }
  .modal-btn.save { background: linear-gradient(135deg, var(--pink-accent), var(--pink-deep)); color: white; }
  .modal-btn:hover { transform: scale(1.02); }

  .param-group { background: var(--bg); border-radius: 14px; padding: 14px 16px; margin-top: 14px; }
  .param-group-title { font-size: 12px; font-weight: 700; color: var(--pink-deep); margin-bottom: 10px; }
  .param-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 0; border-bottom: 1px solid rgba(252,228,236,0.5);
  }
  .param-row:last-child { border-bottom: none; }
  .param-label { font-size: 13px; display: flex; flex-direction: column; gap: 1px; }
  .param-hint { font-size: 10px; color: var(--text-muted); }
  .param-value { display: flex; align-items: center; gap: 8px; }
  .param-input {
    width: 70px; text-align: center; border: 1px solid var(--pink-soft);
    border-radius: 8px; padding: 5px 8px; font-family: inherit; font-size: 13px;
    outline: none; background: white;
  }
  .param-input:focus { border-color: var(--pink-accent); }
  .param-slider { width: 100px; accent-color: var(--pink-accent); cursor: pointer; }

  .toggle-switch { position: relative; width: 40px; height: 22px; cursor: pointer; }
  .toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
  .toggle-track { position: absolute; inset: 0; background: var(--pink-soft); border-radius: 11px; transition: background 0.2s; }
  .toggle-switch input:checked + .toggle-track { background: var(--pink-accent); }
  .toggle-knob {
    position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
    background: white; border-radius: 50%; transition: transform 0.2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  }
  .toggle-switch input:checked ~ .toggle-knob { transform: translateX(18px); }

  /* ===== Memory Panel (full modal) ===== */
  .memory-panel .modal { max-width: 560px; }

  .mem-toolbar {
    display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap;
  }
  .mem-toolbar input {
    flex: 1; min-width: 120px; border: 1px solid var(--pink-soft);
    border-radius: 20px; padding: 7px 14px; font-family: inherit;
    font-size: 13px; outline: none; background: var(--bg);
  }
  .mem-toolbar input:focus { border-color: var(--pink-accent); }

  .mem-toolbar select {
    border: 1px solid var(--pink-soft); border-radius: 12px;
    padding: 6px 10px; font-family: inherit; font-size: 12px;
    outline: none; background: white; color: var(--text);
  }

  .mem-chip-bar {
    display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px;
  }
  .mem-chip {
    font-size: 11px; padding: 3px 10px; border-radius: 12px;
    border: 1px solid var(--pink-soft); background: white;
    cursor: pointer; transition: all 0.15s; color: var(--text-light);
  }
  .mem-chip.active { background: var(--pink-accent); color: white; border-color: var(--pink-accent); }

  .mem-time-group { margin-bottom: 16px; }
  .mem-time-label {
    font-size: 12px; font-weight: 700; color: var(--pink-deep);
    margin-bottom: 8px; padding-left: 4px;
  }

  .mem-card {
    background: var(--bg); border-radius: 12px; padding: 12px 14px;
    margin-bottom: 8px; position: relative; transition: box-shadow 0.2s;
  }
  .mem-card:hover { box-shadow: var(--shadow); }

  .mem-card-header { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
  .mem-card-cat {
    font-size: 10px; padding: 2px 8px; border-radius: 8px;
    background: var(--pink-soft); color: var(--pink-deep);
  }
  .mem-card-date { font-size: 10px; color: var(--text-muted); }
  .mem-card-star {
    margin-left: auto; cursor: pointer; font-size: 14px;
    opacity: 0.3; transition: opacity 0.2s;
  }
  .mem-card-star.important { opacity: 1; }

  .mem-card-content {
    font-size: 13px; line-height: 1.6; color: var(--text);
    white-space: pre-wrap; word-break: break-word;
  }

  .mem-card-tags {
    display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px;
  }
  .mem-card-tag {
    font-size: 10px; padding: 1px 6px; border-radius: 6px;
    background: rgba(233,30,99,0.08); color: var(--pink-deep);
  }

  .mem-card-actions {
    display: none; position: absolute; right: 10px; bottom: 10px; gap: 4px;
  }
  .mem-card:hover .mem-card-actions { display: flex; }

  .mem-empty {
    text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13px;
  }

  .mem-stats {
    font-size: 11px; color: var(--text-muted); text-align: center;
    padding: 8px 0; border-top: 1px solid var(--pink-soft); margin-top: 12px;
  }

  /* Edit memory modal */
  .mem-edit-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 200;
    justify-content: center; align-items: center; padding: 20px;
  }
  .mem-edit-overlay.show { display: flex; }
  .mem-edit-box {
    background: var(--card); border-radius: 16px; padding: 20px;
    max-width: 500px; width: 100%; box-shadow: 0 16px 60px rgba(0,0,0,0.2);
  }
  .mem-edit-box h4 { font-size: 14px; color: var(--pink-deep); margin-bottom: 12px; }
  .mem-edit-box textarea {
    width: 100%; border: 1px solid var(--pink-soft); border-radius: 10px;
    padding: 10px 14px; font-family: inherit; font-size: 14px; min-height: 180px;
    outline: none; resize: vertical; line-height: 1.7;
  }
  .mem-edit-box textarea:focus { border-color: var(--pink-accent); }
  .mem-edit-box select, .mem-edit-box input {
    width: 100%; border: 1px solid var(--pink-soft); border-radius: 10px;
    padding: 7px 12px; font-family: inherit; font-size: 13px; outline: none; margin-top: 8px;
  }

  /* ===== Message Edit Modal ===== */
  .msg-edit-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    z-index: 200; justify-content: center; align-items: flex-end; padding: 0;
  }
  .msg-edit-overlay.show { display: flex; }
  .msg-edit-box {
    background: var(--card); border-radius: 20px 20px 0 0; padding: 20px;
    width: 100%; max-height: 60vh; box-shadow: 0 -8px 40px rgba(0,0,0,0.15);
    animation: msgEditIn 0.25s ease;
  }
  @keyframes msgEditIn { from { transform: translateY(100%); } to { transform: translateY(0); } }
  .msg-edit-box textarea {
    width: 100%; border: 1px solid var(--pink-soft); border-radius: 14px;
    padding: 12px 16px; font-family: inherit; font-size: 14px; min-height: 100px;
    outline: none; resize: none; line-height: 1.7; background: var(--bg);
  }
  .msg-edit-box textarea:focus { border-color: var(--pink-accent); }


  /* ===== Quick Phrases ===== */
  .quick-phrases {
    display: flex;
    gap: 6px;
    padding: 6px 16px;
    overflow-x: auto;
    background: var(--card);
    border-top: 1px solid var(--pink-soft);
    flex-shrink: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease;
  }
  .quick-phrases.open {
    max-height: 46px;
    padding: 6px 16px;
    overflow-x: auto;
  }
  .quick-phrases::-webkit-scrollbar { height: 0; }
  .qp-chip {
    font-family: inherit;
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 16px;
    border: 1px solid var(--pink-soft);
    background: white;
    color: var(--text-light);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s;
  }
  .qp-chip:hover { background: var(--pink-soft); color: var(--pink-deep); }
  .qp-chip.edit-chip {
    border-style: dashed;
    color: var(--text-muted);
  }

  .qp-toggle-btn {
    width: 28px; height: 28px;
    border: none; background: transparent;
    color: var(--text-muted); border-radius: 50%;
    cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: color 0.2s;
    line-height: 0;
  }
  .qp-toggle-btn:hover { color: var(--pink-accent); }
  .qp-toggle-btn.active { color: var(--pink-deep); }
  .qp-toggle-btn.home-active { color: var(--pink-deep); background: rgba(233,30,99,0.08); }

  .chat-area.home-mode { background: #fdf0ea; transition: background 0.4s ease; }

  .reasoning-detail {
    display: none; font-size: 10px; color: var(--text-muted);
    background: rgba(255,243,224,0.7); border-radius: 8px;
    padding: 8px 10px; margin-top: 3px; line-height: 1.6;
    white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto;
  }
  .reasoning-detail.show { display: block; }
  .msg-row.ryo .reasoning-detail { margin-left: 40px; }

  .reasoning-btn {
    width: 18px; height: 18px; border: none;
    background: rgba(255,152,0,0.12); border-radius: 50%;
    cursor: pointer; font-size: 9px;
    display: flex; align-items: center; justify-content: center;
    color: #ef6c00; flex-shrink: 0;
  }
  .reasoning-btn:hover { background: rgba(255,152,0,0.25); }

  .mood-input-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
    z-index: 100; justify-content: center; align-items: center; padding: 20px;
  }
  .mood-input-overlay.show { display: flex; }
  .mood-input-box {
    background: var(--card); border-radius: 20px; padding: 24px;
    max-width: 320px; width: 100%;
    box-shadow: 0 24px 80px rgba(0,0,0,0.15);
    animation: modalIn 0.3s ease;
    text-align: center;
  }
  .mood-picker { display: flex; gap: 10px; justify-content: center; margin: 16px 0; flex-wrap: wrap; }
  .mood-pick-btn {
    font-size: 28px; width: 48px; height: 48px; border-radius: 50%;
    border: 2px solid transparent; background: var(--bg);
    cursor: pointer; transition: all 0.15s;
    display: flex; align-items: center; justify-content: center;
  }
  .mood-pick-btn:hover { border-color: var(--pink-mid); }
  .mood-pick-btn.selected { border-color: var(--pink-deep); background: var(--pink-soft); }

  /* ===== Message Context Menu ===== */
  .msg-ctx-menu {
    display: none;
    position: fixed;
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 50;
    padding: 6px 0;
    min-width: 120px;
  }
  .msg-ctx-menu.show { display: block; }
  .msg-ctx-item {
    padding: 8px 16px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    display: block;
    width: 100%;
    border: none;
    background: none;
    text-align: left;
  }
  .msg-ctx-item:hover { background: var(--pink-soft); }

  /* Toast */
  .toast {
    position:fixed; bottom:80px; left:50%; transform:translateX(-50%);
    background:rgba(0,0,0,0.7); color:#fff; padding:6px 16px;
    border-radius:20px; font-size:12px; z-index:200;
    animation: toastIn 0.3s ease, toastOut 0.3s 1.2s ease forwards;
  }
  @keyframes toastIn { from{opacity:0;transform:translateX(-50%) translateY(10px)} to{opacity:1;transform:translateX(-50%)} }
  @keyframes toastOut { to{opacity:0;transform:translateX(-50%) translateY(-10px)} }

  /* Regenerate button */
  .regen-btn {
    width:18px; height:18px; border:none;
    background:rgba(233,30,99,0.08); border-radius:50%;
    cursor:pointer; font-size:9px;
    display:flex; align-items:center; justify-content:center;
    color:var(--pink-accent); flex-shrink:0;
  }
  .regen-btn:hover { background:rgba(233,30,99,0.18); }

  /* ===== Image upload ===== */
  .img-upload-btn {
    width: 28px; height: 28px;
    border: none; background: transparent;
    color: var(--text-muted); border-radius: 50%;
    cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; position: relative;
    overflow: hidden;
  }
  .img-upload-btn:hover { color: var(--pink-accent); }
  .img-upload-btn input {
    position: absolute; width: 28px; height: 28px;
    top: 0; left: 0; opacity: 0; cursor: pointer;
  }
  .img-preview {
    display: none;
    padding: 6px 16px;
    background: var(--card);
    border-top: 1px solid var(--pink-soft);
    flex-shrink: 0;
  }
  .img-preview.show { display: flex; gap: 8px; align-items: center; }
  .img-preview img {
    width: 60px; height: 60px; object-fit: cover; border-radius: 8px;
  }
  .img-preview-remove {
    width: 20px; height: 20px; border: none;
    background: rgba(233,30,99,0.1); border-radius: 50%;
    cursor: pointer; font-size: 10px; color: var(--pink-deep);
    display: flex; align-items: center; justify-content: center;
  }

  /* ===== Floating Scroll Buttons ===== */
  .scroll-btns {
    position: fixed;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 15;
  }
  .scroll-btn {
    width: 34px; height: 34px;
    border: none; border-radius: 50%;
    background: rgba(255,255,255,0.85);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    color: var(--pink-deep);
    transition: background 0.2s;
  }
  .scroll-btn:hover { background: var(--pink-soft); }

  /* ===== Name label on bubbles ===== */
  .msg-name {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 2px;
  }
  .msg-row.ryo .msg-name { margin-left: 40px; }
  .msg-row.miao .msg-name { margin-right: 40px; text-align: right; }

  .msg-time-above {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 2px;
  }
  .msg-row.ryo .msg-time-above { margin-left: 0; }
  .msg-row.miao .msg-time-above { margin-right: 0; text-align: right; }

  /* User avatar upload */
  .avatar-upload-btn {
    width: 28px; height: 28px; border-radius: 50%;
    overflow: hidden; cursor: pointer; position: relative;
  }
  .avatar-upload-btn img {
    width: 100%; height: 100%; object-fit: cover;
  }
  .avatar-upload-btn input {
    position: absolute; inset: 0; opacity: 0; cursor: pointer;
  }

  .icon-svg { width: 16px; height: 16px; display: inline-block; vertical-align: middle; pointer-events: none; }
  .sidebar-new-btn svg, .sidebar-footer-btn svg, .header-menu svg, .img-upload-btn svg, .send-btn svg, .newline-btn svg, .qp-toggle-btn svg { pointer-events: none; overflow: visible; }
  .sidebar-new-btn, .sidebar-footer-btn, .header-menu { color: var(--pink-deep); line-height: 0; }
  .sidebar-footer-btn:hover, .header-menu:hover { color: var(--pink-accent); }
  .img-upload-btn, .newline-btn { line-height: 0; }
  .send-btn { line-height: 0; }

  /* ===== Tab Pages ===== */
  .tab-page { display:none; flex:1; flex-direction:column; min-height:0; overflow:hidden; }
  .tab-page.active { display:flex; }
  .app-container { flex:1; display:flex; flex-direction:column; min-height:0; overflow:hidden; }

  /* ===== Bottom Nav ===== */
  .bottom-nav {
    display:flex; background:var(--card); border-top:1px solid var(--pink-soft);
    flex-shrink:0; padding:4px 0;
    padding-bottom:max(4px, env(safe-area-inset-bottom));
    z-index:15;
  }
  .nav-btn {
    flex:1; display:flex; flex-direction:column; align-items:center; gap:1px;
    padding:6px 0; cursor:pointer; color:var(--text-muted); font-size:9px;
    border:none; background:none; font-family:inherit; transition:color 0.2s;
  }
  .nav-btn.active { color:var(--pink-deep); }
  .nav-btn:hover { color:var(--pink-accent); }
  .nav-btn .nav-icon { font-size:16px; line-height:0; }
  .nav-btn .nav-icon svg { width:20px; height:20px; }

  /* ===== Home Tab ===== */
  .home-page { overflow-y:auto; padding:14px; -webkit-overflow-scrolling:touch; flex:1; }
  .home-page::-webkit-scrollbar { width:0; }

  .countdown-bar {
    background:#fff8e8; border-radius:14px; padding:10px 14px;
    margin-bottom:12px; display:flex; align-items:center; gap:8px;
    font-size:12px; color:#e65100; border:1px solid #ffe0b2;
    animation:hPop .4s ease both;
  }
  .countdown-bar-days { margin-left:auto; font-weight:700; font-size:13px; color:#bf360c; }

  .home-greeting {
    background:linear-gradient(140deg,#fff5f7 0%,#ffe8f0 40%,#ffd6e7 100%);
    border-radius:20px; padding:20px 18px; margin-bottom:12px;
    position:relative; overflow:hidden;
    box-shadow:0 4px 20px rgba(233,30,99,0.06);
    animation:hPop .45s ease both;
  }
  .home-greeting::after { content:'✿'; position:absolute; bottom:10px; right:16px; font-size:36px; opacity:0.08; color:var(--pink-deep); }
  .hg-top { display:flex; align-items:center; gap:10px; margin-bottom:10px; }
  .hg-avatar { width:44px; height:44px; border-radius:50%; overflow:hidden; border:2.5px solid rgba(255,255,255,0.9); box-shadow:0 2px 8px rgba(233,30,99,0.12); flex-shrink:0; }
  .hg-avatar img { width:100%; height:100%; object-fit:cover; }
  .hg-date { font-size:10px; color:var(--pink-deep); opacity:0.65; }
  .hg-weather { display:inline-block; background:rgba(255,255,255,0.55); padding:1px 8px; border-radius:8px; font-size:10px; color:var(--text-light); margin-left:6px; }
  .hg-name { font-size:13px; font-weight:700; color:var(--pink-deep); margin-top:1px; }
  .hg-text { font-size:17px; font-weight:700; color:var(--text); line-height:1.55; position:relative; z-index:1; }
  .hg-sub {
    font-size:12px; color:var(--text-light); line-height:1.6; margin-top:6px;
    position:relative; z-index:1;
    max-height:40px; overflow:hidden; transition:max-height 0.3s ease;
  }
  .hg-sub.expanded { max-height:300px; }
  .hg-expand { font-size:11px; color:var(--pink-accent); cursor:pointer; margin-top:4px; padding:4px 8px; position:relative; z-index:2; display:inline-block; }

  .hcard { background:var(--card); border-radius:16px; padding:14px; box-shadow:0 2px 12px rgba(0,0,0,0.04); position:relative; overflow:hidden; transition:transform 0.15s; cursor:pointer; }
  .hcard:active { transform:scale(0.97); }
  .hcard-label { font-size:11px; font-weight:700; color:var(--text-light); display:flex; align-items:center; gap:5px; margin-bottom:8px; }
  .hcard-dot { width:6px; height:6px; border-radius:50%; flex-shrink:0; }

  .hrow1 { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:12px; }
  .hrow2 { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:12px; }

  /* mood */
  .hmood-face { font-size:36px; text-align:center; margin:6px 0 8px; }
  .hmood-week { display:flex; gap:4px; justify-content:center; }
  .hmood-pip { width:7px; height:7px; border-radius:50%; }
  .hmood-hint { font-size:9px; color:var(--text-muted); text-align:center; margin-top:4px; }

  /* calendar */
  .hcal-head { font-size:12px; font-weight:700; margin-bottom:6px; display:flex; justify-content:space-between; }
  .hcal-head span { font-size:10px; color:var(--text-muted); font-weight:400; }
  .hcal-grid { display:grid; grid-template-columns:repeat(7,1fr); text-align:center; gap:1px; }
  .hcal-wk { font-size:8px; color:var(--text-muted); padding:2px 0; }
  .hcal-d { font-size:9px; color:var(--text-light); border-radius:50%; width:20px; height:20px; display:flex; align-items:center; justify-content:center; margin:1px auto; position:relative; }
  .hcal-d.today { background:var(--pink-deep); color:#fff; font-weight:700; }
  .hcal-d.event::after { content:''; position:absolute; bottom:0; width:3px; height:3px; border-radius:50%; background:var(--pink-accent); }
  .hcal-d.dim { opacity:0.3; }

  /* fitness */
  .hfit-num { font-size:24px; font-weight:700; color:var(--pink-deep); }
  .hfit-unit { font-size:11px; color:var(--text-muted); }
  .hfit-sub { font-size:10px; color:var(--text-light); margin-top:4px; }
  .hfit-bar-bg { height:5px; background:var(--pink-soft); border-radius:3px; margin-top:6px; }
  .hfit-bar-fg { height:100%; border-radius:3px; background:linear-gradient(90deg,#ff6b8a,#e91e63); }
  .hfit-bar-label { font-size:8px; color:var(--text-muted); margin-top:2px; }

  /* chat card */
  .hchat-card { background:linear-gradient(150deg,#fff0f3,#ffe4ee); border:1px solid rgba(233,30,99,0.08); }
  .hchat-list { display:flex; flex-direction:column; gap:6px; }
  .hchat-item { display:flex; align-items:center; gap:8px; padding:6px 8px; border-radius:10px; background:rgba(255,255,255,0.6); transition:background 0.15s; cursor:pointer; }
  .hchat-item:hover { background:rgba(255,255,255,0.9); }
  .hchat-item-dot { width:6px; height:6px; border-radius:50%; background:var(--pink-accent); flex-shrink:0; }
  .hchat-item-name { font-size:11px; color:var(--text); flex:1; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .hchat-item-time { font-size:9px; color:var(--text-muted); flex-shrink:0; }
  .hchat-new { display:flex; align-items:center; justify-content:center; gap:4px; padding:6px; border:1.5px dashed var(--pink-mid); border-radius:10px; color:var(--text-muted); font-size:10px; cursor:pointer; margin-top:4px; }
  .hchat-new:hover { border-color:var(--pink-accent); color:var(--pink-accent); }

  /* activity */
  .hact-list { display:flex; flex-direction:column; gap:8px; }
  .hact-item { display:flex; gap:8px; align-items:flex-start; }
  .hact-time { font-size:9px; color:var(--text-muted); min-width:34px; text-align:right; padding-top:3px; }
  .hact-dot-col { display:flex; flex-direction:column; align-items:center; }
  .hact-dot { width:8px; height:8px; border-radius:50%; flex-shrink:0; margin-top:4px; border:1.5px solid #fff; }
  .hact-dot.c-work { background:#64b5f6; box-shadow:0 0 0 1.5px #64b5f6; }
  .hact-dot.c-life { background:#ffb74d; box-shadow:0 0 0 1.5px #ffb74d; }
  .hact-dot.c-fit { background:#81c784; box-shadow:0 0 0 1.5px #81c784; }
  .hact-dot.c-study { background:#ba68c8; box-shadow:0 0 0 1.5px #ba68c8; }
  .hact-dot.c-kid { background:#ff8a80; box-shadow:0 0 0 1.5px #ff8a80; }
  .hact-line { width:1.5px; flex:1; background:var(--pink-soft); min-height:14px; }
  .hact-text { font-size:11px; color:var(--text); line-height:1.5; flex:1; }
  .hact-tag { display:inline-block; font-size:8px; padding:1px 6px; border-radius:6px; background:var(--pink-soft); color:var(--pink-deep); margin-left:4px; }
  .hact-add { display:flex; align-items:center; justify-content:center; gap:4px; padding:8px; border:1.5px dashed var(--pink-mid); border-radius:10px; color:var(--text-muted); font-size:11px; cursor:pointer; margin-top:8px; }
  .hact-add:hover { border-color:var(--pink-accent); color:var(--pink-accent); }

  @keyframes hPop { from{opacity:0;transform:translateY(10px) scale(0.97)} to{opacity:1;transform:none} }

  /* Anniversary special */
  .home-greeting.anniv-special {
    background:linear-gradient(140deg,#fff0f3 0%,#ffd6e7 30%,#ffb6d3 60%,#ff9ec2 100%);
    border:1.5px solid rgba(233,30,99,0.15);
  }
  .home-greeting.anniv-special .hg-text { color:#c2185b; }
  .home-greeting.anniv-special::after { content:'♡'; font-size:48px; opacity:0.12; }
  .hrow1 .hcard:nth-child(1){animation:hPop .45s .08s ease both}
  .hrow1 .hcard:nth-child(2){animation:hPop .45s .12s ease both}
  .hrow2 .hcard:nth-child(1){animation:hPop .45s .16s ease both}
  .hrow2 .hcard:nth-child(2){animation:hPop .45s .2s ease both}
  .hact-card{animation:hPop .45s .24s ease both}

  /* ===== Dynamic Tab ===== */
  .dynamic-page { overflow-y:auto; padding:14px; -webkit-overflow-scrolling:touch; }
  .dynamic-placeholder { text-align:center; padding:60px 20px; color:var(--text-muted); font-size:13px; }

  /* ===== Settings Tab ===== */
  .settings-page { overflow-y:auto; padding:14px; -webkit-overflow-scrolling:touch; }
  .settings-page::-webkit-scrollbar { width:0; }
  .settings-card {
    background:var(--card); border-radius:16px; padding:14px 16px;
    box-shadow:0 2px 12px rgba(0,0,0,0.04); margin-bottom:10px;
    display:flex; align-items:center; gap:12px;
    cursor:pointer; transition:transform 0.15s;
  }
  .settings-card:active { transform:scale(0.97); }
  .settings-card-icon { font-size:18px; width:36px; height:36px; border-radius:10px;
    display:flex; align-items:center; justify-content:center;
    background:var(--pink-soft); flex-shrink:0; }
  .settings-card-text { flex:1; }
  .settings-card-title { font-size:13px; font-weight:600; color:var(--text); }
  .settings-card-desc { font-size:10px; color:var(--text-muted); margin-top:1px; }
  .settings-card-arrow { color:var(--text-muted); font-size:12px; }