:root{
  --bg: #0A0A0B;
  --surface: #16161A;
  --surface-2: #1D1D22;
  --surface-3: #26262C;
  --border: #2A2A30;
  --text: #F2F2F0;
  --text-dim: #94949C;
  --text-faint: #5C5C64;
  --accent: #7C6CFF;
  --accent-dim: #4A3FE0;
  --accent-soft: rgba(124,108,255,0.14);
  --danger: #FF6B6B;
  --ok: #3DD68C;
  --radius-lg: 22px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*{box-sizing:border-box; margin:0; padding:0;}
html,body{height:100%;}

/* hidden 必須永遠優先於任何 display 設定 */
[hidden]{ display:none !important; }

body{
  background:
    radial-gradient(ellipse 900px 500px at 50% -10%, rgba(124,108,255,0.10), transparent),
    var(--bg);
  color:var(--text);
  font-family:var(--font-body);
  font-size:15px;
  -webkit-font-smoothing:antialiased;
}
button{font-family:inherit; cursor:pointer; background:none; border:none; color:inherit;}
input,select,textarea{font-family:inherit; color:inherit;}
a{color:inherit; text-decoration:none;}

.page{
  min-height:100vh;
  display:flex;
  flex-direction:column;
}

/* ===== 頂部狀態列 ===== */
.top-strip{
  display:flex; align-items:center; gap:16px;
  padding:16px 22px;
}
.top-brand{ display:flex; align-items:center; gap:8px; flex-shrink:0; }
.top-brand-logo{ width:26px; height:26px; display:block; }
.top-brand-name{ font-family:var(--font-display); font-weight:700; font-size:15px; letter-spacing:-0.01em; }

.new-chat-btn{
  display:flex; align-items:center; gap:7px;
  padding:8px 14px; border-radius:999px;
  border:1px solid var(--border); color:var(--text-dim);
  font-size:13px; font-weight:500;
  transition:border-color .15s, color .15s;
}
.new-chat-btn:hover{ border-color:#454550; color:var(--text); }

.engine-pill{
  margin-left:auto;
  display:flex; align-items:center; gap:8px;
  padding:8px 14px; border-radius:999px;
  border:1px solid var(--border); background:var(--surface);
  font-size:12.5px; color:var(--text-dim);
}
.engine-pill:hover{ border-color:#454550; }
.engine-dot{ width:7px; height:7px; border-radius:50%; background:var(--text-faint); }
.engine-dot.is-set{ background:var(--ok); box-shadow:0 0 6px rgba(61,214,140,.6); }

/* ===== Hero ===== */
.hero{
  text-align:center;
  padding:26px 20px 6px;
  transition:opacity .2s, max-height .2s, padding .2s;
  overflow:hidden;
}
.hero.is-compact{ padding:0; max-height:0; opacity:0; }
.hero-logo{ width:56px; height:56px; margin-bottom:10px; }
.hero-title{
  font-family:var(--font-display); font-weight:800;
  font-size:clamp(32px, 6vw, 52px); letter-spacing:-0.02em;
  text-transform:uppercase;
}
.hero-title span{ color:var(--accent); }
.hero-sub{ margin-top:10px; color:var(--text-dim); font-size:14.5px; }

/* ===== 主舞台 ===== */
.stage{
  flex:1;
  display:flex; flex-direction:column; align-items:center;
  justify-content:center;
  gap:16px;
  padding:20px 16px 32px;
  max-width:920px; width:100%; margin:0 auto;
}
.stage.has-messages{ justify-content:flex-end; }

.messages{
  width:100%; max-width:760px;
  display:flex; flex-direction:column; gap:20px;
  flex:1; overflow-y:auto;
  padding:12px 4px;
}
.stage:not(.has-messages) .messages{ display:none; }

.msg{ display:flex; gap:12px; max-width:100%; }
.msg-user{ flex-direction:row-reverse; }
.msg-avatar{
  width:28px; height:28px; border-radius:8px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  font-size:12px; font-weight:600;
  background:var(--surface-2); color:var(--text-dim);
}
.msg-user .msg-avatar{ background:var(--accent-soft); color:var(--accent); }
.msg-body{ display:flex; flex-direction:column; gap:8px; max-width:80%; }
.msg-user .msg-body{ align-items:flex-end; }
.msg-bubble{
  padding:11px 14px; border-radius:var(--radius-md);
  background:var(--surface); border:1px solid var(--border);
  font-size:14.5px; line-height:1.65; white-space:pre-wrap; word-break:break-word;
}
.msg-user .msg-bubble{ background:var(--accent); color:#0A0A0B; border-color:var(--accent); font-weight:500; }
.msg-media{ border-radius:var(--radius-md); overflow:hidden; border:1px solid var(--border); max-width:340px; }
.msg-media img, .msg-media video{ display:block; width:100%; }
.msg-meta{ font-size:11px; color:var(--text-faint); }

/* ===== 中央卡片 ===== */
.composer-card{
  width:100%; max-width:760px;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  padding:16px 18px 14px;
  box-shadow:0 20px 60px rgba(0,0,0,.35);
  display:flex; flex-direction:column; gap:12px;
}

.card-row{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.card-row-top{ justify-content:space-between; }

.model-picker{ position:relative; display:flex; align-items:center; gap:6px; }
.model-picker-btn{
  display:flex; align-items:center; gap:6px;
  padding:7px 12px; border-radius:999px;
  border:1px solid var(--border); background:var(--surface-2);
  font-size:13px; color:var(--text-dim); max-width:260px;
}
.model-picker-btn:hover{ border-color:#454550; color:var(--text); }
.model-picker-text{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.model-picker-text strong{ color:var(--text); font-weight:600; }
.refresh-btn{
  width:30px; height:30px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  border:1px solid var(--border); color:var(--text-dim);
}
.refresh-btn:hover{ color:var(--text); border-color:#454550; }
.refresh-btn.is-loading svg{ animation:spin .8s linear infinite; }
@keyframes spin{ to{ transform:rotate(360deg); } }

.model-dropdown{
  position:absolute; top:calc(100% + 8px); left:0;
  width:290px; max-height:320px;
  background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius-md); box-shadow:0 14px 34px rgba(0,0,0,.45);
  display:flex; flex-direction:column; z-index:40; overflow:hidden;
}
.model-search{
  margin:8px; padding:8px 10px;
  background:var(--surface-3); border:1px solid var(--border);
  border-radius:var(--radius-sm); font-size:12.5px; outline:none;
}
.model-search:focus{ border-color:var(--accent); }
.model-options{ overflow-y:auto; padding:0 6px 8px; }
.model-option{
  display:flex; flex-direction:column;
  padding:8px 10px; border-radius:var(--radius-sm);
  font-size:12.5px; color:var(--text-dim); text-align:left; width:100%;
}
.model-option:hover{ background:var(--surface-3); color:var(--text); }
.model-option.is-selected{ background:var(--accent-soft); color:var(--accent); }
.model-option .model-owner{ font-size:10.5px; color:var(--text-faint); margin-top:1px; }
.model-empty{ padding:14px 10px; font-size:12px; color:var(--text-faint); line-height:1.6; text-align:center; }

.mode-tag{
  font-size:12.5px; color:var(--text-dim);
  padding:6px 12px; border-radius:999px; background:var(--surface-2);
  border:1px solid var(--border);
}

/* 模式參數列 */
.composer-controls .control-group{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.control-label{ font-size:12px; color:var(--text-faint); margin-right:2px; }
.pill-group{ display:flex; gap:6px; }
.pill{
  padding:5px 11px; border-radius:999px;
  border:1px solid var(--border); color:var(--text-dim);
  font-size:12.5px; transition:all .15s;
}
.pill:hover{ border-color:#454550; color:var(--text); }
.pill.is-active{ background:var(--accent); border-color:var(--accent); color:#0A0A0B; font-weight:600; }
.agent-select{
  background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:6px 10px; font-size:12.5px;
}
.agent-custom{
  background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:6px 10px; font-size:12.5px;
  min-width:220px; flex:1;
}

/* 輸入區 */
.card-row-input{
  align-items:flex-end;
  background:var(--surface-2);
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px 12px 10px;
  position:relative;
}
.card-row-input:focus-within{ border-color:var(--accent); }
.attachments{ display:flex; flex-wrap:wrap; gap:6px; width:100%; order:-1; }
.attachments:empty{ display:none; }
.attachment-chip{
  display:flex; align-items:center; gap:6px;
  background:var(--surface-3); border:1px solid var(--border);
  border-radius:999px; padding:4px 10px 4px 8px; font-size:11.5px; color:var(--text-dim);
}
.attachment-chip button{ color:var(--text-faint); font-size:13px; line-height:1; }

#promptInput{
  flex:1; width:100%; resize:none; background:transparent; border:none; outline:none;
  color:var(--text); font-size:15px; line-height:1.6; max-height:160px; min-height:52px;
  padding:4px 2px;
}
#promptInput::placeholder{ color:var(--text-faint); }

.input-actions{ display:flex; gap:8px; flex-shrink:0; }
.wand-btn{
  width:34px; height:34px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  border:1px solid #6b5a2b; color:#e0b84a;
  background:rgba(224,184,74,0.08);
  transition:all .15s;
}
.wand-btn:hover{ background:rgba(224,184,74,0.16); }
.send-btn{
  width:34px; height:34px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  background:var(--accent); color:#0A0A0B;
  transition:background .15s, opacity .15s;
}
.send-btn:hover{ background:#8f81ff; }
.send-btn:disabled{ opacity:.4; cursor:default; }

/* 底部列 */
.card-row-bottom{ justify-content:space-between; }
.example-btn{
  padding:7px 13px; border-radius:999px;
  border:1px solid var(--border); color:var(--text-dim);
  font-size:12.5px;
}
.example-btn:hover{ border-color:#454550; color:var(--text); }

.mode-switch{
  display:flex; gap:3px;
  background:var(--surface-2); border:1px solid var(--border);
  border-radius:999px; padding:3px;
}
.mode-switch-item{
  padding:6px 12px; border-radius:999px;
  font-size:12.5px; color:var(--text-dim); white-space:nowrap;
  transition:all .15s;
}
.mode-switch-item:hover{ color:var(--text); }
.mode-switch-item.is-active{ background:var(--text); color:#0A0A0B; font-weight:600; }

.bottom-actions{ display:flex; gap:6px; }
.upload-btn, .gear-btn{
  width:32px; height:32px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  border:1px solid var(--border); color:var(--text-dim);
}
.upload-btn:hover, .gear-btn:hover{ color:var(--text); border-color:#454550; }

/* footer */
.footer-tagline{
  text-align:center; font-size:12.5px; color:var(--text-faint);
  max-width:600px; line-height:1.7; margin-top:4px;
}
.footer-cta{
  text-align:center; font-size:12.5px; color:var(--accent); font-weight:600;
}
.footer-cta:hover{ text-decoration:underline; }

/* ===== Modal ===== */
.modal-overlay{
  position:fixed; inset:0; background:rgba(0,0,0,.6);
  display:flex; align-items:center; justify-content:center; z-index:50;
  padding:20px;
}
.modal{
  width:100%; max-width:420px; max-height:90vh; overflow-y:auto;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-lg);
  padding:22px;
}
.modal-head{ display:flex; align-items:center; margin-bottom:18px; }
.modal-head h2{ font-family:var(--font-display); font-size:18px; font-weight:600; flex:1; }
.modal-close{ color:var(--text-faint); font-size:16px; }
.modal-close:hover{ color:var(--text); }

.field-label{ display:block; font-size:12.5px; color:var(--text-dim); margin-bottom:6px; }
.key-input-row{ display:flex; gap:8px; margin-bottom:14px; }
#apiKeyInput{
  flex:1; min-width:0; background:var(--surface-2); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:10px 12px; font-size:13.5px; outline:none;
}
#apiKeyInput:focus{ border-color:var(--accent); }

.ghost-btn{
  padding:9px 14px; border-radius:var(--radius-sm);
  border:1px solid var(--border); color:var(--text-dim); font-size:12.5px; font-weight:500;
  white-space:nowrap;
}
.ghost-btn:hover{ border-color:#454550; color:var(--text); }

.security-note{
  display:flex; gap:9px; padding:12px; border-radius:var(--radius-md);
  background:var(--accent-soft); border:1px solid rgba(124,108,255,.25);
  margin-bottom:16px;
}
.security-note svg{ flex-shrink:0; color:var(--accent); margin-top:1px; }
.security-note p{ font-size:12px; line-height:1.6; color:#C9C4FF; }

.modal-actions{ display:flex; gap:8px; }
.primary-btn{
  flex:1; padding:10px 14px; border-radius:var(--radius-sm);
  background:var(--accent); color:#0A0A0B; font-size:13.5px; font-weight:600;
  text-align:center; transition:background .15s;
}
.primary-btn:hover{ background:#8f81ff; }

.divider{ height:1px; background:var(--border); margin:18px 0; }

.no-key-cta{ text-align:center; }
.no-key-cta p{ font-size:12.5px; color:var(--text-dim); margin-bottom:10px; }
.cta-link{ display:block; }

.superbapi-brand-link{
  display:flex; justify-content:center; margin-top:18px;
  opacity:.9; transition:opacity .15s;
}
.superbapi-brand-link:hover{ opacity:1; }
.superbapi-brand-img{ max-width:100%; height:auto; border-radius:var(--radius-sm); }

/* ===== Scrollbar ===== */
.messages::-webkit-scrollbar, .modal::-webkit-scrollbar{ width:8px; }
.messages::-webkit-scrollbar-thumb, .modal::-webkit-scrollbar-thumb{ background:var(--border); border-radius:8px; }

/* ===== Responsive ===== */
@media (max-width:760px){
  .top-strip{ padding:12px 14px; gap:10px; }
  .top-brand-name{ display:none; }
  .new-chat-btn{ padding:8px 10px; }
  .hero{ padding:14px 16px 4px; }
  .stage{ padding:12px 12px 20px; }
  .composer-card{ padding:14px 14px 12px; border-radius:18px; }
  .card-row-bottom{ flex-wrap:wrap; gap:8px; }
  .mode-switch{ order:3; width:100%; justify-content:center; }
  .example-btn{ order:1; }
  .bottom-actions{ order:2; margin-left:auto; }
}

@media (prefers-reduced-motion: reduce){
  *{ transition:none !important; animation:none !important; }
}
