/* Fonts - Aleo slab serif
   Source: https://github.com/AlessioLaiso/aleo (SIL Open Font License) */
@font-face {
  font-family: 'Aleo';
  src: url('/fonts/Aleo-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Aleo';
  src: url('/fonts/Aleo-Italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'Aleo';
  src: url('/fonts/Aleo-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Aleo';
  src: url('/fonts/Aleo-BoldItalic.woff2') format('woff2');
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}

/* ---- Theme Custom Properties ---- */

:root {
  --color-bg: #faf9f7;
  --color-text: #2d2d2d;
  --color-heading: #1a1a1a;
  --color-text-muted: #555;
  --color-link: #5b4a3f;
  --color-link-underline: #c4b5a5;
  --color-link-hover: #3a2e26;
  --color-border: #ddd5cc;
  --color-border-accent: #c4b5a5;
  --color-code-bg: #eee8e0;
  --color-pre-bg: #2b303b;
  --color-pre-text: #c0c5ce;
  --color-nav: #666;
  --color-social: #888;
  --color-faint: #999;
  --status-switched-bg: #dff0d8;
  --status-switched-text: #3c763d;
  --status-testing-bg: #e8dff0;
  --status-testing-text: #6b3fa0;
  --status-researching-bg: #fcf8e3;
  --status-researching-text: #8a6d3b;
  --status-guide-bg: #d9edf7;
  --status-guide-text: #31708f;
}

[data-theme="dark"] {
  --color-bg: #1c1917;
  --color-text: #d6d3d1;
  --color-heading: #f5f5f4;
  --color-text-muted: #a8a29e;
  --color-link: #c4b5a5;
  --color-link-underline: #6b5d52;
  --color-link-hover: #e7ddd4;
  --color-border: #44403c;
  --color-border-accent: #57534e;
  --color-code-bg: #292524;
  --color-pre-bg: #1a1820;
  --color-pre-text: #c0c5ce;
  --color-nav: #a8a29e;
  --color-social: #78716c;
  --color-faint: #78716c;
  --status-switched-bg: #1a3a1a;
  --status-switched-text: #6fcf6f;
  --status-testing-bg: #2a1a3a;
  --status-testing-text: #b88adf;
  --status-researching-bg: #3a3018;
  --status-researching-text: #d4b86a;
  --status-guide-bg: #1a2a3a;
  --status-guide-text: #6ab4d6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #1c1917;
    --color-text: #d6d3d1;
    --color-heading: #f5f5f4;
    --color-text-muted: #a8a29e;
    --color-link: #c4b5a5;
    --color-link-underline: #6b5d52;
    --color-link-hover: #e7ddd4;
    --color-border: #44403c;
    --color-border-accent: #57534e;
    --color-code-bg: #292524;
    --color-pre-bg: #1a1820;
    --color-pre-text: #c0c5ce;
    --color-nav: #a8a29e;
    --color-social: #78716c;
    --color-faint: #78716c;
    --status-switched-bg: #1a3a1a;
    --status-switched-text: #6fcf6f;
    --status-testing-bg: #2a1a3a;
    --status-testing-text: #b88adf;
    --status-researching-bg: #3a3018;
    --status-researching-text: #d4b86a;
    --status-guide-bg: #1a2a3a;
    --status-guide-text: #6ab4d6;
  }
}

/* ---- Reset & Base ---- */

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

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

body {
  font-family: 'Aleo', Georgia, 'Times New Roman', serif;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.7;
}

/* ---- Typography ---- */

h1, h2, h3, h4 {
  font-family: 'Aleo', Georgia, 'Times New Roman', serif;
  color: var(--color-heading);
  line-height: 1.25;
  margin-bottom: 0.5em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

p {
  margin-bottom: 1.25em;
}

a {
  color: var(--color-link);
  text-decoration-color: var(--color-link-underline);
  text-underline-offset: 0.15em;
  transition: color 0.15s ease;
}

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

blockquote {
  border-left: 3px solid var(--color-border-accent);
  padding-left: 1.25rem;
  margin: 1.5em 0;
  color: var(--color-text-muted);
  font-style: italic;
}

code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9em;
  background: var(--color-code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

pre {
  background: var(--color-pre-bg);
  color: var(--color-pre-text);
  padding: 1.25rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.5em 0;
  line-height: 1.5;
}

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

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

ul, ol {
  margin-bottom: 1.25em;
  padding-left: 1.5em;
}

li {
  margin-bottom: 0.35em;
}

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

figure {
  margin: 1.5em 0;
  text-align: center;
}

figure img {
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

figcaption {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.5em;
}

/* ---- Layout ---- */

.site-layout {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.site-main {
  min-width: 0;
}

/* ---- Sidebar / Nav ---- */

.sidebar {
  margin-bottom: 2.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1rem;
}

.sidebar .site-footer {
  display: none;
}

.site-title {
  font-family: 'Aleo', Georgia, 'Times New Roman', serif;
  font-size: 1.35rem;
  color: var(--color-heading);
  text-decoration: none;
}

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

.nav-links {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  padding: 0;
  margin: 0;
}

.nav-links a {
  font-size: 0.9rem;
  color: var(--color-nav);
  text-decoration: none;
}

.nav-links a:hover {
  color: var(--color-text);
}

/* ---- Search Button ---- */

.search-button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-social);
  display: flex;
  align-items: center;
  padding: 0.25rem;
  transition: color 0.15s ease;
}

.search-button:hover {
  color: var(--color-text);
}

.search-button svg {
  width: 18px;
  height: 18px;
}

/* ---- Search Modal ---- */

.search-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.4);
  justify-content: center;
  align-items: flex-start;
  padding-top: 15vh;
}

.search-modal-overlay.active {
  display: flex;
}

.search-modal {
  width: 90vw;
  max-width: 32rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

[data-theme="dark"] .search-modal {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .search-modal {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

.search-modal-header {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--color-border);
}

.search-modal-header .search-input {
  flex: 1;
  padding: 0.75em 1em;
  font-family: inherit;
  font-size: 1rem;
  color: var(--color-text);
  background: transparent;
  border: none;
  outline: none;
}

.search-modal-header .search-input::placeholder {
  color: var(--color-faint);
}

.search-modal-close {
  padding: 0.5em 0.75em;
  font-size: 1.25rem;
  color: var(--color-faint);
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s ease;
}

.search-modal-close:hover {
  color: var(--color-text);
}

.search-results {
  max-height: 50vh;
  overflow-y: auto;
}

.search-results:empty {
  display: none;
}

.search-result-item {
  display: block;
  padding: 0.6em 1em;
  text-decoration: none;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.active {
  background: var(--color-code-bg);
  color: var(--color-text);
  text-decoration: none;
}

.search-result-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-heading);
}

.search-result-snippet {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.15em;
}

.search-no-results {
  padding: 1em;
  font-size: 0.85rem;
  color: var(--color-faint);
}

/* ---- Featured Post (homepage) ---- */

.featured-post h2 {
  font-size: 1.75rem;
  margin-bottom: 0.2em;
}

.featured-post h2 a {
  color: var(--color-heading);
  text-decoration: none;
}

.featured-post h2 a:hover {
  color: var(--color-link);
}

.featured-post p {
  color: var(--color-text-muted);
}

.read-more {
  font-size: 0.9rem;
}

/* ---- Earlier Posts Grid ---- */

.earlier-posts h2 {
  margin-bottom: 1.25rem;
}

.posts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.post-card h3 {
  margin-bottom: 0.15em;
}

.post-card h3 a {
  color: var(--color-heading);
  text-decoration: none;
}

.post-card h3 a:hover {
  color: var(--color-link);
}

.post-card p {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.5em;
}

/* ---- Post Listings (section pages) ---- */

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

.post-summary h3 {
  margin-bottom: 0.15em;
}

.post-summary h3 a {
  color: var(--color-heading);
  text-decoration: none;
}

.post-summary h3 a:hover {
  color: var(--color-link);
}

.post-summary p {
  color: var(--color-text-muted);
  margin-bottom: 0.5em;
}

/* ---- Social Links ---- */

.social-links {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.social-links a {
  color: var(--color-social);
  text-decoration: none;
  display: flex;
  transition: color 0.15s ease;
}

.social-links a:hover {
  color: var(--color-text);
}

/* ---- Top Controls (Search + Theme Toggle) ---- */

.top-controls {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* ---- Theme Toggle ---- */

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-social);
  display: flex;
  align-items: center;
  padding: 0.25rem;
  transition: color 0.15s ease;
}

.theme-toggle:hover {
  color: var(--color-text);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun {
    display: block;
  }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    display: none;
  }
}

/* ---- Post Meta ---- */

.post-meta {
  font-size: 0.85rem;
  color: var(--color-social);
  margin-bottom: 0.5em;
}

.reading-time {
  color: var(--color-faint);
}

/* ---- Status Badges ---- */

.status-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.2em 0.65em;
  border-radius: 3px;
  margin-bottom: 0.3em;
}

.status-switched {
  background: var(--status-switched-bg);
  color: var(--status-switched-text);
}

.status-testing {
  background: var(--status-testing-bg);
  color: var(--status-testing-text);
}

.status-researching {
  background: var(--status-researching-bg);
  color: var(--status-researching-text);
}

.status-guide {
  background: var(--status-guide-bg);
  color: var(--status-guide-text);
}

/* ---- Tags ---- */

.post-tags {
  margin: 0.5em 0 1em;
}

.tag {
  display: inline-block;
  font-size: 0.8rem;
  background: var(--color-code-bg);
  color: var(--color-link);
  padding: 0.15em 0.6em;
  border-radius: 3px;
  text-decoration: none;
  margin-right: 0.3em;
  margin-bottom: 0.3em;
}

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

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.tag-cloud-item {
  font-size: 1rem;
  padding: 0.3em 0.8em;
}

.tag-count {
  color: var(--color-faint);
  font-size: 0.85em;
}

/* ---- Single Post ---- */

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

.post-header h1 {
  margin-bottom: 0.2em;
}

.post-content h2,
.post-content h3,
.post-content h4 {
  position: relative;
}

.post-content h2 {
  margin-top: 2rem;
}

.post-content h3 {
  margin-top: 1.5rem;
}

.zola-anchor {
  position: absolute;
  right: 100%;
  padding-right: 0.25em;
  font-size: 0.75em;
  font-weight: 400;
  text-decoration: none;
  color: var(--color-border-accent);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.zola-anchor:hover {
  color: var(--color-link-underline);
}

h2:hover .zola-anchor,
h3:hover .zola-anchor,
h4:hover .zola-anchor {
  opacity: 0.6;
}

/* ---- Post Navigation ---- */

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
}

.post-nav a {
  font-size: 0.9rem;
}

.post-nav-next {
  margin-left: auto;
}

/* ---- Footer ---- */

.site-footer p {
  font-size: 0.85rem;
  color: var(--color-faint);
  margin-bottom: 0.25em;
}

/* ---- Section Pages ---- */

.section-description {
  color: var(--color-nav);
  margin-bottom: 2rem;
}

/* ---- Responsive ---- */

@media (max-width: 600px) {
  html {
    font-size: 16px;
  }

  .site-layout {
    padding: 1.25rem 1rem;
  }

  .sidebar {
    flex-direction: column;
    gap: 0.5rem;
  }

  .post-nav {
    flex-direction: column;
  }
}

@media (min-width: 40rem) {
  .posts-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---- Sidebar layout on wide screens ---- */

@media (min-width: 60rem) {
  .site-layout {
    display: grid;
    grid-template-columns: 12rem 1fr;
    gap: 3rem;
    max-width: 60rem;
    padding: 2.5rem 3rem;
    align-items: start;
  }

  .sidebar {
    position: sticky;
    top: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0;
    border-right: 1px solid var(--color-border);
    padding-right: 2rem;
  }

  .sidebar .site-title {
    font-size: 1.2rem;
    margin-bottom: 1rem;
  }

  .nav-links {
    flex-direction: column;
    gap: 0.5rem;
  }

  .nav-links a {
    font-size: 0.95rem;
  }

  .sidebar .social-links {
    margin-top: 1.5rem;
  }

  .sidebar .site-footer {
    display: block;
    margin-top: auto;
    padding-top: 2rem;
  }

  .site-main {
    max-width: 42rem;
  }
}
