/* ====================
   全局样式与变量定义
   ==================== */

/* 基础重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* 变量定义 */
:root {
  /* 深色主题变量 */
  --glass-bg: rgba(255, 255, 255, 0.18);
  --glass-border: rgba(255, 255, 255, 0.25);
  --glass-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  --bg-layer-1: #1a1a2e;
  --bg-layer-2: #16213e;
  --text-primary: rgba(255, 255, 255, 0.9);
  --text-secondary: rgba(255, 255, 255, 0.7);
  --history-bg: rgba(255, 255, 255, 0.1);
  --accent-color: #4dabf7;
}

/* 浅色主题变量覆盖 */
.light-theme {
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(209, 213, 219, 0.3);
  --glass-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
  --bg-layer-1: #f0f2f5;
  --bg-layer-2: #e6e9ef;
  --text-primary: rgba(0, 0, 0, 0.65);
  --text-secondary: rgba(0, 0, 0, 0.45);
  --history-bg: rgba(0, 0, 0, 0.05);
  --accent-color: #1971c2;
}

/* 时间显示优化 */
.time-display, 
.date-display {
  will-change: transform, contents;
  contain: content;
}

/* ====================
   页面布局与背景
   ==================== */

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10vh;
  background: var(--bg-layer-1);
  position: relative;
  overflow: hidden;
  color: var(--text-primary);
  transition: background 0.4s ease;
}

/* iOS Safari 兼容层 */
.ios-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(25, 25, 45, 0.65);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 0;
}

/* 背景图案 */
.bg-pattern {
  position: fixed;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  z-index: -2;
  background: 
    radial-gradient(circle at 10% 20%, rgba(106, 27, 154, 0.4) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(33, 150, 243, 0.4) 0%, transparent 40%),
    linear-gradient(135deg, var(--bg-layer-1) 0%, var(--bg-layer-2) 100%);
  filter: blur(20px);
}

/* 主容器 */
.container {
  position: relative;
  z-index: 1;
  width: 90%;
  max-width: 680px;
  text-align: center;
  padding-top: 15vh;
}

/* ====================
   时间显示区域
   ==================== */

.time-display {
  font-size: 4.5rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  letter-spacing: -2px;
}

.date-display {
  font-size: 1.2rem;
  margin-bottom: 3rem;
  font-weight: bold;
  color: var(--text-secondary);
}

/* ====================
   搜索区域组件
   ==================== */

/* 核心搜索框 */
.search-box {
  background: linear-gradient(
    135deg, 
    rgba(255, 255, 255, 0.15), 
    rgba(255, 255, 255, 0.05)
  );
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-radius: 34px;
  padding: 1px;
  display: flex;
  align-items: center;
  box-shadow: var(--glass-shadow);
  border: 1px solid var(--glass-border);
  transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  margin-top: 30px;
}

.search-box:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

/* 浏览器兼容性回退 */
@supports not (backdrop-filter: blur(16px)) {
  .search-box {
    background: rgba(40, 40, 70, 0.85);
  }
}

/* 搜索输入框 */
.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 6px 15px;
  font-size: 17px;
  color: var(--text-primary);
  min-width: 0;
  border-radius: 24px;
}

.search-input::placeholder {
  color: var(--text-secondary);
}

/* 搜索按钮 */
.search-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
  margin: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.search-btn:hover {
  transform: scale(1.08);
  background: rgba(255, 255, 255, 0.2);
}

.search-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  transition: transform 0.3s;
}

/* ====================
   历史记录区域
   ==================== */

