:root {
  --bg-deep: #0b0e1c;
  --accent-lavender: #c7a9ff;
  --accent-blue: #6aa7ff;
  --accent-pink: #f48cb8;
  --card-light: rgba(255, 255, 255, 0.92);
  --card-dark: rgba(18, 16, 30, 0.78);
  --text-dark: #25283d;
  --text-light: #f4efff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-light);
  background: var(--bg-deep);
  user-select: none;
}

/* ==================== Starry Dreamy Background (matching reference vibe) ==================== */
.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.45s ease;
}

.app-shell[data-bg='starry'] {
  background:
    radial-gradient(circle at 50% 18%, rgba(164, 152, 255, 0.34) 0%, rgba(88, 108, 210, 0.16) 36%, transparent 66%),
    radial-gradient(ellipse at 50% 95%, rgba(186, 155, 255, 0.22) 0%, transparent 50%),
    linear-gradient(180deg, #0b1024 0%, #161d3a 48%, #201a38 100%);
}

.app-shell[data-bg='gothic'] {
  background:
    radial-gradient(circle at 50% 24%, rgba(177, 138, 255, 0.24) 0%, rgba(114, 79, 185, 0.08) 36%, transparent 65%),
    linear-gradient(180deg, #0d0914 0%, #171124 52%, #0f0b17 100%);
}

.app-shell[data-bg='transparent'] {
  background-color: #24212c;
  background-image:
    linear-gradient(45deg, #322e3d 25%, transparent 25%),
    linear-gradient(-45deg, #322e3d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #322e3d 75%),
    linear-gradient(-45deg, transparent 75%, #322e3d 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
}

.app-shell.has-custom-bg {
  background-size: cover !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
}

.custom-bg-scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: rgba(10, 8, 22, 0);
  transition: background 0.25s ease;
}

.app-shell.has-custom-bg .bg-arch {
  opacity: 0.12;
}

.bg-arch {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.38;
  transition: opacity 0.4s ease;
}

.app-shell[data-bg='transparent'] .bg-arch,
.app-shell[data-bg='transparent'] #ambient-canvas {
  opacity: 0;
}

.bg-arch svg {
  height: 92vh;
  max-width: 90vw;
  filter: drop-shadow(0 0 28px rgba(186, 174, 255, 0.25));
}

#ambient-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ==================== WebGL Live2D Stage ==================== */
.character-stage-wrap {
  position: relative;
  z-index: 5;
  width: min(82vh, 96vw);
  height: 98vh;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.otome-char-root,
.otome-char-camera {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.otome-char-camera {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.otome-char-camera.is-ready {
  opacity: 1;
}

.otome-char-aura {
  position: absolute;
  bottom: 14%;
  left: 50%;
  width: 56%;
  height: 62%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(199, 169, 255, 0.22) 0%, rgba(130, 145, 245, 0.08) 46%, transparent 72%);
  filter: blur(22px);
  pointer-events: none;
}

.app-shell[data-bg='transparent'] .otome-char-aura,
.app-shell[data-bg='transparent'] .otome-char-shadow {
  opacity: 0;
}

.otome-char-shadow {
  position: absolute;
  bottom: 3%;
  left: 50%;
  width: 32%;
  height: 24px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(6, 4, 16, 0.6) 0%, transparent 74%);
  filter: blur(5px);
  pointer-events: none;
}

.otome-webgl-wrap {
  position: relative;
  height: 98%;
  aspect-ratio: 920 / 1360;
}

.otome-webgl-canvas,
.otome-fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.otome-webgl-canvas {
  filter: drop-shadow(0 8px 24px rgba(8, 6, 22, 0.3));
}

.otome-fx-canvas {
  pointer-events: none;
  z-index: 4;
}

/* ==================== Top Quick Focus & Background Bar ==================== */
.top-speech-wrap {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  width: min(560px, calc(100vw - 36px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.top-quick-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.pill-chip {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(20, 18, 38, 0.62);
  color: #eee8ff;
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: all 0.2s ease;
  font-family: inherit;
}

.pill-chip:hover {
  background: rgba(164, 134, 245, 0.42);
}

.pill-chip.is-active {
  background: linear-gradient(135deg, #8b74f2, #d489be);
  border-color: rgba(255, 255, 255, 0.55);
  color: #fff;
}

/* ==================== Left Otome Filigree Icon Rail ==================== */
.left-rail {
  position: fixed;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rail-btn {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1.5px solid rgba(236, 220, 255, 0.72);
  background: linear-gradient(155deg, rgba(32, 24, 52, 0.78), rgba(18, 14, 34, 0.88));
  color: #efe5ff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow:
    0 8px 22px rgba(8, 6, 22, 0.42),
    inset 0 0 0 3px rgba(212, 186, 255, 0.14);
  backdrop-filter: blur(14px);
  transition: transform 0.22s ease, background 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  font-family: inherit;
}

.rail-btn::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 1px solid rgba(235, 216, 255, 0.26);
  pointer-events: none;
}

.rail-btn svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px rgba(215, 185, 255, 0.35));
}

.rail-label {
  font-size: 9.5px;
  letter-spacing: 0.08em;
  color: rgba(242, 234, 255, 0.88);
  line-height: 1;
}

.rail-btn:hover {
  transform: scale(1.07);
  border-color: rgba(247, 206, 232, 0.92);
  box-shadow:
    0 10px 26px rgba(138, 108, 235, 0.42),
    inset 0 0 12px rgba(226, 188, 255, 0.25);
}

.rail-btn.is-active {
  background: linear-gradient(145deg, #9b7bf5, #df8ec4);
  border-color: rgba(255, 240, 252, 0.95);
  color: #ffffff;
  box-shadow:
    0 8px 26px rgba(176, 122, 242, 0.56),
    inset 0 0 0 3px rgba(255, 255, 255, 0.22);
}

.rail-btn.is-active .rail-label {
  color: #ffffff;
  font-weight: 600;
}

/* ==================== Frosted Light Popover Cards (Reference Video Style!) ==================== */
.popover-card {
  position: fixed;
  left: 88px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  width: 262px;
  max-height: calc(100vh - 170px);
  overflow-y: auto;
  padding: 15px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.93);
  color: var(--text-dark);
  box-shadow: 0 18px 46px rgba(10, 12, 34, 0.34);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.78);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.cfg-subtabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(70, 82, 126, 0.08);
}

.cfg-subtab {
  border: none;
  background: transparent;
  color: #565f82;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 4px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.18s ease;
}

.cfg-subtab.is-active {
  background: #ffffff;
  color: #6b4cd8;
  box-shadow: 0 2px 8px rgba(45, 52, 92, 0.1);
}

.cfg-pane {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.cfg-pane.is-hidden {
  display: none;
}

.cfg-section-title {
  font-size: 11.5px;
  font-weight: 700;
  color: #6f5ca8;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.cfg-upload-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.upload-btn {
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px dashed rgba(118, 92, 214, 0.55);
  background: rgba(138, 115, 244, 0.1);
  color: #5438b8;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  transition: all 0.18s ease;
}

.upload-btn:hover {
  background: rgba(138, 115, 244, 0.2);
}

.cfg-preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.cfg-color-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.color-pick-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 9px;
  background: #f3f5fc;
  border: 1px solid rgba(70, 82, 126, 0.14);
  font-size: 11.5px;
  color: #464e70;
}

.color-pick-item input[type='color'] {
  width: 24px;
  height: 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.popover-card.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) translateX(-10px);
}

.pop-title {
  font-size: 13px;
  font-weight: 700;
  color: #464e72;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(60, 70, 110, 0.1);
}

/* Expression Pill List (黑脸 / 哭哭 / 脸红 / 生气 / 吐舌) */
.expr-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.expr-item {
  width: 100%;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid rgba(70, 82, 126, 0.12);
  background: rgba(242, 244, 252, 0.9);
  color: #363c58;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.18s ease;
  font-family: inherit;
}

.expr-item:hover {
  background: rgba(226, 232, 252, 0.95);
}

.expr-item.is-active {
  background: rgba(226, 238, 255, 0.98);
  border-color: rgba(104, 152, 248, 0.55);
  color: #2758c5;
  font-weight: 600;
}

.expr-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: transparent;
  transition: all 0.2s ease;
}

.expr-item.is-active .expr-dot {
  background: #ff6b98;
  box-shadow: 0 0 8px rgba(255, 107, 152, 0.75);
}

/* Sliders in Settings Popover (模型缩放 / X轴坐标 / Y轴坐标) */
.cfg-slider {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cfg-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: #464e70;
}

.cfg-label strong {
  color: #2968d8;
  font-weight: 600;
}

.cfg-slider input[type='range'] {
  width: 100%;
  accent-color: #3584f6;
  cursor: pointer;
}

.cfg-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: #464e70;
  cursor: pointer;
}

.cfg-toggle input {
  accent-color: #3584f6;
  cursor: pointer;
}

.cfg-btn-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.cfg-mini-btn {
  padding: 5px 4px;
  border-radius: 8px;
  border: 1px solid rgba(70, 82, 126, 0.18);
  background: #f1f4fc;
  color: #3a4262;
  font-size: 11.5px;
  cursor: pointer;
  font-family: inherit;
}

.cfg-mini-btn:hover {
  background: #e1e9fc;
}

.save-cfg-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid rgba(53, 132, 246, 0.35);
  background: rgba(53, 132, 246, 0.12);
  color: #1f64d6;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.save-cfg-btn:hover {
  background: rgba(53, 132, 246, 0.22);
}

.toast-tip {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(24, 22, 42, 0.88);
  color: #fff;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.toast-tip.is-show {
  opacity: 1;
}

/* ==================== Right Floating Otome Chat Window ==================== */
.chat-fab {
  position: fixed;
  right: 22px;
  bottom: 24px;
  z-index: 32;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1.5px solid rgba(236, 220, 255, 0.72);
  background: linear-gradient(145deg, rgba(145, 112, 240, 0.88), rgba(218, 134, 192, 0.88));
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(14, 10, 34, 0.45);
  backdrop-filter: blur(14px);
  font-family: inherit;
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.chat-fab:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 34px rgba(164, 118, 242, 0.56);
}

.chat-fab.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.95);
}

