/* =========================================================
   Base Reset & Performance Optimizations
========================================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: sans-serif;
  /* 启用硬件加速 */
  transform: translateZ(0);
  backface-visibility: hidden;
  /* 优化字体渲染 */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* 优化滚动性能 */
  -webkit-overflow-scrolling: touch;
}

html {
  background: var(--color-surface);
  /* 优化滚动行为 */
  scroll-behavior: smooth;
}

/* 为支持的浏览器启用CSS containment */
@supports (contain: layout style paint) {
  .content {
    contain: layout style paint;
  }
}

/* =========================================================
   Theme Tokens (Light) – tweak here if you change brand colors
========================================================= */
:root {
  --color-primary: #6200ea;
  /* light mode primary */
  --color-primary-contrast: #ffffff;
  --color-surface: #ffffff;
  --color-text-muted: #888;
  --color-text-dim: #aaa;
  --shadow-elev-1: 0 -2px 10px rgba(0, 0, 0, 0.1);
  --shadow-fab: 0 4px 10px rgba(0, 0, 0, 0.2);
  /* Ripple (light) */
  --ripple-color: rgba(186, 104, 200, 0.35);
  /* soft purple */
}

/* =========================================================
   Layout
========================================================= */
.content {
  margin-bottom: 100px;
  min-height: calc(100vh - 80px); /* fill screen above bottom nav */
  padding: 20px;
  background: inherit;
}

/* 安全区处理 - 确保状态栏区域与应用背景色一致 */
html {
  background: var(--color-surface);
  /* 为状态栏区域设置背景色 */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background-color: var(--color-surface);
}

/* Android全屏模式优化 - 移除系统UI的padding */
@media screen and (max-width: 768px) {
  html {
    /* Android全屏模式下，系统UI被隐藏，不需要额外的padding */
    padding-top: 0;
    padding-left: 0;
    padding-right: 0;
  }
}

body {
  background: var(--color-surface);
  /* 确保状态栏区域有正确的背景色 */
  background-color: var(--color-surface);
}

/* --- iOS shell layout adjustments --- */
html,
body {
  height: 100%;
  overflow: hidden;
  /* 确保状态栏区域背景色一致 */
  background: var(--color-surface);
}
body {
  overscroll-behavior: none;
  /* 为状态栏区域设置背景色 */
  background-color: var(--color-surface);
}
.content {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h, 80px) + max(env(safe-area-inset-bottom), 20px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* smooth iOS momentum */
  contain: content;
  /* 确保内容区域背景色一致 */
  background: var(--color-surface);
}

/* Android全屏模式下的内容区域优化 */
@media screen and (max-width: 768px) {
  .content {
    /* Android全屏模式下，系统UI被隐藏，内容区域可以延伸到屏幕边缘 */
    top: 0;
    left: 0;
    right: 0;
    bottom: calc(var(--nav-h, 80px) + 20px); /* 只保留导航栏高度 + 固定间距 */
  }
}

/* Android设备完全全屏模式专用样式 */
.android-device .content {
  /* Android完全全屏模式：内容区域延伸到屏幕边缘，包括手势条区域 */
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h, 80px) + 10px); /* 减少底部间距，因为手势条已隐藏 */
}

.android-fullscreen .nav-container {
  /* Android完全全屏模式：导航栏固定在屏幕最底部，无系统UI干扰 */
  padding-bottom: 10px; /* 减少底部间距 */
  bottom: 0;
  /* 确保导航栏在屏幕最底部，不被手势条遮挡 */
  position: fixed;
  z-index: 1000;
}

/* Android挖孔屏设备专用样式 */
.android-notch-screen .content {
  /* 挖孔屏设备：内容区域延伸到屏幕边缘，但避开状态栏区域 */
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h, 80px) + 20px);
  /* 为状态栏区域添加顶部padding */
  padding-top: max(env(safe-area-inset-top), 24px);
}

.android-notch-screen .nav-container {
  /* 挖孔屏设备：导航栏适配，保留状态栏区域 */
  padding-bottom: 20px;
  bottom: 0;
  position: fixed;
  z-index: 1000;
  /* 为状态栏区域添加顶部padding */
  padding-top: max(env(safe-area-inset-top), 24px);
}

