/* ============================================================
   DualStar · 小手机主屏
   天气+char提示 → 时间 → 照片+纪念日 → App网格 → Dock
   ============================================================ */

.phone-view {
  position: fixed;
  inset: 0;
  /* iOS 全屏兜底：用大视口高度(100lvh)铺满整块设备，含底部安全区。
     仅 100% 会退化为「视觉视口」高度（URL 栏/安全区被排除），导致底部露出白边。 */
  height: 100vh;
  height: 100lvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* —— 桌面端：手机外壳 —— */
.phone-shell {
  position: relative;
  width: var(--phone-w);
  height: var(--phone-h);
  max-height: 100vh;
  background: var(--bg);
  border-radius: var(--phone-radius);
  box-shadow:
    0 0 0 12px var(--bg-elevated),
    0 0 0 13px var(--border-strong),
    var(--shadow-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.phone-shell > * { flex-shrink: 0; }
.phone-shell > .phone-content { flex-shrink: 1; min-height: 0; }

/* —— 触摸设备 / 独立 PWA / 手机：手机壳一律满屏 ——
   不依赖 JS 的 displayMode，纯 CSS 强制铺满，根除「竖条窄壳」与「底部白边」。
   高度用 100%（填满 .phone-view=inset:0 的整屏，含安全区），
   而非 100dvh（比整屏矮一截，会在底部露出 html 背景形成白边）。 */
@media (max-width: 768px), (pointer: coarse), (any-pointer: coarse), (display-mode: standalone) {
  .phone-view { padding: 0 !important; }
  .phone-shell {
    width: 100% !important;
    /* 触摸/独立 PWA：用大视口高度铺满设备（含底部安全区），根除底部白边 */
    height: 100vh !important;
    height: 100lvh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    margin: 0 !important;
  }
  /* 内容底部不再预留安全区 —— Dock 直接贴底，彻底消除底部白边 */
  .phone-shell > .phone-content {
    padding-bottom: 0 !important;
  }
  /* Dock 与悬浮球(Home Indicator)贴底，去除底部白边（所有触摸/独立 PWA 通用） */
  .phone-dock { margin-bottom: 0 !important; }
  .phone-home-indicator { margin-bottom: 0 !important; }
}

/* —— 全屏模式 —— */
/* 基础样式已由 base.css 统一处理（窗口化） */

/* 全屏模式下的内容容器占满整个手机壳 */
[data-display-mode="fullscreen"] .phone-content {
  flex: 1;
  min-height: 0;
}

/* 全屏模式下：手机壳在任意视口都撑满，避免 >768px 时退化为手机窄壳竖条
   （基础 .phone-shell 用 var(--phone-w)，仅手机竖屏 ≤768px 被覆盖为 100vw；
    iPad / 横屏 iPhone / 宽窗口下会缩成中间一个竖条。全屏模式应始终满屏。） */
[data-display-mode="fullscreen"] .phone-shell {
  width: 100%;
  height: 100%;
  max-height: 100vh;
  max-height: 100lvh;
  border-radius: 0;
  box-shadow: none;
}

/* 平板/桌面端全屏模式：大屏重新布局 */
@media (min-width: 769px) {
  [data-display-mode="fullscreen"] .phone-content {
    display: flex;
    flex-direction: row;
    gap: 32px;
    padding: 32px;
    padding-top: calc(32px + var(--safe-area-top, env(safe-area-inset-top, 0px)));
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
  }

  /* 左侧：大组件区域 */
  [data-display-mode="fullscreen"] .phone-widgets-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-width: 0;
    max-width: 420px;
  }

  /* 右侧：App 区域 */
  [data-display-mode="fullscreen"] .phone-apps-right {
    display: flex;
    flex-direction: column;
    gap: 24px;
    flex: 1;
    min-width: 0;
  }

  /* 天气组件变大 */
  [data-display-mode="fullscreen"] .widget-weather-hero {
    padding: 24px;
    min-height: 140px;
  }

  [data-display-mode="fullscreen"] .weather-hero-icon {
    width: 64px;
    height: 64px;
    font-size: 36px;
  }

  [data-display-mode="fullscreen"] .weather-hero-temp {
    font-size: 48px;
  }

  /* 时间组件变大 */
  [data-display-mode="fullscreen"] .widget-time {
    padding: 28px 24px;
  }

  [data-display-mode="fullscreen"] .widget-time-clock {
    font-size: 64px;
  }

  [data-display-mode="fullscreen"] .widget-time-date {
    font-size: 16px;
  }

  /* 照片+纪念日双列 */
  [data-display-mode="fullscreen"] .widget-pair {
    gap: 16px;
  }

  [data-display-mode="fullscreen"] .widget-photo,
  [data-display-mode="fullscreen"] .widget-anniv {
    min-height: 140px;
  }

  /* App 网格更多列 */
  [data-display-mode="fullscreen"] .app-grid,
  [data-display-mode="fullscreen"] .app-page {
    grid-template-columns: repeat(var(--app-grid-cols, 4), 1fr);
    gap: 24px 16px;
  }

  [data-display-mode="fullscreen"] .app-icon {
    width: 64px;
    height: 64px;
    max-width: 64px;
    font-size: 28px;
    border-radius: 16px;
  }

  [data-display-mode="fullscreen"] .app-icon svg {
    width: 30px;
    height: 30px;
  }

  [data-display-mode="fullscreen"] .app-label {
    font-size: 13px;
  }

  /* Dock 在全屏模式下保持底部位置 */
  [data-display-mode="fullscreen"] .phone-dock {
    margin: 6px 14px 14px;
    padding: 10px;
    justify-content: space-around;
    background: var(--bg-glass);
    border-radius: var(--r-xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
  }

  [data-display-mode="fullscreen"] .phone-dock .app-icon {
    width: 56px;
    height: 56px;
    font-size: 24px;
    border-radius: 14px;
  }

  /* 隐藏 Home Indicator */
  [data-display-mode="fullscreen"] .phone-home-indicator {
    display: none;
  }

  /* 状态栏更宽 */
  [data-display-mode="fullscreen"] .phone-statusbar {
    padding: 12px 24px;
    padding-top: calc(12px + var(--safe-area-top, env(safe-area-inset-top, 0px)));
  }
}

/* —— 触摸平板（如 iPad，>768px 触摸设备）：纯 CSS 双栏全屏布局 ——
   不依赖 JS 的 displayMode；即使旧 theme.js 未强制 fullscreen，iPad 也满屏双栏。 */
@media (min-width: 769px) and (pointer: coarse), (min-width: 769px) and (any-pointer: coarse) {
  .phone-content {
    display: flex;
    flex-direction: row;
    gap: 32px;
    padding: 32px;
    padding-top: calc(32px + var(--safe-area-top, env(safe-area-inset-top, 0px)));
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
  }
  .phone-widgets-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-width: 0;
    max-width: 420px;
  }
  .phone-apps-right {
    display: flex;
    flex-direction: column;
    gap: 24px;
    flex: 1;
    min-width: 0;
  }
  .app-grid,
  .app-page {
    grid-template-columns: repeat(var(--app-grid-cols, 4), 1fr);
    gap: 24px 16px;
  }
  .widget-weather-hero { padding: 24px; min-height: 140px; }
  .widget-time { padding: 28px 24px; }
  .widget-time-clock { font-size: 64px; }
  .widget-pair { gap: 16px; }
  .widget-photo, .widget-anniv { min-height: 140px; }
  .app-icon { width: 64px; height: 64px; max-width: 64px; font-size: 28px; border-radius: 16px; }
  .app-icon svg { width: 30px; height: 30px; }
  .app-label { font-size: 13px; }
  .phone-dock {
    margin: 6px 14px 14px;
    padding: 10px;
    justify-content: space-around;
    background: var(--bg-glass);
    border-radius: var(--r-xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
  }
  .phone-dock .app-icon { width: 56px; height: 56px; font-size: 24px; border-radius: 14px; }
  .phone-home-indicator { display: none; }
  .phone-statusbar { padding: 12px 24px; padding-top: calc(12px + var(--safe-area-top, env(safe-area-inset-top, 0px))); }
}

/* 桌面端更宽的布局 */
@media (min-width: 1200px) {
  [data-display-mode="fullscreen"] .phone-content {
    max-width: 1400px;
    gap: 48px;
    padding: 48px;
    padding-top: calc(48px + var(--safe-area-top, env(safe-area-inset-top, 0px)));
  }

  [data-display-mode="fullscreen"] .phone-widgets-left {
    max-width: 480px;
    gap: 24px;
  }

  [data-display-mode="fullscreen"] .app-grid,
  [data-display-mode="fullscreen"] .app-page {
    grid-template-columns: repeat(var(--app-grid-cols, 5), 1fr);
    gap: 28px 20px;
  }

  [data-display-mode="fullscreen"] .app-icon {
    width: 72px;
    height: 72px;
    max-width: 72px;
    font-size: 32px;
    border-radius: 18px;
  }

  [data-display-mode="fullscreen"] .app-icon svg {
    width: 34px;
    height: 34px;
  }
}

/* —— 壁纸层 —— */
.phone-wallpaper {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 10%, var(--accent-soft) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 90%, var(--highlight) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 100%);
  z-index: 0;
}

.phone-wallpaper::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.4 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.04;
  mix-blend-mode: multiply;
}

/* —— 状态栏 —— */
.phone-statusbar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.3px;
}

