/* ============================================
   Dark Mode Technical Blog - Main Stylesheet
   ============================================ */

/* ---------- CSS Variables (Theming) ---------- */
:root {
  /* Dark theme (default) */
  --bg: #1a1b26;
  --bg-secondary: #24283b;
  --text: #c0caf5;
  --text-muted: #565f89;
  --accent: #ff79c6;
  --accent-secondary: #bb9af7;
  --link: #7dcfff;
  --link-hover: #89ddff;
  --border: #3b4261;
  --success: #9ece6a;
  --warning: #e0af68;
  --error: #f7768e;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Typography */
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
  --line-height: 1.8;
  --letter-spacing: -0.01em;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;

  /* Borders */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

[data-theme="light"] {
  --bg: #f8f9fa;
  --bg-secondary: #e9ecef;
  --text: #212529;
  --text-muted: #6c757d;
  --accent: #d63384;
  --accent-secondary: #6f42c1;
  --link: #0969da;
  --link-hover: #0550ae;
  --border: #dee2e6;
  --success: #198754;
  --warning: #fd7e14;
  --error: #dc3545;
}

/* ---------- Base Reset & Typography ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  max-width: 48rem;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
  font-family: var(--font-mono);
  font-size: 1rem;
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  color: var(--text);
  background-color: var(--bg);
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* ---------- Responsive Layout ---------- */
@media (min-width: 640px) {
  body {
    padding: var(--space-xl) var(--space-lg);
  }
}

@media (min-width: 1024px) {
  body {
    padding: var(--space-2xl) var(--space-xl);
  }
}

/* ---------- Header & Navigation ---------- */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.prompt {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--accent);
}

.prompt::after {
  content: '_';
  animation: blink 1s step-end infinite;
  color: var(--text);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Theme Toggle Button */
#theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  font-size: 1.25rem;
  color: var(--text);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

#theme-toggle:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Show/hide sun/moon icons */
.icon-sun { display: none; }
.icon-moon { display: inline; }

[data-theme="light"] .icon-sun { display: inline; }
[data-theme="light"] .icon-moon { display: none; }

/* ---------- Article Content ---------- */
article {
  line-height: var(--line-height);
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  margin: var(--space-xl) 0 var(--space-md) 0;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}

h1 {
  font-size: 2rem;
  margin-top: 0;
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--accent);
}

h2 {
  font-size: 1.5rem;
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border);
}

h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
h5, h6 { font-size: 1rem; }

/* Paragraphs */
p {
  margin: 0 0 var(--space-lg) 0;
}

/* Links */
a {
  color: var(--link);
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Code Styling ---------- */
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* Inline code */
:not(pre) > code {
  padding: 0.15em 0.4em;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
}

/* Code blocks */
pre {
  margin: var(--space-lg) 0;
  padding: var(--space-md);
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.6;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

pre code {
  padding: 0;
  background: none;
  border: none;
  color: inherit;
}

/* Scrollbar styling for code blocks */
pre::-webkit-scrollbar {
  height: 8px;
}

pre::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: 4px;
}

pre::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

pre::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---------- Blockquotes ---------- */
blockquote {
  margin: var(--space-lg) 0;
  padding: var(--space-md) var(--space-lg);
  border-left: 4px solid var(--accent);
  background-color: var(--bg-secondary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
  color: var(--text-muted);
}

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

/* ---------- Lists ---------- */
ul, ol {
  margin: 0 0 var(--space-lg) 0;
  padding-left: var(--space-xl);
}

li {
  margin-bottom: var(--space-sm);
}

li::marker {
  color: var(--accent);
}

/* Nested lists */
ul ul, ul ol, ol ul, ol ol {
  margin-top: var(--space-sm);
  margin-bottom: 0;
}

/* ---------- Tables ---------- */
table {
  width: 100%;
  margin: var(--space-lg) 0;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border: 1px solid var(--border);
}

th {
  background-color: var(--bg-secondary);
  font-weight: 600;
}

tr:hover {
  background-color: var(--bg-secondary);
}

/* ---------- Horizontal Rule ---------- */
hr {
  margin: var(--space-2xl) 0;
  border: none;
  border-top: 1px solid var(--border);
}

/* ---------- Images ---------- */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: var(--space-lg) auto;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ---------- Selection ---------- */
::selection {
  background-color: var(--accent);
  color: var(--bg);
}

/* ---------- Focus States for Accessibility ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Utility Classes ---------- */
.text-muted {
  color: var(--text-muted);
}

.text-accent {
  color: var(--accent);
}

/* ---------- Mobile Optimizations ---------- */
@media (max-width: 480px) {
  html {
    font-size: 15px;
  }

  h1 {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.3rem;
  }

  pre {
    font-size: 0.8rem;
    padding: var(--space-sm);
  }

  table {
    font-size: 0.8rem;
  }

  th, td {
    padding: var(--space-xs) var(--space-sm);
  }
}

/* ---------- Post List (Home Page) ---------- */
.post-list {
  list-style: none;
  padding: 0;
  margin: var(--space-lg) 0;
}

.post-list li {
  margin-bottom: 0;
  padding: var(--space-md) var(--space-lg);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.post-list li + li {
  margin-top: var(--space-md);
}

.post-list li:hover {
  border-color: var(--accent);
  transform: translateX(4px);
}

.post-list li a {
  display: block;
  font-size: 1.1rem;
  font-weight: 500;
  text-transform: capitalize;
}

.post-list li a::before {
  content: '> ';
  color: var(--accent);
}

/* ---------- Print Styles ---------- */
@media print {
  body {
    background: white;
    color: black;
    max-width: 100%;
  }

  .site-header,
  #theme-toggle {
    display: none;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  pre {
    border: 1px solid #ccc;
    box-shadow: none;
  }
}
