/* ============================================================
   CSS Custom Properties
   ============================================================ */

:root,
html[data-theme="light"] {
  --background: #ddd;
  --foreground: #181818;
  --accent: #208040;
  --muted: #fff;
  --border: #208040;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --max-width: 48rem;
  --spacing: 1rem;
}

html[data-theme="dark"] {
  --background: #202320;
  --foreground: #e8e8e8;
  --accent: #20ff40;
  --muted: #404440;
  --border: #208040;
}

/* ============================================================
   Reset & Base
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-mono);
  background-color: var(--background);
  color: var(--foreground);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--foreground);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
  transition: color 0.15s ease;
}

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

img {
  max-width: 100%;
  height: auto;
  display: block;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ============================================================
   Layout
   ============================================================ */

.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--spacing);
}

main {
  flex: 1;
  padding-block: 2rem;
}

/* ============================================================
   Reading Progress Bar
   ============================================================ */

#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background-color: var(--accent);
  z-index: 200;
  transition: width 0.1s linear;
  pointer-events: none;
}

/* ============================================================
   Skip Link
   ============================================================ */

.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--accent);
  color: var(--background);
  padding: 0.5rem 1rem;
  z-index: 100;
  text-decoration: none;
  font-family: var(--font-mono);
}

.skip-link:focus {
  top: 0;
}

/* ============================================================
   Header & Navigation
   ============================================================ */

#site-header {
  background-color: var(--background);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

#top-nav-wrap {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--spacing);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3.5rem;
  gap: 1rem;
}

#site-logo {
  font-size: 1rem;
  font-weight: bold;
  text-decoration: none;
  color: var(--foreground);
  white-space: nowrap;
  flex-shrink: 0;
}

#site-logo:hover {
  color: var(--accent);
}

/* Desktop nav */
#primary-nav {
  display: flex;
  align-items: center;
  gap: 0;
}

#menu-items {
  display: flex;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0.25rem;
}

#menu-items li a {
  display: block;
  padding: 0.375rem 0.625rem;
  text-decoration: none;
  color: var(--foreground);
  font-size: 0.875rem;
  border: 1px solid transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}

#menu-items li a:hover,
#menu-items li a:focus {
  color: var(--accent);
  border-color: var(--border);
  outline: none;
}

#menu-items li a[aria-current="page"] {
  border-color: var(--border);
  color: var(--accent);
}

/* Theme toggle button */
#theme-toggle {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--foreground);
  padding: 0.375rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, color 0.15s ease;
  line-height: 1;
}

#theme-toggle:hover {
  border-color: var(--border);
  color: var(--accent);
}

#theme-toggle svg {
  display: block;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Light mode: show sun, hide moon */
html[data-theme="light"] #icon-sun {
  transform: rotate(0deg) scale(1);
  opacity: 1;
}
html[data-theme="light"] #icon-moon {
  display: none;
}

/* Dark mode: show moon, hide sun */
html[data-theme="dark"] #icon-moon {
  transform: rotate(0deg) scale(1);
  opacity: 1;
}
html[data-theme="dark"] #icon-sun {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  #theme-toggle svg {
    transition: none;
  }
}

/* Hamburger button */
#menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  padding: 0.375rem 0.625rem;
  line-height: 1;
}

/* Desktop: always show nav regardless of .hidden class */
@media (min-width: 641px) {
  #primary-nav {
    display: flex !important;
  }
}

/* Mobile nav */
@media (max-width: 640px) {
  #menu-btn {
    display: block;
  }

  #primary-nav {
    position: absolute;
    top: 3.5rem;
    left: 0;
    right: 0;
    background-color: var(--background);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem var(--spacing);
    flex-direction: column;
    align-items: flex-start;
  }

  #menu-items {
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    gap: 0;
  }

  #menu-items li {
    width: 100%;
  }

  #menu-items li a {
    padding: 0.5rem 0;
    border: none;
    border-bottom: 1px solid transparent;
    width: 100%;
  }

  #primary-nav.hidden {
    display: none;
  }
}

/* ============================================================
   Breadcrumb
   ============================================================ */

