:root {
  --bg: #f7f7f9;
  --panel: #ffffff;
  --ink: #17171c;
  --ink-2: #55555f;
  --ink-3: #8b8b96;
  --line: #e7e7ec;
  --line-2: #f0f0f3;
  --accent: #6d5efc;
  --accent-soft: #efedff;
  --ok: #18a058;
  --bad: #d0453b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .04), 0 4px 16px rgba(20, 20, 40, .05);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.55 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
body.in-workspace { overflow: hidden; }
[hidden] { display: none !important; }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
.muted { color: var(--ink-3); }
.spacer { flex: 1; }

.primary, .ghost { border-radius: 9px; padding: 8px 14px; border: 1px solid transparent; font-weight: 550; transition: background .15s, border-color .15s, transform .05s; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.primary { background: var(--ink); color: #fff; }
.primary:hover:not(:disabled) { background: #2d2d36; }
.primary:active:not(:disabled) { transform: translateY(1px); }
.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.ghost:hover { background: var(--line-2); color: var(--ink); }
.ghost.danger:hover { color: var(--bad); border-color: #f1c9c5; background: #fdf3f2; }
.small { padding: 5px 10px; font-size: 13px; }

/* top bar */
.topbar { height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.crumb { color: var(--ink-2); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb .sep { color: var(--line); margin-right: 12px; }

/* home */
#home { max-width: 1080px; margin: 0 auto; padding: 0 24px 80px; }
.hero { text-align: center; padding: 72px 0 36px; }
.hero h1 { font-size: clamp(30px, 5vw, 48px); line-height: 1.15; letter-spacing: -.03em; margin: 0 0 14px; font-weight: 750; }
.accent { background: linear-gradient(90deg, #6d5efc, #c24bf0 60%, #f2793b); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { color: var(--ink-2); max-width: 600px; margin: 0 auto 30px; font-size: 15px; }
.composer { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 10px 10px 8px 14px; transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: #c9c3ff; box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.composer.big { max-width: 720px; margin: 0 auto; text-align: left; padding: 14px 14px 10px 18px; }
.composer textarea { width: 100%; border: 0; outline: 0; resize: none; font: inherit; font-size: 15px; background: transparent; color: var(--ink); min-height: 44px; }
.composer.big textarea { font-size: 16px; min-height: 72px; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
.hint { font-size: 12px; color: var(--ink-3); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 13px; color: var(--ink-2); font-size: 13px; transition: all .15s; }
.chip:hover { border-color: #c9c3ff; color: var(--accent); background: var(--accent-soft); }

.section-head { display: flex; align-items: baseline; gap: 10px; margin: 28px 0 14px; }
.section-head h2 { font-size: 17px; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: inherit; text-decoration: none; transition: transform .15s, box-shadow .15s; display: block; }
.card:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(20, 20, 40, .08); }
.thumb { height: 150px; background: var(--line-2); overflow: hidden; position: relative; border-bottom: 1px solid var(--line); }
.thumb iframe { width: 400%; height: 400%; transform: scale(.25); transform-origin: 0 0; border: 0; pointer-events: none; background: #fff; }
.thumb-empty { display: grid; place-items: center; height: 100%; color: var(--ink-3); font-size: 13px; }
.card-body { padding: 10px 12px; display: flex; flex-direction: column; position: relative; }
.card-body b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 30px; }
.card-body .muted { font-size: 12px; }
.icon-btn { position: absolute; right: 8px; top: 9px; border: 0; background: transparent; color: var(--ink-3); border-radius: 6px; padding: 3px 7px; font-size: 12px; opacity: 0; transition: opacity .15s; }
.card:hover .icon-btn, .icon-btn.armed { opacity: 1; }
.icon-btn:hover, .icon-btn.armed { background: #fdf3f2; color: var(--bad); }
.empty-grid { grid-column: 1 / -1; padding: 36px; text-align: center; color: var(--ink-3); border: 1px dashed var(--line); border-radius: var(--radius); }

/* workspace */
#workspace { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; height: calc(100vh - 52px); }
.chat { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 14px; }
.chat .composer { margin: 8px 12px 12px; box-shadow: none; }
.toggle { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }

.steps { display: flex; align-items: center; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line-2); font-size: 12px; color: var(--ink-3); }
.steps span { padding: 2px 9px; border-radius: 999px; background: var(--line-2); transition: all .2s; }
.steps span.now { background: var(--accent-soft); color: var(--accent); font-weight: 600; animation: breathe 1.4s ease-in-out infinite; }
.steps span.done { color: var(--ok); }
.steps span.done::before { content: "✓ "; }
.steps i { flex: 0 0 14px; height: 1px; background: var(--line); }
@keyframes breathe { 50% { opacity: .55; } }

.msg { display: flex; gap: 10px; animation: rise .2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--ink); color: #fff; border-radius: 14px 14px 4px 14px; padding: 9px 13px; max-width: 85%; }
.msg.user .bubble code { background: rgba(255, 255, 255, .15); }
.avatar { flex: 0 0 28px; height: 28px; border-radius: 9px; color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; }
.msg .body { min-width: 0; flex: 1; }
.who { display: flex; gap: 6px; align-items: baseline; font-size: 13px; margin-bottom: 2px; }
.who span { color: var(--ink-3); font-size: 12px; }
.msg.agent .bubble { color: var(--ink); }
.bubble p { margin: 0 0 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 4px 0 6px; padding-left: 18px; }
.bubble li { margin: 2px 0; }
.bubble code { font-family: var(--mono); font-size: 12.5px; background: var(--line-2); padding: 1px 5px; border-radius: 5px; }
.msg.engineer .bubble, .msg.qa .bubble { font-size: 13px; color: var(--ink-2); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; display: inline-block; }
.msg.qa .bubble { border-color: #f3d6c9; background: #fff8f4; }
.version-pill { margin-top: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); border-radius: 999px; padding: 2px 10px; font-size: 12px; display: block; }
.version-pill:hover { background: var(--accent-soft); border-color: #c9c3ff; }
.typing { display: inline-flex; gap: 3px; padding: 6px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: .2; } }
.writing b { font-variant-numeric: tabular-nums; color: var(--ink); }
.writing::after { content: ""; display: inline-block; width: 7px; height: 13px; background: var(--accent); margin-left: 6px; vertical-align: -2px; animation: blink .8s infinite; }
.notice { font-size: 13px; padding: 10px 12px; border-radius: 10px; background: var(--line-2); color: var(--ink-2); }
.notice.error { background: #fdf3f2; color: var(--bad); }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.tabs { display: flex; background: var(--line-2); border-radius: 9px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 4px 12px; border-radius: 7px; color: var(--ink-2); font-size: 13px; }
.tabs button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); font-weight: 600; }
.devices { display: flex; gap: 2px; }
.devices button { border: 0; background: transparent; border-radius: 7px; padding: 5px 7px; color: var(--ink-3); display: grid; place-items: center; }
.devices button svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.devices button.on { background: var(--line-2); color: var(--ink); }
#versionSelect { border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font: inherit; font-size: 13px; background: var(--panel); color: var(--ink); }
#reloadBtn[data-sync]::after { content: " ☁"; color: var(--ok); }

.panes { flex: 1; position: relative; min-height: 0; }
.pane { position: absolute; inset: 0; display: none; flex-direction: column; }
.pane.on { display: flex; }
.frame-wrap { --w: 100%; flex: 1; position: relative; display: flex; justify-content: center; background: var(--bg); min-height: 0; }
.frame-wrap iframe { width: var(--w); max-width: 100%; height: 100%; border: 0; background: #fff; transition: width .25s; }
.frame-wrap.device { padding: 18px 0; }
.frame-wrap.device iframe { border-radius: 14px; box-shadow: 0 0 0 1px var(--line), 0 16px 40px rgba(20, 20, 40, .1); }
.empty-stage { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--ink-3); }
.pulse { width: 52px; height: 52px; border-radius: 16px; background: linear-gradient(135deg, var(--accent), #c24bf0); opacity: .2; animation: breathe 1.6s ease-in-out infinite; }
.qa-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 14px; font-size: 13px; border-top: 1px solid var(--line); }
.qa-bar.ok { background: #f1faf4; color: var(--ok); }
.qa-bar.bad { background: #fdf3f2; color: var(--bad); }
.qa-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code { margin: 0; flex: 1; overflow: auto; background: #16161c; color: #d9d9e3; font: 12.5px/1.6 var(--mono); padding: 14px 0; counter-reset: ln; tab-size: 2; }
.code .ln { display: block; padding: 0 16px 0 60px; position: relative; white-space: pre; }
.code .ln::before { counter-increment: ln; content: counter(ln); position: absolute; left: 0; width: 44px; text-align: right; color: #55556a; }
.code .t { color: #f07178; }
.code .a { color: #ffcb6b; }
.code .s { color: #c3e88d; }
.code .c { color: #6b6b80; font-style: italic; }

.data-head { display: flex; justify-content: space-between; gap: 16px; padding: 16px 20px 10px; align-items: flex-start; }
.data-head p { margin: 2px 0 0; font-size: 13px; max-width: 560px; }
.data-list, .version-list { overflow: auto; padding: 4px 20px 24px; display: flex; flex-direction: column; gap: 8px; }
.version-list { padding-top: 16px; }
.kv { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.kv summary { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.kv pre { margin: 0; padding: 10px 12px; border-top: 1px solid var(--line-2); font: 12px/1.5 var(--mono); max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.empty-data { color: var(--ink-3); padding: 30px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.version { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.version.current { border-color: #c9c3ff; box-shadow: 0 0 0 3px var(--accent-soft); }
.vnum { font-weight: 700; font-family: var(--mono); color: var(--accent); width: 34px; }
.vbody { flex: 1; min-width: 0; }
.vbody > div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vbody .muted { font-size: 12px; }
.vact { display: flex; gap: 6px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 13px; z-index: 50; box-shadow: var(--shadow); }
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(480px, 92vw); box-shadow: 0 24px 60px rgba(20, 20, 40, .2); }
dialog::backdrop { background: rgba(20, 20, 30, .35); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 6px; }
dialog p { margin: 0 0 14px; font-size: 13px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; font: 13px var(--mono); background: var(--bg); color: var(--ink); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 860px) {
  body.in-workspace { overflow: auto; }
  #workspace { grid-template-columns: 1fr; grid-template-rows: auto 70vh; height: auto; }
  .chat { border-right: 0; border-bottom: 1px solid var(--line); max-height: 60vh; }
  .devices { display: none; }
  .hero { padding-top: 44px; }
}
