/**
 * Main Stylesheet for Hugo Blog
 * 
 * Structure:
 * 1. CSS Variables (colors for light/dark themes)
 * 2. Reset & Base Styles
 * 3. Typography
 * 4. Layout Components (Header, Footer, etc.)
 * 5. Post Styles
 * 6. UI Elements (Buttons, Icons, etc.)
 * 7. Responsive Design
 * 8. Print Styles
 */

/* ============================================
   1. CSS VARIABLES - THEMING
   ============================================
   Edit these to change colors throughout the site
   Light and dark mode each have their own color palette
*/

:root[data-theme="light"] {
  --bg-color: #ffffff;           /* Main background color */
  --text-color: #000000;         /* Main text color */
  --text-secondary: #555555;     /* Secondary text (meta info, etc.) */
  --link-color: #005b99;         /* Link color */
  --link-hover: #003d66;         /* Link hover color */
  --border-color: #e0e0e0;       /* Border and divider color */
  --code-bg: #f5f5f5;            /* Code block background */
  --shadow: rgba(0, 0, 0, 0.1);  /* Shadow for elevated elements */
  --button-bg: #f0f0f0;          /* Button background */
  --button-hover: #e0e0e0;       /* Button hover state */
}

:root[data-theme="dark"] {
  --bg-color: #1a1a1a;           /* Dark background */
  --text-color: #e0e0e0;         /* Light text on dark background */
  --text-secondary: #a0a0a0;     /* Muted text */
  --link-color: #4da6ff;         /* Brighter links for visibility */
  --link-hover: #80bfff;         /* Even brighter on hover */
  --border-color: #333333;       /* Subtle borders */
  --code-bg: #2d2d2d;            /* Dark code background */
  --shadow: rgba(255, 255, 255, 0.1); /* Light shadow on dark */
  --button-bg: #2d2d2d;          /* Dark button */
  --button-hover: #3d3d3d;       /* Lighter on hover */
}

/* ============================================
   2. RESET AND BASE STYLES
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  /* Smooth theme transitions */
  transition: background-color 0.3s ease, color 0.3s ease;
}

body {
  /* Primary font: Chilanka for Malayalam, fallback to system fonts */
  font-family: 'Chilanka', cursive, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.75;
  color: var(--text-color);
  background-color: var(--bg-color);
  max-width: 42rem;              /* Comfortable reading width */
  margin: 0 auto;                /* Center content */
  padding: 2.625rem 1.3125rem;  /* Top/bottom and left/right padding */
}

/* ============================================
   3. TYPOGRAPHY
   ============================================ */

h1, h2, h3, h4, h5, h6 {
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-color);
}

h1 {
  font-size: 2.5rem;
  margin-top: 0;  /* No margin on first heading */
}

h2 {
  font-size: 2rem;
}

h3 {
  font-size: 1.5rem;
}

p {
  margin-bottom: 1.75rem;
}

