/* ==========================================================================
   Kraft Masonry — design tokens
   Palette: classic white (light) / near-black (dark) background, warm-ink
   text, pine/teal accent. Type: sans for the site title, serif for post
   titles, sans for body text, monospace for meta ("stamp" feel).
   ========================================================================== */

:root {
  /* color - light theme (default) */
  --color-bg:        #ffffff;
  --color-surface:   #f7f6f2;
  --color-ink:       #232017;
  --color-muted:     #837a64;
  --color-accent:    #2f5d50;
  --color-accent-soft: rgba(47, 93, 80, 0.10);
  --color-on-accent: #fbf8f1;
  --color-line:      #e4dfd1;

  /* type */
  --font-title: "Avenir Next", "Century Gothic", "Futura", "Trebuchet MS", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Source Serif Pro", Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", "Roboto Mono", Consolas, "Liberation Mono", monospace;

  /* layout */
  --container-width: 1180px;
  --radius: 6px;
  --gap: 1.5rem;
}

/* Dark theme — applied when the user (or the init script, based on
   system preference) has explicitly chosen "dark". */
:root[data-theme="dark"] {
  --color-bg:        #121212;
  --color-surface:   #1c1c1e;
  --color-ink:       #f1efe8;
  --color-muted:     #9b958a;
  --color-accent:    #5cc4a9;
  --color-accent-soft: rgba(92, 196, 169, 0.14);
  --color-on-accent: #0e201b;
  --color-line:      #303030;
}

/* No-JS fallback: if the init script hasn't run (no data-theme attribute
   yet), honor the OS-level color scheme directly. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:        #121212;
    --color-surface:   #1c1c1e;
    --color-ink:       #f1efe8;
    --color-muted:     #9b958a;
    --color-accent:    #5cc4a9;
    --color-accent-soft: rgba(92, 196, 169, 0.14);
    --color-on-accent: #0e201b;
    --color-line:      #303030;
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.container {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

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

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

/* ==========================================================================
   Header
   ========================================================================== */

.site-header {
  border-bottom: 1px solid var(--color-line);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding-top: 1.35rem;
  padding-bottom: 1.35rem;
}

.site-logo {
  font-family: var(--font-title);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: var(--color-ink);
}

.site-nav ul {
  display: flex;
  gap: 1.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav a {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-decoration: none;
  color: var(--color-ink);
  border-bottom: 1px solid transparent;
  padding-bottom: 0.15rem;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.site-nav a:hover,
.site-nav a:focus-visible {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

.site-header-actions {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  border: 1px dashed var(--color-line);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-ink);
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.theme-toggle .icon {
  width: 1.1rem;
  height: 1.1rem;
}

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

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

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

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

  :root:not([data-theme]) .theme-toggle .icon-moon {
    display: block;
  }
}

/* ==========================================================================
   Hero — subtitle-only block (title lives in the site header)
   ========================================================================== */

.hero {
  padding: 2.75rem 0 1.5rem;
  text-align: left;
}

/* Each subtitle line is its own <p>, rendered via markdownify.
   Inline markdown (bold, italic, links) is supported. */
.hero-subtitle-line {
  margin: 0 0 0.3rem;
  max-width: 52rem;
  color: var(--color-muted);
  font-size: 1.15rem;
  line-height: 1.6;
}

.hero-subtitle-line:last-of-type {
  margin-bottom: 0;
}

.hero-subtitle-line strong {
  color: var(--color-ink);
  font-weight: 600;
}

.hero-subtitle-line a {
  color: var(--color-accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.hero-rule {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 2rem;
}

.hero-rule::before {
  content: "";
  display: block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-accent);
  flex: none;
}

.hero-rule::after {
  content: "";
  display: block;
  flex: 1 1 auto;
  border-top: 1px dashed var(--color-line);
}

/* ==========================================================================
   Category filter — "luggage tag" pills
   ========================================================================== */

.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1.75rem 0 2.75rem;
}

.filter-btn {
  position: relative;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--color-surface);
  color: var(--color-ink);
  border: 1px dashed var(--color-line);
  border-radius: var(--radius);
  padding: 0.5rem 0.95rem 0.5rem 1.6rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.filter-btn::before {
  content: "";
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  border: 1px solid var(--color-muted);
  background: var(--color-bg);
}

.filter-btn:hover,
.filter-btn:focus-visible {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.filter-btn.is-active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  border-style: solid;
  color: var(--color-on-accent);
}

.filter-btn.is-active::before {
  border-color: var(--color-on-accent);
  background: var(--color-accent);
}

/* ==========================================================================
   Masonry grid (CSS Grid + dense packing)

   Le card sono disposte in una griglia a 3/2/1 colonne. Alcune card
   ricevono la classe "post-card--wide" (vedi partials/post-card.html) e
   occupano 2 colonne: grid-auto-flow: dense richiude eventuali spazi
   vuoti lasciati dalle card più larghe con le card successive.
   ========================================================================== */

.masonry {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: dense;
  align-items: stretch;
  gap: var(--gap);
  padding-bottom: 3.5rem;
}

@media (max-width: 980px) {
  .masonry {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .masonry {
    grid-template-columns: 1fr;
  }

  /* Con una sola colonna una card "larga" non avrebbe nulla in più da
     occupare: si comporta come una card normale. */
  .post-card--wide {
    grid-column: span 1;
  }
}

.post-card--wide {
  grid-column: span 2;
}

.post-card {
  display: flex;
  flex-direction: column;
  min-width: 0;      /* prevents overflow in grid context */
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.post-card[hidden] {
  display: none;
}

.post-card:hover {
  transform: translateY(-2px);
  border-color: var(--color-accent);
  box-shadow: 0 10px 24px rgba(35, 32, 23, 0.08);
}

.post-card-link {
  display: flex;
  flex-direction: column;
  flex: 1;
  text-decoration: none;
  color: inherit;
}

.post-card-image {
  border-bottom: 1px solid var(--color-line);
  background: var(--color-bg);
}

.post-card-image img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.post-card-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1.1rem 1.3rem 1.4rem;
}

/* Card "larga" (2 colonne): su schermi sufficientemente ampi, immagine
   e testo sono affiancati invece che impilati. Sotto questa soglia (o
   su mobile, dove diventa a colonna singola) si comporta come una card
   normale. */
@media (min-width: 760px) {
  .post-card--wide .post-card-link {
    flex-direction: row;
    min-height: 220px;
  }

  .post-card--wide .post-card-image {
    flex: 0 0 42%;
    border-bottom: none;
    border-right: 1px solid var(--color-line);
  }

  .post-card--wide .post-card-image img {
    height: 100%;
    aspect-ratio: auto;
    object-fit: cover;
  }

  .post-card--wide .post-card-body {
    flex: 1;
    min-width: 0;
  }

  .post-card--wide .post-card-title {
    font-size: 1.5rem;
  }
}

.post-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}

.post-card-date {
  white-space: nowrap;
}

.tag {
  display: inline-block;
  border: 1px dashed var(--color-line);
  border-radius: var(--radius);
  padding: 0.1rem 0.5rem;
  color: var(--color-accent);
  background: var(--color-accent-soft);
}

.post-card-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  line-height: 1.3;
  margin: 0 0 0.5rem;
}

.post-card-abstract {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.95rem;
}

/* ==========================================================================
   List / taxonomy pages
   ========================================================================== */

.list-header {
  padding: 3rem 0 1rem;
  text-align: left;
}

.list-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4.5vw, 3rem);
  margin: 0 0 0.5rem;
}

