/* ===== CSS Reset & Variables ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f13;
  --bg2: #1a1a24;
  --surface: #22222e;
  --border: #333344;
  --text: #e8e8f0;
  --text-muted: #888899;
  --accent: #6c63ff;
  --accent2: #ff6584;
  --nav-h: 60px;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 0.3s cubic-bezier(.4,0,.2,1);
}

body.light {
  --bg: #f0f0f5;
  --bg2: #e4e4ed;
  --surface: #ffffff;
  --border: #d0d0e0;
  --text: #1a1a2e;
  --text-muted: #666677;
  --shadow: 0 8px 32px rgba(0,0,0,0.12);
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
}

/* ===== Navigation ===== */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.nav-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.03em;
}

.nav-styles {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  justify-content: center;
}

.style-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.style-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.style-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px; height: 36px;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

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

/* ===== Main Layout ===== */
.main {
  min-height: 100vh;
  padding-top: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: center;
}

.clock-section {
  display: none;
  width: 100%;
  min-height: calc(100vh - var(--nav-h) - 40px);
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s ease;
}

.clock-section.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== Footer ===== */
.footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 40px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ============================================================
   1. DIGITAL CLOCK
   ============================================================ */
.digital-clock {
  text-align: center;
  user-select: none;
}

.digital-time {
  font-size: clamp(4rem, 12vw, 9rem);
  font-weight: 200;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, #a78bfa, #6c63ff, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  filter: drop-shadow(0 0 30px rgba(108,99,255,0.3));
}

.digital-date {
  margin-top: 20px;
  font-size: clamp(1rem, 2.5vw, 1.4rem);
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.digital-ampm {
  margin-top: 8px;
  font-size: 1rem;
  color: var(--accent);
  letter-spacing: 0.3em;
  font-weight: 600;
}

/* ============================================================
   2. ANALOG CLOCK
   ============================================================ */
.analog-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

#analogCanvas {
  border-radius: 50%;
  box-shadow: var(--shadow), 0 0 60px rgba(108,99,255,0.15);
  max-width: 90vw;
  max-height: 90vw;
}

.analog-date {
  font-size: 1.1rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
}

/* ============================================================
   3. FLIP CLOCK  —— 重构版
   ============================================================ */

/* 外层包裹：垂直居中，日期在下方 */
.flip-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  user-select: none;
}

/* 一行三个数字 + 两个冒号 */
.flip-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 冒号 */
.flip-colon {
  font-size: clamp(2.5rem, 7vw, 4.5rem);
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 4px;
  animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0.25; } }

