/* ============================================================
   andypanix — archivio editoriale × terminale
   Carta calda, serif da stampa (Fraunces), mono da terminale
   (IBM Plex Mono). I blocchi di codice restano scuri come
   finestre di terminale incassate nella pagina.
   ============================================================ */

:root {
  --paper: #f6f1e7;
  --paper-raised: #fdfaf3;
  --ink: #2b251c;
  --muted: #847a69;
  --accent: #b4490e;
  --accent-soft: #e9d9c5;
  --rule: #ddd2bd;
  --rule-strong: #c9bca1;
  --code-inline-bg: #ece4d2;
  --maxw: 740px;
  --maxw-wide: 1080px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", "Helvetica Neue", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #191512;
    --paper-raised: #211c17;
    --ink: #eae0cd;
    --muted: #9a8f7b;
    --accent: #e07a36;
    --accent-soft: #3a2c1f;
    --rule: #352e24;
    --rule-strong: #4a4133;
    --code-inline-bg: #2a241d;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 400 17px/1.7 var(--font-body);
  font-feature-settings: "liga", "kern";
}

/* Grana di carta sopra tutto, impercettibile ma presente */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

::selection { background: var(--accent); color: var(--paper); }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 22px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

/* ---------------- Header: prompt di shell ---------------- */

.site-header {
  border-bottom: 1px solid var(--rule-strong);
  box-shadow: 0 3px 0 -2px var(--rule);
  background: var(--paper);
}
.site-header::before {
  content: "";
  display: block;
  height: 4px;
  background: var(--accent);
}
.header-inner {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 18px 22px 14px; flex-wrap: wrap; gap: 10px 18px;
  max-width: var(--maxw-wide); margin: 0 auto;
}
.brand {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -.02em;
  color: var(--ink);
}
.brand:hover { text-decoration: none; color: var(--accent); }
.brand .prompt { color: var(--accent); font-weight: 400; }
.brand .cursor {
  display: inline-block;
  width: .55em; height: 1.05em;
  margin-left: .15em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1.15s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.site-nav { font-family: var(--font-mono); font-size: .85rem; }
.site-nav a { color: var(--muted); margin-left: 18px; }
.site-nav a::before { content: "/"; color: var(--accent); margin-right: 1px; opacity: .7; }
.site-nav a:hover { color: var(--ink); text-decoration: none; }

/* ---------------- Ricerca (Pagefind) ---------------- */

.search-toggle {
  font-family: var(--font-mono);
  font-size: .85rem;
  color: var(--muted);
  background: none;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 2px 9px;
  margin-left: 18px;
  cursor: pointer;
  line-height: 1.4;
}
.search-toggle:hover { color: var(--ink); border-color: var(--accent); }
.search-toggle .search-kbd {
  margin-left: 7px;
  padding: 0 4px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 2px;
  font-size: .8em;
}

body.search-open { overflow: hidden; }

.search-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: color-mix(in srgb, var(--ink) 45%, transparent);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 16px;
  backdrop-filter: blur(2px);
}
.search-overlay[hidden] { display: none; }
.search-panel {
  position: relative;
  width: 100%; max-width: var(--maxw);
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  box-shadow: 0 16px 48px -12px rgba(0,0,0,.4);
  padding: 18px 20px 12px;
  max-height: 80vh; overflow: auto;
}
.search-close {
  position: fixed; top: 18px; right: 22px; z-index: 60;
  font-family: var(--font-mono); font-size: .75rem;
  color: var(--paper); background: var(--accent);
  border: 1px solid var(--accent); border-radius: 3px;
  padding: 3px 10px; cursor: pointer;
}
.search-close:hover { background: var(--ink); border-color: var(--ink); }
.search-error { color: var(--muted); font-size: .9rem; }

