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

:root {
  --bg: #16161e;
  --bg-surface: #1a1b26;
  --text: #c0caf5;
  --text-muted: #565f89;
  --accent: #f7768e;
  --link: #7dcfff;
  --link-hover: #f7768e;
  --border: #292e42;
  --max-width: 68rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #d5d6db;
    --bg-surface: #cbccd1;
    --text: #343b58;
    --text-muted: #848cb5;
    --accent: #f52a65;
    --link: #007197;
    --link-hover: #f52a65;
    --border: #b4b5ba;
  }
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* -- Header & Nav -- */
header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}

@media (max-width: 768px) {
  header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
  }
}

#navbar {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.site-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.nav-links { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }
.nav-links a { color: var(--text-muted); font-size: 0.9rem; }
.nav-links a:hover, .nav-links a.active { color: var(--accent); }

@media (max-width: 768px) {
  #navbar { gap: 0.5rem 1rem; }
  .nav-links { gap: 1rem; width: 100%; justify-content: flex-start; }
  .nav-search { margin-left: auto; }
  #search-input { width: 6rem; }
  #search-input:focus { width: 8rem; }
  .search-dropdown { right: -1rem; width: calc(100vw - 2rem); max-width: 20rem; }
}

/* -- Main -- */
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem;
  flex: 1;
  width: 100%;
}

/* -- Footer -- */
footer {
  border-top: 1px solid var(--border);
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* -- Article -- */
.article-header { margin-bottom: 2rem; }
.article-header h1 { margin: 0.5rem 0; }
.article-header time { color: var(--text-muted); font-size: 0.9rem; }

.tags { margin-top: 0.5rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tags a {
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
}
.tags a:hover { border-color: var(--accent); color: var(--accent); }

/* -- Article body with TOC sidebar -- */
.article-body { position: relative; }

.toc {
  font-size: 0.85rem;
  margin-bottom: 2rem;
  padding: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.toc h2 { font-size: 0.9rem; margin-bottom: 0.5rem; }
.toc ul { list-style: none; padding-left: 1rem; }
.toc li { margin: 0.25rem 0; }
.toc a { color: var(--text-muted); }
.toc a:hover { color: var(--accent); }

@media (min-width: 80rem) {
  .article-body:has(.toc) {
    display: grid;
    grid-template-columns: 16rem 1fr;
    gap: 2rem;
  }

  .article-body:has(.toc) .content {
    order: 2;
  }

  .toc {
    order: 1;
    position: sticky;
    top: 1rem;
    align-self: start;
    margin-bottom: 0;
  }
}

/* -- Content -- */
.content h1, .content h2, .content h3, .content h4 { margin: 1.5em 0 0.5em; }
.content p { margin: 0.75em 0; }
.content ul, .content ol { padding-left: 1.5rem; margin: 0.75em 0; }
.content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--text-muted);
  margin: 1em 0;
}
.content code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-surface);
  padding: 0.15em 0.3em;
  border-radius: 3px;
}
.content pre {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1em 0;
}
.content pre code { background: none; padding: 0; }
.content img { max-width: 100%; height: auto; border-radius: 4px; }
.content table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.content th, .content td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  text-align: left;
}
.content th { background: var(--bg-surface); }

/* -- Lists -- */
.page-list ul { list-style: none; }
.page-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.35rem 0;
  gap: 1rem;
}
.page-list time {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.subsections ul { list-style: none; }
.subsections li { padding: 0.25rem 0; }

/* -- Quote section (homepage) -- */
#quote-section {
  padding: 4rem 0;
  text-align: center;
}

#quote-section blockquote {
  font-size: 1.4rem;
  font-style: italic;
  line-height: 1.6;
  max-width: 40rem;
  margin: 0 auto 1rem;
  color: var(--text);
}

#quote-attribution {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

#quote-context-wrapper {
  max-width: 36rem;
  margin: 0 auto;
  font-size: 0.85rem;
  color: var(--text-muted);
}

#quote-context-wrapper summary {
  cursor: pointer;
  color: var(--link);
}

#quote-context-wrapper summary:hover {
  color: var(--link-hover);
}

#quote-context {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.quote-open, .quote-close {
  font-size: 5rem;
  line-height: 0;
  vertical-align: -0.35em;
  color: var(--accent);
  font-style: normal;
  opacity: 0.6;
}

.quote-open { margin-right: 0.15em; }
.quote-close { margin-left: 0.15em; }

.quote-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.quote-controls button {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.quote-controls button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* -- Recent posts (homepage) -- */
.recent-posts { list-style: none; }

.recent-posts a.recent-card {
  display: block;
  padding: 1rem;
  margin-bottom: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--text);
}

.recent-posts a.recent-card:hover {
  border-color: var(--accent);
}

.recent-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.recent-card-title {
  font-weight: 600;
  color: var(--link);
}

.recent-card-date {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.recent-card-description {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}

.recent-card-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.recent-card-tags span {
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
}

/* -- Projects section -- */
#projects { padding: 3rem 0; }
#projects h2 { margin-bottom: 1.5rem; }

/* -- Sections overview on homepage -- */
.sections-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 1rem;
  margin: 1.5rem 0 2rem;
}

.section-card {
  padding: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.section-card h2 { font-size: 1rem; }

/* -- Nav Search -- */
.nav-search { position: relative; }

#search-input {
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  font-family: var(--font);
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  width: 10rem;
  transition: width 0.2s, border-color 0.2s;
}

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

.search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.4rem;
  width: 20rem;
  max-height: 24rem;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 200;
}

.search-dropdown.open { display: block; }

.search-hit {
  display: block;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
}

.search-hit:last-child { border-bottom: none; }
.search-hit:hover, .search-hit.active { background: var(--bg); }

.search-hit-title {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--link);
}

.search-hit-desc {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.search-empty {
  padding: 0.8rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}


/* -- Search results page -- */
.search-page h1 { margin-bottom: 1rem; }

.search-page-input-wrapper { margin-bottom: 1rem; }

#search-page-input {
  width: 100%;
  max-width: 32rem;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  font-family: var(--font);
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
}

#search-page-input:focus { border-color: var(--accent); }

#search-page-count {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.search-results-list { list-style: none; }

.search-result-card {
  display: block;
  padding: 1rem;
  margin-bottom: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--text);
}

.search-result-card:hover { border-color: var(--accent); }

.search-result-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.search-result-title { font-weight: 600; color: var(--link); }
.search-result-date { color: var(--text-muted); font-size: 0.85rem; }

.search-result-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}

.search-result-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.search-result-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.search-result-tags span {
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
}

.search-match-keys {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* -- Breadcrumbs -- */
.breadcrumbs {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: inline;
}
.breadcrumbs .sep { margin: 0 0.3rem; }
.breadcrumbs .current { color: var(--text); }