.search-history {
  margin-top: 24px;
  max-height: 200px;
  overflow-y: auto;
  text-align: left;
  background: var(--history-bg);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 12px;
  display: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.search-history::-webkit-scrollbar {
  display: none;
}

.search-history.visible {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.history-title {
  font-size: 14px;
  margin-bottom: 8px;
  opacity: 0.7;
}

.history-item {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

.history-text {
  flex-grow: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete-history {
  cursor: pointer;
  margin-left: 10px;
  color: rgba(255, 255, 255, 0.5);
  transition: color 0.2s;
  padding: 4px 6px;
  border-radius: 4px;
}

.delete-history:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.15);
}

.clear-all-history {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 12px;
  transition: all 0.3s ease;
  margin-left: 8px;
  float: right;
}

.clear-all-history:hover {
  color: var(--accent-color);
  background: rgba(255, 255, 255, 0.1);
}

/* ====================
   设置面板组件
   ==================== */

.settings-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  opacity: 0.7;
}

.settings-toggle:hover {
  transform: rotate(15deg) scale(1.1);
  opacity: 1;
  background: rgba(255, 255, 255, 0.2);
}

.settings-toggle svg {
  width: 20px;
  height: 20px;
  transition: transform 0.4s ease;
}

.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  z-index: 999;
  display: none;
}

.settings-overlay.visible {
  display: block;
}

