/*
 * Blox theme for Nicolino
 *
 * Ported from Hugo Blox Tailwind (https://github.com/HugoBlox/kit, MIT).
 * Recreates the Tailwind-based look (slate/zinc neutrals, rounded cards
 * with hover lift, sticky navbar, prose articles) in plain CSS.
 *
 * Colors hook into the base16 CSS custom properties generated as
 * /css/style.css when the `base16` feature is enabled, with Tailwind
 * slate/zinc fallbacks so the theme also works standalone.
 */

:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --radius-card: 1rem;
  --navbar-height: 4rem;
}

/* ---- Color system: base16 roles with Tailwind fallbacks ---- */

[data-theme="light"] {
  --bg: var(--b16-base00, #ffffff);
  --bg-soft: var(--b16-base01, #f4f4f5);
  --fg: var(--b16-base05, #0f172a);
  --fg-strong: var(--b16-base06, #020617);
  --muted: var(--b16-base04, #64748b);
  --border: var(--b16-base02, #e2e8f0);
  --accent: var(--b16-base0D, #0284c7);
  --accent-hover: var(--b16-base0E, #0369a1);
  --code-bg: var(--b16-base01, #f1f5f9);
  --card-bg: var(--b16-base00, rgba(255, 255, 255, 0.9));
  --card-ring: var(--b16-base02, rgba(15, 23, 42, 0.06));
  --shadow-card: 0 4px 6px -1px rgba(15, 23, 42, 0.08),
    0 2px 4px -2px rgba(15, 23, 42, 0.06);
  --shadow-card-hover: 0 20px 25px -5px rgba(2, 132, 199, 0.14),
    0 8px 10px -6px rgba(2, 132, 199, 0.1);
}

[data-theme="dark"] {
  --bg: var(--b16-base00, #09090b);
  --bg-soft: var(--b16-base01, #18181b);
  --fg: var(--b16-base05, #f1f5f9);
  --fg-strong: var(--b16-base07, #f8fafc);
  --muted: var(--b16-base04, #94a3b8);
  --border: var(--b16-base02, #27272a);
  --accent: var(--b16-base0D, #38bdf8);
  --accent-hover: var(--b16-base0E, #7dd3fc);
  --code-bg: var(--b16-base01, #18181b);
  --card-bg: var(--b16-base00, rgba(24, 24, 27, 0.9));
  --card-ring: var(--b16-base02, rgba(255, 255, 255, 0.1));
  --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.4),
    0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-card-hover: 0 20px 25px -5px rgba(56, 189, 248, 0.16),
    0 8px 10px -6px rgba(56, 189, 248, 0.12);
}

/* ---- Base ---- */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.75;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

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

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

noindex {
  display: contents;
}

/* ---- Sticky navbar ---- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.site-header.sticky {
  position: sticky;
  top: 0;
  z-index: 30;
}

.navbar {
  max-width: 80rem;
  margin: 0 auto;
  min-height: var(--navbar-height);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--fg-strong);
  white-space: nowrap;
}

.brand:hover {
  color: var(--fg-strong);
  text-decoration: none;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
}

.nav-menu a {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
}

.nav-menu a:hover {
  color: var(--fg);
  background: var(--bg-soft);
  text-decoration: none;
}

.nav-languages a {
  text-transform: uppercase;
  font-size: 0.75rem;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.5rem;
}

#scheme_toggle,
#github_link {
  background: none;
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--fg);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0.4rem 0.6rem;
}

#github_link {
  display: inline-flex;
  align-items: center;
}

#scheme_toggle:hover,
#github_link:hover {
  background: var(--bg-soft);
  text-decoration: none;
}

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

.search-box {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 0.65rem;
  width: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
  pointer-events: none;
}

.search-input {
  width: 2.25rem;
  height: 2rem;
  padding: 0.35rem 0.6rem 0.35rem 2rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--fg);
  background: var(--bg);
  font: inherit;
  transition: width 0.2s ease;
}

.search-input:hover,
.search-input:focus,
.search-input:not(:placeholder-shown) {
  width: 12rem;
}

.search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#search_results {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: start center;
  padding: 6rem 1rem 1rem;
  background: rgba(0, 0, 0, 0.45);
}

#search_results[hidden] {
  display: none;
}

.search-modal {
  width: min(42rem, 100%);
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  color: var(--fg);
  background: var(--bg);
  box-shadow: var(--shadow-card-hover);
}

.search-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.search-modal h2 {
  margin: 0;
  font-size: 1.125rem;
}

.search-close {
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
}

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

.search-results-list li + li {
  border-top: 1px solid var(--border);
}

.search-results-list a {
  display: block;
  padding: 0.75rem 0;
}

.search-results-list a:hover {
  text-decoration: none;
}

.search-result-title {
  display: block;
  color: var(--fg-strong);
  font-weight: 600;
}

.search-result-snippet,
.search-message {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Mobile menu: hamburger checkbox trick (as in the original theme) */

.nav-toggle {
  position: absolute;
  opacity: 0;
}

.nav-burger {
  display: none;
  margin-left: auto;
  cursor: pointer;
  padding: 0.5rem;
}

.nav-burger span {
  display: block;
  width: 1.25rem;
  height: 2px;
  margin: 5px 0;
  background: var(--fg);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle:checked ~ .nav-burger span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-toggle:checked ~ .nav-burger span:nth-child(2) {
  opacity: 0;
}

.nav-toggle:checked ~ .nav-burger span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@media (max-width: 640px) {
  .nav-burger {
    display: block;
  }

  .nav-menu {
    display: none;
    position: absolute;
    top: var(--navbar-height);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.5rem 1.5rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }

  .nav-toggle:checked ~ .nav-menu {
    display: flex;
  }

  .nav-menu a {
    padding: 0.75rem 0.5rem;
  }

  .nav-actions {
    margin: 0.5rem 0 0;
  }
}

/* ---- Page body ---- */

.page-body {
  max-width: 80rem;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  min-height: calc(100vh - var(--navbar-height) - 6rem);
}

.page-header h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--fg-strong);
  margin: 0 0 1.5rem;
}

/* ---- Card grid (index, galleries) ---- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: 1.5rem;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--card-ring);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-0.5rem);
  box-shadow: var(--shadow-card-hover);
}

.card-cover {
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: linear-gradient(135deg, var(--bg-soft), var(--border));
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.card:hover .card-cover img {
  transform: scale(1.03);
}

.card-cover-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--bg-soft), var(--border));
}

.card-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1.25rem;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.4;
  margin: 0 0 0.5rem;
}

.card-title a {
  color: var(--fg-strong);
}

.card-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.card-tag {
  font-size: 0.75rem;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  background: var(--bg-soft);
  color: var(--muted);
}

.card-tag:hover {
  color: var(--accent);
  text-decoration: none;
}

.card-summary {
  font-size: 0.9375rem;
  color: var(--muted);
  margin: 0.75rem 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.read-more {
  margin-top: auto;
  padding-top: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.list-pagination {
  margin-top: 2.5rem;
  text-align: center;
}

/* ---- Taxonomy terms / item lists ---- */

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

.terms a {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  font-weight: 500;
  color: var(--fg);
}

.terms a:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.index-content ul {
  padding-left: 1.25rem;
}

/* ---- Article (single post) with ToC sidebar ---- */

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16rem;
  gap: 3rem;
  max-width: 72rem;
  margin: 0 auto;
}

.article-layout.no-toc {
  grid-template-columns: minmax(0, 1fr);
  max-width: 46rem;
}

.article-title {
  font-size: clamp(2rem, 4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--fg-strong);
  margin: 0.5rem 0 1rem;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 2rem;
}

.article-updated {
  font-style: italic;
}

.fallback-notice {
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  background: var(--bg-soft);
  font-size: 0.875rem;
}

.toc {
  display: none;
}

@media (min-width: 1024px) {
  .article-layout:not(.no-toc) .toc {
    display: block;
    position: sticky;
    top: calc(var(--navbar-height) + 2rem);
    align-self: start;
    max-height: calc(100vh - var(--navbar-height) - 4rem);
    overflow-y: auto;
    font-size: 0.875rem;
  }

  .toc ul {
    list-style: none;
    padding-left: 0.75rem;
    margin: 0.25rem 0;
    border-left: 2px solid var(--border);
  }

  .toc a {
    display: block;
    padding: 0.2rem 0.5rem;
    border-radius: 0.375rem;
    color: var(--muted);
  }

  .toc a:hover {
    color: var(--accent);
    background: var(--bg-soft);
    text-decoration: none;
  }
}

.toc h2 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 0.5rem;
}

/* ---- Prose-ish article content ---- */

.article-content {
  font-size: 1.0625rem;
  line-height: 1.8;
}

.article-content > * + * {
  margin-top: 1.25em;
}

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4 {
  color: var(--fg-strong);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin-top: 2em;
}

.article-content h1 { font-size: 1.875rem; }
.article-content h2 { font-size: 1.5rem; }
.article-content h3 { font-size: 1.25rem; }
.article-content h4 { font-size: 1.0625rem; }

.article-content a {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-underline-offset: 3px;
}

.article-content blockquote {
  margin: 1.5em 0;
  padding: 0.25em 1.25em;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  border-radius: 0 0.5rem 0.5rem 0;
  color: var(--muted);
}

.article-content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  border-radius: 0.375rem;
  padding: 0.15em 0.4em;
}

.article-content pre {
  border-radius: var(--radius-card);
  padding: 1.25rem;
  overflow-x: auto;
  line-height: 1.7;
  background-color: var(--code-bg, var(--bg-soft));
}

.article-content pre code {
  display: block;
  background: transparent;
  padding: 0;
  color: var(--fg);
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

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

.article-content th {
  color: var(--fg-strong);
  font-weight: 600;
}

.article-content img {
  border-radius: var(--radius-card);
}

.article-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

/* ---- Tags, related, breadcrumbs ---- */

.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 2rem;
}

.tag {
  display: inline-block;
  padding: 0.25rem 0.875rem;
  border-radius: 9999px;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 0.8125rem;
}

.tag:hover {
  color: var(--accent);
  text-decoration: none;
}

.related-posts {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.related-posts h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.breadcrumbs a {
  color: var(--muted);
}

/* ---- Archive ---- */

.archive h2 {
  font-size: 1.5rem;
  color: var(--fg-strong);
}

.archive h3 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.archive ul {
  list-style: none;
  padding: 0;
}

.archive li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.375rem 0;
  border-bottom: 1px dashed var(--border);
}

.archive-date {
  color: var(--muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

/* ---- Books ---- */

.book-layout {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  gap: 3rem;
  max-width: 72rem;
  margin: 0 auto;
}

@media (max-width: 1023px) {
  .book-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .book-sidebar {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
  }
}

.book-title a {
  font-weight: 700;
  color: var(--fg-strong);
}

.book-toc {
  font-size: 0.875rem;
}

.book-toc ul {
  list-style: none;
  padding-left: 0.75rem;
  border-left: 2px solid var(--border);
}

.book-toc a {
  display: block;
  padding: 0.2rem 0.5rem;
  color: var(--muted);
}

.book-toc a:hover,
.book-toc a.active {
  color: var(--accent);
  text-decoration: none;
}

.toc-number {
  color: var(--muted);
  margin-right: 0.375rem;
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: 72rem;
  margin: 2rem auto 0;
}

/* ---- Widget screenshots ---- */

.widget-screenshots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.widget-screenshots figure {
  margin: 0;
  text-align: center;
}

.widget-screenshots img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 0;
}

.widget-screenshots figcaption {
  margin-top: 0.35rem;
  font-size: 0.9rem;
}

@media (max-width: 767px) {
  .widget-screenshots {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---- Gallery ---- */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem;
  align-items: start;
}

.gallery-item img {
  width: 100%;
  height: auto;
  border-radius: 0;
  transition: transform 0.3s ease;
}

.gallery-item:hover img {
  transform: scale(1.03);
}

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

.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 1.5rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--muted);
}

.site-footer p {
  margin: 0.25rem 0;
}
