:root {
  --primary-gradient: linear-gradient(135deg, #ff6b35 0%, #f7931e 50%, #ffb347 100%);
  --secondary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-gradient: linear-gradient(135deg, #0c0c0c 0%, #1a1a2e 50%, #16213e 100%);
  --card-bg: rgba(30, 30, 46, 0.8);
  --card-hover-bg: rgba(40, 40, 66, 0.9);
  --text-primary: #ffffff;
  --text-secondary: #b8bcc8;
  --accent-color: #ff6b35;
  --glass-bg: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.2);
  --shadow-light: rgba(255, 107, 53, 0.1);
  --shadow-dark: rgba(0, 0, 0, 0.3);
  --focus-color: #4a9eff;
  --error-color: #ff6b6b;
  --success-color: #51cf66;
  --warning-color: #ffd43b;
  
  /* Animation variables */
  --animation-fast: 0.15s;
  --animation-medium: 0.3s;
  --animation-slow: 0.6s;
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-in-out-back: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  
  /* Layout variables */
  --max-width: 1200px;
  --nav-height: 70px;
  --card-min-width: 140px;
  --border-radius: 16px;
  --border-radius-small: 8px;
}

/* Reset and base styles */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 20px);
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

/* Accessibility: Skip link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--accent-color);
  color: white;
  padding: 8px;
  border-radius: var(--border-radius-small);
  text-decoration: none;
  font-weight: 600;
  z-index: 10000;
  transition: top var(--animation-fast) ease;
}

.skip-link:focus {
  top: 6px;
}

/* Focus management */
:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  border-radius: var(--border-radius-small);
}

/* Remove outline for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* Loading indicator */
.loading-indicator {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 1;
  visibility: visible;
  transition: opacity var(--animation-medium) ease, visibility var(--animation-medium) ease;
}

.loading-indicator.hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-ring {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(255, 107, 53, 0.3);
  border-top: 4px solid var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Search section styles */
.search-section {
  margin: 2rem 0;
  padding: 0 1rem;
}

.search-container {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius);
  backdrop-filter: blur(20px);
  overflow: hidden;
  transition: all var(--animation-medium) ease;
}

.search-container:focus-within {
  border-color: var(--focus-color);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
}

#site-search {
  flex: 1;
  padding: 1rem 1.5rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
}

#site-search::placeholder {
  color: var(--text-secondary);
  opacity: 0.8;
}

#search-btn,
#clear-search {
  padding: 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--border-radius-small);
  transition: all var(--animation-fast) ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
}

#search-btn:hover,
#clear-search:hover {
  color: var(--accent-color);
  background: var(--glass-bg);
}

.search-results {
  margin-top: 1rem;
  border-radius: var(--border-radius);
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  max-height: 400px;
  overflow-y: auto;
  display: none;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 1rem;
  border-bottom: 1px solid var(--glass-border);
  cursor: pointer;
  transition: background var(--animation-fast) ease;
}

.search-result-item:hover {
  background: var(--glass-bg);
}

.search-result-item:last-child {
  border-bottom: none;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --card-bg: rgba(0, 0, 0, 0.9);
    --glass-border: rgba(255, 255, 255, 0.5);
    --text-secondary: #ffffff;
  }
}

/* 优化滚动性能和触摸体验 */
* {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* 滚动状态优化 */
body.scrolling * {
  pointer-events: none;
}

body.scrolling .link-card {
  transition: none;
}

/* 页面过渡和加载动画 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 页面元素入场动画 */
header {
  animation: slideInFromLeft 1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

nav {
  animation: fadeInUp 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.2s both;
}

main {
  animation: fadeInUp 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.4s both;
}

/* 分类标题动画 */
.category-title {
  opacity: 0;
  animation: slideInFromLeft 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.6s both;
}

.category-title:nth-of-type(2n) {
  animation-delay: 0.8s;
}

.category-title:nth-of-type(3n) {
  animation-delay: 1s;
}

/* 页面切换过渡 */
.page-transition {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, var(--primary-gradient));
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.page-transition.active {
  opacity: 1;
  visibility: visible;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  min-height: 100vh;
  
  /* Performance optimizations */
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header subtitle */
.header-subtitle {
  margin-top: 0.5rem;
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  color: var(--text-secondary);
  font-weight: 400;
  opacity: 0.9;
}

/* Category descriptions */
.category-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin: 0.5rem 0 1.5rem;
  opacity: 0.9;
  font-weight: 400;
}

/* Enhanced card descriptions */
.card-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  opacity: 0.8;
  display: block;
  text-align: center;
  line-height: 1.3;
}

/* 触摸优化 */
.link-card {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

nav a {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 20%, rgba(255, 107, 53, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(118, 75, 162, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 40% 60%, rgba(102, 126, 234, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: -2;
}

header {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.9) 0%, rgba(26, 26, 46, 0.9) 100%);
  backdrop-filter: blur(20px);
  padding: 2rem 1rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

header::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 200%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 107, 53, 0.1), transparent);
  animation: shimmer 3s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

header h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 3px;
  text-shadow: 0 0 30px rgba(255, 107, 53, 0.5);
  position: relative;
  z-index: 2;
}

nav {
  background: rgba(26, 26, 46, 0.9);
  padding: 1rem;
  position: sticky;
  top: 0;
  z-index: 9999;
}

nav ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

nav li {
  margin: 0;
}

nav a {
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.8rem 1.5rem;
  border-radius: 25px;
  background: transparent;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

nav a:hover,
nav a.active {
  background: var(--accent-color);
  color: #000;
  transform: translateY(-1px);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.category-title {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  margin: 3rem 0 2rem;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  border-left: 4px solid transparent;
  border-image: var(--primary-gradient) 1;
  padding-left: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: relative;
  text-shadow: 0 0 30px rgba(255, 107, 53, 0.3);
}

.category-title::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 0;
  width: 4px;
  height: 100%;
  background: var(--primary-gradient);
  border-radius: 2px;
}

.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.link-card {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 1.5rem 1rem;
  text-align: center;
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  will-change: transform, box-shadow;
}

.link-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--primary-gradient);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.link-card a {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 2;
}

.link-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 
    0 20px 40px rgba(0, 0, 0, 0.2),
    0 0 40px var(--shadow-light);
  border-color: var(--accent-color);
}

