/**
 * Gemini Weather - 样式表
 *
 * 目录结构：
 * 1. CSS 变量定义
 * 2. 基础样式
 * 3. 毛玻璃效果（含渲染修复）
 * 4. 滚动条样式
 * 5. 组件样式
 * 6. 动画定义
 * 7. 图片区域动效
 * 8. 侧边栏 Dock
 * 9. 移动端适配
 * 10. 加载动画
 */

/* ==========================================================================
   1. CSS 变量定义
   ========================================================================== */

[v-cloak] {
  display: none;
}

:root {
  /* 毛玻璃效果变量（由 JS 动态修改） */
  --glass-bg: rgba(255, 255, 255, 0.65);
  --glass-bg-hover: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(255, 255, 255, 0.5);

  /* 背景渐变色变量（由 JS 根据图片主色调动态修改） */
  --bg-color-1: #f0f4f8;
  --bg-color-2: #f0f4f8;
  --bg-color-3: #f0f4f8;

  /* 主题色 */
  --color-accent: #6366f1;
  --color-accent-light: rgba(99, 102, 241, 0.1);
  --color-accent-medium: rgba(99, 102, 241, 0.15);
}

/* ==========================================================================
   2. 基础样式
   ========================================================================== */

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(135deg, var(--bg-color-1), var(--bg-color-2), var(--bg-color-3));
  transition: background 0.8s ease-in-out;
}

/* ==========================================================================
   3. 毛玻璃效果

   修复说明：
   backdrop-blur 是 GPU 密集型操作，当多个元素重叠或 CSS 变量动态更新时，
   可能导致浏览器合成层不稳定，出现"分层两半颜色"的渲染问题。

   解决方案：
   - 避免在主内容玻璃层上强制 GPU 合成（易触发分层残影）
   - backface-visibility: hidden: 减少变换时的闪烁
   - isolation: isolate: 隔离渲染上下文，避免混合层污染
   - 仅在 Dock 区域保留 contain，提高稳定性与性能平衡
   ========================================================================== */

/* 所有使用 backdrop-blur 的元素应用渲染修复 */
[class*="backdrop-blur"] {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  isolation: isolate;
}

