/* ==========================================================================
   gabrieleromanato — "Terminal Editorial"
   Tema in sola lettura per en.gabrieleromanato.com
   Display: Fraunces · Utility/code: IBM Plex Mono · dark + verde fosforo
   Le classi rispecchiano esattamente i template EJS dell'app.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;1,9..144,400&family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;1,400&display=swap');

/* ------------------------------ tokens ---------------------------------- */
:root {
  --ink:        #0b0d0b;   /* fondo, quasi-nero appena caldo                 */
  --ink-2:      #11140f;   /* superficie elevata (codice, pannelli)          */
  --paper:      #e8e6da;   /* testo, bianco-fosforo                          */
  --muted:      #898d7c;   /* meta, didascalie                               */
  --green:      #5af78e;   /* accento da terminale, usato con parsimonia     */
  --green-dim:  #2f8d57;   /* bordi/sottolineature accento                   */
  --line:       rgba(232, 230, 218, 0.10); /* hairline                       */
  --line-soft:  rgba(232, 230, 218, 0.06);

  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --wide: 64rem;   /* colonna ampia: home, archivi          */
  --read: 42rem;   /* colonna di lettura: singolo post       */
  --pad: clamp(1.25rem, 4vw, 2.5rem);

  --speed: 160ms;
}

/* ------------------------------ reset ----------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  font-optical-sizing: auto;
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a { color: inherit; }

::selection { background: var(--green); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
  border-radius: 2px;
}

/* mono utility: tutto ciò che è "interfaccia/terminale" */
.site-nav, .post-card__category, .post-card__date, .post-card__more,
.post__category, .post__date, .pagination, .site-footer,
.category-header__description, .nav-toggle {
  font-family: var(--mono);
}

/* --------------------------- header / nav ------------------------------- */
.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.25rem 2rem;
  flex-wrap: wrap;
  max-width: var(--wide);
  margin: 0 auto;
  padding: 1.85rem var(--pad);
  border-bottom: 1px solid var(--line);
}

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

/* firma: caret da terminale lampeggiante */
.site-title::after {
  content: "";
  display: inline-block;
  width: 0.55ch;
  height: 1.05em;
  margin-left: 0.25em;
  background: var(--green);
  vertical-align: -0.14em;
  animation: caret 1.05s steps(1) infinite;
}
@keyframes caret { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .site-title::after { animation: none; }
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav a {
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--muted);
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
  transition: color var(--speed) ease, border-color var(--speed) ease;
}
.site-nav a:hover { color: var(--paper); border-bottom-color: var(--green-dim); }
.site-nav a[aria-current="page"] { color: var(--green); }

.nav-toggle {
  display: none;
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  border-radius: 3px;
}
.nav-toggle:hover { color: var(--paper); border-color: var(--green-dim); }

/* ------------------------------ main ------------------------------------ */
.site-main {
  max-width: var(--wide);
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 3.5rem) var(--pad);
  width: 100%;
}

.empty {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 0.9rem;
}

/* --------------------------- elenco post -------------------------------- */
.post-list { display: flex; flex-direction: column; }

.post-card {
  display: flex;
  gap: 1.85rem;
  padding: 2.1rem 0;
  border-bottom: 1px solid var(--line);
}
.post-card:first-child { padding-top: 0; }

.post-card__media {
  flex: 0 0 200px;
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 3px;
}
.post-card__media img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  filter: grayscale(0.15) contrast(1.02);
  transition: transform 320ms ease, filter var(--speed) ease;
}
.post-card__media:hover img { transform: scale(1.03); filter: none; }

.post-card__body { flex: 1 1 auto; min-width: 0; }

.post-card__category,
.post__category {
  display: inline-block;
  font-size: 0.74rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--muted);
  transition: color var(--speed) ease;
}
.post-card__category::before,
.post__category::before {
  content: ">";
  color: var(--green);
  margin-right: 0.5ch;
}
.post-card__category:hover,
.post__category:hover { color: var(--paper); }

.post-card__title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(1.3rem, 2.6vw, 1.7rem);
  line-height: 1.18;
  margin: 0.55rem 0 0.45rem;
  letter-spacing: -0.01em;
}
.post-card__title a {
  text-decoration: none;
  color: var(--paper);
  background-image: linear-gradient(var(--green-dim), var(--green-dim));
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 260ms ease;
}
.post-card__title a:hover { background-size: 100% 1px; }

.post-card__date,
.post__date {
  display: block;
  font-size: 0.76rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.post-card__excerpt {
  margin: 0.7rem 0 0.9rem;
  color: var(--paper);
  opacity: 0.86;
}
.post-card__excerpt p { margin: 0; }

.post-card__more {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--green);
}
.post-card__more::after {
  content: " →";
  transition: margin-left var(--speed) ease;
}
.post-card__more:hover::after { margin-left: 0.3ch; }

/* ------------------------ intestazione categoria ------------------------ */
.category-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.8rem;
  border-bottom: 1px solid var(--line);
}
.category-header__image {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  margin-bottom: 1.5rem;
  filter: grayscale(0.2);
}
.category-header__title {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0;
}
.category-header__title::before {
  content: "~/";
  font-family: var(--mono);
  font-size: 0.45em;
  font-weight: 500;
  color: var(--green);
  vertical-align: 0.35em;
  margin-right: 0.4ch;
}
.category-header__description {
  margin-top: 0.9rem;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--muted);
  max-width: var(--read);
}
.category-header__description p { margin: 0; }