a {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

/* ============================================
   4. SITE HEADER
   ============================================ */

.site-header {
  margin-bottom: 3.5rem;
}

.site-title {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  font-weight: 700;
}

.site-title a {
  color: var(--text-color);
  text-decoration: none;
}

.site-title a:hover {
  color: var(--link-color);
}

.site-description {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.site-description p {
  margin-bottom: 1rem;
}

.site-description strong {
  color: var(--text-color);
  font-weight: 700;
}

/* ============================================
   5. SOCIAL ICONS
   ============================================
   Used in header and post sharing
*/

.social-icons {
  display: flex;
  gap: 1rem;               /* Space between icons */
  margin-top: 1rem;
}

.social-icons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;      /* Circular buttons */
  background-color: var(--button-bg);
  color: var(--text-color);
  transition: all 0.2s ease;
}

.social-icons a:hover {
  background-color: var(--button-hover);
  transform: translateY(-2px);  /* Slight lift on hover */
  text-decoration: none;
}

.social-icons svg {
  width: 20px;
  height: 20px;
}

/* ============================================
   6. POSTS LIST (Homepage)
   ============================================ */

.posts-list {
  margin-bottom: 3rem;
}

.post-item {
  margin-bottom: 3.5rem;
}

.post-item:last-child {
  margin-bottom: 0;
}

.post-title {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
  margin-top: 0;
  line-height: 1.3;
}

.post-title a {
  color: var(--link-color);  /* Post titles in blue/link color */
  text-decoration: none;
}

.post-title a:hover {
  text-decoration: underline;
}

.post-meta {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.separator {
  margin: 0 0.5rem;  /* Space around bullet separator */
}

.reading-time {
  white-space: nowrap;  /* Keep "X min read" on one line */
}

.post-summary {
  color: var(--text-secondary);
  margin-top: 1rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}

/* "Read More" Link */
.read-more {
  margin-top: 1rem;
}

.read-more-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background-color: var(--button-bg);
  color: var(--link-color);
  border-radius: 0.25rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.read-more-link:hover {
  background-color: var(--button-hover);
  text-decoration: none;
  transform: translateX(4px);  /* Slide right on hover */
}

/* ============================================
   7. SINGLE POST LAYOUT
   ============================================ */

.post {
  margin-bottom: 3rem;
}

.post-header {
  margin-bottom: 2rem;
}

.post-tags {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background-color: var(--code-bg);
  color: var(--text-color);
  border-radius: 0.25rem;
  font-size: 0.875rem;
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.tag:hover {
  background-color: var(--border-color);
  text-decoration: none;
}

/* Post Content Formatting */
.post-content {
  margin-bottom: 3rem;
}

.post-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2rem auto;
  border-radius: 0.5rem;  /* Slightly rounded image corners */
}

.post-content pre {
  background-color: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  border-radius: 0.25rem;
  margin-bottom: 1.75rem;
}

.post-content code {
  background-color: var(--code-bg);
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  font-family: 'Courier New', monospace;
}

.post-content pre code {
  background-color: transparent;
  padding: 0;
}

.post-content blockquote {
  border-left: 4px solid var(--link-color);
  padding-left: 1rem;
  margin: 1.75rem 0;
  color: var(--text-secondary);
  font-style: italic;
}

.post-content ul, .post-content ol {
  margin-bottom: 1.75rem;
  padding-left: 2rem;
}

.post-content li {
  margin-bottom: 0.5rem;
}

/* ============================================
   8. POST SHARING SECTION
   ============================================ */

.post-share {
  margin: 2rem 0;
  padding: 1.5rem;
  background-color: var(--code-bg);
  border-radius: 0.5rem;
}

.share-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.share-icons {
  margin-top: 0;  /* Override default social-icons margin */
}

/* ============================================
   9. POST NAVIGATION (Previous/Next)
   ============================================ */

.post-divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 3rem 0;
}

.post-navigation {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 2rem;
}

.post-nav-item {
  flex: 1;
}

.post-nav-next {
  text-align: right;
}

.post-nav-label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.post-nav-item a {
  color: var(--link-color);
  font-weight: 500;
}

/* ============================================
   10. RELATED POSTS SECTION
   ============================================ */

.related-posts {
  margin: 3rem 0;
  padding: 2rem;
  background-color: var(--code-bg);
  border-radius: 0.5rem;
}

.related-title {
  font-size: 1.5rem;
  margin-top: 0;
  margin-bottom: 1.5rem;
  color: var(--text-color);
}

.related-list {
  display: grid;
  gap: 1.5rem;
}

.related-item {
  padding: 1rem;
  background-color: var(--bg-color);
  border-radius: 0.25rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.related-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.related-link {
  text-decoration: none;
  color: inherit;
}

.related-link:hover {
  text-decoration: none;
}

.related-post-title {
  font-size: 1.125rem;
  margin-bottom: 0.5rem;
  color: var(--link-color);
  font-weight: 600;
}

.related-post-meta {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ============================================
   11. HEADER BUTTONS (Theme Toggle + Language)
   ============================================ */

.header-buttons {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  display: flex;
  gap: 0.5rem;
  z-index: 1000;
}

/* Icon Button Base Style */
.icon-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 2.75rem;
  height: 2.75rem;
  padding: 0.5rem;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 2rem;    /* Pill shape */
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px var(--shadow);
  color: var(--text-color);
  font-size: 0.875rem;
  font-family: inherit;
}

.icon-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
  border-color: var(--link-color);
}

/* Theme Toggle Icons */
.sun-icon, .moon-icon {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

:root[data-theme="light"] .sun-icon {
  opacity: 1;
  transform: rotate(0deg);
}

:root[data-theme="light"] .moon-icon {
  opacity: 0;
  transform: rotate(180deg);
  position: absolute;  /* Hide moon in light mode */
}

:root[data-theme="dark"] .sun-icon {
  opacity: 0;
  transform: rotate(-180deg);
  position: absolute;  /* Hide sun in dark mode */
}

:root[data-theme="dark"] .moon-icon {
  opacity: 1;
  transform: rotate(0deg);
}

/* ============================================
   12. LANGUAGE SELECTOR
   ============================================ */

.language-selector {
  position: relative;
}

.language-label {
  font-weight: 500;
  white-space: nowrap;
}

.language-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 150px;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
}

.language-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.language-option {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--text-color);
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.language-option:hover {
  background-color: var(--button-hover);
  text-decoration: none;
}

.language-option:first-child {
  border-radius: 0.5rem 0.5rem 0 0;
}

.language-option:last-child {
  border-radius: 0 0 0.5rem 0.5rem;
}

/* ============================================
   13. PAGINATION
   ============================================ */

.pagination {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

.pagination a {
  color: var(--link-color);
  font-weight: 500;
}

/* ============================================
   14. BACK TO HOME LINK
   ============================================ */

.back-to-home {
  margin-top: 2rem;
}

.back-to-home a {
  color: var(--link-color);
  font-weight: 500;
}

/* ============================================
   15. PAGE HEADER (for list pages)
   ============================================ */

.page-header {
  margin-bottom: 3rem;
}

.page-description {
  color: var(--text-secondary);
  font-size: 1.125rem;
}

/* ============================================
   16. FOOTER
   ============================================ */

.site-footer {
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.site-footer a {
  color: var(--text-secondary);
}

/* ============================================
   17. RESPONSIVE DESIGN
   ============================================
   Adjustments for smaller screens (tablets and phones)
*/

@media (max-width: 768px) {
  body {
    padding: 1.5rem 1rem;
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .site-title {
    font-size: 2rem;
  }

  .post-title {
    font-size: 1.5rem;
  }

  .post-navigation {
    flex-direction: column;
    gap: 1rem;
  }

  .post-nav-next {
    text-align: left;  /* Left align on mobile */
  }

  .header-buttons {
    top: 1rem;
    right: 1rem;
  }
  
  /* Stack language label on mobile for space */
  .language-label {
    display: none;
  }
  
  .social-icons {
    flex-wrap: wrap;  /* Wrap icons on small screens */
  }
  
  .related-posts {
    padding: 1.5rem 1rem;
  }
}

/* ============================================
   18. PRINT STYLES
   ============================================
   Clean formatting when printing pages
*/

@media print {
  /* Hide interactive elements when printing */
  .header-buttons,
  .post-navigation,
  .back-to-home,
  .site-footer,
  .post-share,
  .social-icons,
  .related-posts {
    display: none;
  }

  /* Force light mode colors for printing */
  body {
    color: #000;
    background-color: #fff;
  }

  a {
    color: #000;
    text-decoration: underline;
  }
  
  /* Show URLs after links */
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
}

/* ============================================
   19. CUSTOM 404 ERROR PAGE
   ============================================
   Friendly error page styling
*/

.error-page {
  text-align: center;
  padding: 4rem 0;
  max-width: 600px;
  margin: 0 auto;
}

.error-code {
  font-size: 8rem;
  font-weight: 700;
  color: var(--link-color);
  line-height: 1;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.error-title {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--text-color);
}

.error-message {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  line-height: 1.6;
}

.error-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 3rem;
  flex-wrap: wrap;
}

.button {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
  font-size: 1rem;
}

.button.primary {
  background-color: var(--link-color);
  color: #ffffff;
}

.button.primary:hover {
  background-color: var(--link-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
  text-decoration: none;
}

.button.secondary {
  background-color: var(--button-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.button.secondary:hover {
  background-color: var(--button-hover);
  transform: translateY(-2px);
  text-decoration: none;
}

.error-suggestions {
  margin-top: 3rem;
  text-align: left;
}

.suggestions-title {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.suggestions-list {
  display: grid;
  gap: 1.5rem;
}

.suggestion-item {
  padding: 1.5rem;
  background-color: var(--code-bg);
  border-radius: 0.5rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.suggestion-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.suggestion-title {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  margin-top: 0;
}

.suggestion-title a {
  color: var(--link-color);
  text-decoration: none;
}

.suggestion-title a:hover {
  text-decoration: underline;
}

.suggestion-meta {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ============================================
   20. ARCHIVE PAGE
   ============================================
   All posts organized by year and month
*/

.archive-header {
  text-align: center;
  margin-bottom: 3rem;
}

.archive-description {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-top: 1rem;
}

.archive-content {
  margin-bottom: 3rem;
}

.archive-year {
  margin-bottom: 3rem;
}

.year-heading {
  font-size: 2rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--link-color);
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.year-number {
  font-weight: 700;
  color: var(--link-color);
}

.year-count {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.archive-month {
  margin-bottom: 2rem;
  margin-left: 1rem;
}

.month-heading {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.archive-posts {
  list-style: none;
  padding: 0;
  margin: 0;
}

.archive-post {
  display: grid;
  grid-template-columns: 4rem 1fr auto auto;
  gap: 1rem;
  align-items: baseline;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 0.25rem;
  transition: background-color 0.2s ease;
}

.archive-post:hover {
  background-color: var(--code-bg);
}

.post-date {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-family: monospace;
}

.post-link {
  color: var(--text-color);
  text-decoration: none;
  font-weight: 500;
}

.post-link:hover {
  color: var(--link-color);
  text-decoration: underline;
}

.post-tags {
  display: flex;
  gap: 0.5rem;
}

.tag-small {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.post-time {
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Responsive archive layout */
@media (max-width: 768px) {
  .archive-post {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  
  .post-date {
    order: -1;
  }
  
  .post-tags {
    order: 2;
  }
  
  .post-time {
    order: 3;
  }
  
  .year-heading {
    font-size: 1.75rem;
  }
  
  .error-code {
    font-size: 5rem;
  }
  
  .error-title {
    font-size: 1.5rem;
  }
}