/* ==========================================================================
   DESIGN TOKENS & VARIABLE SYSTEM
   ========================================================================== */
:root {
  /* Fonts */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-heading: 'Outfit', var(--font-body);

  /* Dimensions */
  --max-width-content: 72ch;
  --max-width-container: 960px;
  --header-height: 72px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* Colors - Light Theme Default */
  --bg-color: #fcfbfa; /* Warm paper white */
  --text-color: #1d1c21; /* Rich charcoal */
  --text-secondary: #656370; /* Muted slate */
  --accent-color: #5850ec; /* Vibrant Indigo */
  --accent-light: rgba(88, 80, 236, 0.1);
  --accent-hover: #4f46e5;
  --border-color: rgba(29, 28, 33, 0.08);
  --card-bg: rgba(255, 255, 255, 0.6);
  --card-hover-bg: #ffffff;
  --header-bg: rgba(252, 251, 250, 0.8);
  --code-bg: #f4f3f0;
  --loader-border: rgba(88, 80, 236, 0.1);
  --tag-bg: #f1f0ed;
  --scrollbar-thumb: #d3d1cb;
  --scrollbar-track: transparent;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(29, 28, 33, 0.03), 0 1px 4px rgba(29, 28, 33, 0.02);
  --shadow-lg: 0 12px 24px rgba(29, 28, 33, 0.06), 0 4px 8px rgba(29, 28, 33, 0.04);

  color-scheme: light dark;
}

[data-theme="dark"] {
  /* Colors - Dark Theme Override */
  --bg-color: #0b0b0d; /* Deep obsidian black */
  --text-color: #e5e5eb; /* Soft silver white */
  --text-secondary: #908e9c; /* Steel grey */
  --accent-color: #818cf8; /* Light Indigo */
  --accent-light: rgba(129, 140, 248, 0.15);
  --accent-hover: #a5b4fc;
  --border-color: rgba(229, 229, 235, 0.08);
  --card-bg: rgba(18, 18, 22, 0.6);
  --card-hover-bg: #121216;
  --header-bg: rgba(11, 11, 13, 0.8);
  --code-bg: #17171c;
  --loader-border: rgba(129, 140, 248, 0.15);
  --tag-bg: #19191e;
  --scrollbar-thumb: #35343d;
  --scrollbar-track: transparent;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.2), 0 1px 4px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   RESET & SYSTEM STYLES
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease, opacity 0.2s ease;
}

/* Remove default browser focus outline for programmatically focused elements */
[tabindex="-1"]:focus {
  outline: none;
}

/* Scrollbar styling */
body {
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  scrollbar-width: thin;
}

@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
  }
  ::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
  }
}

/* ==========================================================================
   LAYOUT COMPONENTS
   ========================================================================== */

/* Reading progress bar */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-color), #a78bfa);
  z-index: 1000;
  transition: width 0.1s ease;
}

/* Glassmorphic Sticky Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background-color: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.header-container {
  width: 100%;
  max-width: var(--max-width-container);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: -0.5px;
}

.logo-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-color);
  transition: transform 0.3s ease;
}

.logo:hover .logo-dot {
  transform: scale(1.6);
}

.nav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-link {
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0.8;
}

.nav-link:hover, .nav-link.active {
  opacity: 1;
  color: var(--accent-color);
}

/* Theme Toggle Button */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border-color);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color);
  transition: background-color 0.2s, border-color 0.2s, transform 0.2s;
  padding: 0;
}

.theme-toggle-btn:hover {
  background-color: var(--border-color);
  transform: scale(1.05);
}

.theme-icon {
  width: 18px;
  height: 18px;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: absolute;
}

/* Hide and show icons based on attribute */
[data-theme="light"] .theme-icon.sun {
  opacity: 0;
  transform: scale(0) rotate(90deg);
}

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

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

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

/* Main Container */
.main-content {
  flex: 1;
  width: 100%;
  max-width: var(--max-width-container);
  margin: 0 auto;
  padding: 48px 24px 96px;
  box-sizing: border-box;
  outline: none; /* remove focus outline since we handle it programmatically */
}

/* Footer styling */
.footer {
  border-top: 1px solid var(--border-color);
  padding: 32px 24px;
  background-color: var(--bg-color);
  transition: background-color 0.3s, border-color 0.3s;
}

