/* ══════════════════════════════════════════════════════════
   NFC 纪念照片与语音播放器 · 样式表
   配色、字体、动画都在这里调整；一般情况无需改动
   ══════════════════════════════════════════════════════════ */

/* ── 主题变量（浅色：柔和暖米色调） ── */
:root {
  --bg: #f3ede4;              /* 页面背景 */
  --bg-glow: #fbf6ec;         /* 背景顶部光晕 */
  --card: #fffdf9;            /* 拍立得相纸颜色 */
  --frame: #ece2d2;           /* 照片内衬细边 */
  --ink: #42362b;             /* 主文字色 */
  --ink-soft: #97897a;        /* 次要文字色 */
  --accent: #bd7256;          /* 主题强调色（陶土橘） */
  --accent-light: #d9a288;
  --accent-soft: rgba(189, 114, 86, 0.14);
  --track: #e8ddcc;           /* 进度条底色 */
  --shadow: 0 1px 2px rgba(66, 50, 34, 0.06),
            0 18px 44px -14px rgba(66, 50, 34, 0.28);
}

/* ── 深色模式：跟随系统自动切换 ── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181310;
    --bg-glow: #241c15;
    --card: #211b15;
    --frame: #2e251c;
    --ink: #ece2d3;
    --ink-soft: #9a8b78;
    --accent: #d99270;
    --accent-light: #e6b497;
    --accent-soft: rgba(217, 146, 112, 0.16);
    --track: #35291f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3),
              0 18px 44px -14px rgba(0, 0, 0, 0.6);
  }
}

/* ── 基础重置：杜绝手机横向滚动条 ── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  max-width: 100%;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;                       /* 手机全屏（含地址栏收起状态） */
  font-family: system-ui, -apple-system, "PingFang SC",
               "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: radial-gradient(130% 90% at 50% -10%, var(--bg-glow), var(--bg));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; /* 去掉手机点按灰色高亮 */
}

/* ── 舞台：全屏居中，适配刘海屏安全区 ── */
.stage {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top))
           calc(20px + env(safe-area-inset-right))
           calc(20px + env(safe-area-inset-bottom))
           calc(20px + env(safe-area-inset-left));
}

/* ── 拍立得卡片 ── */
.polaroid {
  width: min(88vw, 380px);
  margin: 0;
  padding: 14px 14px 20px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  animation: fade-up 0.9s 0.05s cubic-bezier(0.22, 0.68, 0.34, 1) both;
}

/* 桌面端：轻微旋转的拍立得质感，悬停时摆正 */
@media (min-width: 521px) and (hover: hover) {
  .polaroid { transform: rotate(-0.7deg); transition: transform 0.5s ease; }
  .polaroid:hover { transform: rotate(0deg) translateY(-4px); }
}

/* ── 照片区 ── */
.photo-wrap {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent-soft), var(--frame));
  box-shadow: inset 0 0 0 1px var(--frame);
  cursor: pointer;
  outline: none;
}

.photo-wrap:focus-visible .play-btn {
  box-shadow: 0 0 0 3px var(--accent-soft), 0 6px 24px rgba(0, 0, 0, 0.25);
}

#photo {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;         /* 展示比例，可改为 1 / 1（正方形）、3 / 4（竖屏） */
  object-fit: cover;           /* 照片自动裁剪填满，不变形 */
}

/* 照片缺失时的优雅占位（不用改，只是兜底；文字取 photo-wrap 的 data-placeholder） */
.photo-wrap.photo-missing #photo { display: none; }
.photo-wrap.photo-missing::before {
  content: attr(data-placeholder);
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  padding: 24px;
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.9;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

/* 播放中给照片加一层极浅的暖色滤镜 */
.photo-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.03), rgba(0, 0, 0, 0.16));
  transition: background 0.6s ease;
}

.is-playing .photo-overlay {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.08));
}

