:root {
  --bg: #0a0e1a;
  --bg-2: #0e1424;
  --panel: #141b30;
  --panel-2: #1a2340;
  --line: #26304f;
  --text: #e8e2d0;
  --text-dim: #9aa1b8;
  --gold: #d4a94e;
  --gold-soft: #e8c87a;
  --cyan: #5fc3c9;
  --danger: #e06c5a;
  --radius: 14px;
  --maxw: 760px;
}

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

html, body { height: 100%; }

body {
  background: radial-gradient(1200px 600px at 50% -10%, #16203a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

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

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

.logo {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--gold-soft), var(--gold) 60%, #8a6420);
  color: #1a1206;
  display: grid; place-items: center;
  font-size: 22px; font-weight: 800;
  box-shadow: 0 0 18px rgba(212, 169, 78, 0.45);
}

.titles h1 { font-size: 16px; font-weight: 700; letter-spacing: 1px; }
.titles .sub { font-size: 11px; color: var(--text-dim); letter-spacing: 0.5px; }

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

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 17px;
  cursor: pointer;
  transition: 0.15s;
}
.icon-btn:hover { color: var(--gold); border-color: var(--gold); }

.pace-btn {
  padding: 0 12px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--gold-soft);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
  white-space: nowrap;
}
.pace-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- chat ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 12px;
  max-width: var(--maxw);
  margin: 0 auto;
  width: 100%;
  scroll-behavior: smooth;
}

body { display: flex; flex-direction: column; }
.chat { flex: 1; }

.msg { display: flex; margin-bottom: 18px; animation: rise 0.25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.msg-content {
  max-width: 86%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  white-space: normal;
  overflow-wrap: break-word;
}

.msg.user .msg-content {
  background: linear-gradient(135deg, #2a3556, #232c49);
  border: 1px solid #35436b;
  color: #eef0f8;
  border-bottom-right-radius: 4px;
}

.msg.assistant .msg-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.msg-content strong { color: var(--gold-soft); font-weight: 700; }

.msg-content .status {
  background: #0b1120;
  border: 1px solid #2c3a5e;
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.75;
  color: #c7d0e8;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  white-space: pre-wrap;
  overflow-x: auto;
}

.msg-content .divider {
  height: 1px;
  margin: 12px 0;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
}

.msg-content .err { color: var(--danger); font-size: 13px; }

.msg-content .caret {
  display: inline-block;
  width: 8px; height: 16px;
  background: var(--gold);
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 0.8s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- options ---------- */
.options-bar {
  max-width: var(--maxw);
  margin: 0 auto;
  width: 100%;
  padding: 6px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: 0.15s;
}
.option-chip:hover { border-color: var(--gold); background: #1f2a4a; }
.option-chip:active { transform: scale(0.98); }

.opt-letter {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--gold);
  color: #1a1206;
  font-weight: 800;
  font-size: 13px;
  display: grid; place-items: center;
}

/* ---------- composer ---------- */
.composer {
  display: flex;
  gap: 10px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(14, 20, 36, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  bottom: 0;
  z-index: 20;
}

.composer-inner, .input-wrap { display: contents; }

.input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: 0.15s;
}
.input:focus { border-color: var(--gold); }

.send-btn {
  padding: 0 20px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  color: #1a1206;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: 0.15s;
}
.send-btn:hover { filter: brightness(1.06); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(900px 500px at 50% 30%, #16203a, var(--bg));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 24px;
}
.overlay.hidden { display: none; }

.overlay-card {
  text-align: center;
  max-width: 420px;
  width: 100%;
  animation: rise 0.4s ease;
}

.overlay-logo {
  width: 84px; height: 84px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--gold-soft), var(--gold) 60%, #8a6420);
  color: #1a1206;
  display: grid; place-items: center;
  font-size: 44px; font-weight: 800;
  box-shadow: 0 0 40px rgba(212, 169, 78, 0.5);
}

.overlay-card h2 { font-size: 22px; letter-spacing: 2px; margin-bottom: 10px; }
.overlay-intro { color: var(--text-dim); font-size: 14px; margin-bottom: 24px; }

.overlay-card button { width: 100%; margin-bottom: 10px; }
.overlay-note { color: var(--text-dim); font-size: 12px; margin-top: 8px; min-height: 18px; }

/* ---------- buttons ---------- */
.btn-primary, .btn-secondary, .btn-danger {
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
}
.btn-primary { background: linear-gradient(135deg, var(--gold-soft), var(--gold)); color: #1a1206; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--gold); color: var(--gold); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid #5a2c26; }
.btn-danger:hover { background: #2a1613; }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 24px;
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }

.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  max-width: 440px;
  width: 100%;
  animation: rise 0.25s ease;
}

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; letter-spacing: 1px; }

.modal-card label { display: block; font-size: 13px; color: var(--text-dim); margin: 12px 0 6px; }
.modal-card input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.modal-card input:focus { border-color: var(--gold); }
.modal-card select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.modal-card select:focus { border-color: var(--gold); }

.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn-primary { flex: 1; }

.hint { font-size: 12px; color: var(--text-dim); margin-top: 10px; line-height: 1.6; }
.hint code { color: var(--cyan); }

.save-section { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.save-actions { display: flex; gap: 10px; }
.save-actions .btn-secondary { flex: 1; }

.state-body { max-height: 70vh; overflow-y: auto; }
.state-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 2px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.state-row .state-k { color: var(--text-dim); flex: none; }
.state-row .state-v { color: var(--text); text-align: right; overflow-wrap: anywhere; }
.state-sub { margin: 14px 0 4px; font-size: 13px; font-weight: 700; color: var(--gold-soft); letter-spacing: 1px; }

.state-group { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; overflow: hidden; }
.state-group-head {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--gold-soft);
  border: none; cursor: pointer;
  font-size: 14px; font-weight: 700; text-align: left;
  transition: 0.15s;
}
.state-group-head:hover { background: #1f2a4a; }
.state-group-head .chev { display: inline-block; font-size: 11px; transition: transform 0.15s; }
.state-group.open .state-group-head .chev { transform: rotate(90deg); }
.state-group-body { display: none; padding: 2px 12px 8px; }
.state-group.open .state-group-body { display: block; }
.state-group-body .state-row:last-child { border-bottom: none; }

.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: #1f2a4a;
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 60;
  opacity: 0;
  transition: 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 520px) {
  .msg-content { max-width: 92%; font-size: 14px; }
  .titles h1 { font-size: 14px; }
  .titles .sub { display: none; }
}