.chat-fab svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-panel {
  position: fixed;
  right: 22px;
  bottom: 24px;
  z-index: 31;
  width: 326px;
  height: min(468px, calc(100vh - 110px));
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(24, 18, 44, 0.84), rgba(16, 13, 32, 0.90));
  border: 1px solid rgba(226, 206, 255, 0.34);
  box-shadow:
    0 20px 48px rgba(6, 4, 20, 0.52),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.chat-panel.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px) scale(0.97);
}

.chat-panel-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(90deg, rgba(168, 128, 245, 0.22), rgba(235, 148, 204, 0.16));
  border-bottom: 1px solid rgba(226, 206, 255, 0.16);
}

.chat-header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59bd0;
  box-shadow: 0 0 10px rgba(245, 155, 208, 0.9);
  flex-shrink: 0;
}

.chat-title-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.chat-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #f7f0ff;
  letter-spacing: 0.03em;
}

.chat-mood {
  font-size: 10.5px;
  color: rgba(228, 206, 255, 0.78);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid rgba(226, 206, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #eadfff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: background 0.18s ease;
}

.chat-icon-btn:hover {
  background: rgba(206, 174, 255, 0.26);
}

.chat-messages {
  flex: 1;
  padding: 13px 13px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  user-select: text;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(212, 186, 255, 0.28);
  border-radius: 999px;
}

.chat-msg {
  max-width: 86%;
  padding: 9px 12px;
  border-radius: 15px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  animation: chatPopIn 0.22s ease;
}

@keyframes chatPopIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-msg.is-char {
  align-self: flex-start;
  background: rgba(246, 240, 255, 0.93);
  color: #2b2640;
  border-bottom-left-radius: 5px;
  box-shadow: 0 4px 14px rgba(10, 6, 24, 0.22);
}

.chat-msg.is-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #8b72f0, #d883bd);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(118, 74, 198, 0.34);
}

