:root {
  --bg: #0c0d10;
  --surface: #15171c;
  --surface-2: #1d2027;
  --border: #2a2e38;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --brand: #d92d20;
  --brand-hover: #b42318;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  height: 100%;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.flex-1 { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-shell {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 13, 16, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

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

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}
.badge.connected { border-color: rgba(22, 163, 74, 0.45); color: #4ade80; background: rgba(22, 163, 74, 0.14); }
.badge.connecting { border-color: rgba(217, 119, 6, 0.45); color: #fbbf24; background: rgba(217, 119, 6, 0.14); }
.badge.error { border-color: rgba(217, 45, 32, 0.45); color: #f87171; background: rgba(217, 45, 32, 0.14); }

.btn-apk {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--brand);
  padding: 5px 10px;
  border-radius: 8px;
  text-decoration: none;
}

.banner {
  margin: 10px 16px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(217, 45, 32, 0.12);
  border: 1px solid rgba(217, 45, 32, 0.35);
  font-size: 12px;
  line-height: 1.5;
  color: #fecaca;
}

.host-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

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

.host-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}
.host-chip.active {
  border-color: var(--brand);
  background: rgba(217, 45, 32, 0.16);
}
.host-chip-main {
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px 6px 12px;
  cursor: pointer;
}
.host-chip-del {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  padding: 4px 10px 4px 4px;
  cursor: pointer;
}

.main-content {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.panel-header h1 {
  margin: 0 0 8px;
  font-size: 19px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 16px;
}
.muted code {
  color: #fca5a5;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}

.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.form-group textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}

.btn-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-hover); }
.btn.secondary { background: var(--surface-2); border-color: var(--border); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn.small { font-size: 12px; padding: 6px 11px; border-radius: 8px; }

.qr-box {
  margin-bottom: 14px;
  text-align: center;
}
.qr-box video {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.download-card {
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.download-card-title { font-size: 14px; font-weight: 600; }
.download-card-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.section-bar h2 {
  margin: 0;
  font-size: 16px;
  flex: 1;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  color: var(--text);
  cursor: pointer;
}
.card:active { background: var(--surface-2); }

.wt-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.wt-title { font-size: 15px; font-weight: 600; }
.wt-sub { font-size: 12px; color: var(--muted); word-break: break-all; }

.pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.pill.ok { background: rgba(22, 163, 74, 0.18); color: #4ade80; }
.pill.warn { background: rgba(217, 119, 6, 0.22); color: #fbbf24; }
.pill.muted { background: var(--surface-2); color: var(--muted); }

.tab-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 10px;
  padding-bottom: 2px;
}
.tab-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
}
.tab-pill.active {
  background: rgba(217, 45, 32, 0.18);
  border-color: var(--brand);
  color: #fff;
}

.terminal-screen {
  margin: 0 0 10px;
  padding: 12px;
  background: #050608;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: #e5e7eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.48;
  height: 52dvh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.quick-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 10px;
}
.quick-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 8px;
  white-space: nowrap;
  cursor: pointer;
}
.quick-pill.danger {
  border-color: rgba(217, 45, 32, 0.45);
  color: #fca5a5;
}

.composer {
  display: flex;
  gap: 8px;
}
.composer input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  line-height: 1.6;
}
.error-box { border-color: rgba(217, 45, 32, 0.4); }
.error-title { color: #fca5a5; font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.error-desc { font-size: 13px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #1f2937;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  text-align: center;
  z-index: 50;
  border: 1px solid #374151;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #7f1d1d; border-color: #ef4444; }