/* Android标准模式设备专用样式 */
.android-standard .content {
  /* 标准模式：内容区域避开系统UI */
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h, 80px) + max(env(safe-area-inset-bottom), 20px));
  /* 为状态栏和导航栏添加padding */
  padding-top: max(env(safe-area-inset-top), 24px);
  padding-left: max(env(safe-area-inset-left), 0px);
  padding-right: max(env(safe-area-inset-right), 0px);
}

.android-standard .nav-container {
  /* 标准模式：导航栏适配系统UI */
  padding-bottom: max(env(safe-area-inset-bottom), 20px);
  bottom: 0;
  position: fixed;
  z-index: 1000;
  /* 为状态栏区域添加顶部padding */
  padding-top: max(env(safe-area-inset-top), 24px);
}

/* iOS设备保持现有安全区配置 */
.ios-device .content {
  /* iOS设备：保持安全区配置 */
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h, 80px) + max(env(safe-area-inset-bottom), 20px));
}

.ios-safe-area .nav-container {
  /* iOS设备：保持安全区配置 */
  padding-bottom: max(env(safe-area-inset-bottom), 20px);
}

/* iOS设备优化：确保状态栏区域背景色一致 */
.ios-device html {
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background-color: var(--color-surface);
}

.ios-device body {
  background-color: var(--color-surface);
}

/* iOS设备：确保内容区域不遮挡状态栏 */
.ios-device .content {
  padding-top: max(20px, env(safe-area-inset-top));
}
/* Fixed nav stays pinned and respects safe area */
.nav-container {
  padding-bottom: env(safe-area-inset-bottom);
  /* Android底部导航栏适配 */
  padding-bottom: max(env(safe-area-inset-bottom), 20px);
}

/* Android全屏模式下的导航栏优化 */
@media screen and (max-width: 768px) {
  .nav-container {
    /* Android全屏模式下，系统导航栏被隐藏，使用固定底部间距 */
    padding-bottom: 20px;
    /* 确保导航栏在屏幕最底部 */
    bottom: 0;
  }
}

/* Android底部导航栏特殊适配 */
@supports (padding: max(0px)) {
  .nav-container {
    padding-bottom: max(env(safe-area-inset-bottom), 20px);
  }
}

/* 针对Android设备的额外适配 */
@media screen and (max-width: 768px) {
  .nav-container {
    /* 确保在Android设备上有足够的底部间距 */
    padding-bottom: max(env(safe-area-inset-bottom), 24px);
    /* 添加最小高度确保不被遮挡 */
    min-height: calc(80px + max(env(safe-area-inset-bottom), 24px));
  }
}