.phone-statusbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.statusbar-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* —— 主屏内容 —— */
.phone-content {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow: hidden; /* 真手机：主屏不可上下滚动，内容自适应，放不下的应用自动分页 */
  padding: 8px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: none;
}
.phone-content::-webkit-scrollbar { display: none; }

/* 主屏布局：组件区保持自然高度，应用区占满剩余空间（放不下则分页） */
.phone-widgets-left {
  flex-shrink: 0;
  min-width: 0;
}
.phone-apps-right {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* —— 天气组件（hero + 24h 预报） —— */
.widget-weather-hero {
  background: var(--bg-glass);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform var(--dur-fast) var(--ease-out);
}
.widget-weather-hero:active { transform: scale(0.99); }

.weather-hero-top {
  display: flex;
  align-items: center;
  gap: 14px;
}

.weather-hero-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-deep);
  flex-shrink: 0;
}

.weather-hero-main {
  flex: 1;
  min-width: 0;
}

.weather-hero-temp {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
}

.weather-hero-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.weather-hero-city {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 2px;
  letter-spacing: 0.3px;
}

.weather-hero-refresh {
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.weather-hero-refresh:hover {
  background: var(--accent-soft);
  color: var(--accent-deep);
  transform: rotate(90deg);
}
.weather-hero-refresh:active { transform: scale(0.9); }

/* 24h 预报条 */
.weather-hourly {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
.weather-hourly::-webkit-scrollbar { display: none; }

.weather-hourly-item {
  flex: 1 0 auto;
  min-width: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
  border-radius: var(--r-sm);
  transition: background var(--dur-fast);
}
.weather-hourly-item:hover { background: var(--bg-soft); }

.weather-hourly-hour {
  font-size: 9px;
  color: var(--text-tertiary);
  letter-spacing: 0.2px;
}

.weather-hourly-icon {
  color: var(--accent-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}
.weather-hourly-icon svg { width: 18px; height: 18px; }

.weather-hourly-temp {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-display);
}

.weather-hourly-rain {
  font-size: 8px;
  color: var(--accent);
  letter-spacing: 0.2px;
}

/* —— 时间小组件 —— */
.widget-time {
  background: var(--bg-glass);
  border-radius: var(--r-lg);
  padding: 18px 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.widget-time-clock {
  font-family: var(--font-display);
  font-size: 48px;
  font-weight: 600;
  letter-spacing: 2px;
  line-height: 1;
  color: var(--text);
}

.widget-time-clock .colon {
  animation: blink 1.6s steps(2) infinite;
}
@keyframes blink {
  50% { opacity: 0.4; }
}

.widget-time-date {
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  margin-top: 6px;
}

/* —— 照片 + 纪念日 横排 —— */
.widget-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* —— 照片小组件（单张大图） —— */
.widget-photo {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out);
}
.widget-photo:active { transform: scale(0.97); }
/* standalone（不在 widget-pair 里时）也保持正方形，与成对时一致 */
.phone-widgets-left > .widget-photo,
.phone-widgets-left > .widget-unit.widget-photo {
  aspect-ratio: 1;
}

.widget-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.widget-photo-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-tertiary);
  font-size: 11px;
  padding: 8px;
  text-align: center;
}