/* ----------------------------- post singolo ----------------------------- */
.post {
  max-width: var(--read);
  margin: 0 auto;
}
.post__header { margin-bottom: 2rem; }
.post__title {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2.1rem, 5.5vw, 3.4rem);
  line-height: 1.04;
  letter-spacing: -0.025em;
  margin: 0.6rem 0 0.8rem;
}
.post__media {
  margin: 0 0 2.4rem;
}
.post__media img {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* ------------------- contenuto articolo (HTML dei post) ----------------- */
.post__content { font-size: 1.075rem; line-height: 1.8; }
.post__content > * + * { margin-top: 1.35rem; }

.post__content h2,
.post__content h3,
.post__content h4 {
  font-family: var(--display);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-top: 2.6rem;
}
.post__content h2 { font-size: 1.7rem; }
.post__content h3 { font-size: 1.35rem; }
.post__content h4 { font-size: 1.12rem; }

.post__content a {
  color: var(--paper);
  text-decoration: none;
  border-bottom: 1px solid var(--green-dim);
  transition: border-color var(--speed) ease, color var(--speed) ease;
}
.post__content a:hover { color: var(--green); border-bottom-color: var(--green); }

.post__content ul,
.post__content ol { padding-left: 1.3rem; }
.post__content li { margin-top: 0.45rem; }
.post__content li::marker { color: var(--green-dim); }

.post__content blockquote {
  margin: 1.8rem 0;
  padding: 0.4rem 0 0.4rem 1.4rem;
  border-left: 2px solid var(--green-dim);
  color: var(--muted);
  font-style: italic;
}
.post__content blockquote p { margin: 0; }

.post__content img {
  border: 1px solid var(--line);
  border-radius: 4px;
  margin: 1.8rem 0;
}

.post__content table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.86rem;
}
.post__content th,
.post__content td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--line);
}
.post__content th { color: var(--green); font-weight: 600; }

/* codice inline + blocchi (HighlightJS) */
.post__content code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--ink-2);
  border: 1px solid var(--line-soft);
  padding: 0.12em 0.4em;
  border-radius: 3px;
}
.post__content pre {
  position: relative;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1.1rem 1.2rem;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.65;
}
.post__content pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
}

/* bottone "copy" iniettato da main.js */
.code-copy {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--speed) ease, color var(--speed) ease;
}
.post__content pre:hover .code-copy { opacity: 1; }
.code-copy:hover { color: var(--green); border-color: var(--green-dim); }
.code-copy.is-done { color: var(--green); }

/* token HighlightJS, tarati sulla palette del tema
   (funzionano se il contenuto è già evidenziato con HighlightJS) */
.hljs-comment, .hljs-quote { color: var(--muted); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-name, .hljs-tag { color: var(--green); }
.hljs-string, .hljs-attr, .hljs-template-tag, .hljs-addition { color: #d9c89a; }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: #9fd0ff; }
.hljs-title, .hljs-section, .hljs-function .hljs-title { color: #c5b3ff; }
.hljs-type, .hljs-class .hljs-title { color: #7fe7c4; }
.hljs-variable, .hljs-template-variable, .hljs-attribute { color: var(--paper); }
.hljs-meta { color: var(--muted); }
.hljs-deletion { color: #e88; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* ----------------------------- paginazione ------------------------------ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
}
.pagination a { text-decoration: none; color: var(--muted); transition: color var(--speed) ease; }
.pagination a:hover { color: var(--green); }
.pagination__status { color: var(--muted); }
.pagination__prev { margin-right: auto; }
.pagination__next { margin-left: auto; }

/* ------------------------------ footer ---------------------------------- */
.site-footer {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 2.4rem var(--pad) 3rem;
  border-top: 1px solid var(--line);
}
.site-footer p {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* ----------------------------- pagine errore ---------------------------- */
.error-page {
  max-width: var(--read);
  margin: 0 auto;
  text-align: center;
  padding: 3rem 0;
}
.error-page h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(3rem, 12vw, 6rem);
  line-height: 1;
  margin: 0 0 1rem;
}
.error-page--404 h1::after {
  content: " ▍";
  color: var(--green);
  animation: caret 1.05s steps(1) infinite;
}
@media (prefers-reduced-motion: reduce) {
  .error-page--404 h1::after { animation: none; }
}
.error-page p { font-family: var(--mono); font-size: 0.9rem; color: var(--muted); }
.error-page a { color: var(--green); text-decoration: none; }
.error-page a:hover { text-decoration: underline; }

/* ------------------------------ mobile ---------------------------------- */
@media (max-width: 680px) {
  .post-card { flex-direction: column; gap: 1.1rem; }
  .post-card__media { flex-basis: auto; }
  .post-card__media img { aspect-ratio: 16 / 9; }
}

@media (max-width: 600px) {
  .nav-toggle { display: inline-flex; }
  .site-nav { display: none; flex-basis: 100%; }
  .site-nav.is-open { display: block; }
  .site-nav ul { flex-direction: column; gap: 0.85rem; padding-top: 1rem; }
}