.list-description {
  color: var(--color-muted);
  max-width: 46rem;
}

.list-empty {
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding-bottom: 3rem;
}

.term-list {
  list-style: none;
  margin: 0;
  padding: 0 0 3.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.term-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.term-count {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--color-muted);
}

/* ==========================================================================
   Single post — classic layout
   ========================================================================== */

.post-single {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 0 4.5rem;
}

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

.post-title {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 4.5vw, 2.75rem);
  line-height: 1.2;
  margin: 0 0 0.85rem;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}

.post-meta a.tag {
  text-decoration: none;
}

.post-cover {
  margin: 1.75rem 0;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  overflow: hidden;
}

.post-content {
  font-size: 1.15rem;
}

.post-content > * + * {
  margin-top: 1.25rem;
}

.post-content h2,
.post-content h3,
.post-content h4 {
  font-family: var(--font-display);
  line-height: 1.3;
  margin-top: 2rem;
}

.post-content img,
.post-content figure {
  border-radius: var(--radius);
}

.post-content figcaption {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--color-muted);
  text-align: center;
  margin-top: 0.5rem;
}

.post-content blockquote {
  margin: 0;
  padding: 0.25rem 1.25rem;
  border-left: 2px dashed var(--color-line);
  color: var(--color-muted);
  font-style: italic;
}

.post-content pre {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

.post-content code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.post-content hr {
  border: none;
  border-top: 1px dashed var(--color-line);
}

/* ==========================================================================
   Tag footer nella pagina singola del post
   ========================================================================== */

.post-footer {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px dashed var(--color-line);
}

.post-footer-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  margin: 0 0 0.75rem;
}

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

.post-tags .tag {
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.post-tags .tag:hover,
.post-tags .tag:focus-visible {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-on-accent);
}

/* ==========================================================================
   Pagina indice tag (/tags/ e /tags/<slug>/)
   ========================================================================== */

.tag-index-header {
  padding: 3rem 0 1.5rem;
}

.tag-index-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4.5vw, 3rem);
  margin: 0 0 0.35rem;
}

.tag-index-meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding-bottom: 3.5rem;
}

.tag-cloud-item {
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tag-cloud-item:hover,
.tag-cloud-item:focus-visible {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-on-accent);
}

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

.site-footer {
  border-top: 1px solid var(--color-line);
  padding: 1.75rem 0;
  margin-top: 1rem;
}

.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}

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

/* ==========================================================================
   Accessibility
   ========================================================================== */

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