.widget-photo-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 10px;
  color: #fff;
  background: rgba(0,0,0,0.4);
  padding: 3px 8px;
  border-radius: var(--r-full);
  letter-spacing: 0.3px;
}

/* —— 纪念日小组件 —— */
.widget-anniv {
  background: var(--bg-glass);
  border-radius: var(--r-lg);
  padding: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s;
  position: relative;
  overflow: hidden;
}
.widget-anniv:active { transform: scale(0.97); }
.widget-anniv:hover {
  box-shadow: var(--shadow-md);
}

.widget-anniv-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  color: var(--text-tertiary);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-bottom: 10px;
  font-weight: 600;
}
.widget-anniv-header svg { width: 12px; height: 12px; opacity: 0.7; }

.widget-anniv-days {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.5px;
}

.widget-anniv-title {
  font-size: 11px;
  color: var(--text);
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.widget-anniv-date {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 2px;
  letter-spacing: 0.3px;
}

/* 纪念日多卡片列表 */
.widget-anniv-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.widget-anniv-list::-webkit-scrollbar { display: none; }

.anniv-card-mini {
  padding: 6px 8px;
  border-radius: var(--r-sm);
  border-left: 2px solid var(--border);
  background: var(--surface);
  transition: background var(--dur-fast);
}
.anniv-card-mini.first {
  border-left-color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.025);
}
.anniv-card-mini.past {
  opacity: 0.55;
  border-left-color: var(--text-tertiary);
}