/* Tema della UI di Pagefind allineato alla palette */
#search {
  --pagefind-ui-scale: .9;
  --pagefind-ui-primary: var(--accent);
  --pagefind-ui-text: var(--ink);
  --pagefind-ui-background: var(--paper-raised);
  --pagefind-ui-border: var(--rule);
  --pagefind-ui-tag: var(--accent-soft);
  --pagefind-ui-border-width: 1px;
  --pagefind-ui-border-radius: 4px;
  --pagefind-ui-font: var(--font-body);
}
/* Campo di ricerca */
#search .pagefind-ui__search-input {
  font-family: var(--font-mono);
  font-size: 1rem;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  color: var(--ink);
}
#search .pagefind-ui__search-input::placeholder { color: var(--muted); }
#search .pagefind-ui__search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}
#search .pagefind-ui__search-clear { color: var(--muted); background: transparent; }
#search .pagefind-ui__search-clear:hover { color: var(--accent); }
/* Riga conteggio risultati */
#search .pagefind-ui__message {
  font-family: var(--font-mono);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 10px;
}
/* Singolo risultato */
#search .pagefind-ui__result {
  border-top: none;
  border-bottom: 1px solid var(--rule);
  padding: 14px 8px;
  border-radius: 4px;
}
#search .pagefind-ui__result:hover { background: var(--paper); }
#search .pagefind-ui__result-title { margin-bottom: 2px; }
#search .pagefind-ui__result-link {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.18rem;
  color: var(--ink);
}
#search .pagefind-ui__result-link:hover { color: var(--accent); text-decoration: none; }
#search .pagefind-ui__result-excerpt { color: var(--muted); font-size: .92rem; }
/* Termini evidenziati */
#search mark {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 600;
}
/* Sub-risultati (sezioni nella stessa pagina) */
#search .pagefind-ui__result-nested { border-left: 2px solid var(--rule); padding-left: 12px; }
#search .pagefind-ui__result-nested .pagefind-ui__result-link {
  font-family: var(--font-body);
  font-size: .95rem;
  font-weight: 600;
}
/* Bottone "mostra altri" */
#search .pagefind-ui__button {
  font-family: var(--font-mono);
  font-size: .85rem;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  color: var(--ink);
  border-radius: 4px;
}
#search .pagefind-ui__button:hover { border-color: var(--accent); color: var(--accent); }

main.container { padding-top: 40px; padding-bottom: 48px; }
/* Le pagine con sidebar (guide) respirano su tutta la larghezza */
main.container:has(.with-sidebar) { max-width: var(--maxw-wide); }

/* ---------------- Tipografia ---------------- */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 640;
  letter-spacing: -.015em;
  line-height: 1.15;
  color: var(--ink);
}
h1 { font-size: clamp(1.9rem, 4.5vw, 2.6rem); margin: 0 0 .45em; }
h2 { font-size: 1.45rem; margin: 2em 0 .55em; }
h3 { font-size: 1.15rem; margin: 1.7em 0 .45em; }

.content img, .featured {
  max-width: 100%; height: auto;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  box-shadow: 4px 4px 0 var(--accent-soft);
}
.featured { margin: .5em 0 1.4em; }
.content p, .content ul, .content ol { margin: 0 0 1.1em; }

.content blockquote {
  margin: 1.4em 0; padding: .4em 1.2em;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}
.content blockquote p:last-child { margin-bottom: 0; }

.content hr { border: none; margin: 2.4em 0; text-align: center; }
.content hr::after { content: "✲ ✲ ✲"; color: var(--rule-strong); letter-spacing: 1em; font-size: .8rem; }

.content table {
  border-collapse: collapse; width: 100%; margin: 1.4em 0;
  display: block; overflow-x: auto;
  font-size: .95em;
}
.content th { font-family: var(--font-mono); font-size: .85em; text-transform: uppercase; letter-spacing: .04em; }
.content th, .content td { border: 1px solid var(--rule); padding: 7px 12px; text-align: left; }
.content tr:nth-child(even) td { background: var(--paper-raised); }

/* Capolettera editoriale sugli articoli */
.prose-drop > p:first-of-type::first-letter {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 3.1em;
  line-height: .85;
  float: left;
  padding: .06em .12em 0 0;
  color: var(--accent);
}

/* ---------------- Meta, tag, badge ---------------- */

.post-header { margin-bottom: 1.8em; }
.meta {
  font-family: var(--font-mono);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 .9em;
}
.meta::before { content: "── "; color: var(--accent); letter-spacing: 0; }
.meta::after { content: " ──"; color: var(--accent); letter-spacing: 0; }
.meta a { color: var(--muted); text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
.meta a:hover { color: var(--accent); }

.badge {
  font-family: var(--font-mono);
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent);
  padding: 1px 8px;
  border-radius: 2px;
  font-size: .72rem;
  letter-spacing: .05em;
}

.tags { margin-top: 2.2em; padding-top: 1em; border-top: 1px solid var(--rule); }
.tags a {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--muted);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 2px 9px;
  margin: 0 6px 6px 0;
  transition: border-color .15s ease, color .15s ease, transform .15s ease;
}
.tags a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }

/* ---------------- Codice ---------------- */

code {
  font-family: var(--font-mono);
  background: var(--code-inline-bg);
  padding: .12em .4em;
  border-radius: 3px;
  font-size: .86em;
}
/* I blocchi evidenziati da Chroma (gruvbox) portano lo sfondo scuro
   inline: qui solo cornice e respiro, da finestra di terminale. */
