/* ===== Google Fonts ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:ital,wght@0,400;0,600;1,400&display=swap');

/* ===== CSS Variables ===== */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #fafafa;
  --bg-card: #ffffff;
  --border-light: #e8e8e8;
  --border-hover: #d0d0d0;
  --text-primary: #1a1a1a;
  --text-secondary: #6b6b6b;
  --text-muted: #999999;
  --accent: #1a1a1a;
  --accent-soft: #333333;
  --radius: 4px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.10);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font-serif: 'Playfair Display', 'Georgia', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== Reset ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Layout ===== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* ===== Header ===== */
.page-header {
  text-align: center;
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-light);
}

.page-header h1 {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 300;
  letter-spacing: 0.02em;
}

/* ===== Base URL Input ===== */
.url-config {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 560px;
  margin: 0 auto 3rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
}

.url-config label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.url-config input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 0.85rem;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}

.url-config input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(26, 26, 26, 0.08);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.2rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.btn-primary {
  background: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border-light);
}

.btn-secondary:hover {
  border-color: var(--accent);
  background: var(--bg-secondary);
}

/* ===== QR Code Grid ===== */
.qr-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
  margin-bottom: 2rem;
}

.qr-card {
  text-align: center;
  padding: 1.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  transition: var(--transition);
  animation: fadeIn 0.5s ease forwards;
  opacity: 0;
}

.qr-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-sm);
}

.qr-card .qr-wrapper {
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px;
  display: inline-block;
  margin-bottom: 0.85rem;
  transition: var(--transition);
}

.qr-card:hover .qr-wrapper {
  box-shadow: var(--shadow-md);
}

.qr-card .qr-wrapper canvas,
.qr-card .qr-wrapper img {
  display: block;
}

.qr-card .qr-label {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.qr-card .qr-url {
  font-size: 0.68rem;
  color: var(--text-muted);
  word-break: break-all;
  font-family: 'SF Mono', 'Consolas', monospace;
}

/* 逐个出现动画延迟 */
.qr-card:nth-child(1) {
  animation-delay: 0.03s;
}

.qr-card:nth-child(2) {
  animation-delay: 0.06s;
}

.qr-card:nth-child(3) {
  animation-delay: 0.09s;
}

.qr-card:nth-child(4) {
  animation-delay: 0.12s;
}

.qr-card:nth-child(5) {
  animation-delay: 0.15s;
}

.qr-card:nth-child(6) {
  animation-delay: 0.18s;
}

.qr-card:nth-child(7) {
  animation-delay: 0.21s;
}

.qr-card:nth-child(8) {
  animation-delay: 0.24s;
}

.qr-card:nth-child(9) {
  animation-delay: 0.27s;
}

/* ===== Actions ===== */
.actions {
  text-align: center;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-light);
}

/* ===== Viewer Page ===== */
.viewer-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: var(--bg-secondary);
}

.viewer-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.6s ease forwards;
}

.viewer-image-container {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
}

.viewer-image-container img {
  width: 100%;
  display: block;
  object-fit: contain;
  max-height: 65vh;
  transition: var(--transition);
}

.viewer-content {
  padding: 1.75rem;
}

.viewer-title {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ===== Custom Audio Player ===== */
.audio-player {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.play-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--text-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.play-btn:hover {
  background: var(--text-primary);
  color: #fff;
}

.play-btn:active {
  transform: scale(0.95);
}

.audio-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.progress-bar {
  width: 100%;
  height: 3px;
  background: var(--border-light);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: height 0.15s ease;
}

.progress-bar:hover {
  height: 5px;
}

.progress-fill {
  height: 100%;
  background: var(--text-primary);
  border-radius: 2px;
  width: 0%;
  transition: width 0.1s linear;
}

.time-display {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* ===== Error State ===== */
.error-container {
  text-align: center;
  padding: 4rem 2rem;
}

.error-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.error-title {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.error-message {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Print Styles ===== */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }

  .url-config,
  .actions,
  .page-header {
    display: none !important;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }

  .qr-grid {
    display: block;
  }

  .qr-card {
    background: #fff !important;
    border: none !important;
    border-radius: 0 !important;
    opacity: 1 !important;
    animation: none !important;
    transform: none !important;
    padding: 0;

    /* 每个二维码独占一页 */
    page-break-after: always;
    page-break-inside: avoid;

    /* 居中显示 */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
  }

  .qr-card:last-child {
    page-break-after: auto;
  }

  /* 打印时放大二维码 */
  .qr-card .qr-wrapper {
    padding: 20px;
    border: 2px solid #000;
    border-radius: 4px;
    margin-bottom: 1.5rem;
    box-shadow: none !important;
  }

  .qr-card .qr-wrapper canvas,
  .qr-card .qr-wrapper img {
    width: 280px !important;
    height: 280px !important;
  }

  .qr-card .qr-label {
    color: #000;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
  }

  .qr-card .qr-url {
    color: #555;
    font-size: 0.85rem;
  }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .container {
    padding: 2rem 1.25rem;
  }

  .page-header h1 {
    font-size: 1.6rem;
  }

  .qr-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }

  .qr-card {
    padding: 1rem 0.5rem;
  }

  .url-config {
    flex-direction: column;
    align-items: stretch;
  }

  /* ---- Viewer 手机端沉浸式适配 ---- */
  .viewer-wrapper {
    padding: 0;
    background: var(--bg-primary);
    align-items: flex-start;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .viewer-card {
    max-width: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
    animation: none;
    opacity: 1;
  }

  .viewer-image-container {
    border-bottom: none;
  }

  .viewer-image-container img {
    max-height: 60vh;
    max-height: 60dvh;
    object-fit: contain;
    background: #f5f5f5;
  }

  .viewer-content {
    padding: 1.25rem 1.25rem 2rem;
  }

  .viewer-title {
    font-size: 1.15rem;
    margin-bottom: 1rem;
  }

  /* 音频播放器 - 触控优化 */
  .audio-player {
    padding: 0.85rem 1rem;
    border-radius: 12px;
  }

  .play-btn {
    width: 48px;
    height: 48px;
    -webkit-tap-highlight-color: transparent;
  }

  .play-btn svg {
    width: 20px;
    height: 20px;
  }

  /* 进度条加粗 - 手指易拖动 */
  .progress-bar {
    height: 6px;
    border-radius: 3px;
  }

  .progress-bar:hover {
    height: 6px;
  }

  .progress-fill {
    border-radius: 3px;
  }

  .time-display {
    font-size: 0.75rem;
    margin-top: 2px;
  }

  /* 错误状态 */
  .error-container {
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: none;
    border-radius: 0;
  }
}

@media (max-width: 480px) {
  .qr-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .viewer-image-container img {
    max-height: 55vh;
    max-height: 55dvh;
  }

  .viewer-content {
    padding: 1rem 1rem 1.5rem;
  }

  .viewer-title {
    font-size: 1.05rem;
    margin-bottom: 0.85rem;
  }
}

/* ===== iOS 安全区域适配（刘海屏 / 底部横条） ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .viewer-content {
      padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }
  }
}