.anniv-card-days-row {
  display: flex;
  align-items: baseline;
  gap: 2px;
}
.anniv-card-days {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.3px;
}
.anniv-card-mini.past .anniv-card-days {
  color: var(--text-tertiary);
}
.anniv-card-unit {
  font-size: 9px;
  color: var(--text-tertiary);
  letter-spacing: 0.3px;
}

.anniv-card-title {
  font-size: 10px;
  color: var(--text);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.anniv-card-date {
  font-size: 9px;
  color: var(--text-tertiary);
  margin-top: 1px;
  letter-spacing: 0.2px;
}

/* —— 纪念日 widget 新版（v2，带图标 + 主题色） —— */
.widget-anniv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 6px;
  color: var(--text-tertiary);
}
.widget-anniv-empty-icon svg {
  width: 28px;
  height: 28px;
  opacity: 0.4;
}
.widget-anniv-empty-text {
  font-size: 10px;
  letter-spacing: 0.5px;
}

/* 重写 anniv-card-mini：横向布局（图标 + 信息 + 倒数） */
.anniv-card-mini {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border-left: 2px solid var(--card-accent, var(--border));
  cursor: pointer;
  transition: background var(--dur-fast), transform var(--dur-fast) var(--ease-out);
  position: relative;
}
.anniv-card-mini:hover {
  background: var(--bg-soft);
  transform: translateX(1px);
}
.anniv-card-mini.first {
  background: rgba(0, 0, 0, 0.03);
}
.anniv-card-mini.is-today {
  background: linear-gradient(90deg, color-mix(in srgb, var(--card-accent) 18%, transparent), var(--surface));
  border-left-width: 3px;
}
.anniv-card-mini.is-today::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--card-accent);
  margin: 6px;
  animation: widgetPulse 1.8s ease-in-out infinite;
}
@keyframes widgetPulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}
.anniv-card-mini.is-past {
  opacity: 0.55;
}

