/* ============================================
   Responsive Design - 优先移动端
   ============================================ */

/* Tablet: 768-1023px */
@media (max-width: 1023px) {
  .features-grid,
  .tests-grid,
  .listing-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hero-title {
    font-size: var(--text-4xl);
  }

  .stat-number {
    font-size: var(--text-3xl);
  }
}

/* Mobile: <768px */
@media (max-width: 767px) {
  /* --- 导航栏 --- */
  .nav-toggle {
    display: flex;
  }

  .nav-menu {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: var(--space-4);
    background: var(--color-bg);
    transform: translateX(100%);
    transition: transform var(--transition-base);
    overflow-y: auto;
    z-index: 100;
  }

  .nav-menu.is-open {
    transform: translateX(0);
  }

  /* Mobile nav overlay — backdrop */
  .nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
    -webkit-tap-highlight-color: transparent;
  }
  .nav-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .nav-link {
    padding: var(--space-4) var(--space-5);
    font-size: var(--text-lg);
    border-bottom: 1px solid var(--color-border-light);
    transition: all var(--transition-fast);
  }

  .nav-link:hover {
    background: var(--color-primary-bg);
    border-left: 3px solid var(--color-primary);
    padding-left: calc(var(--space-5) - 3px);
  }

  .nav-link:active {
    background: var(--color-primary-lighter);
  }

  .nav-link.active {
    color: var(--color-primary);
    font-weight: 600;
    background: var(--color-primary-bg);
    border-left: 3px solid var(--color-primary);
    border-bottom-color: transparent;
    padding-left: calc(var(--space-5) - 3px);
  }

  /* Hide mobile bottom nav on test taking pages (also defined below in bottom nav section) */

  /* --- Mobile scroll-snap for test cards: swipeable browsing --- */
  .tests-grid,
  .listing-grid {
    position: relative;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    display: grid;
    grid-auto-columns: minmax(75vw, 280px);
    grid-template-columns: unset;
    grid-auto-flow: column;
    padding: 0 var(--space-4) var(--space-4);
    gap: var(--space-3);
    scroll-padding: 0 var(--space-4);
  }
  .tests-grid::-webkit-scrollbar,
  .listing-grid::-webkit-scrollbar {
    display: none;
  }
  .tests-grid,
  .listing-grid {
    scrollbar-width: none;
  }
  .tests-grid > .test-card,
  .listing-grid > .test-card {
    scroll-snap-align: start;
    min-height: 180px;
  }
  /* Hide the arrow on mobile since it's swipeable */
  .tests-grid .test-card .test-arrow {
    display: none;
  }
  /* Subtle swipe hint gradient fade — uses mask-image for proper overlay effect */
  .tests-grid,
  .listing-grid {
    -webkit-mask-image: linear-gradient(90deg, black calc(100% - 48px), transparent);
    mask-image: linear-gradient(90deg, black calc(100% - 48px), transparent);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
  }

  /* Swipe hint text indicator — fades out after 3s */
  .tests-grid::before,
  .listing-grid::before {
    content: '← ' attr(data-swipe-hint) ' →';
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-muted);
    background: color-mix(in srgb, var(--color-bg) 85%, transparent);
    padding: var(--space-1) var(--space-4);
    border-radius: var(--radius-full);
    z-index: 2;
    pointer-events: none;
    opacity: 0.7;
    animation: swipe-hint-fade 4s ease-out forwards;
    animation-delay: 2s;
    white-space: nowrap;
    letter-spacing: 0.05em;
  }

  @keyframes swipe-hint-fade {
    0% { opacity: 0.7; }
    70% { opacity: 0.7; }
    100% { opacity: 0; transform: translateX(-50%) translateY(4px); }
  }

  /* Mobile: hide hero particles for performance, show animated gradient instead */
  .hero-particle {
    display: none;
  }
  /* Mobile hero: soft animated gradient background replaces particles */
  .hero-bg::before {
    animation-duration: 8s;
    opacity: 0.6;
  }
  .hero-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background:
      radial-gradient(ellipse at 30% 40%, color-mix(in srgb, var(--color-primary) 10%, transparent) 0%, transparent 60%),
      radial-gradient(ellipse at 70% 60%, color-mix(in srgb, var(--color-accent) 6%, transparent) 0%, transparent 60%);
    opacity: 0.5;
    animation: mobile-hero-ambient 6s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 0;
  }
  @keyframes mobile-hero-ambient {
    0% { opacity: 0.3; transform: scale(1); }
    100% { opacity: 0.7; transform: scale(1.08); }
  }
  /* --- Hero --- */
  .hero-section {
    padding: var(--space-10) 0 var(--space-8);
  }

  .hero-title {
    font-size: var(--text-3xl);
    margin-bottom: var(--space-4);
  }

  .hero-subtitle {
    font-size: var(--text-base);
    margin-bottom: var(--space-5);
    -webkit-line-clamp: 3;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .hero-badge {
    margin-bottom: var(--space-4);
    font-size: var(--text-xs);
    padding: var(--space-1) var(--space-3);
  }

  .hero-actions {
    flex-direction: column;
    width: 100%;
    margin-bottom: var(--space-6);
  }

  .hero-actions .btn {
    width: 100%;
  }

  .hero-stats {
    gap: var(--space-4);
  }

  .stat-number {
    font-size: var(--text-2xl);
  }

  .hero-actions .btn-primary {
    animation: cta-pulse 3s ease-in-out infinite;
  }

  /* --- Mobile: collapse hero category pills behind "show more" --- */
  .hero-category-pills {
    max-height: 28px;
    overflow: hidden;
    position: relative;
    transition: max-height 0.45s cubic-bezier(0.16, 1, 0.3, 1);
    padding-bottom: 0;
    margin-bottom: var(--space-3);
  }
  .hero-category-pills.is-expanded {
    max-height: 400px;
    transition: max-height 0.55s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .hero-category-pills::after {
    content: '展开全部 ▾';
    display: block;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-primary);
    padding: var(--space-1) 0;
    cursor: pointer;
    position: relative;
    z-index: 2;
    transition: color var(--transition-fast), transform var(--transition-fast);
    background: linear-gradient(180deg, transparent, var(--color-bg) 30%);
    margin-top: -20px;
    padding-top: 20px;
  }
  html[lang="en"] .hero-category-pills::after {
    content: 'Show All ▾';
  }
  .hero-category-pills.is-expanded::after {
    content: '收起 ▴';
    background: none;
    margin-top: 0;
    padding-top: var(--space-1);
  }
  html[lang="en"] .hero-category-pills.is-expanded::after {
    content: 'Collapse ▴';
  }
  .hero-category-pills::-webkit-details-marker { display: none; }

  /* Mobile: test card description shorter to reduce visual noise */
  .test-card-desc {
    -webkit-line-clamp: 2;
    font-size: var(--text-sm);
    line-height: 1.4;
  }
  .test-card-footer {
    margin-top: auto;
  }
  /* Mobile: make direct test button full width */
  .test-card-actions {
    flex-direction: row;
    gap: var(--space-1);
  }
  .test-card-actions .test-card-start {
    flex: 1;
    text-align: center;
    justify-content: center;
    font-size: var(--text-xs);
  }
  .test-card-actions .test-popularity {
    display: none;
  }

  /* --- Grids 单列（features-grid 变单列，article-grid 变单列，tests/listing 保持横滑） --- */
  .features-grid,
  .article-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  /* --- 间距 --- */
  .features-section,
  .tests-section {
    padding: var(--space-10) 0;
  }

  .cta-section {
    padding: var(--space-12) 0;
  }

  .section-header {
    margin-bottom: var(--space-8);
  }

  .section-title {
    font-size: var(--text-2xl);
  }

  /* --- 页面标题 --- */
  .page-title {
    font-size: var(--text-3xl);
  }

  .page-header {
    padding: var(--space-8) var(--space-4) var(--space-6);
  }

  /* --- 页脚 --- */
  .footer-links {
    gap: var(--space-8);
    flex-direction: column;
  }

  .site-footer {
    padding: var(--space-10) 0 var(--space-6);
  }

  /* --- 容器 --- */
  .container,
  .container-narrow {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  /* --- 卡片内边距收紧以适应窄屏 --- */
  .card {
    padding: var(--space-4);
  }
}

/* Mobile: back-to-top button above bottom nav */
@media (max-width: 767px) {
  .back-to-top {
    bottom: calc(60px + var(--space-4));
    z-index: 100;
  }
  body.has-test-page .back-to-top {
    bottom: var(--space-6);
    z-index: 50;
  }
}

/* Small mobile: <420px */
@media (max-width: 419px) {
  .hero-title {
    font-size: var(--text-2xl);
  }

  .hero-stats {
    flex-direction: column;
    gap: var(--space-4);
  }

  .stat-number {
    font-size: var(--text-xl);
  }
}

/* ====== Mobile Bottom Tab Navigation ====== */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 767px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    z-index: 99;
    justify-content: space-around;
    align-items: stretch;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }

  [data-theme="dark"] .mobile-bottom-nav {
    background: color-mix(in srgb, var(--color-bg-alt) 95%, transparent);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.2);
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    padding: var(--space-1) 0;
    text-decoration: none;
    color: var(--color-text-muted);
    transition: color var(--transition-fast);
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav-item svg {
    transition: transform var(--transition-fast);
  }

  .mobile-nav-item:active svg {
    transform: scale(0.85);
  }

  .mobile-nav-item.active {
    color: var(--color-primary);
    font-weight: 700;
  }

  .mobile-nav-item.active svg {
    stroke-width: 2.5;
    filter: drop-shadow(0 0 6px color-mix(in srgb, var(--color-primary) 30%, transparent));
  }

  .mobile-nav-item.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--color-primary);
    border-radius: 0 0 var(--radius-full) var(--radius-full);
    box-shadow: 0 0 8px color-mix(in srgb, var(--color-primary) 40%, transparent);
  }

  .mobile-nav-label {
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
  }

  /* Adjust main content padding to account for bottom nav + ensure content not hidden */
  .main-content {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }

  /* On test-taking pages, hide the mobile bottom nav (quiz has its own sticky nav) */
  body.has-test-page .mobile-bottom-nav {
    display: none;
  }

  body.has-test-page .main-content {
    /* Keep padding-bottom intact — components.css adds 80px for sticky CTA */
  }

  /* Quiz sticky nav needs extra bottom padding on mobile with bottom nav */
  .quiz-nav {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-3));
  }
}

