:root {
  /* warm charcoal + orange palette */
  --bg: #1a1816;
  --side: #211e1b;
  --panel: #2a2723;
  --panel2: #353029;
  --line: #443e36;
  --text: #f6f2ec;
  --sub: #c2b9ad;
  --faint: #8f867a;
  --accent: #e8853a;        /* primary orange */
  --accent-soft: #f0a96b;
  --green: #4a9e7f;
  --amber: #e0a52e;
  --purple: #b98c5a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ── Login ── */
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.logo-row { display: flex; align-items: center; justify-content: center; gap: 11px; margin-bottom: 26px; }
.brand { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.brand b { color: var(--accent); }
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.login-sub { font-size: 14px; color: var(--sub); line-height: 1.6; margin-bottom: 30px; }
#gbtn-wrap { display: flex; justify-content: center; min-height: 0; margin-bottom: 14px; }
.demo-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; background: #fff; color: #1f1f1f; border: none; border-radius: 10px; padding: 12px; font-size: 14px; font-weight: 600; }
.login-foot { font-size: 11.5px; color: var(--faint); margin-top: 22px; line-height: 1.6; }
.badge { display: inline-block; background: var(--panel2); border: 1px solid var(--line); color: var(--sub); font-size: 11px; padding: 4px 10px; border-radius: 20px; margin-bottom: 24px; }

/* ── App shell ── */
#app { display: none; min-height: 100vh; }
.shell { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar { width: 210px; background: var(--side); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; flex-shrink: 0; }
.side-brand { display: flex; align-items: center; gap: 9px; padding: 0 6px 18px; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; color: var(--sub); border: none; border-radius: 9px; padding: 10px; font-size: 13.5px; font-weight: 500; margin-bottom: 2px; transition: background .15s, color .15s; }
.nav-btn:hover { background: var(--panel); color: var(--text); }
.nav-btn.on { background: var(--panel2); color: var(--text); font-weight: 600; }
.nav-btn.on svg { stroke: var(--accent); }
.nav-btn svg { flex-shrink: 0; }
.user-box { margin-top: auto; display: flex; align-items: center; gap: 9px; padding: 12px 8px 4px; border-top: 1px solid var(--line); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; flex-shrink: 0; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-meta { min-width: 0; flex: 1; }
.user-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-mail { font-size: 10.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.signout { background: none; border: none; color: var(--faint); font-size: 11px; padding: 4px; text-decoration: underline; }

/* ── Content area: normal top-to-bottom flow, centered with a max width ── */
.content { flex: 1; min-width: 0; padding: 32px 32px 40px; }
.content > * { max-width: 880px; margin-left: auto; margin-right: auto; }
.h-title, .h-sub, .stats, .row, .flow, .res-head, .cards, .tpl-grid,
.empty, .run-item, .setbox, .usage, .plans, .bill-note {
  max-width: 880px; margin-left: auto; margin-right: auto;
}
.h-title { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; width: 100%; }
.h-sub { font-size: 13.5px; color: var(--sub); margin-top: 4px; margin-bottom: 24px; width: 100%; }

.stats { display: flex; gap: 12px; margin-bottom: 22px; }
.stat { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 17px; min-width: 0; }
.stat-l { font-size: 11.5px; color: var(--faint); margin-bottom: 6px; }
.stat-v { font-size: 24px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-v.sm { font-size: 14px; }

.row { display: flex; gap: 10px; margin-bottom: 18px; }
.topic-input { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; color: var(--text); font-size: 14.5px; padding: 13px 15px; outline: none; min-width: 0; transition: border-color .15s; }
.topic-input:focus { border-color: var(--accent); }
.launch { display: flex; align-items: center; gap: 7px; background: var(--accent); color: #fff; border: none; border-radius: 11px; font-size: 14px; font-weight: 600; padding: 0 20px; white-space: nowrap; transition: background .15s; }
.launch:hover { background: var(--accent-soft); }
.launch:disabled { background: var(--panel2); color: var(--sub); }

.flow { display: flex; align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px 16px; margin-bottom: 18px; }
.node { display: flex; flex-direction: column; align-items: center; width: 112px; }
.circle { width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; background: var(--panel2); border: 2px solid var(--line); font-size: 15px; font-weight: 700; color: var(--faint); transition: all 0.3s; }
.node-name { font-size: 12.5px; font-weight: 600; margin-top: 9px; color: var(--sub); }
.node-role { font-size: 10.5px; color: var(--faint); margin-top: 1px; }
.link { width: 30px; height: 2px; background: var(--line); margin-top: 24px; border-radius: 2px; transition: all 0.3s; }

.res-head { display: flex; align-items: center; margin-bottom: 14px; }
.res-head span { font-size: 14.5px; font-weight: 600; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 15px 16px; display: flex; flex-direction: column; transition: border-color .15s; }
.card:hover { border-color: var(--accent); }
.card-h { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 8px; }
.card-n { flex-shrink: 0; width: 23px; height: 23px; border-radius: 7px; background: var(--panel2); display: grid; place-items: center; font-size: 11.5px; font-weight: 700; color: var(--accent); }
.card-t { font-size: 13.5px; font-weight: 600; line-height: 1.4; }
.card-b { font-size: 12.5px; color: var(--sub); line-height: 1.6; flex: 1; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); color: var(--sub); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; font-size: 12px; font-weight: 600; transition: all .15s; }
.btn:hover { color: var(--text); border-color: var(--accent); }
.btn.filled { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.filled:hover { background: var(--accent-soft); color: #fff; }
.btn.copy { margin-top: 12px; align-self: flex-start; }

.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.tpl { text-align: left; background: var(--panel); border: 1.5px solid var(--line); border-radius: 14px; padding: 17px; position: relative; color: var(--text); transition: border-color .15s, transform .15s; }
.tpl:hover { border-color: var(--accent); transform: translateY(-2px); }
.tpl.on { border-color: var(--accent); }
.tpl-ico { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; margin-bottom: 12px; }
.tpl-name { font-size: 14.5px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.tpl-desc { font-size: 12px; color: var(--sub); line-height: 1.5; }

.err { background: #3a2018; border: 1px solid #7a4126; color: #f0bba8; border-radius: 11px; padding: 11px 14px; font-size: 13px; margin-bottom: 16px; }
.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 13px; padding: 40px 20px; text-align: center; font-size: 13px; color: var(--sub); }
.run-item { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 14px 16px; margin-bottom: 11px; }

.setbox { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; max-width: 500px; }
.slider { width: 100%; accent-color: var(--accent); }
.tone-btn { background: var(--panel2); color: var(--sub); border: 1px solid var(--line); border-radius: 8px; padding: 7px 13px; font-size: 12.5px; font-weight: 500; transition: all .15s; }
.tone-btn:hover { color: var(--text); }
.tone-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Billing ── */
.usage { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 24px; }
.usage-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--sub); margin-bottom: 11px; }
.usage-top b { color: var(--text); }
.bar { height: 9px; background: var(--panel2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--amber), var(--accent)); border-radius: 6px; transition: width 0.4s; }
.usage-note { font-size: 11.5px; color: var(--faint); margin-top: 10px; }
.plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.plan { position: relative; background: var(--panel); border: 1.5px solid var(--line); border-radius: 15px; padding: 20px 18px; display: flex; flex-direction: column; transition: transform .15s; }
.plan:hover { transform: translateY(-3px); }
.plan-badge { position: absolute; top: -10px; left: 18px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; padding: 3px 10px; border-radius: 20px; letter-spacing: 0.3px; }
.plan-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.plan-price { font-size: 28px; font-weight: 800; color: var(--text); margin-bottom: 16px; }
.plan-price span { font-size: 12px; font-weight: 500; color: var(--faint); margin-left: 3px; }
.plan-feats { flex: 1; display: flex; flex-direction: column; gap: 9px; margin-bottom: 18px; }
.feat { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; color: var(--sub); line-height: 1.4; }
.feat svg { flex-shrink: 0; margin-top: 1px; }
.plan-cta { border: 1px solid var(--line); border-radius: 9px; padding: 10px; font-size: 12.5px; font-weight: 600; color: #fff; transition: filter .15s; }
.plan-cta:hover { filter: brightness(1.1); }
.plan-cta.cur { background: var(--panel2); color: var(--faint); cursor: default; }
.plan-cta.cur:hover { filter: none; }
.bill-note { font-size: 11.5px; color: var(--faint); margin-top: 18px; }
.limit-banner { background: linear-gradient(90deg, rgba(232,133,58,.18), rgba(232,133,58,.06)); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 15px; font-size: 13px; color: var(--text); margin-bottom: 18px; max-width: 880px; margin-left: auto; margin-right: auto; }
.lb-btn { background: var(--accent); color: #fff; border: none; border-radius: 7px; padding: 5px 11px; font-size: 12px; font-weight: 600; cursor: pointer; margin: 0 3px; }

/* ── Post-payment celebration ── */
.confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 9998; }
.celebrate-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 9999; animation: fadein .25s ease; }
.celebrate-card { background: var(--panel); border: 1px solid var(--accent); border-radius: 18px; padding: 32px 30px; text-align: center; max-width: 340px; box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: pop .35s cubic-bezier(.2,1.3,.5,1); }
.celebrate-emoji { font-size: 48px; margin-bottom: 10px; }
.celebrate-title { font-size: 21px; font-weight: 800; color: var(--text); margin-bottom: 8px; }
.celebrate-sub { font-size: 13.5px; color: var(--sub); line-height: 1.6; margin-bottom: 20px; }
.celebrate-close { display: inline-flex; height: 42px; padding: 0 24px; border-radius: 11px; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Builder / canvas ── */
.builder-wrap { display: flex; gap: 14px; margin-bottom: 14px; max-width: 880px; margin-left:auto; margin-right:auto; }
.palette { width: 180px; flex-shrink: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.palette-title { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .5px; margin: 4px 4px 10px; }
.pal-item { display: flex; align-items: center; gap: 9px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin-bottom: 7px; cursor: grab; transition: border-color .15s; }
.pal-item:hover { border-color: var(--accent); }
.pal-item:active { cursor: grabbing; }
.pal-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.pal-name { font-size: 12.5px; font-weight: 600; color: var(--text); }
.pal-role { font-size: 10.5px; color: var(--faint); }
.pal-del { margin-left: auto; width: 16px; height: 16px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); color: var(--sub); font-size: 11px; line-height: 13px; text-align: center; cursor: pointer; flex-shrink: 0; }
.pal-del:hover { color: var(--accent); border-color: var(--accent); }
.new-agent { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 4px; }
.na-in { width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; color: var(--text); font-size: 12px; padding: 8px 9px; margin-bottom: 7px; outline: none; }
.na-in:focus { border-color: var(--accent); }
.na-task { resize: none; min-height: 70px; line-height: 1.45; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.na-task::-webkit-scrollbar { width: 6px; }
.na-task::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.na-task::-webkit-scrollbar-track { background: transparent; }
.na-colors { display: flex; gap: 6px; margin: 2px 0 4px; }
.na-color { width: 20px; height: 20px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.na-color.on { border-color: var(--text); }
.canvas { flex: 1; position: relative; min-height: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 22px 22px; }
.canvas-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.canvas-hint { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); text-align: center; color: var(--faint); font-size: 13px; line-height: 1.7; pointer-events: none; }
.cnode { position: absolute; width: 60px; display: flex; flex-direction: column; align-items: center; cursor: grab; user-select: none; }
.cnode:active { cursor: grabbing; }
.cnode-c { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; border: 2px solid rgba(255,255,255,.15); box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.cnode.linking .cnode-c { box-shadow: 0 0 0 4px var(--accent); }
.cnode-name { font-size: 11px; color: var(--sub); margin-top: 5px; font-weight: 600; }
.cnode-del { position: absolute; top: -6px; right: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); color: var(--sub); font-size: 12px; line-height: 13px; text-align: center; cursor: pointer; opacity: 0; transition: opacity .15s; }
.cnode:hover .cnode-del { opacity: 1; }
.save-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; max-width: 880px; margin-left:auto; margin-right:auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.save-bar .topic-input { max-width: none; flex: 1; }
.save-bar .btn, .save-bar .launch { flex-shrink: 0; height: 44px; padding: 0 20px; border-radius: 11px; font-size: 13.5px; display: inline-flex; align-items: center; justify-content: center; }
.save-bar .btn { background: var(--panel2); }
.tpl-del { position: absolute; top: 11px; right: 13px; width: 20px; height: 20px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); color: var(--sub); font-size: 14px; line-height: 18px; text-align: center; cursor: pointer; opacity: 0; transition: opacity .15s; z-index: 2; }
.tpl:hover .tpl-del { opacity: 1; }

/* ── Mobile ── */
@media (max-width: 640px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: none; border-bottom: 1px solid var(--line); padding: 12px; }
  .nav-btn { width: auto; }
  .user-box { margin-top: 0; margin-left: auto; border-top: none; padding: 4px; }
  .content { padding: 24px 18px; }
  .cards, .tpl-grid, .plans { grid-template-columns: 1fr; }
  .stats { flex-wrap: wrap; }
}
