/* 紫藤 —— 移动优先，深色，克制 */

:root {
  --bg: #14101C;
  --bg-2: #1C1725;
  --bg-3: #241E30;
  --line: #2E2840;
  --v400: #8B7BB8;
  --v300: #A99BD0;
  --v200: #C8BCE6;
  --tx: #EDE8F5;
  --tx-2: #9E95B0;
  --tx-3: #6B6379;
  --me: #6E5FA8;
  --ok: #6FBF8E;
  --danger: #D46B6B;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--tx);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; overflow: hidden; }

.screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.screen.active { display: flex; }

.hidden { display: none !important; }
.dim { color: var(--tx-2); }
.small { font-size: 12px; }
.val { color: var(--v300); font-weight: 600; }

/* ==================== 建档 ==================== */
#onboard { overflow-y: auto; }

.ob-head {
  padding: calc(var(--safe-t) + 28px) 20px 8px;
}
.step-tag {
  font-size: 12px; color: var(--v300);
  letter-spacing: .5px; margin-bottom: 10px;
}
.ob-head h1 {
  margin: 0 0 6px;
  font-size: 26px; font-weight: 700; letter-spacing: -.5px;
}
.ob-head p { margin: 0; color: var(--tx-3); font-size: 13px; }

.ob-body {
  padding: 20px 20px calc(var(--safe-b) + 32px);
}
.ob-body.center {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 60vh; text-align: center;
}

.field { margin-bottom: 20px; }
.field > label {
  display: block;
  font-size: 13px; color: var(--tx-2);
  margin-bottom: 9px;
}

input[type=text], textarea {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--tx);
  font-size: 16px;
  padding: 13px 14px;
  font-family: inherit;
  outline: none;
}
input[type=text]:focus, textarea:focus { border-color: var(--v400); }

/* 分段控件 */
.seg {
  display: flex; gap: 8px;
  background: var(--bg-2);
  padding: 4px; border-radius: 14px;
}
.seg-btn {
  flex: 1; padding: 11px 0;
  background: transparent; border: 0;
  color: var(--tx-2); font-size: 15px; font-family: inherit;
  border-radius: 10px; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn.active { background: var(--v400); color: var(--bg); font-weight: 600; }

/* 选项 chips */
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chip {
  padding: 9px 15px;
  background: var(--bg-3);
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--tx-2); font-size: 14px;
  cursor: pointer; transition: all .15s;
  font-family: inherit;
}
.chip.active {
  background: rgba(139,123,184,.18);
  border-color: var(--v400);
  color: var(--v200);
}

/* 滑块 */
input[type=range] {
  width: 100%; height: 28px;
  -webkit-appearance: none; appearance: none;
  background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; background: var(--bg-3); border-radius: 2px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; margin-top: -9px;
  border-radius: 50%; background: var(--v400);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

/* 按钮 */
.btn-primary {
  width: 100%; padding: 16px;
  background: var(--v400); border: 0; border-radius: 14px;
  color: var(--bg); font-size: 16px; font-weight: 700;
  font-family: inherit; cursor: pointer;
  margin-top: 8px;
  transition: opacity .15s;
}
.btn-primary:active { opacity: .8; }
.btn-primary:disabled { opacity: .4; cursor: default; }

.btn-ghost {
  width: 100%; padding: 14px;
  background: transparent; border: 1px solid var(--line);
  border-radius: 14px; color: var(--tx-2);
  font-size: 15px; font-family: inherit; cursor: pointer;
  margin-top: 10px;
}
.btn-ghost:active { background: var(--bg-2); }

/* 候选图 */
.candidates {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 22px;
}
.cand {
  position: relative;
  aspect-ratio: 2/3;
  border-radius: 12px; overflow: hidden;
  background: var(--bg-3);
  border: 2px solid transparent;
  cursor: pointer; transition: all .2s;
  opacity: .5;
}
.cand.active { border-color: var(--v400); opacity: 1; }
.cand img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cand .tag {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 4px; font-size: 10px; text-align: center;
  background: rgba(0,0,0,.55); color: var(--v200);
}

/* spinner */
.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--bg-3);
  border-top-color: var(--v400);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 图库直选列表 */
.preset-list {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 18px;
}
.preset-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: left;
  font-family: inherit;
  color: var(--tx);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.preset-item:active { background: var(--bg-3); border-color: var(--v400); }
.preset-item img, .preset-item .ph {
  width: 54px; height: 54px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-3);
  display: block;
}
.preset-item .meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.preset-item .meta b { font-size: 15px; font-weight: 600; }
.preset-item .meta span { font-size: 12px; color: var(--tx-2); }

/* ==================== 聊天 ==================== */
.chat-head {
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 10px) 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  flex-shrink: 0;
}
.chat-head .who {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; gap: 1px;
}
.chat-head .who > span:first-child {
  font-size: 16px; font-weight: 600;
}
.status { font-size: 11px; color: var(--tx-3); }
.status.ok { color: var(--ok); }
.status.bad { color: var(--danger); }

.icon-btn {
  width: 40px; height: 40px;
  background: transparent; border: 0;
  color: var(--tx-2); font-size: 22px;
  cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--bg-3); }

.msgs {
  flex: 1; overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg { display: flex; flex-direction: column; max-width: 82%; }
.msg.her { align-self: flex-start; align-items: flex-start; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.sys {
  align-self: center; max-width: 92%;
  font-size: 11px; color: var(--tx-3);
  text-align: center; padding: 3px 0;
}

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
}
.msg.her .bubble {
  background: var(--bg-3);
  border-bottom-left-radius: 5px;
}
.msg.me .bubble {
  background: var(--me);
  border-bottom-right-radius: 5px;
  color: #fff;
}

.msg img.photo {
  max-width: 220px; width: 100%;
  border-radius: 14px;
  display: block; margin-top: 6px;
  background: var(--bg-3);
}
.photo-wrap { position: relative; }
.photo-wrap .tag {
  position: absolute; bottom: 8px; left: 8px;
  background: rgba(0,0,0,.6);
  color: var(--v200); font-size: 10px;
  padding: 2px 7px; border-radius: 6px;
}

/* 正在输入 */
.typing {
  display: flex; gap: 4px; align-items: center;
  padding: 0 20px 6px;
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--tx-3);
  animation: blink 1.3s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%,60%,100% { opacity: .25; }
  30% { opacity: 1; }
}

/* 输入区 */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(var(--safe-b) + 10px);
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 11px 14px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.4;
}
.send {
  width: 42px; height: 42px; flex-shrink: 0;
  border-radius: 50%; border: 0;
  background: var(--v400); color: var(--bg);
  font-size: 19px; font-weight: 700;
  cursor: pointer; transition: opacity .15s;
}
.send:disabled { opacity: .35; cursor: default; }

/* 设置面板 */
#settings.sheet { background: var(--bg); }

/* toast */
.toast {
  position: fixed;
  bottom: calc(var(--safe-b) + 80px);
  left: 50%; transform: translateX(-50%);
  background: rgba(36,30,48,.96);
  color: var(--tx);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 84vw;
  text-align: center;
  z-index: 100;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
  animation: toastIn .2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
}

/* 滚动条 */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

/* 焦点可见：键盘/无障碍操作时保留轮廓，触摸时不显示 */
:focus-visible { outline: 2px solid var(--v300); outline-offset: 2px; }
.bad { color: var(--danger); }
