/* Base Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

:root {
  --primary-color: #ff4444;
  --secondary-color: #0066ff;
  --accent-color: #00cc88;
  --text-color: #000000;
  --text-secondary: #000000;
  --link-color: #0066ff;
  --link-hover: #0052cc;
  --link-visited: #6633cc;
  --border-color: #e5e5e5;
  --bg-accent: #f8faff;
  --code-bg: #f0f8ff;
  --code-border: #c0d0ff;
  --font-body: "Georgia", "Times New Roman", serif;
  --font-heading: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Monaco", "Cascadia Code", "Roboto Mono", "Consolas", "Courier New", monospace;
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2rem;
  --space-xl: 3rem;
  --space-2xl: 4rem;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;
  --max-width: 46rem;
  --border-radius: 8px;
  --border-radius-sm: 4px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

html {
  font-size: 18px;
  line-height: 1.7;
  scroll-behavior: smooth;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*:focus {
  outline: 3px solid var(--secondary-color);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (min-width: 768px) {
  html {
    font-size: 20px;
  }
}

@media (min-width: 1024px) {
  html {
    font-size: 22px;
  }
}

body {
  font-family: var(--font-body);
  font-size: var(--text-lg);
  color: var(--text-color);
  background: white;
  line-height: 1.75;
  transition: opacity 0.3s ease;
}

/* Loading state */
body.loading {
  opacity: 0.7;
  pointer-events: none;
}

/* Skip to content link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--secondary-color);
  color: white;
  padding: 8px;
  text-decoration: none;
  z-index: 1000;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition: all 0.3s ease;
}

.skip-link:focus {
  top: 6px;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-lg) var(--space-sm);
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: var(--space-xl);
  animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-color);
  letter-spacing: -0.025em;
  margin-top: var(--space-xl);
  margin-bottom: var(--space-md);
}

h1:first-child,
h2:first-child,
h3:first-child {
  margin-top: 0;
}

h1 { font-size: var(--text-5xl); }
h2 { font-size: var(--text-4xl); }
h3 { font-size: var(--text-3xl); }
h4 { font-size: var(--text-2xl); }
h5 { font-size: var(--text-xl); }
h6 { font-size: var(--text-lg); }

p {
  margin-bottom: var(--space-md);
  max-width: 65ch;
  text-align: justify;
  hyphens: auto;
}

/* Better paragraph spacing in post content */
.post-content p + p {
  margin-top: var(--space-md);
}

.post-content p + h2,
.post-content p + h3,
.post-content p + h4 {
  margin-top: var(--space-xl);
}

/* Improve readability of long text */
.post-content {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Better list styling */
.post-content ul li::marker {
  color: var(--secondary-color);
}

.post-content ol li::marker {
  color: var(--secondary-color);
  font-weight: 600;
}

a {
  color: var(--link-color);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 2px;
  transition: all 0.2s ease;
}

/* Smooth animations for better UX */
*, *::before, *::after {
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration-thickness: 3px;
}

a:visited {
  color: var(--link-visited);
}

a:focus {
  outline: 2px solid var(--secondary-color);
  outline-offset: 2px;
  border-radius: var(--border-radius-sm);
}

.site-header {
  text-align: center;
  padding: var(--space-xl) 0;
  border-bottom: 3px solid var(--primary-color);
  margin-bottom: var(--space-2xl);
  position: relative;
}

.site-header::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 6px;
  background: var(--accent-color);
  border-radius: 3px;
}

.site-title {
  font-size: var(--text-4xl);
  font-weight: 800;
  margin: 0 0 var(--space-md);
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.site-title a {
  text-decoration: none;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.site-title a:hover {
  background: linear-gradient(135deg, var(--secondary-color), var(--accent-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.main-nav {
  display: flex;
  justify-content: center;
  gap: var(--space-lg);
  margin-top: var(--space-md);
}

.nav-link {
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--border-radius);
  background: var(--bg-accent);
  text-decoration: none;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--secondary-color);
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.nav-link:hover {
  background: var(--secondary-color);
  color: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-lg);
}

.post-item {
  padding: var(--space-md);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  transition: all 0.3s ease;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-md);
  align-items: center;
  background: linear-gradient(135deg, #ffffff 0%, #fafbff 100%);
}

.post-item:hover {
  border-color: var(--secondary-color);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.post-item:active {
  transform: translateY(0);
}

.post-date {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--secondary-color);
  background: var(--bg-accent);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--border-radius-sm);
  white-space: nowrap;
  border: 1px solid var(--code-border);
}

.post-link {
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-lg);
  color: var(--text-color);
  line-height: 1.4;
}

.post-link:hover {
  color: var(--secondary-color);
}

.post-header {
  text-align: center;
  margin-bottom: var(--space-2xl);
  padding: var(--space-xl) 0;
  background: linear-gradient(135deg, #fafbff 0%, #f0f8ff 100%);
  border-radius: var(--border-radius);
  border: 2px solid var(--border-color);
}

.post-title {
  font-size: clamp(var(--text-3xl), 5vw, var(--text-5xl));
  margin: 0 0 var(--space-md);
  background: linear-gradient(135deg, var(--text-color), var(--secondary-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.post-meta {
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--secondary-color);
  background: var(--bg-accent);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--border-radius);
  display: inline-block;
  border: 1px solid var(--code-border);
}

.post-category {
  background: var(--primary-color);
  color: white;
  padding: 2px var(--space-xs);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-xs);
  margin-left: var(--space-sm);
}

.post-tags {
  margin-top: var(--space-xs);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.post-tag {
  background: var(--accent-color);
  color: white;
  padding: 2px var(--space-xs);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
}

.post-content {
  margin-bottom: var(--space-2xl);
}

.post-content > * {
  max-width: 65ch;
}

.post-content h2,
.post-content h3,
.post-content h4 {
  margin-top: var(--space-2xl);
}

/* Lists in Content */
.post-content ul,
.post-content ol {
  margin: var(--space-md) 0 var(--space-lg) var(--space-lg);
  max-width: 60ch;
}

.post-content li {
  margin-bottom: var(--space-xs);
  line-height: 1.7;
}

/* Code */
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-weight: 600;
  background: var(--code-bg);
  color: var(--secondary-color);
  padding: 0.2em 0.4em;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--code-border);
}

pre {
  background: var(--code-bg);
  border: 2px solid var(--code-border);
  border-radius: var(--border-radius);
  padding: var(--space-lg);
  overflow-x: auto;
  margin: var(--space-lg) 0;
  box-shadow: var(--shadow-sm);
  position: relative;
}

pre::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color), var(--accent-color));
  border-radius: var(--border-radius) var(--border-radius) 0 0;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-color);
}

