/* ============ 时间像小马车 · 故事书风格 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --accent: #ff8c42;
  --accent-deep: #f0731f;
  --purple: #5b4b9e;
  --purple-deep: #3d3580;
  --ink: #33305a;
  --paper: rgba(255, 255, 255, 0.92);
  --shadow: 0 10px 30px rgba(30, 20, 70, 0.35);
  --radius: 20px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: linear-gradient(180deg, #1a1440 0%, #3b2a6e 100%);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }
#app > canvas { position: absolute; inset: 0; display: block; }

button { font-family: inherit; cursor: pointer; border: none; background: none; }

.hidden { display: none !important; }

/* ============ 顶栏 ============ */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; z-index: 30; pointer-events: none;
}
.brand {
  color: #fff; font-weight: 900; font-size: 18px;
  text-shadow: 0 2px 8px rgba(0,0,0,.45);
  background: rgba(20, 12, 50, 0.35); backdrop-filter: blur(6px);
  padding: 8px 16px; border-radius: 999px;
}
.brand span { font-size: 12px; font-weight: 400; opacity: .85; margin-left: 6px; }
.topbar-actions { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  position: relative; width: 42px; height: 42px; border-radius: 50%;
  background: var(--paper); font-size: 17px; color: var(--ink);
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  transition: transform .15s ease, background .2s;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { transform: scale(1.1); }
.icon-btn:active { transform: scale(.95); }
.icon-btn.off { background: #cfc9e6; opacity: .7; }
.ai-dot {
  position: absolute; top: 3px; right: 3px; width: 8px; height: 8px;
  border-radius: 50%; background: #b9b3d6; transition: background .2s;
}
.ai-dot.on { background: #35d07f; box-shadow: 0 0 6px #35d07f; }

/* ============ 场景 UI 覆盖层 ============ */
.scene-ui {
  position: absolute; inset: 0; z-index: 20; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity .4s ease, visibility .4s;
}
body[data-scene="plaza"] #ui-plaza,
body[data-scene="cart"]  #ui-cart,
body[data-scene="time"]  #ui-time,
body[data-scene="elder"] #ui-elder { opacity: 1; visibility: visible; }
.scene-ui .btn-primary, .scene-ui .caption, .plaza-title, .time-controls { pointer-events: auto; }

.caption {
  position: absolute; top: 74px; left: 50%; transform: translateX(-50%);
  background: var(--paper); color: var(--ink);
  padding: 10px 22px; border-radius: 999px; font-size: 15px; font-weight: 600;
  box-shadow: var(--shadow); white-space: nowrap; max-width: 92vw; overflow: hidden;
  text-overflow: ellipsis;
}

/* 场景一标题 */
.plaza-title {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
  text-align: center; color: #fff; width: min(92vw, 700px);
}
.plaza-title h1 {
  font-size: clamp(44px, 9vw, 92px); font-weight: 900; letter-spacing: 4px;
  text-shadow: 0 0 24px rgba(255, 213, 128, .55), 0 6px 0 rgba(125, 84, 20, .85), 0 14px 40px rgba(0,0,0,.55);
  color: #ffe9b8; animation: floaty 4s ease-in-out infinite;
}
.plaza-title .sub {
  margin-top: 14px; font-size: clamp(15px, 2.4vw, 20px); letter-spacing: 6px;
  opacity: .92; text-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.plaza-title .hint { margin-top: 18px; font-size: 13px; opacity: .75; letter-spacing: 2px; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.plaza-title .btn-primary { margin-top: 26px; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ============ 按钮 ============ */
.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff; font-size: 17px; font-weight: 700; letter-spacing: 1px;
  padding: 13px 32px; border-radius: 999px;
  box-shadow: 0 6px 0 #c65a12, 0 12px 24px rgba(0,0,0,.35);
  transition: transform .12s ease, box-shadow .12s ease, filter .2s;
}
.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.06); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #c65a12, 0 6px 14px rgba(0,0,0,.3); }
.btn-primary.big { font-size: 21px; padding: 16px 44px; }
.btn-ghost {
  background: #ece8fa; color: var(--purple-deep); font-weight: 700;
  padding: 12px 24px; border-radius: 999px; font-size: 15px;
  transition: background .2s;
}
.btn-ghost:hover { background: #ddd6f5; }

/* 场景三控制 */
.time-controls {
  position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  background: var(--paper); padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow);
}
.scrub { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--purple-deep); }
.scrub input[type="range"] { width: 150px; accent-color: var(--accent); cursor: pointer; }

/* 场景四聊天按钮 */
#btn-open-chat { position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%); }

/* ============ 底部导航 ============ */
#scene-nav {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; z-index: 30;
}
.nav-arrow {
  width: 40px; height: 40px; border-radius: 50%; background: var(--paper);
  color: var(--ink); font-size: 22px; line-height: 1;
  box-shadow: 0 4px 12px rgba(0,0,0,.25); transition: transform .15s;
}
.nav-arrow:hover { transform: scale(1.12); }
.nav-dots {
  display: flex; gap: 4px; background: var(--paper);
  padding: 6px 10px; border-radius: 999px; box-shadow: var(--shadow);
}
.dot {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px;
  border-radius: 999px; color: #7a739f; font-size: 13px; font-weight: 600;
  transition: background .2s, color .2s;
}
.dot i {
  width: 10px; height: 10px; border-radius: 50%; background: #c9c2e8;
  transition: background .2s, box-shadow .2s;
}
.dot:hover { background: #f0edfb; }
.dot.active { background: var(--purple); color: #fff; }
.dot.active i { background: #ffd57f; box-shadow: 0 0 8px #ffd57f; }

/* ============ 气泡 ============ */
#bubble {
  position: absolute; z-index: 25; transform: translate(-50%, -100%);
  background: var(--paper); color: var(--ink); font-weight: 700; font-size: 15px;
  padding: 10px 18px; border-radius: 16px; box-shadow: var(--shadow);
  max-width: 260px; text-align: center; pointer-events: none;
  animation: popIn .25s cubic-bezier(.34, 1.56, .64, 1);
}
#bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
  border: 8px solid transparent; border-top-color: var(--paper); border-bottom: 0;
}
@keyframes popIn { from { transform: translate(-50%, -90%) scale(.6); opacity: 0; } to { transform: translate(-50%, -100%) scale(1); opacity: 1; } }

/* ============ 聊天面板 ============ */
#chat-panel {
  position: absolute; right: 16px; bottom: 80px; z-index: 40;
  width: min(400px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 120px));
  display: flex; flex-direction: column;
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
  animation: slideUp .3s cubic-bezier(.34, 1.3, .64, 1);
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: linear-gradient(135deg, var(--purple) 0%, var(--purple-deep) 100%);
  color: #fff;
}
.chat-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  animation: swing 3s ease-in-out infinite; transform-origin: top center;
}
@keyframes swing { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
.chat-title { flex: 1; font-weight: 800; font-size: 16px; }
.chat-title small { display: block; font-size: 11px; font-weight: 400; opacity: .8; margin-top: 2px; }
.chat-actions { display: flex; gap: 6px; }
.mini-btn {
  width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,.16);
  color: #fff; font-size: 14px; display: flex; align-items: center; justify-content: center;
  transition: background .2s, transform .12s;
}
.mini-btn:hover { background: rgba(255,255,255,.3); transform: scale(1.08); }
.mini-btn.off { opacity: .45; }
#chat-panel .mini-btn { background: #ece8fa; color: var(--purple-deep); }
#chat-panel .mini-btn:hover { background: #ddd6f5; }