/* iOS和Android通用安全区适配 */
@supports (padding: max(0px)) {
  /* 确保在所有设备上都有最小安全间距 */
  .nav-container {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  
  .content {
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
  }
}

/* 针对不同设备的特殊适配 */
@media screen and (max-width: 414px) {
  /* 小屏设备适配 */
  .nav-container {
    padding-bottom: max(env(safe-area-inset-bottom), 16px);
  }
}

@media screen and (min-width: 768px) {
  /* 大屏设备适配 */
  .nav-container {
    padding-bottom: max(env(safe-area-inset-bottom), 32px);
  }
}
/* Ensure modal still covers viewport without enabling body scroll */
.modal {
  position: fixed !important;
  inset: 0 !important;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* =========================================================
   Bottom Navigation
========================================================= */
.nav-container {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 80px;
  background: var(--color-surface);
  box-shadow: var(--shadow-elev-1);
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  z-index: 10;
}

/* 增强的导航栏入场动画 */
.nav-container {
  will-change: transform, opacity;
  transform: translateZ(0); /* GPU加速 */
  animation: navSlideUpEnhanced 600ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes navSlideUpEnhanced {
  0% {
    transform: translate3d(0, 100%, 0);
    opacity: 0;
  }
  40% {
    transform: translate3d(0, -8px, 0);
    opacity: 0.8;
  }
  70% {
    transform: translate3d(0, 4px, 0);
    opacity: 0.95;
  }
  85% {
    transform: translate3d(0, -2px, 0);
    opacity: 1;
  }
  100% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

.nav-item {
  flex: 1;
  text-align: center;
  position: relative;
  z-index: 1;
}

/* 增强的导航按钮 */
.nav-item > button.icon {
  background: none;
  border: none;
  padding: 8px;
  font-size: 24px;
  cursor: pointer;
  color: var(--color-text-dim);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  transform: translateZ(0); /* GPU加速 */
}

.nav-item > button.icon::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--color-primary);
  opacity: 0;
  border-radius: inherit;
  transform: scale(0.8);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: -1;
}

.nav-item > button.icon:hover::before {
  opacity: 0.08;
  transform: scale(1);
}

.nav-item > button.icon:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  transform: translateY(-1px) translateZ(0);
}

.nav-item > button.icon:active {
  transform: translateY(0) scale(0.95) translateZ(0);
  transition-duration: 0.1s;
}

/* 激活状态增强 */
.nav-item.active button {
  color: var(--color-primary);
  transform: translateY(-2px) translateZ(0);
}

.nav-item.active button::before {
  opacity: 0.12;
  transform: scale(1);
}

/* labels */
.nav-label {
  font-family: "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 13.5px;
  color: var(--color-text-muted);
  margin-top: 2px;
  text-align: center;
  line-height: 1.2;
  user-select: none;
  font-weight: 500;
  letter-spacing: 0.5px;
  transition: color 0.3s, font-weight 0.3s;
}

.nav-item.active .nav-label {
  color: var(--color-primary);
  font-weight: 600;
}

/* 增强的选择指示器 */
.indicator {
  position: absolute;
  bottom: 0;
  height: 4px;
  width: 25%;
  left: 0;
  background: linear-gradient(90deg, var(--color-primary), rgba(98, 0, 234, 0.8));
  border-radius: 4px 4px 0 0;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: translateZ(0); /* GPU加速 */
  box-shadow: 0 -2px 8px rgba(98, 0, 234, 0.3);
}

.indicator::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--color-primary);
  border-radius: inherit;
  opacity: 0.6;
  animation: indicatorGlow 2s ease-in-out infinite;
}

@keyframes indicatorGlow {
  0%, 100% {
    opacity: 0.6;
    transform: scaleY(1);
  }
  50% {
    opacity: 0.8;
    transform: scaleY(1.2);
  }
}

/* center (FAB-like) button */
.center-button-wrapper {
  position: absolute;
  top: -35px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
}

.center-button {
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, var(--color-primary) 0%, rgba(98, 0, 234, 0.9) 100%);
  color: var(--color-primary-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-fab), 0 0 0 0 rgba(98, 0, 234, 0.4);
  position: relative;
  clip-path: path('M35,62.27l-4.23-3.85C15.75,44.8,5.83,35.82,5.83,24.79 C5.83,15.81,12.89,8.75,21.87,8.75c5.08,0,9.95,2.36,13.13,6.1C38.18,11.11,43.05,8.75,48.13,8.75 C57.11,8.75,64.17,15.81,64.17,24.79c0,11.03-9.92,20.01-24.94,33.63L35,62.27z');
  transform: translateZ(0); /* GPU加速 */
  overflow: hidden;
}

.center-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.center-button:hover {
  transform: translateY(-4px) scale(1.05) translateZ(0);
  box-shadow: var(--shadow-fab), 0 8px 25px rgba(98, 0, 234, 0.4);
}

.center-button:hover::before {
  opacity: 1;
}

.center-button:active {
  transform: translateY(-2px) scale(0.98) translateZ(0);
  transition-duration: 0.1s;
}

.center-button ion-icon {
  width: 32px;
  height: 32px;
  transform: translateY(-2px);
}

/* 涟漪效果 */
.center-button.ripple::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 0 var(--ripple-color);
  opacity: 0;
  animation: fabRing 900ms ease-out 120ms both;
}

@keyframes fabRing {
  0% {
    opacity: 1;
    box-shadow: 0 0 0 0 var(--ripple-color);
  }
  60% {
    opacity: 0.7;
  }
  100% {
    opacity: 0;
    box-shadow: 0 0 0 22px rgba(0, 0, 0, 0);
  }
}

