/* =========================================
   1. Design Tokens & Variables
   ========================================= */
:root {
  /* Fonts */
  --font-main:
    "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
  --font-mono: "Courier New", monospace;

  /* Layout */
  --container-width: 1000px;
  --header-height: 60px;

  /* Colors - Light Mode (Default) */
  --text-main: #1a1a1a;
  --text-muted: #666666;
  --text-inverted: #e0e0e0; /* Used for code text in light mode */

  --bg-body: #e8f4f8;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f5f5f5; /* Light grey headers, hover states */
  --bg-surface-hover: #f0f0f0;

  --border-color: #e0e0e0;
  --border-color-strong: #dddddd;
  --border-focus: #1a1a1a;

  --color-primary: #0066cc;
  --color-primary-hover: #0052a3;
  --color-primary-transparent: rgba(0, 102, 204, 0.3);

  /* Special handling for code blocks (always dark-ish) */
  --bg-code: #363535;
  --bg-code-header: #2a2a2a;
  --border-code: #2a2a2a;

  /* Callouts */
  --callout-default: 158, 158, 158;
}

/* Colors - Dark Mode Override */
body.dark-mode {
  --text-main: #c8c8c8;
  --text-muted: #a0a0a0;
  --text-inverted: #c8c8c8;

  --bg-body: #252525;
  --bg-surface: #2a2a2a;
  --bg-surface-alt: #303030; /* Slightly lighter than surface */
  --bg-surface-hover: #383838;

  --border-color: #3a3a3a;
  --border-color-strong: #444444;
  --border-focus: #c8c8c8;

  --color-primary: #6ba3ff;
  --color-primary-hover: #5090e0;
  --color-primary-transparent: rgba(107, 163, 255, 0.4);

  --bg-code: #2a2a2a;
  --bg-code-header: #303030;
  --border-code: #444444;
}

/* =========================================
   2. Reset & Global Styles
   ========================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  height: 100%;
}

body {
  font-family: var(--font-main);
  line-height: 1.6;
  color: var(--text-main);
  background-color: var(--bg-body);
  padding: 20px;
  font-size: 16px; /* 1rem */
  overflow-x: hidden;
}

.container {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 20px 40px;
}

/* Typography */
h1,
h2,
h3 {
  margin: 1.5em 0 0.5em 0;
  font-weight: 600;
  color: var(--text-main);
}

h1 {
  font-size: 1.5em;
}
h1:first-child {
  margin-top: 0;
}
h2 {
  font-size: 1.2em;
}

/* Clickable h2 links */
h2 a {
  color: inherit;
  text-decoration: none;
}
h2 a:hover {
  text-decoration: underline;
}

p {
  margin: 1em 0;
}

ul,
ol {
  margin: 1em 0;
  padding-left: 2em;
}

li {
  margin: 0.5em 0;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
  margin: 1em 0;
}

/* =========================================
   3. Site Header & Top Nav
   ========================================= */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}

.main-header h1 {
  margin: 0;
}

.top-nav {
  max-width: var(--container-width);
  margin: 0 auto 1em auto;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.top-nav .site-name {
  font-size: 1.5em;
  font-weight: 600;
}

.top-nav .site-name a {
  color: var(--text-main);
  text-decoration: none;
}

.top-nav .nav-right {
  display: flex;
  gap: 1.5em;
  align-items: center;
}

.top-nav .nav-right a {
  color: var(--text-main);
  text-decoration: none;
}
.top-nav .nav-right a:hover {
  text-decoration: underline;
}

/* Menu Toggle (Mobile) */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  padding: 0.3em;
  cursor: pointer;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
}
.menu-toggle svg {
  width: 28px;
  height: 28px;
}

