/* ============================================================
   ArtCanvas — design tokens
   ============================================================ */
:root {
  --paper:      #FBF8F2;
  --paper-2:    #F6F1E7;
  --panel:      #FEFCF8;
  --ink:        #1C1915;
  --ink-2:      #575047;
  --ink-3:      #8C8377;
  --line:       rgba(28, 25, 21, 0.10);
  --line-2:     rgba(28, 25, 21, 0.16);
  --gold:       #A87A2C;
  --gold-soft:  #F3E6CD;
  --red:        #C93A2B;
  --teal:       #1F7A72;
  --violet:     #6B4FA8;
  --stage-a:    #EDE6D8;
  --stage-b:    #DCD2C0;
  --shadow-sm:  0 1px 2px rgba(28, 25, 21, .06), 0 4px 14px rgba(28, 25, 21, .05);
  --shadow-md:  0 6px 26px rgba(28, 25, 21, .12);
  --radius:     14px;
  --serif: "Noto Serif SC", "Songti SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  flex: 0 0 auto;
  height: 66px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 248, 242, .86);
  backdrop-filter: blur(12px);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 15px; height: 15px;
  background: linear-gradient(140deg, #E8C36A, #A87A2C);
  transform: rotate(45deg);
  border-radius: 3px;
  box-shadow: 0 0 0 3px rgba(168, 122, 44, .12);
}
.brand-text h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: .04em;
  font-weight: 600;
  line-height: 1.1;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 11px;
  letter-spacing: .02em;
  color: var(--ink-3);
}

.artwork-meta {
  margin-left: 10px;
  padding-left: 18px;
  border-left: 1px solid var(--line-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.am-title { display: flex; align-items: baseline; gap: 8px; }
.am-cn { font-family: var(--serif); font-size: 14px; font-weight: 600; }
.am-en { font-size: 11px; color: var(--ink-3); font-style: italic; letter-spacing: .02em; }
.am-sub { font-size: 11px; color: var(--ink-3); letter-spacing: .01em; white-space: nowrap; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #2E9E5B;
  box-shadow: 0 0 0 3px rgba(46, 158, 91, .14);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}
.ghost-btn {
  font: inherit;
  font-size: 12px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
  transition: .18s;
}
.ghost-btn:hover { background: #fff; border-color: var(--line-2); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ============================================================
   Workspace
   ============================================================ */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 396px;
}

.stage-wrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 14px 14px 16px;
  gap: 10px;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, #F2ECDF 0%, transparent 60%),
    linear-gradient(158deg, var(--stage-a) 0%, var(--stage-b) 100%);
  box-shadow: inset 0 0 0 1px rgba(28,25,21,.07), inset 0 2px 24px rgba(90, 72, 45, .12);
  cursor: grab;
  touch-action: none;
}
.stage:active { cursor: grabbing; }
.stage.tool-active { cursor: crosshair; }
#canvas { position: absolute; inset: 0; display: block; }

.stage-tag {
  position: absolute;
  top: 12px; left: 14px;
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: rgba(255,255,255,.72);
  background: rgba(24, 20, 16, .38);
  padding: 4px 9px;
  border-radius: 99px;
  backdrop-filter: blur(6px);
  pointer-events: none;
  mix-blend-mode: normal;
}

.stage-hint {
  position: absolute;
  left: 14px; bottom: 14px;
  font-size: 11px;
  color: rgba(255,255,255,.78);
  background: rgba(24, 20, 16, .34);
  padding: 5px 10px;
  border-radius: 99px;
  backdrop-filter: blur(6px);
  pointer-events: none;
  transition: opacity .4s;
}
.stage-hint.fade { opacity: 0; }

.tool-mode {
  position: absolute;
  top: 12px; right: 14px;
  font-size: 11px;
  color: #fff;
  background: rgba(201, 58, 43, .92);
  padding: 5px 10px;
  border-radius: 99px;
  pointer-events: none;
}

/* Toolbar */
.stage-tools {
  position: absolute;
  left: 50%; bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  background: rgba(255, 253, 249, .92);
  border: 1px solid rgba(28,25,21,.09);
  border-radius: 13px;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(14px);
}
.tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 9px;
  font: inherit;
  font-size: 11.5px;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: .16s;
  white-space: nowrap;
}
.tool svg {
  width: 15px; height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool:hover { background: rgba(28,25,21,.055); color: var(--ink); }
.tool.active { background: var(--ink); color: #FBF8F2; }
.tool.icon-only { padding: 0 8px; }
.tool-sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 3px; }

/* Timeline */
.timeline {
  flex: 0 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px 13px;
  box-shadow: var(--shadow-sm);
}
.tl-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}
.tl-title {
  font-family: var(--serif);
  font-size: 12.5px;
  letter-spacing: .04em;
  color: var(--ink-2);
}
.tl-btn {
  font: inherit;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.tl-btn:hover { background: var(--paper-2); }
.tl-track { display: flex; gap: 6px; }
.tl-step {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  padding: 7px 9px 8px;
  text-align: left;
  font: inherit;
  background: var(--paper-2);
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  overflow: hidden;
  transition: .2s;
}
.tl-step:hover { border-color: var(--line-2); }
.tl-idx {
  display: block;
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--ink-3);
  letter-spacing: .06em;
}
.tl-name {
  display: block;
  font-size: 11.5px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-step.done .tl-name { color: var(--ink); }
.tl-step.active {
  background: #fff;
  border-color: rgba(168,122,44,.45);
  box-shadow: 0 2px 10px rgba(168,122,44,.16);
}
.tl-step.active .tl-name { color: var(--ink); font-weight: 600; }
.tl-step.active::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0; height: 2px; width: 100%;
  background: linear-gradient(90deg, var(--gold), #E4C27E);
}
.tl-step.done .tl-idx::after { content: " ✓"; color: var(--teal); }

/* ============================================================
   Panel
   ============================================================ */
.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
}
.tabs {
  flex: 0 0 auto;
  height: 46px;
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}
.tab {
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-3);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0 10px;
  cursor: pointer;
  transition: .18s;
}
.tab:hover { color: var(--ink-2); }
.tab.active { color: var(--ink); border-bottom-color: var(--gold); font-weight: 600; }
.tab em {
  font-style: normal;
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--ink-3);
  background: var(--paper-2);
  border-radius: 99px;
  padding: 1px 5px;
  margin-left: 2px;
}