.center-button.pulse {
  animation: heartPulse 0.6s ease-in-out;
}

@keyframes heartPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}

/* icons */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.icon:hover {
  transform: scale(1.2);
  opacity: 0.8;
}

.icon ion-icon {
  width: 24px;
  height: 24px;
  line-height: 1;
}

.center-button ion-icon {
  width: 28px;
  height: 28px;
}

/* =========================================================
   Modal
========================================================= */
.modal {
  position: fixed;
  z-index: 999;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: background 0.3s;
  pointer-events: auto;
}

@keyframes popSlideUpEnhanced {
  0% {
    transform: translate3d(0, 30px, 0) scale3d(0.9, 0.9, 1);
    opacity: 0;
  }
  50% {
    transform: translate3d(0, -8px, 0) scale3d(1.02, 1.02, 1);
    opacity: 0.8;
  }
  75% {
    transform: translate3d(0, 4px, 0) scale3d(0.98, 0.98, 1);
    opacity: 0.95;
  }
  90% {
    transform: translate3d(0, -2px, 0) scale3d(1.01, 1.01, 1);
    opacity: 1;
  }
  100% {
    transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
    opacity: 1;
  }
}

.modal-content {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 100px;
  bottom: 120px;
  margin: 0 auto;
  background: linear-gradient(145deg, #ffffff 0%, #fafbfc 100%);
  border-radius: 20px;
  padding: 32px 16px 24px 16px;
  box-shadow: 
    0 20px 40px rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(255, 255, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  will-change: transform, opacity;
  backface-visibility: hidden;
  transform: translateZ(0); /* GPU加速 */
  animation: popSlideUpEnhanced 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  font-family: "Segoe UI", "PingFang SC", Arial, sans-serif;
  overflow-y: auto;
  z-index: 1001;
  pointer-events: auto;
  width: auto;
  min-width: unset;
  max-width: 500px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
  z-index: 1;
}

@media (max-width: 480px) {
  .modal-content {
    left: 4px;
    right: 4px;
    padding: 16px 4px;
    max-width: 90vw;
  }
}

@keyframes popSlideDown {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  20% {
    transform: translateY(-1px) scale(0.998);
    opacity: 0.96;
  }
  100% {
    transform: translateY(24px) scale(0.985);
    opacity: 0;
  }
}

.modal-content.closing {
  animation: popSlideDown 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

/* =========================================================
   Dark Mode
========================================================= */
@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #bb86fc;
    /* dark mode primary */
    --color-primary-contrast: #18181c;
    --color-surface: #23232a;
    --color-text-muted: #888;
    --color-text-dim: #888;
    /* Ripple (dark) */
    --ripple-color: rgba(203, 148, 217, 0.5);
    /* brighter purple for contrast */
  }

  html,
  body,
  .content,
  #content {
    background: #18181c !important;
    color: #e5e5e5;
    /* 确保暗色模式下状态栏区域背景色一致 */
    background-color: #18181c !important;
  }

  .nav-container {
    background: var(
      --color-surface
    ) !important; /* restore intended dark mode surface color */
    box-shadow: none; /* remove darker band above the bar */
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  .nav-item > button.icon {
    color: var(--color-text-muted);
  }

  .nav-item.active button {
    color: var(--color-primary);
  }

  .indicator {
    background: var(--color-primary);
  }

  .center-button {
    background: var(--color-primary);
    color: var(--color-primary-contrast);
  }

  .modal {
    background: rgba(24, 24, 28, 0.5);
  }

  .modal-content {
    background: var(--color-surface);
    color: #e5e5e5;
  }

  .nav-label {
    color: var(--color-text-muted);
    font-family: "PingFang SC", "Segoe UI", Arial, sans-serif;
  }

  .nav-item.active .nav-label {
    color: var(--color-primary);
    font-weight: 600;
  }
}
@media (prefers-reduced-motion: reduce) {
  .modal-content {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .modal-content.closing {
    animation-duration: 0.01ms !important;
  }
  .nav-container {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .center-button::after {
    animation: none !important;
  }
}

@media (max-width: 380px) {
  .modal-content {
    animation-duration: 0.42s;
  }
}
