:root {
  --bg: #080a0f;
  --bg-soft: #0d1017;
  --panel: #101420;
  --panel-2: #151a28;
  --panel-3: #1a2030;
  --line: #232a3d;
  --line-soft: #1b2131;
  --text: #e9edf7;
  --muted: #8b95ab;
  --muted-2: #626c82;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(124, 92, 255, .16), transparent 60%),
    radial-gradient(800px 500px at 92% 0%, rgba(34, 211, 238, .10), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* ───────────── 口令页 ───────────── */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 400px at 50% 0%, rgba(124, 92, 255, .18), transparent 65%),
    var(--bg);
  z-index: 50;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  padding: 34px 28px 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .045), rgba(255, 255, 255, .01));
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gate-logo {
  width: 54px;
  height: 54px;
  margin: 0 auto 4px;
  display: grid;
  place-items: center;
  font-size: 26px;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--accent), #4b32d8);
  box-shadow: 0 12px 30px rgba(124, 92, 255, .4);
}

.gate-card h1 { font-size: 20px; letter-spacing: .01em; }
.gate-card .muted { margin-bottom: 6px; }

.gate-card input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.gate-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .18);
}

.error { color: var(--danger); font-size: 12.5px; }

/* ───────────── 主框架 ───────────── */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 60px;
  flex: 0 0 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(8, 10, 15, .72);
  backdrop-filter: blur(14px);
  z-index: 5;
}

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

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  font-size: 15px;
  background: linear-gradient(145deg, var(--accent), #4b32d8);
  box-shadow: 0 6px 18px rgba(124, 92, 255, .35);
}

.brand-name { font-weight: 600; letter-spacing: .02em; }

.brand-tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 9px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--panel);
}

.pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 10px rgba(52, 211, 153, .8);
}

.pill.busy i { background: var(--warn); box-shadow: 0 0 10px rgba(251, 191, 36, .8); }

/* ───────────── 工作区 ───────────── */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 368px;
  gap: 16px;
  padding: 16px 20px 0;
}

.stage-card {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(255, 255, 255, .028), rgba(255, 255, 255, .006));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.stage-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 5px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  transition: .15s;
}

.seg button.on { background: var(--panel-3); color: var(--text); }
.seg button:disabled { opacity: .35; cursor: not-allowed; }

.stage-tools { display: flex; align-items: center; gap: 8px; }

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  transition: .15s;
}

.chip-btn .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-2);
  transition: .15s;
}

.chip-btn:hover { color: var(--text); border-color: var(--line); }

.chip-btn.on {
  color: #fff;
  border-color: rgba(124, 92, 255, .7);
  background: rgba(124, 92, 255, .16);
}

.chip-btn.on .dot { background: var(--accent); box-shadow: 0 0 10px rgba(124, 92, 255, .9); }

.brush-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 4px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: var(--bg-soft);
}

.mini {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.mini.on { background: var(--panel-3); color: var(--text); }
.mini:hover { color: var(--text); }

#brush-size {
  width: 84px;
  accent-color: var(--accent);
}

.stage-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background-image:
    linear-gradient(rgba(255, 255, 255, .022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .022) 1px, transparent 1px);
  background-size: 26px 26px;
  background-position: center;
  overflow: hidden;
}

#stage {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  display: none;
  touch-action: none;
}

#stage.ready { display: block; }
#stage.masking { cursor: crosshair; }

.stage-empty {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.empty-icon { font-size: 34px; opacity: .8; }
.empty-title { color: var(--text); font-size: 15px; }

.link {
  border: 0;
  background: none;
  color: var(--accent-2);
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.compare-line {
  position: absolute;
  top: 18px;
  bottom: 18px;
  width: 2px;
  background: rgba(255, 255, 255, .85);
  box-shadow: 0 0 14px rgba(0, 0, 0, .6);
  pointer-events: none;
}

.compare-line span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34px;
  height: 34px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}

.compare-line span::before {
  content: "◀ ▶";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 8px;
  color: #111;
  letter-spacing: 1px;
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(8, 10, 15, .74);
  backdrop-filter: blur(6px);
  z-index: 3;
}

.spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(124, 92, 255, .2);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.stage-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 8px;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line-soft);
}


/* ───────────── 模型选择器（带价格） ───────────── */
.model-picker { position: relative; }

.model-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}

.model-trigger:hover { border-color: var(--line); }
.model-trigger[aria-expanded="true"] {
  border-color: rgba(124, 92, 255, .7);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .14);
}