/* Mobile: hero category pills & search bar */
@media (max-width: 767px) {
  .hero-category-pills {
    gap: var(--space-1);
    padding: 0 var(--space-4);
    margin-top: var(--space-3);
  }
  .hero-category-pill {
    font-size: 11px;
    padding: var(--space-1) var(--space-2);
  }
  /* Hide scroll indicator on mobile — it wastes space */
  .hero-scroll-indicator {
    display: none;
  }

  .hero-search {
    max-width: 100%;
    margin-left: var(--space-4);
    margin-right: var(--space-4);
  }
  .hero-search-form {
    padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3);
  }
  .hero-search-input {
    font-size: var(--text-sm);
    padding: var(--space-2) 0;
  }
  .hero-search-submit {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-xs);
  }
}

/* Mobile: how-it-works grid to single column */
@media (max-width: 767px) {
  .how-grid {
    grid-template-columns: 1fr;
    gap: var(--space-6);
  }
  /* Hide connecting lines when grid is single-column */
  .how-grid::before,
  .how-grid::after {
    display: none;
  }
}

/* Mobile: filter bar scrollable */
@media (max-width: 767px) {
  .filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding: 0 var(--space-4);
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .filter-bar::-webkit-scrollbar {
    display: none;
  }
  .filter-tag {
    flex-shrink: 0;
  }
  .listing-page .page-header {
    padding: var(--space-8) var(--space-4) var(--space-6);
  }
  .search-result-info {
    flex-direction: column;
    gap: var(--space-2);
  }
}