.breadcrumb {
  font-size: 0.8125rem;
  margin-bottom: 1.5rem;
  color: var(--foreground);
  opacity: 0.7;
}

.breadcrumb a {
  color: var(--foreground);
  text-decoration-color: var(--border);
}

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

.breadcrumb .sep {
  margin-inline: 0.35rem;
}

/* ============================================================
   Hero Section (Homepage)
   ============================================================ */

.hero {
  padding-block: 2rem 1rem;
}

.hero h1 {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 0 0 0.75rem;
  font-family: var(--font-mono);
}

.hero p {
  margin: 0;
  line-height: 1.6;
  max-width: 40rem;
}

/* ============================================================
   Section Headings
   ============================================================ */

.section-heading {
  font-size: 1.125rem;
  font-weight: bold;
  margin: 2rem 0 1rem;
  font-family: var(--font-mono);
}

.section-heading::before {
  content: "## ";
  color: var(--accent);
}

/* ============================================================
   Post List (archive, home)
   ============================================================ */

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

.post-list-item {
  padding-block: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.post-list-item:first-child {
  border-top: 1px solid var(--border);
}

.post-list-item h2,
.post-list-item h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: bold;
  font-family: var(--font-mono);
}

.post-list-item h2 a,
.post-list-item h3 a {
  text-decoration: none;
  color: var(--foreground);
}

.post-list-item h2 a:hover,
.post-list-item h3 a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent);
}

.post-meta {
  font-size: 0.8125rem;
  color: var(--foreground);
  opacity: 0.7;
  margin-bottom: 0.5rem;
}

.post-excerpt {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.post-excerpt p {
  margin: 0;
}

/* ============================================================
   Single Post
   ============================================================ */

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

.post-title {
  font-size: 1.375rem;
  font-weight: bold;
  margin: 0 0 0.5rem;
  line-height: 1.3;
  font-family: var(--font-mono);
}

.post-date {
  font-size: 0.8125rem;
  opacity: 0.7;
}

/* Post tags */
.post-tags {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.post-tag {
  font-size: 0.8125rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--foreground);
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

/* Post featured image */
.post-thumbnail {
  margin-bottom: 2rem;
}

.post-thumbnail img {
  width: 100%;
  border: 1px solid var(--border);
}

/* ============================================================
   Prose / Post Content
   ============================================================ */

.prose {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--foreground);
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  font-family: var(--font-mono);
  font-weight: bold;
  margin: 2rem 0 0.75rem;
  line-height: 1.3;
}

.prose h1 { font-size: 1.375rem; }
.prose h2 { font-size: 1.25rem; }
.prose h3 { font-size: 1.125rem; }
.prose h4 { font-size: 1rem; }

.prose h2::before { content: "## "; color: var(--accent); }
.prose h3::before { content: "### "; color: var(--accent); }
.prose h4::before { content: "#### "; color: var(--accent); }

.prose p {
  margin: 0 0 1.25rem;
}

.prose a {
  color: var(--foreground);
  text-decoration: underline;
  text-decoration-color: var(--accent);
}

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

.prose ul,
.prose ol {
  margin: 0 0 1.25rem;
  padding-left: 1.5rem;
}

.prose li {
  margin-bottom: 0.375rem;
}

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

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

.prose blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.5rem 0 0.5rem 1.25rem;
  color: var(--foreground);
  opacity: 0.85;
}

.prose blockquote p {
  margin: 0;
}

.prose code {
  background-color: var(--muted);
  padding: 0.125rem 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.875em;
  border: 1px solid var(--border);
}

.prose pre {
  background-color: var(--muted);
  border: 1px solid var(--border);
  padding: 1rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  line-height: 1.5;
}

.prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9375rem;
}

.prose th,
.prose td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.prose th {
  background-color: var(--muted);
  font-weight: bold;
}

