/*
Template Name: 半梦隅黑金盛宴
Thumbnail: 08.jpg
*/

:root {
  /* ===== 黑金主题色 ===== */
  --gold: #d4af37;
  --gold-light: #f5d061;
  --gold-deep: #b8922f;
  --primary: var(--gold);
  --primary-dark: var(--gold-deep);

  --bg-base: #050505;
  --bg-panel: #111115;
  --bg-panel-soft: #0d0d11;
  --bg-elevated: #17171c;

  --text-main: #f4f4f5;
  --text-soft: #d4d4d8;
  --text-light: #a1a1aa;

  --border-color: #27272a;
  --border-glow: rgba(212, 175, 55, 0.28);

  --user-bubble: linear-gradient(135deg, #caa436 0%, #f0c95a 100%);
  --ai-bubble: #141419;
  --danger: #ef4444;

  --pc-bg: radial-gradient(circle at 30% 10%, #1a1a1f 0%, #0b0b0d 45%, #050505 100%);
  --app-height: 100dvh;
}

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

html {
  margin: 0;
  padding: 0;
  height: var(--app-height);
  background: var(--pc-bg);
}

body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text-main);
  overflow: hidden;
  background:
    linear-gradient(155deg, rgba(212, 175, 55, 0.16) 0%, rgba(8, 8, 10, 0.62) 38%, rgba(5, 5, 5, 0.82) 100%);
  background-color: #070708; /* 图片未加载时先显示底色，减少“闪” */
  display: flex;
  justify-content: center;
  align-items: center;
}

body::before,
html::before,
body::after,
html::after {
  display: none;
}

#app {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(212, 175, 55, 0.10) 0%, rgba(212, 175, 55, 0) 50%),
    rgba(5, 5, 5, 0.18); /* 让 body 背景图能透上来 */
}

/* ================= 登录界面 ================= */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(5, 5, 5, 0.92);
  backdrop-filter: blur(6px);
}

.login-card {
  position: relative;
  width: 90%;
  max-width: 320px;
  padding: 40px 30px;
  text-align: center;
  border: 1px solid var(--border-glow);
  border-radius: 20px;
  background: linear-gradient(180deg, #111115 0%, #0d0d11 100%);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.55), 0 0 25px rgba(212, 175, 55, 0.16);
  animation: fadeIn 0.3s ease forwards;
}

.login-card h2 {
  margin: 0 0 10px;
  color: var(--gold-light);
  font-weight: 500;
  font-size: 1.3rem;
  letter-spacing: 0.08em;
}

.login-card p {
  margin-bottom: 28px;
  color: var(--text-light);
  font-size: 0.9rem;
}

.login-card input {
  width: 100%;
  margin-bottom: 22px;
  padding: 12px 0;
  border: none;
  border-bottom: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-soft);
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: 0.25s ease;
}

.login-card input:focus {
  border-bottom-color: var(--gold);
  box-shadow: 0 8px 18px -10px rgba(212, 175, 55, 0.5);
}

.login-card button {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 12px;
  background: linear-gradient(135deg, #b8922f 0%, #e9c35a 100%);
  color: #171717;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: 0.2s ease;
}

.login-card button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(212, 175, 55, 0.35);
}

.login-error {
  margin-bottom: 14px;
  color: #f87171;
  font-size: 0.85rem;
}

/* ================= 侧边栏（顶部下拉） ================= */
#sidebar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  width: 100%;
  height: auto;
  max-height: 68vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transform: translateY(-102%);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  background: linear-gradient(180deg, #121216 0%, #0b0b0e 100%);
  border-bottom: 1px solid var(--border-glow);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

#sidebar.open {
  transform: translateY(0);
}

.sidebar-header {
  flex-shrink: 0;
  padding: 18px 14px;
}

.sidebar-btn[style] {
  width: 100%;
  margin-bottom: 6px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02) !important;
  border: 1px solid transparent !important;
  color: var(--text-soft) !important;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: 0.2s ease;
}

.sidebar-btn[style]:hover {
  background: rgba(212, 175, 55, 0.08) !important;
  border-color: rgba(212, 175, 55, 0.25) !important;
  color: var(--gold-light) !important;
}