.settings-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  background: rgba(50, 50, 70, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 25px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  display: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  max-height: 75vh;
  overflow-y: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.settings-card::-webkit-scrollbar {
  display: none;
}

.settings-card.visible {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -45%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-title {
  font-size: 1.3rem;
  font-weight: 500;
}

.close-settings {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.2s;
}

.close-settings:hover {
  color: white;
}

.settings-section {
  margin-bottom: 25px;
  padding-bottom: 12px;
}

.section-title {
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.engine-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.engine-option {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid transparent;
}

.engine-option:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.engine-option.active {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.engine-icon {
  width: 36px;
  height: 36px;
  margin-bottom: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.engine-icon img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  filter: drop-shadow(0 0 1px rgba(0,0,0,0.25));
  border-radius: 50%;
}

.theme-options {
  display: flex;
  gap: 15px;
}

.theme-option {
  flex: 1;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.theme-option.active {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

/* 开关组件 */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
  margin-top: 10px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: .4s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: var(--accent-color);
}

input:checked + .toggle-slider:before {
  transform: translateX(26px);
}

.seconds-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.seconds-text {
  font-size: 0.9rem;
}

/* ====================
   滚动消息区域
   ==================== */

.scrolling-message-container {
  position: fixed;
  bottom: 60px;
  left: 0;
  width: 100%;
  text-align: center;
  z-index: 2;
  padding: 0 5%;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.scrolling-message-container.hide-on-focus {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

/* ====================
   加载动画组件
   ==================== */

.loader {
  display: none;
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: var(--text-primary);
  animation: spin 1s linear infinite;
  margin-right: 10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ====================
   联想搜索框
   ==================== */

.suggestion-box {
  width: 100%;
  max-width: 680px;
  margin: 5px auto 0;
  border-radius: 24px 24px 24px 24px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-top: none;
  max-height: 300px;
  overflow-y: auto;
  display: none;
  z-index: 10;
  position: relative;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.suggestion-box::-webkit-scrollbar {
  display: none;
}

.suggestion-item {
  padding: 12px 20px;
  font-size: 16px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  text-align: left;
  border-radius: 0 !important;
}

.suggestion-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

.suggestion-item:first-child {
  padding-top: 15px;
}

.suggestion-item:last-child {
  padding-bottom: 15px;
  border-radius: 0 0 24px 24px;
}

.suggestion-highlight {
  color: var(--accent-color);
  font-weight: 500;
}

.highlighted {
  background: rgba(77, 171, 247, 0.15) !important;
}

/* ====================
   动画效果定义
   ==================== */

/* 历史记录动画 */
.search-history.leaving {
  animation: fadeOutHistory 0.3s ease forwards;
}

@keyframes fadeOutHistory {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(10px); display: none; }
}

/* 联想框动画 */
.suggestion-box.leaving {
  animation: fadeOutSuggestions 0.3s ease forwards;
}

@keyframes fadeOutSuggestions {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-10px); display: none; }
}

/* 设置卡片动画 */
@keyframes fadeOut {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0; transform: translate(-50%, -45%) scale(0.98); }
}

@keyframes fadeOutOverlay {
  from { opacity: 1; }
  to { opacity: 0; }
}

.settings-card.leaving {
  animation: fadeOut 0.3s ease forwards;
}

.settings-overlay.leaving {
  animation: fadeOutOverlay 0.3s ease forwards;
}

/* 微妙的脉动动画 */
@keyframes subtlePulse {
  0% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.05); opacity: 0.9; }
  100% { transform: scale(1); opacity: 0.7; }
}

/* ====================
   媒体查询（响应式设计）
   ==================== */

/* iOS 模糊效果增强 */
@media (max-device-width: 812px) and (-webkit-min-device-pixel-ratio: 2),
       (max-device-width: 667px) {
  .ios-overlay {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: rgba(20, 20, 40, 0.75);
  }
  
  .search-box {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
}

/* 移动端优化 */
@media (max-width: 768px) {
  body { 
    padding-top: 5vh; 
  }
  
  .time-display { 
    font-size: 3.5rem; 
  }
  
  .date-display { 
    font-size: 1rem; 
    margin-bottom: 2rem; 
  }
  
  .search-box {
    flex-direction: row;
    border-radius: 34px;
    padding: 1px;
    font-weight: bold;
  }
  
  .search-input {
    margin-bottom: 0;
    padding: 6px 15px;
    border-radius: 24px 0 0 24px;
  }
  
  .search-btn {
    margin: 2px;
    width: 36px;
    height: 36px;
    border-radius: 24px;
  }
  
  .search-box:focus-within {
    transform: translateY(-8px) scale(1.02); 
  }
  
  .search-box:hover {
    transform: translateY(-8px) scale(1.02); 
  }
  
  /* 设置面板移动端适配 */
  .settings-toggle {
    max-height: 85vh;
    width: 90%;
    bottom: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
  }
  
  .settings-toggle svg {
    width: 18px;
    height: 18px;
  }

  .engine-options {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 浅色主题适配 */
.light-theme {
  /* 历史记录文字颜色 */
  .history-item {
    color: rgba(0, 0, 0, 0.7);
  }
  
  .history-title {
    color: rgba(0, 0, 0, 0.55);
  }
  
  /* 设置面板 */
  .settings-card {
    background: rgba(64, 72, 92, 0.92);
    border: 1px solid rgba(72, 78, 87, 0.6);
  }
  
  .settings-title,
  .section-title,
  .engine-option span,
  .theme-option span,
  .seconds-text {
    color: rgba(0, 0, 0, 0.85);
  }
  
  .settings-header {
    border-bottom: 1px solid rgba(190, 200, 215, 0.4);
  }
  
  .close-settings {
    color: rgba(100, 110, 130, 0.7);
  }
  
  .engine-option {
    background: rgba(94, 100, 107, 0.8);
  }
  
  .engine-option.active {
    background: rgba(166, 176, 185, 0.9);
    border-color: rgba(180, 195, 210, 0.6);
  }
  
  .toggle-slider {
    background-color: rgba(180, 190, 200, 0.3);
  }
  
  input:checked + .toggle-slider {
    background-color: #6ba3d8;
  }
  
  /* 清除按钮 */
  .clear-all-history:hover {
    color: #1971c2;
    background: rgba(0, 0, 0, 0.05);
  }
}

.settings-toggle {
  background: none !important;
  backdrop-filter: none !important;
  box-shadow: none !important;
  border: none !important;
  opacity: 0.3;
  transition: opacity 0.3s ease;
}

.settings-toggle:hover {
  opacity: 0.7;
  transform: none !important;
  background: none !important;
}

.settings-toggle svg {
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}

.light-theme .settings-toggle svg {
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}

/* 移动端调整 */
@media (max-width: 768px) {
  .settings-toggle {
    width: 28px;
    height: 28px;
    bottom: 12px;
    right: 12px;
  }
  
  .settings-toggle svg {
    width: 18px;
    height: 18px;
  }
}