.anniv-card-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--card-accent, var(--text-tertiary)) 12%, transparent);
  color: var(--card-accent, var(--text-tertiary));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.anniv-card-info {
  flex: 1;
  min-width: 0;
}

.anniv-card-info .anniv-card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  margin-top: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.anniv-card-info .anniv-card-date {
  font-size: 9px;
  color: var(--text-tertiary);
  margin-top: 1px;
  letter-spacing: 0.2px;
}

.anniv-card-days-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
  line-height: 1;
}

.anniv-card-days-block .anniv-card-days {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--card-accent, var(--text));
  letter-spacing: -0.3px;
}

.anniv-card-mini.is-past .anniv-card-days-block .anniv-card-days {
  color: var(--text-tertiary);
}

.anniv-card-days-block .anniv-card-unit {
  font-size: 8px;
  color: var(--text-tertiary);
  margin-top: 2px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 600;
}

/* SVG 容器在 widget 中 */
.widget-anniv .anniv-icon-svg {
  display: flex;
  align-items: center;
  justify-content: center;
}
.widget-anniv .anniv-icon-svg svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* —— App 网格（分页结构：renderApps 实际使用 .app-page） —— */
.app-pages-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.app-pages-scroll {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden; /* 应用区只允许横向翻页，禁止纵向滚动 */
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.app-pages-scroll::-webkit-scrollbar { display: none; }
.app-page {
  flex: 0 0 100%;
  min-width: 100%;
  height: 100%; /* 占满应用区高度 */
  scroll-snap-align: start;
  display: grid;
  grid-template-columns: repeat(var(--app-grid-cols, 4), 1fr);
  /* 行高由内容决定（图标+文字），不再拉伸铺满 —— 真手机效果：
     图标为固定尺寸、行距一致，整块在应用区垂直居中，消除"间隔很远"。 */
  grid-template-rows: repeat(var(--app-rows, 4), min-content);
  align-content: center;
  gap: 14px 4px;
  padding: 6px 4px 4px;
  box-sizing: border-box;
}
/* 兼容旧引用 */
.app-grid {
  display: grid;
  grid-template-columns: repeat(var(--app-grid-cols, 4), 1fr);
  gap: 14px 6px;
  padding: 6px 4px 4px;
}
.app-page-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 0 2px;
}
.app-page-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-strong, rgba(0, 0, 0, 0.35));
  opacity: 0.45;
  transition: opacity 0.2s ease;
}
.app-page-dot.active {
  opacity: 1;
  background: var(--accent, #5A7363);
}

.app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out);
}
.app-item:active { transform: scale(0.92); }
.app-item:hover .app-icon {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.app-item .app-icon {
  transition: transform var(--dur-fast) var(--ease-out),
              filter var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

.app-icon {
  /* 填满所在网格列（最多 62px），让图标更大、横向间隔更紧凑，贴近真手机 */
  width: 100%;
  max-width: 62px;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: var(--shadow-md);
  position: relative;
}
.app-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.18) 0%, transparent 50%, rgba(0,0,0,0.08) 100%);
  pointer-events: none;
  z-index: 1;
}
.app-icon > * { position: relative; z-index: 2; }
.app-icon svg, .dock-icon svg { width: 28px; height: 28px; }