/* 玻璃卡片基础样式 */
.bg-glass {
  transition: background-color 0.8s ease-in-out;
  box-shadow:
    0 4px 24px -4px rgba(0, 0, 0, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* 仅保留 Dock 的渲染隔离，避免主内容出现分层重绘异常 */
.dock-container {
  contain: layout paint;
}

/* ==========================================================================
   4. 滚动条样式
   ========================================================================== */

/* 垂直滚动条（亮色系） */
.custom-scrollbar::-webkit-scrollbar {
  width: 5px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* 水平滚动条（移动端城市列表） */
.custom-scrollbar-x::-webkit-scrollbar {
  height: 4px;
}

.custom-scrollbar-x::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar-x::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}

.custom-scrollbar-x::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   5. 组件样式
   ========================================================================== */

/* 键盘快捷键提示 */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  color: #64748b;
  background-color: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 0.375rem;
  box-shadow: 0 1px 0 #cbd5e1;
}

/* 垂直文字（侧边栏城市名） */
.writing-vertical {
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0.1em;
}

/* 逐小时预报列表项 */
.space-y-1 > div {
  border-radius: 12px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.space-y-1 > div:hover {
  background: rgba(255, 255, 255, 0.7) !important;
  transform: translateX(4px);
  box-shadow:
    -4px 0 0 0 rgba(99, 102, 241, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.05);
}

/* 预报列表容器：预留右侧空间防止悬浮时出现横向滚动条 */
.max-h-\[180px\].overflow-y-auto {
  padding-right: 4px;
  overflow-x: hidden;
}

/* 预报列表中的天气图标 */
.space-y-1 > div .p-1,
.space-y-1 > div .p-1\.5 {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.space-y-1 > div:hover .p-1,
.space-y-1 > div:hover .p-1\.5 {
  transform: scale(1.15) rotate(-5deg);
}

/* 左右切换按钮 */
button[class*="absolute"][class*="rounded-full"] {
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

button[class*="absolute"][class*="rounded-full"]:hover {
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.12),
    0 4px 8px rgba(0, 0, 0, 0.08);
}

button[class*="absolute"][class*="rounded-full"]:active {
  transform: translateY(-50%) scale(0.95);
}

/* ==========================================================================
   6. 动画定义
   ========================================================================== */

/* 浮动动画（天气图标） */
@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.animate-float {
  animation: float 4s ease-in-out infinite;
}

/* 搜索面板展开动画 */
@keyframes expand-search {
  0% {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.search-expand-enter-active {
  animation: expand-search 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.search-expand-leave-active {
  animation: expand-search 0.25s cubic-bezier(0.16, 1, 0.3, 1) reverse;
}

/* 页面元素入场动画 */
@keyframes slideUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInRight {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideRight {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.animate-slide-up {
  opacity: 0;
  transform: translateY(20px);
  animation: slideUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.animate-fade-in-right {
  opacity: 0;
  transform: translateX(20px);
  animation: fadeInRight 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.1s forwards;
}

.animate-slide-right {
  opacity: 0;
  transform: translateX(-20px);
  animation: slideRight 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Toast 提示动画 */
.toast-anim-enter-active,
.toast-anim-leave-active {
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast-anim-enter-from,
.toast-anim-leave-to {
  opacity: 0;
  transform: translate(-50%, -20px) scale(0.9);
}

/* ==========================================================================
   7. 图片区域动效
   ========================================================================== */

/* 小时预报容器：避免 backdrop 与合成层叠加导致的分层渲染异常 */
.hourly-forecast-panel {
  position: relative;
  isolation: isolate;
  transform: none !important;
  will-change: auto !important;
}

/* 图片区域：轻微上浮，替代鼠标跟随 3D 倾斜 */
.image-shell {
  overflow: visible;
}

.image-card {
  transition:
    transform 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow:
    0 12px 36px -14px rgba(15, 23, 42, 0.28),
    0 6px 18px rgba(15, 23, 42, 0.12);
}

.image-shell:hover .image-card {
  transform: translateY(-6px) scale(1.01);
  box-shadow:
    0 20px 46px -16px rgba(15, 23, 42, 0.34),
    0 14px 26px -10px rgba(99, 102, 241, 0.24);
}

/* ==========================================================================
   8. 侧边栏 Dock（macOS 风格）
   ========================================================================== */

.dock-container {
  position: relative;
  align-items: center;
  justify-content: flex-start;
  padding-top: 1rem;
  padding-bottom: 1rem;
  background-color: rgba(248, 250, 252, 0.72) !important;
  border-color: rgba(255, 255, 255, 0.78) !important;
  backdrop-filter: blur(16px) saturate(135%);
  -webkit-backdrop-filter: blur(16px) saturate(135%);
  box-shadow:
    0 10px 28px -10px rgba(15, 23, 42, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  /* 隐藏滚动条但保留滚动功能 */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* 侧边栏统一使用固定中性色玻璃，避免动态背景导致可读性下降 */
nav .bg-glass {
  background-color: rgba(248, 250, 252, 0.68) !important;
  border-color: rgba(255, 255, 255, 0.74) !important;
}

.dock-container::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.42),
    rgba(255, 255, 255, 0.2)
  );
}

.dock-container > * {
  position: relative;
  z-index: 1;
}

.dock-container::-webkit-scrollbar {
  width: 0;
  display: none;
}

/* Dock 项目（城市按钮） */
.dock-item {
  transform-origin: center center;
  will-change: transform;
  background: rgba(255, 255, 255, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.dock-item:hover {
  box-shadow:
    0 4px 16px var(--color-accent-medium),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* ==========================================================================
   9. 移动端适配
   ========================================================================== */

@media (max-width: 768px) {
  /* 隐藏水平滚动条 */
  .custom-scrollbar-x {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .custom-scrollbar-x::-webkit-scrollbar {
    display: none;
  }

  /* 图片容器 */
  .aspect-square {
    aspect-ratio: 1 / 1;
    max-height: 35vh;
    width: auto;
    margin: 0 auto;
  }

  /* 主内容区域 */
  #app > main {
    padding-top: 0;
    gap: 0.75rem;
  }

  /* 城市标题 */
  #app h1 {
    font-size: 1.75rem !important;
    line-height: 1.1 !important;
    margin-bottom: 0.25rem !important;
  }

  /* 内容区域间距 */
  #app .flex.flex-col.gap-6 {
    gap: 0.5rem;
  }

  /* 徽标样式 */
  #app .flex.items-center.gap-3 > span {
    padding: 0.25rem 0.5rem;
    font-size: 0.65rem;
  }

  /* 天气预报列表 */
  #app .space-y-1 > div {
    padding: 0.375rem;
  }
}

/* ==========================================================================
   10. 加载动画
   ========================================================================== */

/* 加载容器 */
.initial-loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 2rem;
}

/* 城市图标容器 */
.loading-cities {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

/* 城市图标 */
.loading-city-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-accent-light), rgba(99, 102, 241, 0.2));
  border: 2px solid rgba(99, 102, 241, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: city-bounce 1.5s ease-in-out infinite;
}

/* 城市图标错开动画 */
.loading-city-icon:nth-child(1) { animation-delay: 0s; }
.loading-city-icon:nth-child(2) { animation-delay: 0.1s; }
.loading-city-icon:nth-child(3) { animation-delay: 0.2s; }
.loading-city-icon:nth-child(4) { animation-delay: 0.3s; }
.loading-city-icon:nth-child(5) { animation-delay: 0.4s; }
.loading-city-icon:nth-child(6) { animation-delay: 0.5s; }

@keyframes city-bounce {
  0%, 100% {
    transform: translateY(0) scale(1);
    opacity: 0.6;
  }
  50% {
    transform: translateY(-12px) scale(1.1);
    opacity: 1;
  }
}

/* 加载文字 */
.loading-text {
  font-size: 1.125rem;
  font-weight: 600;
  color: #475569;
  text-align: center;
  animation: text-pulse 2s ease-in-out infinite;
}

.loading-subtext {
  font-size: 0.875rem;
  color: #64748b;
  margin-top: 0.5rem;
  animation: text-pulse 2s ease-in-out infinite 0.5s;
}

@keyframes text-pulse {
  0%, 100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

/* 进度条 */
.loading-progress-bar {
  width: 200px;
  height: 4px;
  background: var(--color-accent-light);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 1rem;
}

.loading-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #818cf8, #6366f1);
  background-size: 200% 100%;
  border-radius: 2px;
  animation: progress-slide 1.5s ease-in-out infinite;
}

@keyframes progress-slide {
  0% {
    width: 0%;
    background-position: 0% 0%;
  }
  50% {
    width: 70%;
    background-position: 100% 0%;
  }
  100% {
    width: 100%;
    background-position: 0% 0%;
  }
}

/* 天气图标旋转 */
.loading-weather-icon {
  animation: weather-spin 3s linear infinite;
}

@keyframes weather-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 光晕效果 */
.loading-glow {
  position: absolute;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, var(--color-accent-medium) 0%, transparent 70%);
  border-radius: 50%;
  animation: glow-pulse 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes glow-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.8;
  }
}

/* 加载状态淡出 */
.loading-fade-leave-active {
  transition: all 0.5s ease-out;
}

.loading-fade-leave-to {
  opacity: 0;
  transform: scale(0.95) translateY(-20px);
}