.footer-container {
  max-width: var(--max-width-container);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

@media (min-width: 640px) {
  .footer-container {
    flex-direction: row;
  }
}

.copyright {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0;
}

.footer-links {
  display: flex;
  gap: 24px;
}

.footer-link {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.footer-link:hover {
  color: var(--accent-color);
}

/* ==========================================================================
   HOMEPAGE / POST LIST VIEW
   ========================================================================== */
.home-view {
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.blog-intro {
  margin-bottom: 24px;
}

.blog-intro h1 {
  font-family: var(--font-heading);
  font-size: 2.8rem;
  font-weight: 800;
  margin: 0 0 12px;
  letter-spacing: -1px;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--text-color) 60%, var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.blog-intro p {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin: 0;
  max-width: 60ch;
  line-height: 1.5;
}

.posts-list {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* Post Card Layout */
.post-card {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  border-radius: var(--radius-lg);
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  transition: background-color 0.3s, border-color 0.3s, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s;
}

@media (min-width: 768px) {
  .post-card {
    flex-direction: row;
    gap: 32px;
    align-items: center;
  }
}

.post-card:hover {
  transform: translateY(-4px);
  background-color: var(--card-hover-bg);
  border-color: rgba(88, 80, 236, 0.2);
  box-shadow: var(--shadow-md);
}

/* Cover Image inside Card */
.card-image-link {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: block;
}

@media (min-width: 768px) {
  .card-image-link {
    width: 280px;
    flex-shrink: 0;
  }
}

.card-image {
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  display: block;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.post-card:hover .card-image {
  transform: scale(1.04);
}

/* Card Content Details */
.card-content {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.card-date, .card-read-time {
  display: flex;
  align-items: center;
}

.bullet-separator {
  width: 4px;
  height: 4px;
  background-color: var(--border-color);
  border-radius: 50%;
}

.card-tags {
  display: flex;
  gap: 6px;
}

.tag {
  background-color: var(--tag-bg);
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  transition: background-color 0.2s, color 0.2s;
}

.post-card:hover .tag {
  background-color: var(--accent-light);
  color: var(--accent-color);
}

.card-title {
  margin: 0 0 10px 0;
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.3px;
}

.card-title a:hover {
  color: var(--accent-color);
}

.card-summary {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin: 0 0 16px 0;
  line-height: 1.5;
}

.card-read-more {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-color);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.card-read-more svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}

.post-card:hover .card-read-more svg {
  transform: translateX(4px);
}

/* ==========================================================================
   POST DETAIL VIEW & TYPOGRAPHY
   ========================================================================== */
.post-view {
  max-width: var(--max-width-content);
  margin: 0 auto;
}

.post-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.post-back-btn:hover {
  color: var(--accent-color);
}

.post-back-btn svg {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.post-back-btn:hover svg {
  transform: translateX(-4px);
}

.post-hero-image {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: var(--radius-lg);
  object-fit: cover;
  margin-bottom: 40px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.post-header {
  margin-bottom: 32px;
}

.post-title {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.15;
  margin: 0 0 16px;
  letter-spacing: -0.8px;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.post-tags {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.post-body {
  font-size: 1.1rem;
  line-height: 1.75;
  color: var(--text-color);
}

/* Typography styles inside markdown articles */
.post-body p {
  margin-top: 0;
  margin-bottom: 24px;
}

.post-body h2 {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 40px;
  margin-bottom: 16px;
  letter-spacing: -0.4px;
}

.post-body h3 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 32px;
  margin-bottom: 12px;
  letter-spacing: -0.2px;
}

.post-body hr {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 40px 0;
}

.post-body blockquote {
  margin: 32px 0;
  padding: 16px 24px;
  border-left: 4px solid var(--accent-color);
  background-color: var(--accent-light);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
}

.post-body blockquote p:last-child {
  margin-bottom: 0;
}

.post-body ul, .post-body ol {
  margin-top: 0;
  margin-bottom: 24px;
  padding-left: 24px;
}

.post-body li {
  margin-bottom: 8px;
}

/* Code Styles */
.post-body pre {
  margin: 32px 0;
  border-radius: var(--radius-md);
  overflow-x: auto;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  background-color: #1e1e24 !important; /* Forces dark theme for code pre */
}

/* Ensure code blocks don't wrap and have clean padding */
.post-body code {
  font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  font-size: 0.9em;
  background-color: var(--code-bg);
  padding: 3px 6px;
  border-radius: 4px;
}

.post-body pre code {
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  display: block;
}

/* ==========================================================================
   STATE INDICATORS (LOADERS, ERRORS)
   ========================================================================== */
.loader-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 250px;
}

.loader {
  width: 48px;
  height: 48px;
  border: 3px solid var(--loader-border);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-view {
  text-align: center;
  padding: 48px 24px;
  max-width: 480px;
  margin: 0 auto;
}

.error-title {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 800;
  margin: 0 0 12px;
}

.error-text {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--accent-color);
  color: #ffffff;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: 30px;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

/* ==========================================================================
   NATIVE CSS VIEW TRANSITIONS
   ========================================================================== */
@media (prefers-reduced-motion: no-preference) {
  /* View Transition Names to crossfade components */
  .main-content {
    view-transition-name: main-content;
  }
  
  /* Morph the Hero cover image between views */
  .transition-hero {
    view-transition-name: hero-image;
  }
}

/* Stop all view transitions animations when user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}
