:root {
  --bg: #1a1418;
  --glass: rgba(255, 255, 255, 0.14);
  --glass-strong: rgba(255, 255, 255, 0.22);
  --text: #fff;
  --muted: rgba(255, 255, 255, 0.72);
  --accent: #ff8fab;
  --user-bubble: #8b6cff;
  --ai-bubble: rgba(255, 255, 255, 0.92);
  --ai-text: #2d2430;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

.hidden {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: #000;
  color: var(--text);
}

.app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
}

.bg-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.bg-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 8%;
}

.bg-gradient {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.28) 0%, transparent 18%, transparent 50%, rgba(0, 0, 0, 0.45) 100%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.12), transparent 28%, transparent 72%, rgba(0, 0, 0, 0.15));
}

.top-bar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--glass);
  color: #fff;
  backdrop-filter: blur(12px);
  font-size: 18px;
}

.mode-pill {
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 182, 198, 0.88);
  color: #4d2030;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(12px);
}

.profile-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 12%;
}

.profile-name {
  font-size: 0.82rem;
  font-weight: 700;
}

.profile-sub {
  font-size: 0.7rem;
  color: var(--muted);
}

.side-rail {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-42%);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rail-btn {
  width: 54px;
  border: none;
  border-radius: 16px;
  padding: 8px 6px;
  background: var(--glass);
  color: #fff;
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
}

.rail-btn span {
  font-size: 1.15rem;
}

.rail-btn.active {
  background: rgba(255, 143, 171, 0.55);
}

.home-bubble {
  position: absolute;
  left: 18px;
  top: 34%;
  z-index: 2;
  max-width: 58%;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  color: #3d2b35;
  font-size: 0.95rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.home-bubble::after {
  content: "";
  position: absolute;
  left: 18px;
  bottom: -8px;
  border: 8px solid transparent;
  border-top-color: rgba(255, 255, 255, 0.9);
}

.chat-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 118px;
  top: 88px;
  z-index: 2;
  padding: 0 12px;
  overflow: hidden;
}

.chat-layer.hidden {
  display: none;
}

.chat-list {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 12px;
  scrollbar-width: none;
}

.chat-list::-webkit-scrollbar {
  display: none;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: fadeUp 0.25s ease;
}

.msg-row.user {
  justify-content: flex-end;
}

.msg-row.ai {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.55;
  font-size: 0.95rem;
  word-break: break-word;
}

.bubble.user {
  background: linear-gradient(135deg, #9f7cff, #7d57ff);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.bubble.ai {
  background: var(--ai-bubble);
  color: var(--ai-text);
  border-bottom-left-radius: 6px;
}

.bubble.image-note {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 0.82rem;
}

.read-mark {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.72);
}

.tts-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  flex-shrink: 0;
}

.tts-btn.tts-busy {
  background: rgba(255, 200, 120, 0.45);
  animation: tts-pulse 1s ease-in-out infinite;
}

.tts-btn.tts-pending {
  box-shadow: 0 0 0 2px #ff8fab;
}

@keyframes tts-pulse {
  50% { opacity: 0.55; }
}

.msg-image {
  max-width: 180px;
  border-radius: 14px;
  margin-top: 6px;
  display: block;
}

.dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  padding: 10px 12px calc(12px + var(--safe-bottom));
}

.dock-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 24px;
  background: rgba(245, 245, 247, 0.92);
  backdrop-filter: blur(16px);
}

.dock-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #fff;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  cursor: pointer;
}

.dock-btn.call {
  background: linear-gradient(135deg, #ff9eb8, #ff7f9d);
}

.dock-btn.send {
  background: linear-gradient(135deg, #8b6cff, #6f4ef5);
  color: #fff;
}

.dock-btn.recording {
  animation: pulse 1s infinite;
  background: #ff4d6d;
  color: #fff;
}

.text-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1rem;
  outline: none;
  color: #222;
  min-width: 0;
}

.dock-hint {
  margin-top: 8px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}

.mode-menu {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  min-width: 180px;
  padding: 8px;
  border-radius: 16px;
  background: rgba(30, 24, 28, 0.92);
  backdrop-filter: blur(14px);
}

.mode-menu.hidden {
  display: none;
}

.mode-item {
  width: 100%;
  border: none;
  background: transparent;
  color: #fff;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.mode-item.active,
.mode-item:hover {
  background: rgba(255, 143, 171, 0.25);
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.28);
  font-size: 1rem;
}

.loading.hidden {
  display: none;
}

.home-view.chat-open .home-bubble {
  display: none;
}

.home-view.chat-open .bg-image {
  object-position: center 12%;
}

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

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
}

@media (max-width: 380px) {
  .side-rail {
    display: none;
  }
}
