:root {
  --bg: #0a0b0b;
  --bg-2: #101212;
  --panel: #141716;
  --panel-2: #1a1e1d;
  --line: #262b2a;
  --line-2: #323837;
  --text: #ecefed;
  --text-2: #a9b1ae;
  --muted: #727b78;
  --emerald: #2fd18b;
  --emerald-2: #1fa56c;
  --emerald-deep: #0d3b28;
  --emerald-glow: rgba(47, 209, 139, 0.18);
  --amber: #e9b55c;
  --danger: #ef7a72;
  --radius: 18px;
  --radius-sm: 12px;
  --serif: "Cormorant Garamond", "Times New Roman", serif;
  --sans: "Manrope", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(47, 209, 139, 0.09), transparent 60%),
    radial-gradient(900px 500px at -10% 20%, rgba(255, 255, 255, 0.035), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.sheen {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: repeating-linear-gradient(115deg, transparent 0 140px, rgba(255,255,255,0.012) 140px 141px);
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.muted { color: var(--muted); font-weight: 400; }
.zh { font-family: "Noto Sans SC", var(--sans); }

a { color: var(--emerald); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 48px);
  padding-top: max(14px, env(safe-area-inset-top));
  background: rgba(10, 11, 11, 0.78);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none !important; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(145deg, #1c2120, #0c0e0e);
  border: 1px solid var(--line-2);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 0 24px var(--emerald-glow);
}
.brand-mark svg { width: 20px; height: 20px; fill: var(--emerald); }
.brand-word { font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: 0.14em; }
.brand-word em { font-style: italic; color: var(--emerald); letter-spacing: 0.06em; }

.topnav { display: flex; gap: 6px; }
.navlink {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  color: var(--text-2); font-size: 14px; font-weight: 500;
  border: 1px solid transparent;
  transition: color .2s, border-color .2s, background .2s;
}
.navlink:hover { color: var(--text); border-color: var(--line-2); background: rgba(255,255,255,0.02); text-decoration: none; }
.kb-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px rgba(233,181,92,.6); }
.kb-dot[data-state="ok"] { background: var(--emerald); box-shadow: 0 0 10px var(--emerald-glow); }

main { position: relative; z-index: 1; max-width: 1240px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 48px); }

/* ---------- Hero ---------- */
.hero { padding: clamp(36px, 7vw, 84px) 0 clamp(24px, 4vw, 40px); max-width: 760px; }
.eyebrow {
  margin: 0 0 14px; font-size: 12px; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--emerald);
}
.hero h1 {
  margin: 0; font-family: var(--serif); font-weight: 500;
  font-size: clamp(40px, 7vw, 76px); line-height: 1.02; letter-spacing: -0.01em;
}
.hero h1 em {
  font-style: italic;
  background: linear-gradient(100deg, #e9fff4 0%, var(--emerald) 45%, #9be8c5 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lede { margin: 20px 0 0; color: var(--text-2); font-size: clamp(15px, 1.6vw, 18px); max-width: 620px; }
.lede.small { font-size: 15px; }

/* ---------- Panels ---------- */
.studio {
  display: grid; grid-template-columns: 1fr 1fr; gap: clamp(16px, 2vw, 24px);
  scroll-margin-top: 90px;
}
.panel {
  position: relative;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(18px, 2.4vw, 28px);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 30px 60px -30px rgba(0,0,0,0.8);
}
.panel::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px; border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, transparent, rgba(47,209,139,0.35), transparent);
}
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.01em; }
.step {
  font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--emerald);
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%;
  border: 1px solid var(--line-2); background: rgba(47,209,139,0.05);
}
.badge {
  margin-left: auto; font-size: 12px; color: var(--text-2);
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line-2);
}

