:root {
  --bg: #0b0e14;
  --panel: #141924;
  --panel-2: #1b2231;
  --text: #e8edf7;
  --muted: #8b97ad;
  --line: #26304a;
  --accent: #4f8cff;
  --accent-2: #2f6fe0;
  --user: #2b5fd9;
  --danger: #ff6b6b;
  --warn: #f0b35b;
  --ok: #4ad295;
  --radius: 14px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
#app { height: 100%; display: flex; flex-direction: column; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.screen { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #101522, #0b0e14);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 12px; color: var(--muted); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.icon-btn:active { background: var(--panel-2); }

.content { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 18px; }

/* ---------- pairing ---------- */
.brand { display: flex; flex-direction: column; gap: 6px; margin: 26px 0 20px; }
.brand .logo { width: 54px; height: 54px; border-radius: 16px; background: linear-gradient(135deg, #4f8cff, #7a5cff); display: grid; place-items: center; font-weight: 700; font-size: 22px; }
.brand h2 { margin: 10px 0 0; font-size: 24px; letter-spacing: .2px; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field textarea {
  width: 100%; padding: 12px 13px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: #3c5c96; }

.btn {
  width: 100%; padding: 13px 16px; border-radius: 13px; border: 1px solid transparent;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 600;
}
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--panel); border-color: var(--line); color: var(--text); font-weight: 500; }
.btn.small { width: auto; padding: 9px 14px; font-size: 14px; }
.btn.danger { background: #3a1b22; border-color: #5c2630; color: #ffb3b3; }

.fingerprint {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.6; color: #b9c6dc;
  background: #0e131d; border: 1px dashed #33405f; border-radius: 10px;
  padding: 10px 12px; word-break: break-all;
}
.hint { font-size: 12px; color: var(--muted); line-height: 1.6; }
.error { color: #ff9d9d; font-size: 13px; line-height: 1.6; }
.ok { color: var(--ok); font-size: 13px; }

.check { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0; font-size: 13px; color: #c3cde0; line-height: 1.5; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }

/* ---------- sessions ---------- */
.session-list { display: flex; flex-direction: column; gap: 10px; }
.session-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel);
}
.session-card:active { background: var(--panel-2); }
.session-card .dot { width: 9px; height: 9px; border-radius: 50%; background: #39445c; flex: none; }
.session-card .dot.live { background: var(--ok); box-shadow: 0 0 10px rgba(74,210,149,.55); }
.session-card .body { flex: 1; min-width: 0; }
.session-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-card .meta { font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; font-size: 14px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 4px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 86%; padding: 11px 13px; border-radius: 14px; line-height: 1.55; font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: linear-gradient(180deg, #2d63df, #2450bb); border-bottom-right-radius: 5px; }
.bubble.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.pending { color: var(--muted); font-style: italic; }
.bubble.error { border-color: #5c2630; color: #ffb3b3; }

.tool-chip {
  align-self: flex-start; max-width: 86%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  color: #9fb3d6; background: #0f1420; border: 1px solid #2b3550;
  border-radius: 10px; padding: 7px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tool-chip.err { border-color: #5c2630; color: #ffadad; }

.status-line { align-self: flex-start; color: var(--muted); font-size: 12px; padding: 2px 4px; }

.composer {
  border-top: 1px solid var(--line);
  background: #0e121c;
  padding: 10px 12px 12px;
  display: flex; gap: 10px; align-items: flex-end;
}
.composer textarea {
  flex: 1; resize: none; max-height: 130px; min-height: 44px;
  padding: 12px 13px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--panel); outline: none;
  line-height: 1.4;
}
.composer textarea:focus { border-color: #3c5c96; }
.send {
  width: 46px; height: 44px; border-radius: 13px; border: none;
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #fff; font-size: 18px;
}
.send:disabled { opacity: .4; }

/* ---------- interaction cards ---------- */
.card {
  margin: 10px 12px; padding: 13px 14px;
  border: 1px solid #6b5527; border-radius: 14px;
  background: linear-gradient(180deg, #221b0f, #19150d);
}
.card h4 { margin: 0 0 4px; font-size: 14px; }
.card p { margin: 0 0 10px; font-size: 13px; color: #d9c9a8; line-height: 1.5; white-space: pre-wrap; }
.card .row { display: flex; gap: 8px; }
.card .row .btn { flex: 1; padding: 10px; }

.question-option {
  display: block; width: 100%; text-align: left; margin-bottom: 8px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel);
}
.question-option.selected { border-color: var(--accent); background: #16233d; }

.footer-note { padding: 10px 16px 20px; color: var(--muted); font-size: 12px; line-height: 1.6; }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb; --panel: #fff; --panel-2: #eef2f9; --text: #121723;
    --muted: #5e6b82; --line: #d8e0ee; --user: #2d63df;
  }
  body { background: var(--bg); }
}