.sidebar-btn[style*="fef2f2"] {
  color: #fca5a5 !important;
}

.sidebar-btn[style*="fef2f2"]:hover {
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
}

.super-card {
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02) !important;
  color: var(--text-main);
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.015);
}

.super-card h3 {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid var(--border-color);
}

/* ================= 主聊天区 ================= */
#main {
  position: absolute;
  inset: 0;
  left: 0;
  z-index: 10;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(5, 5, 5, 0.38); /* 半透明关键 */
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

#chat-history {
  position: relative;
  width: 100%;
  max-width: 800px;
  padding: 20px 16px 108px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

#chat-history::-webkit-scrollbar {
  width: 6px;
}
#chat-history::-webkit-scrollbar-thumb {
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.75), rgba(184, 146, 47, 0.75));
}
#chat-history::-webkit-scrollbar-track {
  background: transparent;
}

.ai-avatar-sidebar,
.ai-avatar-chat {
  border: 1px solid rgba(212, 175, 55, 0.35);
  background: #0f0f13;
  object-fit: cover;
}

.ai-avatar-sidebar {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 14px;
  display: block;
}

.ai-avatar-chat {
  width: 40px;
  height: 40px;
  margin-right: 10px;
  align-self: flex-start;
  flex-shrink: 0;
  border-radius: 10px;
}

.msg-row {
  width: 100%;
  display: flex;
  animation: fadeIn 0.2s ease forwards;
}
.msg-row.user {
  justify-content: flex-end;
}
.msg-row.ai {
  justify-content: flex-start;
}

.msg-wrap {
  max-width: 76%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.bubble {
  width: fit-content;
  max-width: 100%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 0.98rem;
  line-height: 1.65;
  word-wrap: break-word;
  position: relative;
}

.msg-row.user .bubble {
  background: var(--user-bubble);
  color: #1a1a1a;
  box-shadow: 0 6px 16px rgba(212, 175, 55, 0.22);
}

.msg-row.ai .bubble {
  background: var(--ai-bubble);
  color: var(--text-soft);
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
}

.bubble pre {
  margin: 6px 0;
  padding: 10px;
  overflow-x: auto;
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: 10px;
  background: #0c0c10;
  color: #f4f4f5;
  font-size: 0.88rem;
}

.bubble code {
  padding: 2px 5px;
  border-radius: 5px;
  font-family: Consolas, monospace;
  background: rgba(212, 175, 55, 0.16);
  color: var(--gold-light);
}

.msg-row.user .bubble code {
  background: rgba(0, 0, 0, 0.12);
  color: #3b2b00;
}

.bubble p {
  margin: 0 0 6px;
}
.bubble p:last-child {
  margin: 0;
}

.bubble img {
  max-width: min(100%, 240px);
  max-height: 300px;
  margin-top: 6px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid rgba(212, 175, 55, 0.25);
}

.msg-status {
  margin-top: 4px;
  padding: 0 2px;
  color: var(--text-light);
  font-size: 0.74rem;
}
.msg-row.user .msg-status {
  text-align: right;
}

.msg-actions {
  margin-top: 4px;
  padding: 0 2px;
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  opacity: 0;
  transition: 0.2s;
}
.msg-row:hover .msg-actions {
  opacity: 1;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-light);
  cursor: pointer;
}
.action-btn:hover {
  color: var(--gold);
}

/* ================= 底部输入区域 ================= */
.input-trigger-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 100;
  width: 100%;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(180deg, #0c0c0f 0%, #08080b 100%);
  border-top: 1px solid var(--border-color);
}

.bottom-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(212, 175, 55, 0.2);
  color: var(--gold);
  cursor: pointer;
  transition: 0.2s;
}

.bottom-icon-btn:hover {
  color: var(--gold-light);
  background: rgba(212, 175, 55, 0.1);
  border-color: rgba(212, 175, 55, 0.4);
}

.fake-input-btn {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-radius: 12px;
  background: #121216;
  border: 1px solid var(--border-color);
  color: var(--text-light);
  font-size: 0.95rem;
  cursor: text;
}

/* ================= 遮罩与弹窗 ================= */
#overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  background: rgba(0, 0, 0, 0.45);
}

