/* ============ 基础 ============ */
:root {
  --blue: #2563eb;
  --blue-2: #3b82f6;
  --bg: #f6f8fc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --user-bubble: #2563eb;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 16px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --card: #131c2e;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --border: #23304a;
  --user-bubble: #2563eb;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

/* hidden 属性必须压过后面 .drawer 里的 display:flex，否则抽屉关不掉 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

::selection { background: rgba(37, 99, 235, .25); }

pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ============ 访问码页 ============ */
body.is-gate {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(37, 99, 235, .12), transparent 60%),
    var(--bg);
}

.gate { width: 100%; max-width: 380px; }

.gate-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 34px 28px 28px;
  text-align: center;
}

.gate-logo {
  width: 52px; height: 52px;
  margin: 0 auto 16px;
  border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  color: #fff; font-size: 24px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, .35);
}

.gate-card h1 { margin: 0 0 6px; font-size: 19px; font-weight: 650; }
.gate-hint { margin: 0 0 22px; font-size: 13px; color: var(--muted); }

.gate-input {
  width: 100%;
  padding: 13px 16px;
  text-align: center;
  letter-spacing: .5em;
  text-indent: .5em;
  font-size: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.gate-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}

.gate-btn {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(37, 99, 235, .3);
  transition: transform .08s, box-shadow .15s;
}
.gate-btn:hover { box-shadow: 0 8px 22px rgba(37, 99, 235, .4); }
.gate-btn:active { transform: translateY(1px); }
.gate-btn:disabled { opacity: .6; cursor: default; }

.gate-err {
  min-height: 20px;
  margin-top: 12px;
  font-size: 13px;
  color: #ef4444;
}

/* ============ 主界面 ============ */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 900px;
  margin: 0 auto;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 650; font-size: 15px; letter-spacing: .2px;
}
.brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .16);
}

.seg {
  display: flex;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 11px;
}
.seg-btn {
  border: 0; background: transparent;
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 13.5px; font-weight: 550;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}
.seg-btn.is-on {
  background: var(--card);
  color: var(--blue);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
}

.topbar-right { margin-left: auto; display: flex; gap: 4px; }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ============ 对话区 ============ */
.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 16px 8px;
  scroll-behavior: smooth;
}

.empty {
  height: 100%;
  display: grid; place-content: center;
  text-align: center;
  gap: 6px;
  padding-bottom: 8vh;
}
.empty-title { font-size: 22px; font-weight: 650; letter-spacing: -.2px; }
.empty-sub { font-size: 13.5px; color: var(--muted); }

.msg {
  display: flex;
  margin-bottom: 18px;
  animation: rise .22s ease-out;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg.user { justify-content: flex-end; }

.bubble {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg.ai { justify-content: flex-start; }
.card {
  max-width: 88%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.card-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--muted);
  margin-bottom: 10px;
}
.chip {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 11.5px;
}
.chip.blue { color: var(--blue); border-color: rgba(37, 99, 235, .3);
  background: rgba(37, 99, 235, .08); }

.status { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }

.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  height: 3px; margin-top: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress > i {
  display: block; height: 100%; width: 30%;
  background: linear-gradient(90deg, var(--blue), var(--blue-2));
  border-radius: 999px;
  animation: slide 1.6s ease-in-out infinite;
}
@keyframes slide {
  0% { margin-left: -30%; }
  100% { margin-left: 100%; }
}

.media {
  display: grid;
  gap: 10px;
}
.media img, .media video {
  width: 100%;
  /* 竖图（9:16）铺满宽度会过高，限制高度并留白居中 */
  max-height: 58vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
  background: var(--bg);
}
.media-foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px;
  font-size: 12px; color: var(--muted);
}
.media-foot a {
  color: var(--blue); text-decoration: none;
  padding: 4px 10px;
  border: 1px solid rgba(37, 99, 235, .3);
  border-radius: 8px;
}
.media-foot a:hover { background: rgba(37, 99, 235, .08); }

.err-box {
  color: #ef4444; font-size: 13.5px;
  background: rgba(239, 68, 68, .08);
  border: 1px solid rgba(239, 68, 68, .25);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ============ 输入区 ============ */
.composer-wrap {
  flex: none;
  padding: 8px 16px 18px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.opts {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 10px;
}
.opt {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.opt select, .opt input {
  border: 0; background: transparent; outline: none;
  font-size: 12.5px; font-weight: 550;
  color: var(--text);
  cursor: pointer;
  max-width: 190px;
}
.opt input[readonly] { cursor: default; }

.thumbs {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 10px;
}
.thumb {
  position: relative;
  width: 62px; height: 62px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px;
  border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff; font-size: 11px; line-height: 1;
  cursor: pointer;
}

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 8px 8px 10px;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .1), var(--shadow);
}

.composer textarea {
  flex: 1;
  border: 0; outline: none;
  background: transparent;
  resize: none;
  max-height: 160px;
  padding: 8px 2px;
  line-height: 1.55;
}

.attach {
  width: 34px; height: 34px; flex: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 18px; line-height: 1;
  cursor: pointer;
  transition: all .15s;
}
.attach:hover { border-color: var(--blue); color: var(--blue); }

.send {
  width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 11px;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  color: #fff;
  font-size: 17px; line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .3);
  transition: opacity .15s, transform .08s;
}
.send:disabled { opacity: .45; cursor: default; box-shadow: none; }
.send:not(:disabled):active { transform: translateY(1px); }