/* Mobile: share buttons */
@media (max-width: 767px) {
  .share-buttons {
    gap: var(--space-2);
    justify-content: center;
  }
  .share-btn {
    min-width: 56px;
    padding: var(--space-2) var(--space-2);
    height: 56px;
  }
  .share-btn-label {
    font-size: 10px;
  }
  .share-btn-native {
    background: var(--color-primary-bg);
    border-color: var(--color-primary-light);
    min-width: 64px;
  }
}

/* ====== CTA pulse animation (mobile hero button) ====== */
@keyframes cta-pulse {
  0%, 100% { box-shadow: 0 4px 14px rgb(124 58 237 / 0.3), 0 0 0 0 rgb(124 58 237 / 0.1); }
  50% { box-shadow: 0 4px 24px rgb(124 58 237 / 0.5), 0 0 0 8px rgb(124 58 237 / 0); }
}

/* ====== Back to Top Button ====== */
.back-to-top {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgb(124 58 237 / 0.35);
  z-index: 50;
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity var(--transition-base), transform var(--transition-base), box-shadow var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover {
  background: var(--color-primary-hover);
  box-shadow: 0 6px 20px rgb(124 58 237 / 0.45);
  transform: translateY(-2px);
}

.back-to-top:active {
  transform: scale(0.92);
}

/* ====== Test Card Badges ====== */

.test-badge-featured {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
  color: var(--color-accent-hover);
  white-space: nowrap;
}

.test-card-emoji {
  font-size: 1.2em;
  vertical-align: middle;
  margin-right: var(--space-1);
}

/* ====== Hero Category Pills — quick test filter ====== */
.hero-category-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin: var(--space-4) auto var(--space-6);
  max-width: 500px;
  animation: fade-in-up 0.6s ease 0.3s both;
}