.pane { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* Messages */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 18px 8px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(28,25,21,.14); border-radius: 9px; border: 2px solid var(--panel); }

.msg { margin-bottom: 18px; max-width: 100%; animation: fadeUp .34s ease both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg.assistant .msg-body {
  font-size: 13.5px;
  line-height: 1.78;
  color: var(--ink);
  letter-spacing: .005em;
}
.msg-body p { margin: 0 0 9px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { font-weight: 600; color: var(--ink); }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
}
.kind {
  font-size: 10px;
  letter-spacing: .04em;
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 500;
}
.kind.fact { color: #8A5F14; background: var(--gold-soft); }
.kind.obs  { color: #14615B; background: #DCEFEC; }
.kind.interp { color: #4E3684; background: #E9E2F7; }
.msg-src {
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: .02em;
}
.msg-src::before { content: "来源 "; opacity: .7; }

.msg.user { display: flex; justify-content: flex-end; }
.msg.user .msg-body {
  max-width: 84%;
  font-size: 13px;
  line-height: 1.6;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 13px 13px 3px 13px;
  padding: 9px 13px;
  color: var(--ink);
}

.msg.system {
  font-size: 11.5px;
  color: var(--ink-3);
  font-family: var(--mono);
  letter-spacing: .01em;
  border-left: 2px solid var(--gold-soft);
  padding-left: 9px;
  line-height: 1.6;
}
.msg.system b { font-weight: 600; color: var(--ink-2); font-family: var(--sans); }
.msg.system .acts { color: var(--ink-2); }

.caret {
  display: inline-block;
  width: 6px; height: 13px;
  background: var(--gold);
  vertical-align: -2px;
  margin-left: 1px;
  animation: blink 1s steps(2) infinite;
  border-radius: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Composer */
.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 10px 14px 14px;
  background: var(--panel);
}
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 9px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  font: inherit;
  font-size: 11.5px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: 99px;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: .16s;
}
.chip:hover { background: var(--paper-2); color: var(--ink); border-color: rgba(168,122,44,.5); }

#form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 11px;
  padding: 4px 4px 4px 13px;
  transition: .18s;
}
#form:focus-within { border-color: rgba(168,122,44,.6); box-shadow: 0 0 0 3px rgba(168,122,44,.1); }
#input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  padding: 8px 0;
}
#input::placeholder { color: var(--ink-3); }
#send {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  transition: .16s;
}
#send:hover { background: #332C24; }
#send svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Events */
.pane-events { overflow: hidden; }
.ev-note {
  flex: 0 0 auto;
  font-size: 11px;
  line-height: 1.7;
  color: var(--ink-3);
  padding: 11px 16px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}
.ev-note code {
  font-family: var(--mono);
  font-size: 10.5px;
  background: #fff;
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--ink-2);
}
.events-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 14px 20px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
}
.events-list::-webkit-scrollbar { width: 8px; }
.events-list::-webkit-scrollbar-thumb { background: rgba(28,25,21,.14); border-radius: 9px; border: 2px solid var(--panel); }