.mt-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mt-price {
  flex: 0 0 auto;
  font-size: 11.5px;
  color: #cbbaff;
  background: rgba(124, 92, 255, .14);
  border: 1px solid rgba(124, 92, 255, .32);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.mt-price.free { color: #86efac; background: rgba(52, 211, 153, .12); border-color: rgba(52, 211, 153, .3); }
.mt-caret { flex: 0 0 auto; font-size: 10px; color: var(--muted); }

.model-menu {
  position: fixed;
  z-index: 60;
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 5px;
  background: #141926;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .6);
}

.model-opt {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  transition: background .12s;
}

.model-opt:hover { background: var(--panel-3); }

.model-opt.on {
  background: rgba(124, 92, 255, .16);
  box-shadow: inset 0 0 0 1px rgba(124, 92, 255, .45);
}

.mo-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }

.mo-name {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mo-hint {
  font-size: 11px;
  color: var(--muted-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mo-price {
  flex: 0 0 auto;
  font-size: 11.5px;
  color: #cbbaff;
  background: rgba(124, 92, 255, .13);
  border: 1px solid rgba(124, 92, 255, .3);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.mo-price.free { color: #86efac; background: rgba(52, 211, 153, .12); border-color: rgba(52, 211, 153, .3); }


/* ───────────── 深度思考开关 ───────────── */
.think-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
  padding: 8px 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  cursor: pointer;
  transition: border-color .15s, opacity .15s;
}

.think-row:hover { border-color: var(--line); }
.think-row.disabled { opacity: .45; cursor: not-allowed; }

.think-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.think-title { font-size: 12.5px; }
.think-sub { font-size: 11px; color: var(--muted-2); }

.think-row input { display: none; }

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 21px;
  border-radius: 999px;
  background: #2a3145;
  transition: background .18s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #8b95ab;
  transition: transform .18s, background .18s;
}

.think-row input:checked + .switch { background: rgba(124, 92, 255, .75); }
.think-row input:checked + .switch::after { transform: translateX(17px); background: #fff; }

/* ───────────── 按钮 ───────────── */
.btn {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: .15s;
}

.btn:hover { border-color: #33405c; background: #1f2637; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }

.primary {
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #8b6bff, #6d4df0 55%, #4f37c9);
  box-shadow: 0 10px 26px rgba(109, 77, 240, .35);
  transition: transform .12s, box-shadow .15s, filter .15s;
}

.primary:hover { filter: brightness(1.08); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .55; cursor: not-allowed; filter: grayscale(.3); }
.primary.wide { width: 100%; }

/* ───────────── 侧栏 ───────────── */
.side {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.side-scroll {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.side-foot-card {
  flex: 0 0 auto;
  padding: 12px 14px;
  gap: 6px;
}

.card {
  flex: 0 0 auto;
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, .008));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.card.grow { flex: 1 0 auto; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-head h3 {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .08em;
}

.count { font-size: 11.5px; color: var(--muted-2); }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}

.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 4px;
  border-radius: 9px;
  font-size: 12.5px;
  transition: .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs button:hover:not(:disabled) { color: var(--text); }

.tabs button.on {
  background: var(--panel-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

.tabs button:disabled { opacity: .35; cursor: not-allowed; }

.select, .textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.select:focus, .textarea:focus {
  border-color: rgba(124, 92, 255, .75);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .14);
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.textarea {
  flex: 1 1 auto;
  min-height: 74px;
  resize: none;
  line-height: 1.6;
}

.hint { font-size: 11.5px; color: var(--muted-2); margin-top: -4px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 11.5px; color: var(--muted); }

.chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
}

.chips::-webkit-scrollbar { display: none; }

.chips button {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 5px 10px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  transition: .15s;
}

.chips button:hover { color: var(--text); border-color: var(--line); }

.status {
  font-size: 12px;
  color: var(--muted);
  min-height: 17px;
  text-align: center;
}

.status.err { color: var(--danger); }
.status.ok { color: var(--ok); }

.result-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.result-actions .btn { padding: 7px 12px; font-size: 12.5px; }

/* ───────────── 历史 ───────────── */
.history {
  flex: 0 0 auto;
  margin: 14px 20px 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, .025), rgba(255, 255, 255, .006));
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 116px;
}

.history-head { display: flex; align-items: center; gap: 10px; }
.history-head h3 { font-size: 12.5px; color: var(--muted); letter-spacing: .08em; }

.history-list {
  flex: 1;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.history-empty {
  display: flex;
  align-items: center;
  color: var(--muted-2);
  font-size: 12.5px;
}

.hist-item {
  position: relative;
  flex: 0 0 auto;
  width: 96px;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  padding: 0;
  transition: .15s;
}

.hist-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hist-item:hover { border-color: rgba(124, 92, 255, .7); transform: translateY(-2px); }

.hist-item .hist-badge {
  position: absolute;
  left: 4px;
  bottom: 4px;
  right: 4px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .62);
  color: #dbe2f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.hist-item .hist-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 10px;
  opacity: 0;
  transition: .15s;
}

.hist-item:hover .hist-del { opacity: 1; }

/* ───────────── 提示 ───────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  padding: 10px 18px;
  border-radius: 12px;
  background: #1d2434;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .22s;
  z-index: 99;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(248, 113, 113, .5); color: #fecaca; }

/* ───────────── 滚动条 ───────────── */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #262d40; border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

/* ───────────── 响应式 ───────────── */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 320px; }
}

@media (max-width: 900px) {
  .app { height: auto; min-height: 100%; overflow-x: hidden; overflow-y: auto; }

  .workspace {
    grid-template-columns: minmax(0, 1fr);   /* minmax(0,…) 防止被内容撑宽 */
    padding: 12px 14px 0;
    gap: 12px;
  }

  /* 网格子项默认 min-width:auto，会被工具栏撑爆，必须归零 */
  .stage-card, .side { min-width: 0; }
  .stage-card { min-height: 0; }

  .stage-head { flex-wrap: wrap; row-gap: 8px; }
  .stage-tools { flex-wrap: wrap; row-gap: 6px; }
  .stage-body { padding: 10px; min-height: 34vh; }

  .stage-foot { gap: 6px; }
  .stage-foot .btn { padding: 7px 11px; font-size: 12.5px; }
  .result-actions .btn { padding: 7px 10px; }

  .side { overflow: visible; }
  .side-scroll { overflow: visible; }

  .history { margin: 12px 14px 14px; height: 108px; }
  .topbar { padding: 0 14px; }
  .brand-tag { display: none; }
}