.app-icon.wechat   { background: linear-gradient(135deg, #8FA89A 0%, #B5C9B8 100%); }
.app-icon.mail     { background: linear-gradient(135deg, #B89976 0%, #D4B896 100%); }
.app-icon.sms      { background: linear-gradient(135deg, #7A9CB8 0%, #A8C0D4 100%); }
.app-icon.anniv    { background: linear-gradient(135deg, #C9A8A0 0%, #D8B8B0 100%); }
.app-icon.album    { background: linear-gradient(135deg, #A8A29E 0%, #C9C3B6 100%); }
.app-icon.settings { background: linear-gradient(135deg, #A8A29E 0%, #C9C3B6 100%); }
.app-icon.worldbook { background: linear-gradient(135deg, #8A7355 0%, #B89976 100%); }
.app-icon.mask     { background: linear-gradient(135deg, #6B7B8A 0%, #95A5B5 100%); }
.app-icon.switch-offline { background: linear-gradient(135deg, #5A7363 0%, #8FA89A 100%); }
/* —— 补全缺失的图标渐变（此前缺失导致图标显示为白色） —— */
.app-icon.music    { background: linear-gradient(135deg, #7A8B6F 0%, #A3B58F 100%); }
.app-icon.rednote  { background: linear-gradient(135deg, #E86A5E 0%, #F2907F 100%); }
.app-icon.taobao   { background: linear-gradient(135deg, #F2A03D 0%, #F7C04A 100%); }
.app-icon.regex    { background: linear-gradient(135deg, #5F7E8C 0%, #8FA9B8 100%); }

.app-label {
  font-size: 11px;
  color: var(--text);
  letter-spacing: 0.3px;
}

.app-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid var(--bg);
  z-index: 10;
  box-shadow: 0 2px 6px rgba(220, 80, 80, 0.4);
  pointer-events: none;
}

/* —— Dock —— */
.phone-dock {
  position: relative;
  z-index: 2;
  margin: 6px 14px 14px;
  padding: 10px;
  background: var(--bg-glass);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--r-md);
  transition: transform var(--dur-fast) var(--ease-out);
}
.dock-item:active { transform: scale(0.92); }
.dock-item:hover .dock-icon {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.dock-item .dock-icon {
  transition: transform var(--dur-fast) var(--ease-out),
              filter var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

.dock-icon {
  width: 54px;
  height: 54px;
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: var(--shadow-md);
  position: relative;
}
.dock-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.18) 0%, transparent 50%, rgba(0,0,0,0.08) 100%);
  pointer-events: none;
  z-index: 1;
}
.dock-icon > * { position: relative; z-index: 2; }

.dock-icon.settings  { background: linear-gradient(135deg, #A8A29E 0%, #C9C3B6 100%); }
.dock-icon.worldbook { background: linear-gradient(135deg, #8A7355 0%, #B89976 100%); }
.dock-icon.mask      { background: linear-gradient(135deg, #6B7B8A 0%, #95A5B5 100%); }
.dock-icon.switch-offline { background: linear-gradient(135deg, #5A7363 0%, #8FA89A 100%); }

.dock-label {
  font-size: 10px;
  color: var(--text);
  letter-spacing: 0.3px;
}

/* —— Home indicator —— */
.phone-home-indicator {
  position: relative;
  z-index: 2;
  width: 134px;
  height: 5px;
  background: var(--text);
  opacity: 0.4;
  border-radius: var(--r-full);
  margin: 0 auto 6px;
}

/* —— 切换线下过渡 —— */
.phone-shell.switching {
  animation: phoneSwitchOut 0.5s var(--ease-in-out) forwards;
}

@keyframes phoneSwitchOut {
  to {
    transform: scale(0.9);
    opacity: 0;
    filter: blur(8px);
  }
}

/* —— char 切换浮层 —— */
.char-switcher {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 800;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base);
}
.char-switcher.active {
  opacity: 1;
  pointer-events: auto;
}
.char-switcher-sheet {
  background: var(--bg-elevated);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 20px 16px 32px;
  width: 100%;
  max-width: 420px;
  max-height: 70vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--dur-base) var(--ease-out);
}
.char-switcher.active .char-switcher-sheet {
  transform: translateY(0);
}
.char-switcher-title {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
}
.char-switcher-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--dur-fast);
}
.char-switcher-item:hover { background: var(--bg-soft); }
.char-switcher-item.selected {
  background: var(--accent-soft);
}
.char-switcher-item-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-deep);
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
}
.char-switcher-item-avatar img { width: 100%; height: 100%; object-fit: cover; }
.char-switcher-item-name {
  flex: 1;
  font-size: 15px;
  color: var(--text);
}

/* —— 照片选择浮层 —— */
.photo-picker {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 800;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base);
}
.photo-picker.active {
  opacity: 1;
  pointer-events: auto;
}
.photo-picker-sheet {
  background: var(--bg-elevated);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 20px 16px 32px;
  width: 100%;
  max-width: 420px;
  max-height: 70vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--dur-base) var(--ease-out);
}
.photo-picker.active .photo-picker-sheet {
  transform: translateY(0);
}
.photo-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.photo-picker-item {
  aspect-ratio: 1;
  border-radius: var(--r-md);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  border: 3px solid transparent;
  transition: background-color var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast), opacity var(--dur-fast), transform var(--dur-fast);
}
.photo-picker-item.loading {
  background: var(--bg-soft);
  filter: none;
  animation: photoPickerPulse 1.2s ease-in-out infinite;
}
@keyframes photoPickerPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 0.3; }
}
.photo-picker-item:hover { transform: scale(0.96); }
.photo-picker-item.selected {
  border-color: var(--accent);
}

/* ============================================================
   主屏编辑模式 · 长按进入 · app 拖拽排序
   ============================================================ */

/* 编辑模式：app 抖动 */
.phone-shell.edit-mode .app-item {
  animation: appShake 0.6s ease-in-out infinite;
  animation-delay: var(--shake-delay, 0s);
  will-change: transform;
}
.phone-shell.edit-mode .app-item:nth-child(2n)  { --shake-delay: 0.08s; }
.phone-shell.edit-mode .app-item:nth-child(3n)  { --shake-delay: 0.16s; }
.phone-shell.edit-mode .app-item:nth-child(4n)  { --shake-delay: 0.04s; }
.phone-shell.edit-mode .app-item:nth-child(5n)  { --shake-delay: 0.12s; }

@keyframes appShake {
  0%, 100% { transform: rotate(0deg); }
  20%      { transform: rotate(-2.2deg); }
  40%      { transform: rotate(2.2deg); }
  60%      { transform: rotate(-1.6deg); }
  80%      { transform: rotate(1.6deg); }
}

/* 编辑模式下禁用 app-item 的 :active 缩放与 hover 上浮，避免与抖动冲突 */
.phone-shell.edit-mode .app-item:active { transform: none; }
.phone-shell.edit-mode .app-item:hover .app-icon {
  box-shadow: var(--shadow-md);
  transform: none;
}

/* 移除角标（编辑模式下显示） */
.app-remove-badge {
  display: none;
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  align-items: center;
  justify-content: center;
  z-index: 11;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  cursor: pointer;
  pointer-events: auto;
}
.app-remove-badge svg {
  width: 12px !important;
  height: 12px !important;
  stroke-width: 2.4;
}
.phone-shell.edit-mode .app-remove-badge {
  display: flex;
}

/* 编辑模式下 dock 也允许 wrap，避免 dock 太挤 */
.phone-shell.edit-mode .phone-dock {
  overflow: visible;
}

/* 拖拽中的 ghost（跟随指针） */
.dragging-ghost {
  position: fixed !important;
  pointer-events: none !important;
  z-index: 99999;
  opacity: 0.92;
  transform: scale(1.08);
  box-shadow: 0 12px 32px rgba(0,0,0,0.28);
  animation: none !important;
  margin: 0 !important;
  transition: none !important;
}
.dragging-ghost .app-remove-badge { display: none !important; }

/* 拖拽源（被拖动的原元素）半透明 */
.app-item.dragging-source {
  opacity: 0.25;
  animation: none !important;
  transform: none !important;
}

/* drop target 高亮 */
.app-item.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  border-radius: var(--r-md);
  animation: none !important;
}

/* —— Widget 编辑模式 / 拖拽 —— */
/* 编辑模式：widget 抖动 */
.phone-shell.edit-mode .widget-unit {
  animation: appShake 0.6s ease-in-out infinite;
  animation-delay: var(--shake-delay, 0s);
  will-change: transform;
}
.phone-shell.edit-mode .widget-unit:nth-child(2n) { --shake-delay: 0.08s; }
.phone-shell.edit-mode .widget-unit:nth-child(3n) { --shake-delay: 0.16s; }
.phone-shell.edit-mode .widget-unit:nth-child(4n) { --shake-delay: 0.04s; }
.phone-shell.edit-mode .widget-unit:nth-child(5n) { --shake-delay: 0.12s; }

/* widget 移除角标（编辑模式下显示） */
.widget-remove-badge {
  display: none;
}
.phone-shell.edit-mode .widget-remove-badge {
  display: flex;
}
/* photo widget 有 overflow:hidden，角标改到内部 */
.widget-photo .widget-remove-badge {
  top: 6px;
  right: 6px;
}

/* widget 拖拽中：source 半透明 */
.widget-unit.dragging-source {
  opacity: 0.25;
  animation: none !important;
  transform: none !important;
}

/* widget drop target 高亮 */
.widget-unit.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  animation: none !important;
}

/* widget ghost（跟随指针） */
.dragging-ghost.widget-ghost {
  border-radius: var(--r-lg);
  transform: scale(1.04);
}

/* 编辑模式下禁用内部交互（点击由 JS 兜底，避免误触） */
.phone-shell.edit-mode .weather-hero-refresh,
.phone-shell.edit-mode .widget-photo img,
.phone-shell.edit-mode .widget-photo-empty,
.phone-shell.edit-mode .widget-anniv-list {
  pointer-events: none;
}

/* 编辑模式底部条 */
.phone-edit-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}
.phone-edit-overlay.active {
  pointer-events: none;
  opacity: 1;
  background: transparent;
}
/* 编辑模式底部条单独接收事件（按钮可点） */
.phone-edit-overlay.active .phone-edit-bar {
  pointer-events: auto;
}

.phone-edit-bar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%) translateY(20px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  max-width: calc(var(--phone-w, 100vw) - 24px);
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
.phone-edit-bar::-webkit-scrollbar { display: none; }
.phone-edit-overlay.active .phone-edit-bar {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.phone-edit-bar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding-right: 8px;
  border-right: 1px solid var(--border);
}

.phone-edit-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.phone-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.phone-edit-btn:hover { transform: scale(1.04); }
.phone-edit-btn:active { transform: scale(0.96); }
.phone-edit-btn svg { width: 14px; height: 14px; }
.phone-edit-btn#editFinish {
  background: var(--text);
}


/* ============================================================
   手机端（≤768px）：主屏组件紧凑化，把空间还给 App 网格（真手机布局）
   ============================================================ */
@media (max-width: 768px) {
  /* 天气组件更紧凑 */
  .widget-weather-hero {
    padding: 8px 10px;
    gap: 6px;
  }
  .weather-hero-icon { width: 34px; height: 34px; }
  .weather-hero-temp { font-size: 20px; }
  .weather-hero-desc { font-size: 11px; }
  .weather-hero-refresh { width: 26px; height: 26px; }
  .weather-hourly { padding-top: 6px; }
  .weather-hourly-item { min-width: 32px; padding: 2px 1px; gap: 2px; }
  .weather-hourly-icon svg { width: 13px; height: 13px; }

  /* 时间组件更紧凑 */
  .widget-time { padding: 8px 12px; gap: 2px; }
  .widget-time-clock { font-size: 34px; }
  .widget-time-date { margin-top: 3px; font-size: 11px; }

  /* 照片 + 纪念日：均为正方形，与图片并排一致 */
  .widget-pair { gap: 8px; }
  .widget-pair .widget-photo { aspect-ratio: 1; }
  .widget-pair .widget-anniv { padding: 10px; aspect-ratio: 1; }
  .widget-anniv-header { margin-bottom: 6px; }
  .widget-anniv-days { font-size: 26px; }

  /* 应用区保底高度（至少能放 1 行图标） */
  .phone-apps-right { min-height: 120px; }

  /* Dock 与悬浮球(Home Indicator)贴底，去除底部白边 */
  .phone-dock { margin-bottom: 0; }
  .phone-home-indicator { margin-bottom: 0; }
}
