:root {
  --bg: #05040f;
  --text: #f6f1ff;
  --muted: rgba(246, 241, 255, 0.66);
  --accent: #ffc6e0;
  --gold: #ffd59a;
  --glass: rgba(22, 18, 48, 0.55);
  --glass-border: rgba(255, 220, 240, 0.18);
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --serif: "Songti SC", "Noto Serif SC", "STSong", "SimSun", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#universe {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#universe.dragging { cursor: grabbing; }
#universe.pointing { cursor: pointer; }

.hidden { display: none !important; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

button, input { font: inherit; color: inherit; }

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- 密码门 ---------- */
.layer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 10;
  transition: opacity 1.2s ease, visibility 1.2s;
}
.layer.leaving { opacity: 0; visibility: hidden; pointer-events: none; }

#gate-form {
  width: min(360px, 100%);
  padding: 36px 28px 30px;
  text-align: center;
  animation: rise 1.4s ease both;
}

.gate-eyebrow {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.3em;
  color: var(--muted);
}

#gate-title {
  margin: 0 0 26px;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.12em;
  background: linear-gradient(120deg, #fff 10%, var(--accent) 55%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#gate-hint {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--muted);
}

#gate-input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.07);
  font-size: 18px;
  letter-spacing: 0.3em;
  text-align: center;
}
#gate-input.shake { animation: shake 0.45s ease; border-color: #ff8fab; }

#gate-error {
  min-height: 22px;
  margin: 8px 0 6px;
  font-size: 13px;
  color: #ffb3c6;
}

#gate-form button {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(120deg, #ff9ec7, #c7a6ff);
  color: #1c1030;
  font-weight: 600;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#gate-form button:hover { transform: translateY(-1px); box-shadow: 0 8px 26px rgba(255, 158, 199, 0.4); }
#gate-form button:active { transform: translateY(1px); }

/* ---------- 计时器 ---------- */
#counter {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 5;
  text-align: center;
  pointer-events: none;
  animation: fadeIn 2s ease 0.6s both;
  text-shadow: 0 0 18px rgba(255, 198, 224, 0.45);
}
.counter-label { margin: 0; font-size: 13px; letter-spacing: 0.3em; color: var(--muted); }
.counter-value {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.counter-value small { margin: 0 6px 0 3px; font-size: 13px; color: var(--muted); }
#c-days { font-size: 34px; color: var(--accent); }
#counter-next {
  margin: 8px auto 0;
  max-width: 88vw;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
#counter-next.celebrate {
  font-size: 15px;
  letter-spacing: 0.15em;
  color: var(--gold);
  animation: glow 2.4s ease-in-out infinite;
}

/* ---------- 提示与音乐 ---------- */
#tooltip {
  position: fixed;
  z-index: 6;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(20, 14, 40, 0.8);
  border: 1px solid var(--glass-border);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
}

#guide {
  position: fixed;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.15em;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
  animation: fadeIn 1.5s ease 1.5s both, fadeOut 1.5s ease 9s forwards;
}

#music-toggle {
  position: fixed;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 7;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 20px;
  cursor: pointer;
}
#music-toggle[aria-pressed="true"] .note { display: inline-block; animation: spin 4s linear infinite; }
#music-toggle[aria-pressed="false"] { opacity: 0.55; }

#timeline-toggle {
  position: fixed;
  left: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 7;
  height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 14px;
  letter-spacing: 0.15em;
  cursor: pointer;
  animation: fadeIn 1.5s ease 1.5s both;
}