pre {
  padding: 16px 18px;
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.5;
  border: 1px solid var(--rule-strong);
  box-shadow: 4px 4px 0 var(--accent-soft);
  margin: 1.4em 0;
}
pre code { background: none; padding: 0; font-size: .84rem; }
.highlight { margin: 1.4em 0; }
.highlight pre { margin: 0; }

/* ---------------- Liste di post: indice con puntini ---------------- */

.post-list { list-style: none; padding: 0; margin: 0 0 1em; }
.post-list li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 0;
}
.post-list li + li { border-top: 1px solid var(--rule); }
.post-list a { color: var(--ink); }
.post-list a:hover { color: var(--accent); text-decoration: none; }
.post-list .leader { flex: 1; min-width: 24px; border-bottom: 2px dotted var(--rule-strong); transform: translateY(-4px); }
.post-list time {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
}

.term-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.term-list li { margin: 0; }
.term-list a {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: .88rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 5px 12px;
  transition: border-color .15s ease, transform .15s ease;
}
.term-list a:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.term-list .count { color: var(--accent); font-size: .78rem; margin-left: .5em; }

/* ---------------- Home ---------------- */

.hero { padding: 18px 0 30px; border-bottom: 1px solid var(--rule); margin-bottom: 14px; }
.hero-kicker {
  font-family: var(--font-mono);
  font-size: .8rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 .6em;
}
.hero-title {
  font-size: clamp(2.8rem, 9vw, 4.6rem);
  font-weight: 700;
  margin: 0 0 .2em;
  letter-spacing: -.03em;
}
.hero-title .tld { color: var(--muted); font-style: italic; font-weight: 500; }
.hero .lead { color: var(--muted); font-size: 1.1rem; max-width: 34em; margin: 0; }

.home-section { padding-top: 14px; }
.home-section h2 { margin-top: 1.2em; }
.home-section h2::before { content: "## "; font-family: var(--font-mono); font-weight: 400; color: var(--accent); font-size: .8em; vertical-align: .12em; }
.more-link { font-family: var(--font-mono); font-size: .85rem; }

/* Comparsa in scena al caricamento */
@media (prefers-reduced-motion: no-preference) {
  .hero, .home-section, .post-header, article.content > h1 {
    animation: rise .55s cubic-bezier(.2, .7, .3, 1) both;
  }
  .home-section:nth-of-type(2) { animation-delay: .12s; }
  .home-section:nth-of-type(3) { animation-delay: .22s; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- Guide: layout con sidebar ---------------- */

.layout.with-sidebar {
  display: grid;
  grid-template-columns: 264px minmax(0, var(--maxw));
  gap: 48px;
  align-items: start;
}
.sidebar {
  position: sticky; top: 18px;
  font-size: .88rem;
  border-right: 1px solid var(--rule);
  padding-right: 22px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}
.sidebar h3 {
  font-family: var(--font-mono);
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 0 0 .8em;
}
.sidebar h3 a { color: var(--accent); }
.book-tree, .book-children { list-style: none; margin: .25em 0; padding-left: 0; }
.book-tree .book-tree { border-left: 1px solid var(--rule); margin-left: .35em; padding-left: 1em; }
.book-tree li { margin: 5px 0; }
.book-tree a { color: var(--ink); }
.book-tree a:hover { color: var(--accent); text-decoration: none; }
.book-children li { margin: 7px 0; padding-left: 1.2em; position: relative; }
.book-children li::before { content: "→"; position: absolute; left: 0; color: var(--accent); }

/* ---------------- Allegati, gallery, prev/next ---------------- */

.attachments {
  margin: 2em 0;
  padding: 14px 18px;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 2px;
}
.attachments h3 {
  margin: 0 0 .5em;
  font-family: var(--font-mono);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.attachments ul { margin: 0; padding-left: 18px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 1.4em 0; }
.gallery img { width: 100%; height: 116px; object-fit: cover; }

.prevnext {
  display: flex; justify-content: space-between; gap: 18px;
  margin-top: 2.8em; padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono); font-size: .82rem;
}

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

.site-footer {
  border-top: 1px solid var(--rule-strong);
  margin-top: 64px;
  color: var(--muted);
  font-size: .85rem;
}
.site-footer .container { padding-top: 22px; padding-bottom: 36px; }
.site-footer .eof {
  font-family: var(--font-mono);
  text-align: center;
  letter-spacing: .3em;
  color: var(--rule-strong);
  margin-top: 1.6em;
}

/* ---------------- Mobile ---------------- */

@media (max-width: 760px) {
  .layout.with-sidebar { grid-template-columns: 1fr; gap: 0; }
  .sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--rule);
    padding: 0 0 16px;
    margin-bottom: 22px;
  }
  .post-list .leader { display: none; }
  .post-list li { flex-wrap: wrap; gap: 4px 10px; }
}