/* 每个数字单元 */
.flip-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 卡片容器：relative，裁剪溢出 */
.flip-card {
  position: relative;
  width: clamp(72px, 16vw, 120px);
  height: clamp(90px, 20vw, 150px);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* 上半静态（显示当前值上半部分） */
.flip-upper {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  background: var(--surface);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

/* 下半静态（显示当前值下半部分） */
.flip-lower {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 50%;
  background: var(--surface);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 2px;
  overflow: hidden;
}

/* 上下半共用字体 */
.flip-upper span,
.flip-lower span {
  font-size: clamp(2.2rem, 7vw, 4.5rem);
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  /* 让 span 高度 = 整个卡片高度，这样上半只显示上半部分 */
  height: clamp(90px, 20vw, 150px);
  display: flex;
  align-items: center;
}

/* 翻转动画层：覆盖在上半，绕底边翻转 */
.flip-anim {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  transform-origin: bottom center;
  transform-style: preserve-3d;
  z-index: 10;
  pointer-events: none;
  /* 默认隐藏，JS 触发时再显示 */
  display: none;
}

/* 动画层正面：显示旧值上半 */
.flip-anim-top {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  backface-visibility: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 2px;
  overflow: hidden;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* 动画层背面：显示新值下半（翻转后露出） */
.flip-anim-bot {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  backface-visibility: hidden;
  transform: rotateX(180deg);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 2px;
  overflow: hidden;
  border-radius: 0 0 var(--radius) var(--radius);
}

.flip-anim-top span,
.flip-anim-bot span {
  font-size: clamp(2.2rem, 7vw, 4.5rem);
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  height: clamp(90px, 20vw, 150px);
  display: flex;
  align-items: center;
}

/* 翻转关键帧 */
@keyframes doFlip {
  0%   { transform: rotateX(0deg); }
  100% { transform: rotateX(-180deg); }
}

.flip-anim.running {
  display: block;
  animation: doFlip 0.4s cubic-bezier(.4,0,.2,1) forwards;
}

/* 日期行 */
.flip-date-row {
  font-size: clamp(0.95rem, 2vw, 1.2rem);
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-align: center;
}

/* ============================================================
   4. NEON CLOCK
   ============================================================ */
.neon-clock {
  text-align: center;
  padding: 60px 40px;
  background: #050508;
  border-radius: 24px;
  border: 1px solid #1a1a2e;
  box-shadow: 0 0 60px rgba(0,0,0,0.8);
}

.neon-time {
  font-size: clamp(3.5rem, 11vw, 8rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  color: #00ffff;
  text-shadow:
    0 0 7px #00ffff,
    0 0 10px #00ffff,
    0 0 21px #00ffff,
    0 0 42px #0ff,
    0 0 82px #0ff,
    0 0 92px #0ff,
    0 0 102px #0ff,
    0 0 151px #0ff;
  animation: neonFlicker 5s infinite alternate;
}

.neon-date {
  margin-top: 20px;
  font-size: clamp(1rem, 2.5vw, 1.5rem);
  letter-spacing: 0.3em;
  color: #ff00ff;
  text-shadow:
    0 0 7px #ff00ff,
    0 0 10px #ff00ff,
    0 0 21px #ff00ff,
    0 0 42px #f0f,
    0 0 82px #f0f;
  font-weight: 600;
}

@keyframes neonFlicker {
  0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% {
    text-shadow:
      0 0 7px #00ffff,
      0 0 10px #00ffff,
      0 0 21px #00ffff,
      0 0 42px #0ff,
      0 0 82px #0ff,
      0 0 92px #0ff;
  }
  20%, 24%, 55% {
    text-shadow: none;
    color: rgba(0,255,255,0.6);
  }
}

/* ============================================================
   5. MINIMAL CLOCK
   ============================================================ */
.minimal-clock {
  text-align: center;
  user-select: none;
}

.minimal-time {
  font-size: clamp(5rem, 15vw, 12rem);
  font-weight: 100;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.minimal-seconds {
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 300;
  color: var(--accent);
  letter-spacing: 0.2em;
  margin-top: 8px;
}

.minimal-date {
  margin-top: 16px;
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.minimal-progress {
  margin-top: 32px;
  width: min(400px, 80vw);
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-left: auto;
  margin-right: auto;
}

.minimal-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width 1s linear;
}

/* ============================================================
   6. RETRO CLOCK
   ============================================================ */
.retro-clock {
  position: relative;
  width: min(480px, 90vw);
}

.retro-screen {
  background: #0a1a0a;
  border: 3px solid #1a4a1a;
  border-radius: 8px;
  padding: 32px 40px;
  box-shadow:
    0 0 0 6px #0d2a0d,
    0 0 0 8px #1a4a1a,
    0 0 40px rgba(0,255,0,0.1),
    inset 0 0 40px rgba(0,0,0,0.5);
  font-family: 'Courier New', 'Lucida Console', monospace;
}

.retro-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
}

.retro-label {
  font-size: 0.85rem;
  color: #2a6a2a;
  letter-spacing: 0.3em;
  font-weight: 700;
}

.retro-value {
  font-size: clamp(1.4rem, 4vw, 2rem);
  color: #00cc00;
  letter-spacing: 0.15em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 8px rgba(0,204,0,0.6);
}

.retro-divider {
  height: 1px;
  background: #1a4a1a;
}

.retro-scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
  border-radius: 8px;
  pointer-events: none;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .nav { padding: 0 12px; gap: 8px; }
  .nav-logo { font-size: 0.95rem; }
  .style-btn { padding: 5px 10px; font-size: 0.75rem; }
  .flip-colon { margin: 0 2px; }
  .neon-clock { padding: 40px 20px; }
  .retro-screen { padding: 24px 20px; }
}
