/* Reset and base */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --ink: #333;
  --muted: #666;
  --bg: #f5f5f5;
  --card: #fff;
  --brand: #204a87;
  --brand-2: #1a3d6e;
  --border: #e0e0e0;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--bg);
}

/* A11y: skip link */
.visually-hidden-focusable {
  position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden;
}
.visually-hidden-focusable:focus {
  position: static; width: auto; height: auto; padding: .5rem .75rem; background: #fff; border: 1px solid var(--border);
}

/* Header */
header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
nav {
  max-width: 1200px; margin: 0 auto; padding: 0 1rem;
  display: flex; justify-content: space-between; align-items: center;
}
.logo { font-size: 1.25rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.nav-links { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.nav-links a {
  color: var(--brand); text-decoration: none; transition: color .2s, text-decoration-color .2s;
}
.nav-links a:hover { color: #5c7cfa; text-decoration: underline; }
.nav-links a.active { color: var(--brand-2); text-decoration: underline; }

/* Main */
main {
  max-width: 1200px; margin: 2rem auto; padding: 0 1rem;
  min-height: calc(100vh - 200px);
}

/* Hero - Gradient Background */
.hero {
  text-align: center;
  padding: 3rem 1rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-md);
}
.hero h1 { 
  font-size: 2.5rem; 
  margin-bottom: 1rem; 
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.hero p { 
  font-size: 1.2rem; 
  color: rgba(255,255,255,0.95); 
  max-width: 600px; 
  margin: 0 auto;
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Pattern grid for homepage and collections */
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}
.pattern-card {
  background: var(--card);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  transition: transform .2s, box-shadow .2s;
  box-shadow: var(--shadow-md);
  display: block;
}
.pattern-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.pattern-card img {
  display: block;
  width: 100%;
  height: 280px;
  object-fit: cover;
  background: #f0f0f0;
}
.pattern-card h3 {
  padding: 1rem 1rem .25rem; font-size: 1rem; font-weight: 600;
}
.pattern-card p {
  padding: 0 1rem 1rem; font-size: .95rem; color: var(--muted);
}

/* Pattern detail page */
.pattern-container {
  background: #fff; border-radius: 8px; padding: 2rem;
  display: grid; grid-template-columns: 1fr 1fr; gap: 3rem;
  box-shadow: var(--shadow-md);
}
.pattern-image img { width: 100%; border-radius: 8px; display: block; }
.pattern-details h1 { font-size: 2rem; margin-bottom: 1rem; color: var(--ink); }
.description { font-size: 1.1rem; color: var(--muted); margin-bottom: 1.5rem; line-height: 1.7; }

.tags { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.5rem; }
.tag {
  background: #f0f0f0; padding: .25rem .75rem; border-radius: 20px;
  font-size: .9rem; color: var(--muted);
}
.pattern-info { margin-bottom: 2rem; }
.pattern-info p { margin-bottom: .5rem; color: var(--muted); }

.buy-button {
  display: inline-block; background: var(--brand); color: #fff;
  padding: 1rem 2rem; border-radius: 6px; text-decoration: none;
  font-size: 1.1rem; font-weight: 600; transition: background .2s;
}
.buy-button:hover { background: var(--brand-2); }

.additional-info { margin-top: 2rem; padding-top: 2rem; border-top: 1px solid var(--border); color: var(--muted); }

/* Related patterns */
.related-patterns { margin-top: 3rem; }
.related-patterns h2 { font-size: 1.5rem; margin-bottom: 1.5rem; color: var(--ink); }

/* Collection pages */
.collection-header {
  text-align: center; padding: 2rem 0; background: #fff; border-radius: 8px;
  margin-bottom: 2rem; box-shadow: var(--shadow-md);
}
.collection-header h1 { font-size: 2.5rem; margin-bottom: .5rem; color: var(--ink); }
.collection-header p { font-size: 1.1rem; color: var(--muted); }

/* 404 page */
.error-404 {
  text-align: center; padding: 4rem 2rem; background: #fff; border-radius: 8px; box-shadow: var(--shadow-md);
}
.error-404 h1 { font-size: 6rem; color: var(--brand); margin-bottom: 1rem; }
.error-404 h2 { font-size: 2rem; margin-bottom: 1rem; color: var(--ink); }
.error-404 p { font-size: 1.1rem; color: var(--muted); margin-bottom: 2rem; }

/* Footer */
footer {
  background: #fff; border-top: 1px solid var(--border);
  padding: 2rem 0; text-align: center; margin-top: 3rem;
}
footer p { color: var(--muted); font-size: .9rem; }

/* Responsive */
@media (max-width: 768px) {
  .nav-links { gap: 0.75rem; font-size: .85rem; }
  .pattern-container { grid-template-columns: 1fr; gap: 2rem; padding: 1rem; }
  .pattern-details h1 { font-size: 1.5rem; }
  .pattern-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
  .collection-header h1 { font-size: 2rem; }
  .error-404 h1 { font-size: 4rem; }
  .hero { padding: 2rem 1rem; }
  .hero h1 { font-size: 1.75rem; }
  .hero p { font-size: 1rem; }
}

/* Mobile Navigation - Compact Horizontal Scroll */
@media (max-width: 480px) {
  header {
    padding: 0.5rem 0;
  }
  nav { 
    flex-direction: column;
    gap: 0.5rem;
    padding: 0;
  }
  .logo { 
    text-align: center;
    font-size: 1rem;
    padding: 0 1rem;
  }
  .nav-links { 
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    gap: 0.5rem;
    padding: 0 1rem 0.25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
  }
  .nav-links::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome/Safari */
  }
  .nav-links a { 
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.35rem 0.6rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 4px;
    white-space: nowrap;
  }
  .nav-links a.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
  }
  .hero {
    padding: 1.5rem 1rem;
    margin-bottom: 1.5rem;
  }
  .hero h1 { 
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
  }
  .hero p { 
    font-size: 0.9rem;
  }
  main {
    margin: 1rem auto;
  }
  .pattern-grid { 
    grid-template-columns: 1fr;
    gap: 1rem;
    margin: 1rem 0;
  }
  .buy-button { 
    width: 100%; 
    text-align: center; 
  }
}

/* Optional image skeleton. Add class="skeleton" to <img> to enable. */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e6e6e6 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}
@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Dark Theme - Automatic based on OS setting */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e0e0e0;
    --muted: #a0a0a0;
    --bg: #1a1a1a;
    --card: #2a2a2a;
    --brand: #6b9bd1;
    --brand-2: #5a8bc0;
    --border: #404040;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
  }
  
  body {
    background-color: var(--bg);
    color: var(--ink);
  }
  
  header, footer {
    background: var(--card);
    border-color: var(--border);
  }
  
  .hero {
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
  }
  
  .pattern-card, .pattern-container, .collection-header, .error-404 {
    background: var(--card);
  }
  
  .pattern-card:hover {
    box-shadow: var(--shadow-lg);
  }
  
  .pattern-card img {
    background: #1a1a1a;
  }
  
  .logo {
    color: var(--ink);
  }
  
  .nav-links a {
    color: var(--brand);
    background: var(--card);
    border-color: var(--border);
  }
  
  .nav-links a:hover {
    color: #8bb3e3;
  }
  
  .nav-links a.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
  }
  
  .tag {
    background: #3a3a3a;
    color: var(--muted);
  }
  
  .visually-hidden-focusable:focus {
    background: var(--card);
    border-color: var(--border);
  }
}

/* Print */
@media print {
  header, footer, .nav-links, .buy-button, .related-patterns { display: none; }
  body { background: #fff; }
  .pattern-container { box-shadow: none; border: 1px solid #ddd; }
}