.foot-note {
  margin-top: 8px;
  min-height: 16px;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

/* ============ 历史抽屉 ============ */
.scrim {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .38);
  z-index: 20;
  animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(380px, 88vw);
  background: var(--card);
  border-left: 1px solid var(--border);
  z-index: 21;
  display: flex; flex-direction: column;
  animation: slideIn .2s ease-out;
  box-shadow: -12px 0 40px rgba(15, 23, 42, .16);
}
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } }

.drawer-head {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 12px;
  display: grid; gap: 10px;
}

.hitem {
  display: flex; gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color .15s;
}
.hitem:hover { border-color: var(--blue); }
.hitem img, .hitem video {
  width: 54px; height: 54px; flex: none;
  object-fit: cover;
  border-radius: 8px;
  background: var(--card);
}
.hitem .hmeta { min-width: 0; flex: 1; }
.hitem .hp {
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.hitem .ht { font-size: 11px; color: var(--muted); margin-top: 3px; }
.drawer-empty {
  text-align: center; color: var(--muted);
  font-size: 13px; padding: 40px 0;
}

/* ============ 移动端 ============ */
@media (max-width: 640px) {
  .topbar { padding: 10px 12px; gap: 10px; }
  .brand span:not(.dot) { display: none; }
  .chat { padding: 16px 12px 6px; }
  .composer-wrap { padding: 6px 12px 14px; }
  .card, .bubble { max-width: 94%; }
  .opt select { max-width: 128px; }
}

/* ============ 创作台视觉优化 ============ */
:root {
  --blue: #625bf6;
  --blue-2: #8b5cf6;
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #202238;
  --muted: #777b91;
  --border: #e7e8f1;
  --user-bubble: #655cf4;
  --shadow: 0 10px 30px rgba(40, 39, 92, .07);
  --radius: 18px;
}

html[data-theme="dark"] {
  --bg: #10111b;
  --card: #191a29;
  --text: #f0efff;
  --muted: #a09fb8;
  --border: #2d2e43;
  --user-bubble: #655cf4;
  --shadow: 0 12px 32px rgba(0, 0, 0, .26);
}

body.is-app {
  background:
    radial-gradient(ellipse at 50% -18%, rgba(124, 108, 255, .13), transparent 48%),
    var(--bg);
}

.app {
  width: 100%;
  max-width: 1080px;
  height: 100dvh;
  min-height: 520px;
  background: color-mix(in srgb, var(--card) 45%, transparent);
  border-inline: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.topbar {
  min-height: 68px;
  padding: 12px 24px;
  gap: 22px;
  background: color-mix(in srgb, var(--card) 82%, transparent);
  border-bottom-color: color-mix(in srgb, var(--border) 78%, transparent);
}

.brand {
  font-size: 16px;
  letter-spacing: -.25px;
}
.brand .dot {
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #625bf6, #b05cff);
  box-shadow: 0 0 0 5px rgba(112, 91, 246, .12);
}

.seg {
  padding: 4px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--bg) 86%, var(--card));
}
.seg-btn {
  min-width: 74px;
  padding: 7px 16px;
  border-radius: 10px;
  font-weight: 600;
}
.seg-btn.is-on {
  color: #625bf6;
  box-shadow: 0 2px 8px rgba(30, 30, 60, .10);
}
.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: 17px;
}
.icon-btn:hover {
  border-color: var(--border);
  background: var(--card);
  color: var(--blue);
}

.chat {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 34px 28px 16px;
  scroll-padding-bottom: 24px;
}
.empty {
  gap: 10px;
  padding-bottom: 10vh;
}
.empty::before {
  content: "✦";
  width: 66px;
  height: 66px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(113, 91, 246, .18);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(110, 93, 246, .14), rgba(185, 111, 255, .10));
  color: #725ff4;
  font-size: 31px;
  box-shadow: 0 12px 30px rgba(102, 87, 220, .12);
}
.empty-title {
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 720;
  letter-spacing: -1px;
}
.empty-sub {
  font-size: 14px;
}