/* ── 大播放按钮 ── */
.play-btn {
  position: relative;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  background: rgba(30, 22, 15, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
              background 0.35s ease;
}

.play-btn:active { transform: scale(0.92); }

.play-btn svg { width: 34px; height: 34px; }
.icon-play  { margin-left: 4px; }   /* 三角形视觉居中微调 */
.icon-pause { display: none; }
.is-playing .icon-play  { display: none; }
.is-playing .icon-pause { display: block; }

/* 呼吸光环：吸引第一次点击；播放后放缓 */
.play-btn::after {
  content: "";
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  animation: breathe 2.8s ease-out infinite;
  pointer-events: none;
}

.is-playing .play-btn::after {
  animation-duration: 4.2s;
  border-color: rgba(255, 255, 255, 0.45);
}

@keyframes breathe {
  0%   { transform: scale(1);    opacity: 0.85; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* ── 文字区 ── */
.caption {
  padding: 18px 8px 6px;
  text-align: center;
}

.title {
  margin: 0 0 7px;
  font-family: Georgia, "Songti SC", "Noto Serif SC", "SimSun", serif;
  font-size: 1.42rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
  animation: fade-up 0.8s 0.3s cubic-bezier(0.22, 0.68, 0.34, 1) both;
}

.date {
  margin: 0 0 12px;
  font-size: 0.72rem;
  letter-spacing: 0.32em;
  text-indent: 0.32em;          /* 抵消最后一个字的字距，视觉居中 */
  color: var(--ink-soft);
  animation: fade-up 0.8s 0.42s cubic-bezier(0.22, 0.68, 0.34, 1) both;
}

.message {
  margin: 0;
  font-family: Georgia, "Songti SC", "Noto Serif SC", "SimSun", serif;
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.85;
  color: var(--ink-soft);
  animation: fade-up 0.8s 0.54s cubic-bezier(0.22, 0.68, 0.34, 1) both;
}

/* ── 播放器 ── */
.player {
  margin-top: 14px;
  padding: 14px 12px 10px;
  border-top: 1px solid var(--frame);
  animation: fade-up 0.8s 0.66s cubic-bezier(0.22, 0.68, 0.34, 1) both;
}

/* 波形动画：默认静止，播放时跳动 */
.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 26px;
  margin-bottom: 10px;
}

.waveform .bar {
  width: 4px;
  border-radius: 99px;
  background: linear-gradient(180deg, var(--accent-light), var(--accent));
  transform: scaleY(0.22);
  transform-origin: center;
  animation: wave 1.05s ease-in-out infinite alternate;
  animation-play-state: paused;   /* 暂停时不消耗性能 */
}

.is-playing .waveform .bar { animation-play-state: running; }

/* 每根柱子不同的高度与节奏，跳动更自然 */
.waveform .bar:nth-child(1) { height: 55%; animation-delay: -0.10s; }
.waveform .bar:nth-child(2) { height: 85%; animation-delay: -0.45s; }
.waveform .bar:nth-child(3) { height: 65%; animation-delay: -0.80s; }
.waveform .bar:nth-child(4) { height: 100%; animation-delay: -0.25s; }
.waveform .bar:nth-child(5) { height: 70%; animation-delay: -0.65s; }
.waveform .bar:nth-child(6) { height: 90%; animation-delay: -0.95s; }
.waveform .bar:nth-child(7) { height: 50%; animation-delay: -0.35s; }

@keyframes wave {
  from { transform: scaleY(0.22); }
  to   { transform: scaleY(1); }
}

/* 进度条 + 时间 */
.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.time {
  min-width: 2.7em;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;  /* 数字等宽，跳动不抖动 */
  color: var(--ink-soft);
}

.time:last-child { text-align: right; }

.progress {
  position: relative;
  flex: 1;
  height: 26px;                 /* 扩大可点击区域 */
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;           /* 拖动进度时阻止页面滚动 */
}

.progress-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 99px;
  background: var(--track);
}

.progress-fill {
  position: relative;
  width: 0%;
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-light), var(--accent));
  transition: width 0.15s linear;
}

/* 进度圆点 */
.progress-fill::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%) scale(0.9);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: inset 0 0 0 2.5px var(--accent);
  transition: transform 0.2s ease;
}

.progress:active .progress-fill::after { transform: translateY(-50%) scale(1.25); }

/* 音量 */
.volume {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 0 2px;
}

.volume svg {
  width: 17px;
  height: 17px;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.volume input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(90deg,
              var(--accent) 0%, var(--accent) var(--vol, 100%), var(--track) var(--vol, 100%));
  cursor: pointer;
  outline: none;
}

.volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: inset 0 0 0 2.5px var(--accent);
}

.volume input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2.5px solid var(--accent);
  border-radius: 50%;
  background: var(--card);
}

/* ── 底部提示文字 ── */
.hint {
  margin: 22px 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  color: var(--ink-soft);
  animation: fade-up 1s 1.1s cubic-bezier(0.22, 0.68, 0.34, 1) both,
             hint-pulse 3.4s 2.2s ease-in-out infinite;
}

/* 音频加载失败时，提示文字变色 */
.hint.hint-error {
  color: var(--accent);
  animation: fade-up 1s both;
  letter-spacing: 0.05em;
  text-indent: 0.05em;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

/* ── 淡入动画 ── */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── 尊重系统"减弱动态效果"设置 ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .waveform .bar { transform: scaleY(0.6); }
}

/* ── 矮屏手机（横屏 / 小屏）：收紧留白保证不裁切 ── */
@media (max-height: 700px) {
  .stage { justify-content: flex-start; }
  .polaroid { margin-top: 8px; }
  .hint { margin-top: 14px; }
}