/* Blockquotes */
blockquote {
  border-left: 4px solid var(--primary-color);
  margin: var(--space-lg) 0;
  padding: var(--space-lg);
  background: linear-gradient(135deg, #fafafa 0%, #f5f5f5 100%);
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  font-style: italic;
  position: relative;
  box-shadow: var(--shadow-sm);
}

blockquote::before {
  content: '"';
  position: absolute;
  top: -10px;
  left: var(--space-md);
  font-size: var(--text-4xl);
  color: var(--primary-color);
  font-weight: 700;
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: var(--space-lg) auto;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  loading: lazy;
}

/* Critical rendering optimization */
.above-fold {
  contain: layout style paint;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-lg) 0;
  font-size: var(--text-sm);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

th, td {
  padding: var(--space-sm);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  font-weight: 700;
  font-family: var(--font-heading);
}

tbody tr:nth-child(even) {
  background: var(--bg-accent);
}

tbody tr:hover {
  background: var(--code-bg);
}

/* Navigation */
.site-nav {
  text-align: center;
  margin: var(--space-2xl) 0;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-md);
  margin: var(--space-2xl) 0;
  font-family: var(--font-heading);
  font-weight: 600;
}

.pagination a {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-accent);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  text-decoration: none;
  color: var(--secondary-color);
  transition: all 0.3s ease;
}

.pagination a:hover {
  background: var(--secondary-color);
  color: white;
  border-color: var(--secondary-color);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Footer */
.site-footer {
  margin-top: var(--space-2xl);
  padding-top: var(--space-xl);
  border-top: 3px solid var(--border-color);
  text-align: center;
  font-family: var(--font-heading);
  font-size: var(--text-sm);
}

.footer-content {
  display: grid;
  gap: var(--space-md);
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.footer-links a {
  text-decoration: none;
  font-weight: 600;
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--border-radius-sm);
  transition: all 0.2s ease;
}

.footer-links a:hover {
  background: var(--bg-accent);
  color: var(--secondary-color);
}

.footer-meta {
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

/* Related Posts */
.related-posts {
  margin-top: var(--space-xl);
  font-size: var(--text-sm);
}

.related-posts h3 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-sm);
}

.related-posts .post-list {
  gap: var(--space-xs);
}

.related-posts .post-item {
  padding: var(--space-xs);
  font-size: var(--text-sm);
}

.related-posts .post-date {
  font-size: var(--text-xs);
  padding: 2px var(--space-xs);
}

.related-posts .post-link {
  font-size: var(--text-sm);
  font-weight: 500;
}

/* Archive */
.archive-year {
  font-size: var(--text-3xl);
  margin: var(--space-2xl) 0 var(--space-md);
  color: var(--primary-color);
  font-weight: 800;
  position: relative;
  padding-left: var(--space-lg);
}

.archive-year::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: var(--space-xs);
  height: 60%;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  border-radius: var(--border-radius-sm);
}

/* Responsive Design */
@media (max-width: 768px) {
  .wrapper {
    padding: var(--space-md) var(--space-sm);
    gap: var(--space-lg);
  }
  
  .site-header {
    padding: var(--space-lg) 0;
  }
  
  .main-nav {
    flex-direction: column;
    gap: var(--space-sm);
  }
  
  .nav-link {
    padding: var(--space-md);
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .post-item {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
    text-align: center;
    padding: var(--space-md);
    min-height: 60px;
  }
  
  .post-date {
    justify-self: center;
  }
  
  .post-link {
    padding: var(--space-xs) 0;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .pagination {
    flex-direction: column;
    gap: var(--space-sm);
  }
  
  .pagination a {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .footer-links {
    flex-direction: column;
    gap: var(--space-sm);
  }
  
  .footer-links a {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm);
  }
  
  .site-nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm) var(--space-md);
  }
  
  p {
    text-align: left;
    hyphens: none;
  }
  
  /* Larger text on mobile for better readability */
  html {
    font-size: 20px;
  }
  
  .post-content {
    font-size: 1.05rem;
    line-height: 1.8;
  }
}

/* Print Styles */
@media print {
  :root {
    --text-color: #000;
    --link-color: #000;
  }
  
  .site-nav,
  .pagination,
  .footer-links {
    display: none;
  }
  
  .wrapper {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  
  .site-header::after {
    display: none;
  }
  
  a {
    color: #000 !important;
    text-decoration: none !important;
  }
  
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
}

/* Focus and accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  html {
    scroll-behavior: auto !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000;
    --text-color: #000;
    --link-color: #0000ff;
  }
}