/* ---------- 浮层 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 2, 10, 0.72);
  animation: fadeIn 0.35s ease both;
}
.overlay.covered { visibility: hidden; }

.close {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.lightbox-body { margin: 0; text-align: center; animation: zoomIn 0.4s ease both; }
#lightbox { touch-action: pinch-zoom; } /* 单指滑动交给翻页，双指仍可放大 */
#lightbox-img {
  display: block;
  max-width: min(92vw, 1100px);
  max-height: min(76vh, calc(100vh - 170px));
  border-radius: 14px;
  box-shadow: 0 0 60px rgba(255, 198, 224, 0.25);
  transition: opacity 0.25s ease;
}
.lightbox-body figcaption { margin-top: 14px; font-size: 15px; color: var(--text); }
#lightbox-date { margin-right: 10px; color: var(--muted); font-size: 13px; }
.lightbox-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 8px; }
.lightbox-nav button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
#photo-index { min-width: 64px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
#lightbox.single .lightbox-nav { display: none; }
#lightbox.loading #lightbox-img { opacity: 0.35; }
#lightbox.loading::after {
  content: "";
  position: fixed;
  top: 45%;
  left: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.memory-body {
  width: min(560px, 100%);
  max-height: 82vh;
  overflow-y: auto;
  padding: 30px 28px;
  animation: zoomIn 0.4s ease both;
  line-height: 1.85;
}
#memory-cover { width: 100%; max-height: 240px; object-fit: cover; border-radius: 12px; margin-bottom: 18px; }
#memory-date { margin: 0; font-size: 13px; letter-spacing: 0.2em; color: var(--gold); }
#memory-title { margin: 4px 0 16px; font-family: var(--serif); font-size: 24px; }
#memory-content h3, #memory-content h4 { margin: 20px 0 8px; font-family: var(--serif); }
#memory-content p { margin: 0 0 12px; }
#memory-content strong { color: var(--accent); }
#memory-content blockquote {
  margin: 14px 0;
  padding: 6px 0 6px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-family: var(--serif);
}
#memory-content img { display: block; width: 100%; border-radius: 12px; margin: 8px 0; }
#memory-content ul, #memory-content ol { padding-left: 22px; margin: 0 0 12px; }

/* ---------- 时间轴 ---------- */
.timeline-body {
  width: min(560px, 100%);
  max-height: 82vh;
  overflow-y: auto;
  padding: 28px 26px;
  animation: zoomIn 0.4s ease both;
}
.timeline-body:focus-visible, .memory-body:focus-visible { outline: 1px solid var(--glass-border); }
#timeline-title { margin: 0; font-family: var(--serif); font-size: 24px; }
.timeline-sub { margin: 22px 0 8px; font-size: 13px; font-weight: 400; letter-spacing: 0.3em; color: var(--gold); }
#upcoming { list-style: none; margin: 0; padding: 0; }
#upcoming li {
  display: flex;
  flex-wrap: wrap; /* 窄屏放不下时，日期换到下一行靠右，名字保持完整 */
  justify-content: space-between;
  align-items: baseline;
  gap: 2px 12px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 15px;
}
.up-name { flex: 1 1 auto; }
.up-when { flex: none; margin-left: auto; font-size: 13px; color: var(--muted); }

#timeline-list { list-style: none; margin: 0; padding: 0; }
.tl-year { margin: 14px 0 8px; font-family: var(--serif); font-size: 20px; color: var(--accent); }
.tl-day { position: relative; margin-left: 5px; padding: 0 0 18px 20px; border-left: 1px solid rgba(255, 198, 224, 0.25); }
.tl-day::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.tl-date { margin: 0 0 6px; font-size: 13px; letter-spacing: 0.1em; color: var(--gold); }
.tl-mark { margin: 0 0 8px; font-size: 14px; color: var(--accent); }
.tl-mark::before { content: "♥ "; }
.tl-memory {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 10px 14px;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  font-family: var(--serif);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.tl-memory::before { content: "✦ "; color: var(--gold); }
.tl-memory:hover { background: rgba(255, 255, 255, 0.1); }
.tl-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.tl-photo { min-width: 0; padding: 0; border: 0; background: none; cursor: pointer; }
.tl-photo img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 10px; }
.tl-photo span {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; }

/* ---------- 动画 ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes zoomIn { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes glow { 50% { text-shadow: 0 0 22px rgba(255, 213, 154, 0.9); } }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* ---------- 手机 ---------- */
@media (max-width: 520px) {
  .counter-value { font-size: 20px; }
  #c-days { font-size: 28px; }
  .counter-value small { margin: 0 4px 0 2px; font-size: 12px; }
  #gate-title { font-size: 26px; }
  .memory-body, .timeline-body { padding: 24px 20px; }
  /* 底部两侧有时间轴和音乐按钮，提示语挪到它们上方 */
  #guide { bottom: calc(max(20px, env(safe-area-inset-bottom)) + 60px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