/* Dark Mode Toggle */
.dark-mode-toggle {
  background: none;
  border: none;
  color: var(--text-main);
  padding: 0.5em;
  cursor: pointer;
  border-radius: 8px;
  width: 44px; /* adjusted generic size */
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.top-nav .nav-right .dark-mode-toggle {
  width: 36px;
  height: 36px;
  position: static;
}
.top-nav .nav-right .dark-mode-toggle svg {
  width: 24px;
  height: 24px;
}

.dark-mode-toggle:hover {
  background-color: var(--bg-surface-alt);
}
body.dark-mode .dark-mode-toggle {
  border-color: var(--text-main);
}

/* Icon Switching Logic */
.dark-mode-toggle .sun-icon {
  display: block;
}
.dark-mode-toggle .moon-icon {
  display: none;
}
body.dark-mode .dark-mode-toggle .sun-icon {
  display: none;
}
body.dark-mode .dark-mode-toggle .moon-icon {
  display: block;
}

/* =========================================
   4. Search Component
   ========================================= */
.search-container {
  position: relative;
}

.search-input {
  border: 0.7px solid var(--border-focus);
  background: none;
  color: var(--text-main);
  padding: 0.3em 0.8em;
  font-family: var(--font-main);
  font-size: 0.9em;
  width: 200px;
}
.search-input::placeholder {
  color: var(--text-muted);
}
.search-input:focus {
  outline: none;
}

.search-results {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5em;
  width: 400px;
  max-height: 500px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-color-strong);
  box-shadow: 0 4px 12px var(--shadow-color, rgba(0, 0, 0, 0.15));
  z-index: 1000;
}

/* Fix generic shadow for dark mode via localized var or specific override */
body.dark-mode .search-results {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.search-result-item {
  display: block;
  padding: 1em;
  border-bottom: 1px solid var(--bg-surface-alt);
  text-decoration: none;
  color: inherit;
  transition: background-color 0.2s;
}
.search-result-item:hover {
  background-color: var(--bg-surface-alt);
}
.search-result-item:last-child {
  border-bottom: none;
}

.search-result-title {
  font-weight: 600;
  margin-bottom: 0.3em;
  color: var(--text-main);
}

.search-result-meta {
  display: flex;
  gap: 0.8em;
  font-size: 0.85em;
  color: var(--text-muted);
  margin-bottom: 0.4em;
}

.search-result-type {
  text-transform: capitalize;
  font-weight: 500;
}

.search-result-summary {
  font-size: 0.9em;
  color: var(--text-muted);
  line-height: 1.4;
  /* Adjust specific grey if needed, but muted usually works */
  filter: brightness(0.9);
}

.search-no-results {
  padding: 1.5em;
  text-align: center;
  color: var(--text-muted);
}
.search-no-results code {
  background: var(--bg-surface-hover);
  padding: 0.2em 0.4em;
  font-size: 0.9em;
  border-radius: 3px;
}

/* =========================================
   5. Posts & Tags
   ========================================= */
.post-list {
  list-style: none;
  padding: 0;
}
.post-list li {
  margin: 1.5em 0;
  padding: 0;
}
.post-list li a {
  font-size: 1.2em;
}
.post-list li p {
  margin: 0.3em 0 0 0;
}

.post-meta {
  color: var(--text-muted);
  font-size: 0.9em;
  margin: 0.2em 0 0 0;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin: 0.3em 0 0 0;
}

.tag {
  display: inline-block;
  background-color: var(--bg-surface-hover);
  color: var(--text-main);
  padding: 0.2em 0.6em;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.2s;
}
.tag:hover {
  background-color: var(
    --border-color
  ); /* slightly darker than surface-hover */
  text-decoration: none;
}

/* Fix tag size in post lists */
.post-list .tag {
  font-size: 0.8em;
}

.tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin: 1em 0 2em 0;
}

.back-link {
  margin: 0 0 1em 0;
  font-size: 0.9em;
}
.back-link a {
  color: var(--text-muted);
}

/* =========================================
   6. Navigation Links (Bottom)
   ========================================= */
.nav-links {
  display: flex;
  justify-content: space-between;
  margin: 2em 0;
  padding: 1em 0;
}

