:root {
  --bg: #0b0d14;
  --panel: #131724;
  --panel-2: #1a2032;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f1f4fa;
  --muted: #8f9bb6;
  --accent: #f472b6;
  --accent-2: #8b5cf6;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #fb7185;
  --radius: 15px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body, #root {
  margin: 0; padding: 0; height: 100dvh; width: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, textarea, select { font: inherit; color: inherit; }

.app-shell {
  display: flex; flex-direction: column; height: 100dvh; width: 100%;
  max-width: 960px; margin: 0 auto; background: var(--bg); position: relative;
}

/* Compact Mobile App Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(19, 23, 36, 0.94); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  box-shadow: 0 0 14px rgba(244, 114, 182, 0.4);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-weight: 700; font-size: 15.5px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.gpu-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: var(--panel-2); cursor: pointer;
  flex-shrink: 0; min-height: 34px;
}
.gpu-btn.online { color: var(--ok); border-color: rgba(52, 211, 153, 0.45); background: rgba(52, 211, 153, 0.1); }
.gpu-btn.busy { color: var(--warn); border-color: rgba(251, 191, 36, 0.45); background: rgba(251, 191, 36, 0.1); }
.gpu-btn.offline { color: var(--accent); border-color: rgba(244, 114, 182, 0.4); background: rgba(244, 114, 182, 0.1); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

.main-area { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* Chat Stream */
.chat-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.msg-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 12px; display: flex; flex-direction: column; gap: 14px;
}
.msg-row { display: flex; flex-direction: column; max-width: 86%; }
.msg-row.user { align-self: flex-end; align-items: flex-end; }
.msg-row.assistant { align-self: flex-start; align-items: flex-start; }
.msg-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-bottom: 3px; padding: 0 4px; }
.badge-hb { color: var(--accent); font-weight: 600; }
.bubble {
  padding: 10px 14px; border-radius: 17px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; font-size: 15px;
}
.msg-row.user .bubble { background: linear-gradient(135deg, #db2777, #7c3aed); color: #fff; border-bottom-right-radius: 5px; }
.msg-row.assistant .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg-media { margin-top: 7px; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); max-width: 340px; width: 100%; background: #000; }
.msg-media img, .msg-media video { display: block; width: 100%; max-height: 420px; object-fit: cover; cursor: pointer; }
.msg-audio { margin-top: 7px; width: 260px; max-width: 100%; height: 38px; }
.msg-actions { display: flex; align-items: center; gap: 6px; margin-top: 5px; flex-wrap: wrap; }

/* Mobile Composer */
.composer {
  padding: 8px 10px 10px; border-top: 1px solid var(--border);
  background: rgba(19, 23, 36, 0.96); display: flex; flex-direction: column; gap: 7px; flex-shrink: 0;
}
.composer-tools { display: flex; align-items: center; gap: 8px; overflow-x: auto; padding-bottom: 2px; font-size: 12px; color: var(--muted); }
.composer-tools input[type="text"] {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 11px; font-size: 13px; width: 130px; flex-shrink: 0;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-row textarea {
  flex: 1; min-height: 42px; max-height: 120px; resize: none;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 21px;
  padding: 9px 14px; font-size: 16px; line-height: 1.35; outline: none;
}
.composer-row textarea:focus { border-color: rgba(244, 114, 182, 0.65); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; border: none; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; font-weight: 700;
}
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Fixed Native Bottom Tab Bar */
.bottom-nav {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(19, 23, 36, 0.96); border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); flex-shrink: 0;
}
.tab-item {
  border: none; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 5px 0; border-radius: 10px; cursor: pointer; font-size: 11px; font-weight: 500;
}
.tab-item svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab-item.active { color: var(--accent); }

/* Scrollable Pages (Archives / Gallery / Settings) */
.scroll-page {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 12px 28px; display: flex; flex-direction: column; gap: 13px;
}
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 9px; }

.opt-card {
  text-align: left; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel-2); cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
}
.opt-card.selected {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(244,114,182,.16), rgba(139,92,246,.18));
}
.opt-title { font-weight: 600; font-size: 13.5px; }
.opt-sub { font-size: 12px; color: var(--muted); line-height: 1.45; }

.chip {
  display: inline-block; padding: 2px 7px; border-radius: 6px;
  font-size: 11px; background: rgba(255,255,255,.07); color: var(--muted); margin-right: 4px;
}
.chip-btn {
  padding: 6px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); cursor: pointer;
}
.chip-btn.active { color: #fff; border-color: var(--accent); background: rgba(244, 114, 182, 0.22); }

.tiny-btn {
  padding: 5px 10px; font-size: 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); cursor: pointer;
}
.tiny-btn:active { opacity: 0.7; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); cursor: pointer; font-weight: 600; font-size: 14px; min-height: 42px;
}
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; }
.btn.danger { border-color: rgba(251, 113, 133, 0.45); color: var(--danger); background: rgba(251, 113, 133, 0.1); }
.btn.full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field textarea, .field select {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; font-size: 16px; outline: none; width: 100%;
}
.field textarea { min-height: 82px; resize: vertical; font-size: 15px; }
.check-row { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; white-space: nowrap; }

.stat-box {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px;
  padding: 9px 11px; display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.stat-val { font-size: 17px; font-weight: 700; color: var(--accent); min-width: 22px; text-align: center; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--border); }
.star-btn { border: none; background: transparent; cursor: pointer; font-size: 16px; padding: 0 1px; color: var(--warn); }

.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery-item { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.gallery-item img, .gallery-item video { width: 100%; height: 180px; object-fit: cover; display: block; cursor: pointer; }
.gallery-cap { padding: 7px 9px; font-size: 11.5px; color: var(--muted); }

/* Bottom Sheet & Modals */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.sheet-box {
  background: var(--panel); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0; width: 100%; max-width: 560px;
  max-height: 86dvh; overflow-y: auto; padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet-handle { width: 38px; height: 4px; border-radius: 99px; background: rgba(255,255,255,0.22); margin: 0 auto 12px; }
.modal-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 110;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  max-width: 720px; width: 100%; max-height: 85dvh; overflow: auto; padding: 16px;
}
.modal-img { max-width: 94vw; max-height: 88dvh; border-radius: 12px; }
pre.md-pre { background: var(--bg); padding: 10px; border-radius: 9px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(62px + env(safe-area-inset-top));
  background: #1f2740; border: 1px solid rgba(244,114,182,.55); color: var(--text);
  padding: 9px 15px; border-radius: 999px; font-size: 13px; z-index: 120;
  box-shadow: 0 8px 26px rgba(0,0,0,.5); max-width: 90vw; text-align: center;
}

@media (min-width: 768px) {
  .app-shell { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .sheet-bg { align-items: center; padding: 20px; }
  .sheet-box { border-radius: 18px; border: 1px solid var(--border); padding: 18px; }
  .msg-row { max-width: 72%; }
}