.msg { margin-bottom: 22px; }
.bubble {
  padding: 13px 17px;
  border-radius: 19px;
  line-height: 1.65;
}
.msg.user .bubble {
  background: linear-gradient(135deg, #625bf6, #8061f2);
  box-shadow: 0 8px 20px rgba(98, 91, 246, .18);
}
.card {
  padding: 16px;
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card-head { gap: 9px; }
.chip { padding: 3px 9px; }
.chip.blue {
  color: #6558e8;
  border-color: rgba(101, 88, 232, .22);
  background: rgba(101, 88, 232, .07);
}
.media img, .media video {
  border-radius: 14px;
}
.media-foot a {
  color: #6558e8;
  border-color: rgba(101, 88, 232, .25);
  border-radius: 10px;
  padding: 6px 13px;
  font-weight: 600;
}

.composer-wrap {
  width: 100%;
  padding: 12px 28px 22px;
  background: linear-gradient(to top, var(--bg) 78%, transparent);
}
.opts, .thumbs, .composer, .foot-note {
  width: 100%;
  max-width: 920px;
  margin-left: auto;
  margin-right: auto;
}
.opts { gap: 9px; }
.opt {
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--card) 92%, var(--bg));
  transition: border-color .15s, box-shadow .15s;
}
.opt:focus-within {
  border-color: rgba(101, 88, 232, .55);
  box-shadow: 0 0 0 3px rgba(101, 88, 232, .09);
}
.opt select, .opt input { font-weight: 600; }

/* 参数下拉：去掉系统原生外观，换成自绘箭头 */
.opt select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 4px 22px 4px 2px;
  border: 0;
  border-radius: 8px;
  background-color: transparent;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23777b91' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.75 6 7.75l3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  background-size: 12px 12px;
  text-overflow: ellipsis;
  transition: color .15s;
}
.opt select:hover { color: var(--blue); }
.opt select:focus { outline: none; }
.opt select::-ms-expand { display: none; }

/* 展开后的选项列表（Firefox / Chrome 生效） */
.opt select option,
.opt select optgroup {
  background: var(--card);
  color: var(--text);
  font-weight: 500;
}
.opt input { padding: 4px 2px; border: 0; background: transparent; outline: none; }

html[data-theme="dark"] .opt select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23a09fb8' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.75 6 7.75l3-3'/%3E%3C/svg%3E");
}
html[data-theme="dark"] .opt select option {
  background: #191a29;
  color: #f0efff;
}
.composer {
  min-height: 62px;
  padding: 10px 10px 10px 12px;
  border-radius: 20px;
  box-shadow: 0 14px 36px rgba(40, 39, 92, .10);
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--blue) 45%, var(--border));
  box-shadow: 0 2px 10px rgba(40, 39, 92, .06);
}
.composer textarea {
  min-height: 38px;
  padding: 8px 6px;
}
.composer textarea:focus,
.composer textarea:focus-visible { outline: none; }
.composer textarea::placeholder { color: #999caf; }
.attach {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  font-size: 21px;
}
.send {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: linear-gradient(135deg, #625bf6, #8b5cf6);
  box-shadow: 0 7px 16px rgba(98, 91, 246, .27);
}
.foot-note { margin-top: 9px; }

.drawer {
  border-radius: 20px 0 0 20px;
}
.drawer-head { padding: 18px 20px; }
.drawer-body { padding: 14px; gap: 11px; }
.hitem {
  padding: 9px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 78%, var(--card));
}
.hitem img, .hitem video { border-radius: 10px; }

.gate-card {
  border-radius: 26px;
  padding: 38px 32px 30px;
  box-shadow: 0 24px 70px rgba(52, 45, 120, .12);
}
.gate-logo {
  border-radius: 18px;
  background: linear-gradient(135deg, #625bf6, #b05cff);
}
.gate-btn {
  background: linear-gradient(135deg, #625bf6, #8b5cf6);
  border-radius: 13px;
}

button, a, select { -webkit-tap-highlight-color: transparent; }
/* 只在键盘操作时给按钮/链接描边；输入控件靠容器高亮，避免双圈 */
button:focus-visible, a:focus-visible {
  outline: 2px solid rgba(101, 88, 232, .45);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .app {
    min-height: 100dvh;
    border-inline: 0;
  }
  .topbar {
    min-height: 60px;
    padding: 9px 12px;
    gap: 10px;
  }
  .brand span:not(.dot) { display: none; }
  .seg-btn { min-width: 58px; padding-inline: 12px; }
  .chat { padding: 24px 14px 10px; }
  .empty { padding-bottom: 7vh; }
  .empty::before { width: 58px; height: 58px; border-radius: 19px; }
  .empty-title { font-size: 25px; }
  .composer-wrap { padding: 8px 12px max(14px, env(safe-area-inset-bottom)); }
  .opts { gap: 7px; }
  .opt { min-height: 35px; padding: 5px 9px; }
  .composer { min-height: 58px; border-radius: 17px; }
  .card, .bubble { max-width: 96%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