#overlay.show {
  display: block;
  animation: fadeIn 0.2s;
}

.modal-wrap {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 5, 0.65);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  width: 90%;
  max-width: 400px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--border-glow);
  border-radius: 16px;
  background: linear-gradient(180deg, #131318 0%, #0d0d11 100%);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.55), 0 0 24px rgba(212, 175, 55, 0.15);
  animation: fadeIn 0.2s ease;
}

#modalInput {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  resize: none;
  outline: none;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: #0f0f13;
  color: var(--text-main);
  font-size: 1rem;
  line-height: 1.5;
}

#modalInput:focus {
  border-color: rgba(212, 175, 55, 0.45);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
}

#realSendBtn[style],
.modal-card button[onclick="closeInputPanel()"][style] {
  padding: 10px 24px !important;
  border-radius: 10px !important;
  font-size: 1rem !important;
  transition: 0.2s ease !important;
}

.modal-card button[onclick="closeInputPanel()"][style] {
  background: #1a1a20 !important;
  color: var(--text-soft) !important;
  border: 1px solid var(--border-color) !important;
}

.modal-card button[onclick="closeInputPanel()"][style]:hover {
  background: #212129 !important;
}

#realSendBtn[style] {
  background: linear-gradient(135deg, #b8922f 0%, #eac65e 100%) !important;
  color: #171717 !important;
  border: 1px solid rgba(212, 175, 55, 0.35) !important;
  font-weight: 700 !important;
}

#realSendBtn[style]:hover {
  filter: brightness(1.04);
}

#uploadImgBtn[style] {
  background: transparent !important;
  color: var(--text-light) !important;
  transition: 0.2s !important;
}

#uploadImgBtn[style]:hover {
  background: rgba(212, 175, 55, 0.1) !important;
  color: var(--gold-light) !important;
  border-radius: 8px;
}

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 2000;
  transform: translate(-50%, -50%);
  padding: 12px 24px;
  border-radius: 10px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  background: rgba(17, 17, 17, 0.92);
  color: var(--gold-light);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
}

.cursor-blink {
  display: inline-block;
  width: 2px;
  height: 16px;
  margin-left: 2px;
  vertical-align: middle;
  background: var(--gold);
  animation: blink 1s infinite;
}

/* ========= 底部药丸（兼容 inline style） ========= */
div[style*="bottom: calc(100% + 12px)"][style*="overflow-x: auto"] {
  overflow-x: auto !important;
  overflow-y: hidden !important;
  flex-wrap: nowrap !important;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-right: 2px;
}
div[style*="bottom: calc(100% + 12px)"][style*="overflow-x: auto"]::-webkit-scrollbar {
  display: none;
}
div[style*="bottom: calc(100% + 12px)"][style*="overflow-x: auto"] > div {
  flex: 0 0 auto !important;
  white-space: nowrap !important;
}

/* ================= 动画 ================= */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* ================= 响应式 ================= */
@media (min-width: 768px) {
  body {
    padding: 24px;
  }
#app {
  position: relative;
  width: 390px;
  max-width: 390px;
  height: min(844px, calc(100dvh - 48px));
  max-height: calc(100dvh - 48px);
  border-radius: 42px;
  border: 12px solid #1a1a1a;
  box-shadow:
    0 30px 60px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 35px rgba(212, 175, 55, 0.16);
}
  /* 保留“关闭刘海/手势条”的最终效果：不生成 #app::before / #app::after */
  .login-overlay,
  .modal-wrap {
    position: absolute;
  }
  /* PC端药丸：禁用横向滚动，自动换行 */
  div[style*="bottom: calc(100% + 12px)"][style*="overflow-x: auto"] {
    overflow-x: hidden !important;
    overflow-y: visible !important;
    flex-wrap: wrap !important;
    row-gap: 8px;
    column-gap: 8px;
  }
  div[style*="bottom: calc(100% + 12px)"][style*="overflow-x: auto"] > div {
    font-size: 0.75rem !important;
    padding: 3px 10px !important;
  }
}

@media (max-width: 767px) {
  .input-trigger-bar {
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  }

  .login-card {
    width: 92%;
    padding: 30px 20px;
  }
}