/* =========================================================
   个人导航 · iOS 桌面瀑布流风格 (美化版 v2)
   ========================================================= */

/* ---------- 主题变量 ---------- */
:root {
  /* 浅色 */
  --text-color: #1c1c1e;
  --text-secondary: #6b6b70;
  --text-muted: #98989e;
  --card-bg: rgba(255, 255, 255, 0.62);
  --card-border: rgba(255, 255, 255, 0.9);
  --card-shadow: 0 8px 32px rgba(31, 38, 135, 0.12);
  --card-hover-shadow: 0 16px 40px rgba(31, 38, 135, 0.2);
  --input-bg: rgba(255, 255, 255, 0.7);
  --accent: #007aff;
  --footer-bg: rgba(255, 255, 255, 0.5);
  --title-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);

  /* 动态背景色块（浅色） */
  --blob-1: rgba(120, 160, 255, 0.55);
  --blob-2: rgba(255, 140, 180, 0.45);
  --blob-3: rgba(140, 255, 220, 0.45);
  --base-bg: #eef2f9;
}

[data-theme="dark"] {
  --text-color: #f5f5f7;
  --text-secondary: #aeaeb2;
  --text-muted: #6d6d72;
  --card-bg: rgba(40, 40, 48, 0.55);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --card-hover-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  --input-bg: rgba(40, 40, 48, 0.6);
  --accent: #0a84ff;
  --footer-bg: rgba(20, 20, 26, 0.5);
  --title-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

  --blob-1: rgba(80, 120, 220, 0.4);
  --blob-2: rgba(190, 80, 140, 0.35);
  --blob-3: rgba(60, 200, 170, 0.3);
  --base-bg: #0b0b0f;
}

/* ---------- 基础重置 ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-color);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
  transition: color 0.4s ease;
  -webkit-font-smoothing: antialiased;
  background: var(--base-bg);
}

/* ---------- 动态渐变背景色块 ---------- */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.9;
  will-change: transform;
}

.blob-1 {
  width: 42vmax; height: 42vmax;
  top: -10vmax; left: -8vmax;
  background: var(--blob-1);
  animation: drift1 22s ease-in-out infinite alternate;
}
.blob-2 {
  width: 38vmax; height: 38vmax;
  bottom: -12vmax; right: -10vmax;
  background: var(--blob-2);
  animation: drift2 26s ease-in-out infinite alternate;
}
.blob-3 {
  width: 30vmax; height: 30vmax;
  top: 40%; left: 55%;
  background: var(--blob-3);
  animation: drift3 30s ease-in-out infinite alternate;
}

@keyframes drift1 {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(8vmax, 10vmax) scale(1.15); }
}
@keyframes drift2 {
  0%   { transform: translate(0, 0) scale(1.1); }
  100% { transform: translate(-10vmax, -6vmax) scale(0.95); }
}
@keyframes drift3 {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-12vmax, 8vmax) scale(1.2); }
}

a { color: inherit; text-decoration: none; }

/* ---------- 顶部区域（时钟 + 搜索） ---------- */
.topbar {
  padding: max(2.5rem, env(safe-area-inset-top)) 1.5rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.hero {
  text-align: center;
  animation: fadeDown 0.8s ease both;
}

.greeting {
  font-size: clamp(1rem, 2.5vw, 1.35rem);
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.clock {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  text-shadow: var(--title-shadow);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.clock-date {
  font-size: clamp(0.85rem, 2vw, 1rem);
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* ---------- 搜索框 ---------- */
.search-wrap {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  animation: fadeDown 0.8s ease 0.15s both;
}

.search-form {
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1.1rem;
  color: var(--text-secondary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.95rem 1rem 0.95rem 2.85rem;
  font-size: 1rem;
  color: var(--text-color);
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  outline: none;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--card-shadow);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.search-input::placeholder { color: var(--text-secondary); }

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15), var(--card-shadow);
}

/* 搜索引擎切换 */
.engine-switch {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
}

.engine-btn {
  padding: 0.4rem 0.95rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 22px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all 0.25s;
}

.engine-btn:hover {
  color: var(--text-color);
  transform: translateY(-1px);
}

.engine-btn.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.35);
}

/* ---------- 图标瀑布流主区域 ---------- */
.apps-grid {
  flex: 1;
  padding: 2rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* 分类分组 */
.category {
  animation: fadeUp 0.6s ease both;
}

.category-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding-left: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.category-title::before {
  content: "";
  width: 3px;
  height: 0.95rem;
  border-radius: 2px;
  background: var(--accent);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 1.5rem 0.75rem;
}

/* 单个图标卡片 */
.app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: popIn 0.5s ease both;
}

.app-item:hover { transform: translateY(-5px) scale(1.04); }
.app-item:active { transform: scale(0.92); }

.app-icon {
  width: 60px;
  height: 60px;
  border-radius: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
  transition: box-shadow 0.25s;
}

/* 玻璃高光 */
.app-icon::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.28), transparent);
  pointer-events: none;
  border-radius: 17px 17px 0 0;
}

/* 有真实图片：隐藏框、高光、阴影 */
.app-icon.has-image {
  background: none;
  border: none;
  box-shadow: none;
  border-radius: 14px;
}
.app-icon.has-image::after {
  display: none;
}

.app-item:hover .app-icon { box-shadow: var(--card-hover-shadow); }

.app-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  position: absolute;
  top: 0; left: 0;
}

/* 首字母层 */
.app-letter {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.app-name {
  font-size: 0.76rem;
  color: var(--text-color);
  text-align: center;
  max-width: 84px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 页脚 ---------- */
.footer {
  padding: 1rem 1.5rem max(1rem, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--footer-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-top: 1px solid var(--card-border);
}

.footer-stats {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.footer-stats span { display: inline-flex; align-items: center; gap: 0.3rem; }

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--input-bg);
  color: var(--text-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle:hover {
  transform: rotate(20deg);
  color: var(--accent);
}

/* 主题图标显示控制 */
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ---------- 动画定义 ---------- */
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  0%   { opacity: 0; transform: scale(0.8); }
  60%  { transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}

/* ---------- 响应式 ---------- */
@media (max-width: 480px) {
  .apps-grid { gap: 1.5rem; padding: 1.5rem 1rem 1.5rem; }
  .category-grid { gap: 1.25rem 0.5rem; }
  .app-icon { width: 56px; height: 56px; border-radius: 15px; }
  .app-letter { font-size: 1.35rem; }
  .app-name { font-size: 0.7rem; max-width: 76px; }
  .footer-stats { gap: 0.7rem; }
}

@media (min-width: 768px) {
  .category-grid { gap: 2rem 1rem; }
  .app-icon { width: 68px; height: 68px; border-radius: 19px; }
  .app-name { max-width: 96px; }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .blob { animation: none; }
}