/* ---------- Fields ---------- */
.field {
  width: 100%; display: block;
  background: #0c0e0e; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 16px; font: inherit; font-size: 16px; line-height: 1.55;
  resize: vertical; transition: border-color .2s, box-shadow .2s;
}
.field::placeholder { color: #5a625f; }
.field:focus { outline: none; border-color: var(--emerald-2); box-shadow: 0 0 0 4px var(--emerald-glow); }
.field.mono { font-family: var(--mono); font-size: 14px; }
.msg { min-height: 170px; }
.reply { min-height: 280px; font-size: 16.5px; }
.reply-wrap { position: relative; }
.reply-loading {
  position: absolute; inset: 1px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: rgba(12,14,14,0.85);
}
.reply-loading[hidden] { display: none; }
.reply-loading span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--emerald);
  animation: pulse 1.1s infinite ease-in-out;
}
.reply-loading span:nth-child(2) { animation-delay: .15s; }
.reply-loading span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .2; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.controls { display: grid; gap: 16px; margin-top: 18px; }
.control { border: 0; margin: 0; padding: 0; min-width: 0; }
.control legend { font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; padding: 0; }
.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: #0c0e0e; border: 1px solid var(--line); border-radius: 14px; padding: 4px;
}
.segmented.two { grid-template-columns: repeat(2, 1fr); }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; }
.segmented span {
  display: block; text-align: center; padding: 10px 8px; border-radius: 10px;
  font-size: 14px; font-weight: 600; color: var(--text-2);
  transition: background .2s, color .2s, box-shadow .2s;
}
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span {
  color: #04130c;
  background: linear-gradient(180deg, #4fe0a1, var(--emerald-2));
  box-shadow: 0 6px 18px -6px rgba(47,209,139,0.6), inset 0 1px 0 rgba(255,255,255,0.35);
}
.segmented input:focus-visible + span { outline: 2px solid var(--emerald); outline-offset: 2px; }

.extra, .sync { margin-top: 16px; }
.extra summary, .sync summary {
  cursor: pointer; font-size: 14px; color: var(--text-2); font-weight: 500;
  list-style: none; display: inline-flex; gap: 6px; align-items: center;
}
.extra summary::-webkit-details-marker, .sync summary::-webkit-details-marker { display: none; }
.extra summary::before, .sync summary::before { content: "+"; color: var(--emerald); font-weight: 700; width: 14px; }
.extra[open] summary::before, .sync[open] summary::before { content: "–"; }
.extra .field { margin-top: 10px; }

/* ---------- Buttons ---------- */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 12px;
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line-2); color: var(--text); background: transparent;
  transition: transform .15s, box-shadow .2s, background .2s, border-color .2s, opacity .2s;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--emerald); outline-offset: 3px; }
.btn.primary {
  color: #04130c; border-color: transparent;
  background: linear-gradient(180deg, #4fe0a1 0%, var(--emerald-2) 100%);
  box-shadow: 0 12px 28px -12px rgba(47,209,139,0.7), inset 0 1px 0 rgba(255,255,255,0.4);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 16px 34px -12px rgba(47,209,139,0.9), inset 0 1px 0 rgba(255,255,255,0.4); }
.btn.ghost:hover:not(:disabled) { border-color: var(--emerald-2); background: rgba(47,209,139,0.06); }
.btn .spinner {
  display: none; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(4,19,12,0.3); border-top-color: #04130c; animation: spin .7s linear infinite;
}
.btn.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
#generateBtn { flex: 1 1 auto; max-width: 260px; }

.hint { font-size: 13px; color: var(--muted); }
kbd {
  font-family: var(--mono); font-size: 11px; padding: 2px 6px; border-radius: 6px;
  border: 1px solid var(--line-2); background: #0c0e0e; color: var(--text-2);
}
.fineprint { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); }