.link-card:hover::before {
  opacity: 0.1;
}

.link-card i {
  font-size: 2.2rem;
  margin-bottom: 1rem;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 0 10px rgba(255, 107, 53, 0.3));
}

.link-card:hover i {
  transform: scale(1.2) rotateY(360deg);
  filter: drop-shadow(0 0 20px rgba(255, 107, 53, 0.6));
}

.link-card h3 {
  font-size: 0.95rem;
  margin: 0;
  color: var(--text-primary);
  line-height: 1.4;
  font-weight: 600;
  max-width: 100%;
  height: auto;
  overflow: visible;
  padding: 0 0.5rem;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.link-card:hover h3 {
  color: var(--text-primary);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

footer {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.9) 0%, rgba(26, 26, 46, 0.9) 100%);
  backdrop-filter: blur(20px);
  color: var(--text-secondary);
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  border-top: 1px solid var(--glass-border);
  margin-top: 4rem;
}

footer nav {
  margin-top: 1rem;
  background-color: transparent;
  position: static;
  padding: 0;
  box-shadow: none;
  backdrop-filter: none;
  border: none;
}

footer nav a {
  color: var(--text-secondary);
  margin: 0 1rem;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border-radius: 15px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  transition: all 0.3s ease;
}

footer nav a:hover {
  color: var(--text-primary);
  background: var(--card-hover-bg);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px var(--shadow-light);
}

@media (max-width: 1200px) {
  main {
    padding: 1.5rem;
    max-width: 95%;
  }

  .link-grid {
    grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
    gap: 1.2rem;
  }

  header h1 {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
  }

  nav {
    padding: 0.8rem;
  }

  nav a {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 768px) {
  html {
    font-size: 15px;
  }

  main {
    padding: 1rem;
  }

  .link-grid {
    grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
    gap: 1rem;
  }

  nav {
    padding: 0.6rem;
    flex-direction: column;
  }

  nav ul {
    flex-wrap: wrap;
    justify-content: center;
  }

  nav a {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    margin: 0.2rem;
  }

  .category-title {
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    margin: 2rem 0 1.5rem;
  }

  .link-card {
    padding: 1.2rem 0.8rem;
    min-height: 100px;
    border-radius: 15px;
  }

  .link-card i {
    font-size: 1.8rem;
    margin-bottom: 0.8rem;
  }

  header {
    padding: 1.5rem 1rem;
  }

  header h1 {
    font-size: clamp(1.6rem, 6vw, 2.2rem);
    letter-spacing: 2px;
  }

  .link-card h3 {
    font-size: 0.8rem;
    height: 2.4em;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  main {
    padding: 1rem 0.8rem;
  }

  .link-grid {
    grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
    gap: 0.8rem;
  }

  header {
    padding: 1.2rem 0.8rem;
  }

  header h1 {
    font-size: clamp(1.4rem, 6vw, 1.8rem);
    letter-spacing: 1.5px;
  }

  nav {
    padding: 0.5rem;
  }

  nav a {
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
    margin: 0.15rem;
  }

  .category-title {
    font-size: clamp(1.1rem, 4vw, 1.4rem);
    margin: 1.5rem 0 1rem;
    letter-spacing: 1.5px;
  }

  .link-card {
    padding: 1rem 0.7rem;
    min-height: 85px;
    border-radius: 12px;
  }

  .link-card i {
    font-size: 1.5rem;
    margin-bottom: 0.6rem;
  }

  .link-card h3 {
    font-size: 0.8rem;
    padding: 0 0.3rem;
  }

  footer {
    padding: 1.5rem 0.8rem;
  }

  footer nav a {
    margin: 0 0.5rem;
    font-size: 0.75rem;
    padding: 0.4rem 0.8rem;
  }
}

/* Error handling styles */
.error-toast {
  position: fixed !important;
  top: 20px !important;
  right: 20px !important;
  background: var(--error-color) !important;
  color: white !important;
  padding: 1rem !important;
  border-radius: var(--border-radius) !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
  z-index: 10000 !important;
  font-family: inherit !important;
  max-width: 300px !important;
  animation: slideInRight 0.3s ease-out !important;
}

.error-toast button {
  background: rgba(255,255,255,0.2) !important;
  border: none !important;
  color: white !important;
  padding: 0.5rem 1rem !important;
  border-radius: var(--border-radius-small) !important;
  cursor: pointer !important;
  margin-top: 0.5rem !important;
  font-family: inherit !important;
}

.error-toast button:hover {
  background: rgba(255,255,255,0.3) !important;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Performance optimizations */
.link-card,
.search-container,
header,
nav {
  contain: layout style;
}

/* Improved print styles */
@media print {
  .search-section,
  nav,
  .loading-indicator {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .link-card {
    break-inside: avoid;
    background: transparent !important;
    border: 1px solid #ccc !important;
    page-break-inside: avoid;
  }
}