.chat-msg.is-typing {
  color: #6b5b8e;
  letter-spacing: 0.15em;
  font-style: italic;
}

.chat-quick-chips {
  padding: 6px 12px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  border-top: 1px solid rgba(226, 206, 255, 0.1);
}

.chat-chip {
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(226, 206, 255, 0.26);
  background: rgba(168, 134, 244, 0.14);
  color: #ede2ff;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.18s ease;
}

.chat-chip:hover {
  background: rgba(212, 146, 224, 0.34);
  border-color: rgba(246, 212, 248, 0.56);
}

.chat-input-form {
  padding: 8px 10px 10px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.chat-input-box {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(226, 206, 255, 0.28);
  background: rgba(255, 255, 255, 0.11);
  color: #f8f2ff;
  font-size: 12.5px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.chat-input-box::placeholder {
  color: rgba(224, 210, 248, 0.58);
}

.chat-input-box:focus {
  border-color: rgba(235, 178, 242, 0.72);
  background: rgba(255, 255, 255, 0.16);
}

.chat-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #9176f4, #df88c4);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(154, 108, 236, 0.42);
  transition: transform 0.18s ease;
}

.chat-send-btn:hover {
  transform: scale(1.07);
}

@media (max-width: 720px) {
  .left-rail {
    left: 12px;
    gap: 12px;
  }
  .chat-panel {
    right: 12px;
    bottom: 14px;
    width: calc(100vw - 24px);
    height: 44vh;
  }
  .chat-fab {
    right: 14px;
    bottom: 16px;
  }
  .rail-btn {
    width: 48px;
    height: 48px;
  }
  .popover-card {
    left: 70px;
    width: 236px;
    padding: 13px;
  }
}