/* ---------- Notices ---------- */
.notice { margin: 16px 0 0; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; }
.notice[hidden] { display: none; }
.notice.subtle { background: rgba(233,181,92,0.06); border: 1px solid rgba(233,181,92,0.22); color: #e8d3ac; }
.notice.warn { background: rgba(233,181,92,0.07); border: 1px solid rgba(233,181,92,0.28); color: #ecdcbc; }
.notice.warn strong { color: var(--amber); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.notice.warn p { margin: 6px 0; }
.notice.warn ul { margin: 0; padding-left: 18px; }
.notice.error { background: rgba(239,122,114,0.08); border: 1px solid rgba(239,122,114,0.3); color: #f3c0bb; }

/* ---------- Knowledge ---------- */
.knowledge {
  display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: clamp(20px, 3vw, 40px);
  padding: clamp(56px, 8vw, 100px) 0 40px; scroll-margin-top: 70px;
}
.kb-intro h2 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: clamp(30px, 3.6vw, 42px); line-height: 1.08; }
.kb-intro { position: sticky; top: 100px; align-self: start; }
.save-state { display: inline-flex; align-items: center; gap: 8px; margin-top: 22px; font-size: 13px; color: var(--text-2); }
.save-state .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.save-state[data-state="saving"] .dot { background: var(--amber); animation: pulse 1s infinite; }
.save-state[data-state="saved"] .dot { background: var(--emerald); box-shadow: 0 0 10px var(--emerald-glow); }
.save-state[data-state="error"] .dot { background: var(--danger); }

.kb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kb-field { display: grid; gap: 8px; }
.kb-field.wide { grid-column: 1 / -1; }
.kb-label { font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-2); }
.kb-label .muted { text-transform: none; letter-spacing: 0; }
.kb-form textarea { min-height: 170px; font-size: 15px; }

.sync p { color: var(--text-2); font-size: 14px; margin: 10px 0; }
.sync-row { display: flex; gap: 10px; margin-top: 10px; }
.sync-row .field { flex: 1; padding: 11px 14px; }

/* ---------- Footer & toast ---------- */
.foot {
  position: relative; z-index: 1; max-width: 1240px; margin: 0 auto;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  padding: 28px clamp(16px, 4vw, 48px) max(28px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); font-size: 13px;
}
.foot > span:first-child { font-family: var(--serif); letter-spacing: .14em; font-size: 16px; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  background: #0f1312; border: 1px solid var(--emerald-2); color: var(--text);
  box-shadow: 0 20px 40px -12px rgba(0,0,0,0.8), 0 0 30px var(--emerald-glow);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .studio { grid-template-columns: 1fr; }
  .knowledge { grid-template-columns: 1fr; }
  .kb-intro { position: static; }
}
@media (max-width: 640px) {
  .topnav .navlink:first-child { display: none; }
  .navlink { padding: 8px 12px; font-size: 13px; }
  .brand-word { font-size: 21px; }
  .kb-grid { grid-template-columns: 1fr; }
  .segmented span { padding: 11px 4px; font-size: 13.5px; }
  .actions .btn { flex: 1 1 auto; }
  #generateBtn { max-width: none; }
  .hint { display: none; }
  .reply { min-height: 240px; }
  .sync-row { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- CLEARPRO dashboard ---------- */
[hidden] { display: none !important; }
main { max-width: 1200px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 48px) 60px; position: relative; z-index: 1; }
.login { max-width: 440px; margin: 8vh auto 0; }
.login h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(38px, 8vw, 56px); margin: 6px 0 20px; }
.login h1 em { color: var(--emerald); }
.topnav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.navlink.active { color: var(--emerald); }
.btn.small { padding: 7px 14px; font-size: 13px; min-height: 0; }
.statusbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.conn-line { margin: 4px 0 0; font-weight: 600; }
.conn-line .pill { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; background: var(--muted); }
.conn-line .pill.ok { background: var(--emerald); box-shadow: 0 0 10px var(--emerald); }
.conn-line .pill.warn { background: var(--amber); }
.conn-line .pill.bad { background: var(--danger); }
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 48px; height: 28px; border-radius: 99px; background: var(--line-2); position: relative; transition: background .2s; flex: none; }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .track { background: var(--emerald-2); }
.switch input:checked + .track .thumb { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--emerald); outline-offset: 3px; }
.switch.small { font-size: 14px; }
.inbox { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.conv { width: 100%; text-align: left; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer; font: inherit; }
.conv:hover, .conv.active { border-color: var(--emerald-2); }
.conv .row { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.conv .prev { color: var(--text-2); font-size: 13px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line-2); color: var(--text-2); margin-left: 6px; }
.tag.human { color: var(--amber); border-color: var(--amber); }
.tag.attn { color: var(--danger); border-color: var(--danger); }
.thread-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.thread-head h2 { margin: 0; font-size: 18px; }
.msgs { display: flex; flex-direction: column; gap: 10px; max-height: 52vh; overflow-y: auto; padding: 6px 2px; }
.bubble { max-width: 82%; padding: 10px 14px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.bubble.out { align-self: flex-end; background: var(--emerald-deep); border-color: var(--emerald-2); }
.bubble .meta { display: block; font-size: 11px; color: var(--text-2); margin-top: 6px; }
.bubble .flag { display: block; font-size: 12px; color: var(--amber); margin-top: 4px; }
.send-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 14px; }
.appt { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; display: grid; gap: 6px; }
.appt .row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.appt select { background: var(--bg); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px; padding: 6px 10px; font: inherit; }
.steps { padding-left: 20px; display: grid; gap: 22px; }
.kv { display: grid; gap: 6px; margin: 10px 0; } .kv dd { margin: 0; } .kv dt { color: var(--text-2); font-size: 13px; }
code { font-family: var(--mono); font-size: 13px; color: var(--emerald); }
.notice.ok { border: 1px solid var(--emerald-2); color: var(--emerald); background: rgba(47,209,139,.06); }
@media (max-width: 960px) { .inbox { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .send-row { grid-template-columns: 1fr; } .bubble { max-width: 94%; } }