.hero-category-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: all var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
}

.hero-category-pill:hover {
  background: var(--color-primary-bg);
  border-color: var(--color-primary-light);
  color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.hero-category-pill:active {
  transform: scale(0.96);
}

.hero-category-pill .pill-emoji {
  font-size: 0.9em;
  line-height: 1;
}

/* ====== Hero Search Bar — quick test finder ====== */
.hero-search {
  max-width: 500px;
  margin: 0 auto var(--space-6);
  animation: fade-in-up 0.6s ease 0.15s both;
}

.hero-search-form {
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.hero-search-form:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-lighter), var(--shadow-md);
}

.hero-search-icon {
  flex-shrink: 0;
  color: var(--color-text-muted);
  margin-right: var(--space-2);
}

.hero-search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: var(--text-base);
  color: var(--color-text);
  padding: var(--space-2) 0;
  outline: none;
  min-width: 0;
  font-family: var(--font-sans);
}

.hero-search-input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.7;
}

.hero-search-submit {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-5);
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.hero-search-submit:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.hero-search-submit:active {
  transform: scale(0.97);
}

/* ====== Scroll-down indicator ====== */
.hero-scroll-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-8);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  opacity: 0.5;
  animation: fade-in-up 0.6s ease 0.6s both;
  cursor: pointer;
  transition: opacity var(--transition-fast), color var(--transition-fast);
}

.hero-scroll-indicator:hover,
.hero-scroll-indicator:focus-visible {
  opacity: 0.8;
  color: var(--color-primary);
}

.hero-scroll-indicator:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

.hero-scroll-indicator .scroll-arrow {
  animation: scroll-indicator 2s ease-in-out infinite;
  color: var(--color-primary-light);
}

@keyframes scroll-indicator {
  0%, 100% { transform: translateY(0); opacity: 0.6; }
  50% { transform: translateY(8px); opacity: 1; }
}


/* ====== Test Animation: Celebration ====== */
.test-celebration {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  animation: fade-in-up 0.6s ease both;
}

.celebration-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
  animation: celebration-bounce 1s ease infinite;
}

@keyframes celebration-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.celebration-text {
  font-size: var(--text-2xl);
  font-weight: 800;
  margin-bottom: var(--space-2);
}

/* ====== Question Stepper (mobile) ====== */
.question-stepper {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  margin-bottom: var(--space-6);
  justify-content: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.question-stepper::-webkit-scrollbar {
  display: none;
}

.stepper-dot {
  width: 10px;
  min-width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-border);
  transition: all var(--transition-fast);
}

.stepper-dot.is-active {
  background: var(--color-primary);
  transform: scale(1.3);
}

.stepper-dot.is-completed {
  background: var(--color-primary-light);
}

[data-theme="dark"] .stepper-dot {
  background: var(--color-border);
}

[data-theme="dark"] .stepper-dot.is-active {
  background: var(--color-primary-light);
}

[data-theme="dark"] .stepper-dot.is-completed {
  background: color-mix(in srgb, var(--color-primary) 50%, transparent);
}

/* ====== No Items Fallback ====== */
.no-items {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-8);
  color: var(--color-text-muted);
  font-size: var(--text-base);
}

/* Print */
@media print {
  .site-header,
  .site-footer,
  .theme-toggle,
  .nav-toggle {
    display: none !important;
  }

  .main-content {
    padding-top: 0;
  }

  body {
    background: white;
    color: black;
  }
}

/* ====== Mobile: Newsletter Section ====== */
@media (max-width: 767px) {
  .newsletter-section {
    padding: var(--space-6) var(--space-4);
    margin-left: var(--space-4);
    margin-right: var(--space-4);
  }
  .newsletter-section h3 {
    font-size: var(--text-xl);
  }
  .newsletter-form {
    flex-direction: column;
    max-width: 100%;
  }
  .newsletter-input {
    text-align: center;
  }
  .newsletter-submit {
    width: 100%;
    justify-content: center;
  }

  .reviews-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .footer-social {
    gap: var(--space-2);
  }
}

/* ====== Tablet: Newsletter & Reviews ====== */
@media (min-width: 768px) and (max-width: 1023px) {
  .reviews-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