.prose img {
  max-width: 100%;
  border: 1px solid var(--border);
  margin: 1.5rem 0;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ============================================================
   Tags Index Page
   ============================================================ */

.tags-index {
  margin-top: 1.5rem;
}

.tag-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-list li a {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--foreground);
  font-size: 0.875rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tag-list li a:hover {
  background-color: var(--accent);
  color: var(--background);
  border-color: var(--accent);
}

.tag-count {
  opacity: 0.6;
  font-size: 0.8125rem;
}

/* ============================================================
   Search Form
   ============================================================ */

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.search-form input[type="search"] {
  flex: 1;
  background-color: var(--muted);
  border: 1px solid var(--border);
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  padding: 0.5rem 0.75rem;
  outline: none;
}

.search-form input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.search-form button[type="submit"] {
  background-color: var(--accent);
  border: 1px solid var(--accent);
  color: var(--background);
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.search-form button[type="submit"]:hover {
  opacity: 0.85;
}

/* Inline search in nav */
#nav-search-form {
  display: flex;
  align-items: center;
}

#nav-search-input {
  background-color: var(--muted);
  border: 1px solid var(--border);
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 0.25rem 0.5rem;
  width: 8rem;
  outline: none;
  transition: width 0.2s ease, border-color 0.15s ease;
}

#nav-search-input:focus {
  border-color: var(--accent);
  width: 12rem;
}

/* ============================================================
   Heading Anchor Links
   ============================================================ */

.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  position: relative;
}

.heading-anchor {
  position: absolute;
  left: -1.25rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.875em;
  text-decoration: none;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.15s ease;
  padding-right: 0.25rem;
  line-height: 1;
}

.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.prose h4:hover .heading-anchor,
.prose h5:hover .heading-anchor,
.prose h6:hover .heading-anchor,
.heading-anchor:focus {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .heading-anchor {
    transition: none;
  }
}

/* ============================================================
   Copy Code Button
   ============================================================ */

.prose pre {
  position: relative;
}

.copy-code-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--background);
  border: 1px solid var(--border);
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
  line-height: 1.4;
}

.prose pre:hover .copy-code-btn,
.copy-code-btn:focus {
  opacity: 1;
}

.copy-code-btn.copied {
  background-color: var(--accent);
  color: var(--background);
  border-color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  .copy-code-btn {
    transition: none;
  }
}

/* ============================================================
   Back to Top Button
   ============================================================ */

#back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--background);
  border: 1px solid var(--border);
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 0.375rem 0.625rem;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, color 0.15s ease, border-color 0.15s ease;
  z-index: 50;
}

#back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

#back-to-top:hover {
  color: var(--accent);
  border-color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  #back-to-top {
    transition: none;
  }
}

/* ============================================================
   Go Back Button
   ============================================================ */

.post-header-top {
  margin-bottom: 0.75rem;
}

#go-back {
  background: none;
  border: none;
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 0;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s ease, color 0.15s ease;
}

#go-back:hover {
  opacity: 1;
  color: var(--accent);
}

#go-back.hidden {
  display: none;
}

/* ============================================================
   Pagination
   ============================================================ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.pagination a,
.pagination span {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--foreground);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.pagination a:hover {
  background-color: var(--accent);
  color: var(--background);
  border-color: var(--accent);
}

.pagination .current {
  background-color: var(--accent);
  color: var(--background);
  border-color: var(--accent);
}

.pagination .disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================================
   No Results / 404
   ============================================================ */

.no-results {
  padding-block: 2rem;
}

.no-results h1 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

/* ============================================================
   Page Header (archive titles)
   ============================================================ */

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

.page-header h1 {
  font-size: 1.375rem;
  font-weight: bold;
  margin: 0 0 0.5rem;
  font-family: var(--font-mono);
}

.page-header p {
  margin: 0;
  font-size: 0.9375rem;
  opacity: 0.75;
}

/* ============================================================
   Footer
   ============================================================ */

#site-footer {
  border-top: 1px solid var(--border);
  padding-block: 1.5rem;
  margin-top: auto;
}

.footer-inner {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--spacing);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.footer-social {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}

.footer-social li a {
  text-decoration: none;
  color: var(--foreground);
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.footer-social li a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.footer-copyright {
  font-size: 0.8125rem;
  opacity: 0.7;
}

/* ============================================================
   Utility Classes
   ============================================================ */

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