.ev { padding: 6px 0 7px; border-bottom: 1px dashed rgba(28,25,21,.08); }
.ev-head { display: flex; align-items: baseline; gap: 7px; }
.ev-type {
  flex: 0 0 auto;
  font-size: 9.5px;
  letter-spacing: .03em;
  padding: 1.5px 5px;
  border-radius: 4px;
  background: var(--paper-2);
  color: var(--ink-2);
}
.ev-type.custom { background: #FDECE9; color: var(--red); }
.ev-type.text { background: #E9F0FB; color: #2C5CA8; }
.ev-type.tool { background: #EDF2E6; color: #4B7A3A; }
.ev-type.run { background: #E6F3EA; color: #2E7A4C; }
.ev-type.state { background: #F0EDF9; color: var(--violet); }
.ev-name { color: var(--ink); font-size: 10.5px; }
.ev-time { margin-left: auto; color: var(--ink-3); font-size: 9.5px; }
.ev-body { color: var(--ink-3); font-size: 10.5px; margin-top: 3px; word-break: break-word; }
.ev-json {
  margin: 5px 0 0;
  padding: 7px 8px;
  background: var(--paper-2);
  border-radius: 6px;
  font-size: 9.5px;
  line-height: 1.55;
  color: var(--ink-2);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 190px;
  overflow: auto;
}

/* Pending / modal */
.msg.pending .msg-body {
  color: var(--ink-3);
  font-size: 12.5px;
}
.msg.pending .dots::after {
  content: "";
  animation: dots 1.2s steps(4) infinite;
}
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; }
}
.msg-body.typing::after {
  content: "";
  display: inline-block;
  width: 6px; height: 13px;
  margin-left: 1px;
  vertical-align: -2px;
  background: var(--gold);
  border-radius: 1px;
  animation: blink 1s steps(2) infinite;
}

.agent-btn { display: inline-flex; align-items: center; gap: 6px; }
.agent-btn::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
}
.agent-btn.cloud::before { background: #2E9E5B; box-shadow: 0 0 0 3px rgba(46,158,91,.14); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(28, 25, 21, .34);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.modal-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 22px 18px;
  box-shadow: 0 24px 60px rgba(28,25,21,.22);
}
.modal-card h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .03em;
}
.modal-sub {
  margin: 0 0 16px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-3);
}
.modal-sub code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--paper-2);
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--ink-2);
}
.opt-list { display: grid; gap: 8px; margin-bottom: 14px; }
.opt {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  cursor: pointer;
  transition: .16s;
}
.opt:hover { border-color: rgba(168,122,44,.5); background: #fff; }
.opt input { margin: 3px 0 0; accent-color: var(--gold); }
.opt-main { display: flex; flex-direction: column; gap: 2px; }
.opt-main b { font-size: 12.5px; font-weight: 600; }
.opt-main em { font-style: normal; font-size: 11px; color: var(--ink-3); }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 11.5px; color: var(--ink-2); margin-bottom: 6px; }
.field input,
.field select {
  width: 100%;
  font: inherit;
  font-size: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: .16s;
}
.field select {
  appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% + 1px), calc(100% - 11px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.field input:focus,
.field select:focus { border-color: rgba(168,122,44,.6); box-shadow: 0 0 0 3px rgba(168,122,44,.1); }

.field-hint {
  margin: -6px 0 12px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-3);
}

/* 固定模型值：外观对齐 .field input，但不可编辑 */
.model-fixed {
  font-size: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--paper-2);
  color: var(--ink-2);
}
.model-fixed code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink);
  font-weight: 600;
}

.modal-msg {
  min-height: 16px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-2);
  margin-bottom: 10px;
}
.modal-msg.err { color: var(--red); }
.modal-msg.ok { color: var(--teal); }

/* 本地代理快捷行 */
.proxy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -4px 0 12px;
}
.proxy-state {
  font-size: 11px;
  color: var(--ink-3, var(--ink-2));
  opacity: .75;
}
.proxy-state.ok { color: var(--teal); opacity: 1; }
.proxy-state.err { color: var(--red); opacity: 1; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.primary-btn {
  font: inherit;
  font-size: 12px;
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #FBF8F2;
  cursor: pointer;
  transition: .16s;
}
.primary-btn:hover { background: #332C24; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1080px) {
  .app { height: 100dvh; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 56vh) minmax(0, 1fr);
  }
  .stage-wrap { padding: 10px 10px 6px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .artwork-meta { display: none; }
  .tool span { display: none; }
  .tool { padding: 0 8px; }
  .stage-hint { display: none; }
  .brand-text p { display: none; }
  .messages { padding: 14px 14px 6px; }
}

@media (max-width: 560px) {
  .topbar { height: 56px; padding: 0 12px; gap: 10px; }
  .brand-text h1 { font-size: 17px; }
  .workspace { grid-template-rows: minmax(260px, 50vh) minmax(0, 1fr); }
  .tl-step { padding: 6px 6px 7px; }
  .tl-name { font-size: 10.5px; }
}