#chat-msgs {
  flex: 1; overflow-y: auto; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 10px; user-select: text;
}
.msg { display: flex; gap: 8px; max-width: 88%; animation: msgIn .25s ease; }
@keyframes msgIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.msg .avatar {
  flex: none; width: 30px; height: 30px; border-radius: 50%; margin-top: 2px;
  background: linear-gradient(135deg, var(--purple), var(--purple-deep));
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.msg .body { padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.55; }
.msg.elder .body { background: #f0edfb; color: var(--ink); border-top-left-radius: 4px; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .body { background: linear-gradient(135deg, var(--accent), var(--accent-deep)); color: #fff; border-top-right-radius: 4px; }
.msg .note { font-size: 11px; opacity: .55; margin-top: 4px; }
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: #a99fd6;
  animation: blink 1s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,80%,100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }

#chat-chips {
  display: flex; gap: 6px; padding: 8px 12px 2px; overflow-x: auto; scrollbar-width: none;
}
#chat-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font-size: 12px; font-weight: 600; color: var(--purple-deep);
  background: #ece8fa; padding: 7px 12px; border-radius: 999px;
  transition: background .15s, transform .12s;
}
.chip:hover { background: #ffe1c9; transform: translateY(-1px); }

.chat-input-row {
  display: flex; gap: 8px; padding: 10px 12px 14px; align-items: center;
}
.chat-input-row input {
  flex: 1; border: 2px solid #ddd6f5; border-radius: 999px;
  padding: 10px 16px; font-size: 14px; font-family: inherit; outline: none;
  transition: border-color .2s; color: var(--ink); user-select: text;
}
.chat-input-row input:focus { border-color: var(--accent); }
.send-btn {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep)); color: #fff;
  font-weight: 700; font-size: 14px; padding: 10px 20px; border-radius: 999px;
  box-shadow: 0 3px 0 #c65a12; transition: transform .12s;
}
.send-btn:hover { transform: translateY(-1px); }
.send-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #c65a12; }
.mic-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; font-size: 17px;
  background: #ece8fa; display: flex; align-items: center; justify-content: center;
  transition: background .2s, transform .12s;
}
.mic-btn:hover { background: #ddd6f5; }
.mic-btn.rec { background: #ff5c5c; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,92,92,.5); } 50% { box-shadow: 0 0 0 10px rgba(255,92,92,0); } }

/* ============ 设置弹窗 ============ */
.modal {
  position: absolute; inset: 0; z-index: 60;
  background: rgba(15, 10, 40, 0.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal-card {
  width: min(460px, 94vw); max-height: 90vh; overflow-y: auto;
  background: #fff; border-radius: var(--radius); padding: 20px 22px;
  box-shadow: var(--shadow); animation: popIn2 .25s cubic-bezier(.34,1.4,.64,1);
  color: var(--ink);
}
@keyframes popIn2 { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-card header b { font-size: 17px; }
.modal-card header .mini-btn { background: #ece8fa; color: var(--purple-deep); }
.modal-card label { display: block; font-size: 13px; font-weight: 700; color: #6d66a0; margin: 12px 0 6px; }
.modal-card select, .modal-card input[type="text"], .modal-card input[type="password"] {
  width: 100%; border: 2px solid #e4e0f5; border-radius: 12px; padding: 10px 12px;
  font-size: 14px; font-family: inherit; outline: none; color: var(--ink);
  transition: border-color .2s; background: #fbfaff;
}
.modal-card select:focus, .modal-card input:focus { border-color: var(--accent); }
.key-row { display: flex; gap: 8px; align-items: center; }
.key-row .mini-btn { flex: none; }
.set-note { font-size: 12px; color: #8b84b3; line-height: 1.7; margin-top: 14px; background: #f6f4fd; padding: 10px 12px; border-radius: 10px; }
.set-actions { display: flex; gap: 10px; margin-top: 16px; }
#set-result { font-size: 13px; margin-top: 10px; min-height: 18px; font-weight: 600; }
#set-result.ok { color: #1d9e63; }
#set-result.err { color: #d64545; }

/* ============ 提示 / 过场 / 加载 ============ */
#toast {
  position: absolute; top: 74px; left: 50%; transform: translateX(-50%);
  z-index: 50; background: rgba(30, 22, 66, 0.88); color: #ffe9b8;
  font-size: 14px; font-weight: 600; padding: 10px 22px; border-radius: 999px;
  box-shadow: var(--shadow); pointer-events: none; white-space: nowrap;
  animation: popIn2 .2s ease;
}
#fade {
  position: absolute; inset: 0; z-index: 45; background: #14102e;
  opacity: 0; pointer-events: none; transition: opacity .38s ease;
}
#fade.on { opacity: 1; }
#loader {
  position: absolute; inset: 0; z-index: 80; background: linear-gradient(180deg, #1a1440, #3b2a6e);
  display: flex; flex-direction: column; gap: 16px; align-items: center; justify-content: center;
  color: #ffe9b8; transition: opacity .5s; font-size: 15px; letter-spacing: 2px;
}
#loader.gone { opacity: 0; pointer-events: none; }
.loader-icon { font-size: 54px; animation: swing 1.6s ease-in-out infinite; transform-origin: top center; }

/* 外层文档的 !important 声明按级联规则优先于 Shadow DOM :host 的 !important */
qoder-sites-badge, #qoder-sites-watermark { display: none !important; }

/* ============ 响应式 ============ */
@media (max-width: 640px) {
  .brand span { display: none; }
  .brand { font-size: 15px; padding: 7px 12px; }
  .dot span { display: none; }
  .dot { padding: 7px 9px; }
  #chat-panel { right: 8px; left: 8px; width: auto; height: min(560px, calc(100vh - 100px)); }
  .caption { font-size: 13px; padding: 8px 16px; top: 66px; }
  .time-controls { flex-direction: column; gap: 8px; border-radius: 20px; bottom: 86px; }
}