.nav-links a {
  padding: 0.5em 1em;
  border: none;
  transition: background-color 0.2s;
  flex-basis: 48%;
  /* Border color was explicitly handled in dark mode, but transparent in light? 
     Original CSS had `border: none` then `dark-mode... border-color`. 
     Assuming generic hover effect. */
}

body.dark-mode .nav-links a {
  border: 1px solid var(--text-main);
  border-width: 0 0 0 0; /* Original logic was fuzzy here, cleaning up to background only for consistency */
}

.nav-links a:hover {
  text-decoration: none;
  background-color: var(--bg-surface-alt);
}

/* Link Buttons (Linktree style) */
.link-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.8em;
  max-width: 240px;
  margin: 2em auto;
}

.link-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  padding: 0.4em 1em;
  text-align: center;
  text-decoration: none;
  color: var(--text-main);
  border: none;
  border-radius: 8px;
  transition: background-color 0.2s;
  font-weight: 500;
}

.link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.link-icon svg {
  width: 20px;
  height: 20px;
}

.link-button:hover {
  background-color: var(--bg-surface-alt);
  text-decoration: none;
}

/* =========================================
   7. Pagination
   ========================================= */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 2em 0;
  padding: 1em 0;
  gap: 1em;
  flex-wrap: wrap;
}

.pagination-link {
  padding: 0.5em 1em;
  border: none;
  text-decoration: none;
  transition: background-color 0.2s;
  white-space: nowrap;
}
.pagination-link:hover {
  background-color: var(--bg-surface-alt);
  text-decoration: none;
}

.pagination-disabled {
  padding: 0.5em 1em;
  color: #999; /* This is light grey in both modes usually, or muted */
  white-space: nowrap;
}
body.dark-mode .pagination-disabled {
  color: #707070;
}

.pagination-info {
  color: var(--text-muted);
  font-size: 0.9em;
  white-space: nowrap;
}

/* =========================================
   8. Footer & Callouts
   ========================================= */
.site-footer {
  max-width: var(--container-width);
  margin: 1em auto 0 auto;
  padding: 1em 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9em;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.site-footer p {
  margin: 0.3em 0;
}

.callout {
  margin: 1em 0;
  padding: 0;
  border-left: 4px solid rgb(var(--callout-color, 158, 158, 158));
  background-color: rgba(var(--callout-color, 158, 158, 158), 0.1);
  border-radius: 4px;
  overflow: hidden;
}

body.dark-mode .callout {
  background-color: rgba(var(--callout-color, 158, 158, 158), 0.15);
}

.callout-title {
  padding: 0.5em 1em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.callout-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.callout-icon svg {
  width: 20px;
  height: 20px;
}

.callout-title-text {
  flex: 1;
}

.callout-content {
  padding: 0 1em 0.5em 1em;
  color: var(--text-main);
}
.callout-content p:first-child {
  margin-top: 0;
}
.callout-content p:last-child {
  margin-bottom: 0;
}

/* =========================================
   9. Mobile / Media Queries
   ========================================= */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  .container {
    padding: 10px;
  }
  h1 {
    font-size: 1.3em;
  }
  h2 {
    font-size: 1.1em;
  }

  /* Nav */
  .top-nav {
    flex-wrap: wrap;
    position: relative;
  }
  .menu-toggle {
    display: flex;
  }
  .top-nav .nav-right {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 1em;
    padding: 1em 0;
    align-items: flex-start;
  }
  .top-nav .nav-right.nav-open {
    display: flex;
  }

  /* Search */
  .search-results {
    width: 90vw;
    max-width: 400px;
  }
  .search-container {
    width: 100%;
  }
  .search-input {
    width: 100%;
  }

  /* Links & Pagination */
  .link-button {
    padding: 0.35em 0.9em;
    font-size: 0.95em;
  }
  .nav-links {
    flex-direction: column;
    gap: 1em;
  }
  .nav-links a {
    flex-basis: auto;
    width: 100%;
  }

  .pagination {
    justify-content: center;
    gap: 0.5em;
  }
  .pagination-link,
  .pagination-disabled {
    padding: 0.4em 0.8em;
    font-size: 0.9em;
  }
}
