/*
 * Same look as marcopilloni.com (Bento Night): dark by default, light on request.
 * The inline script in <head> sets data-theme and data-filter before paint.
 */
:root {
    color-scheme: dark;
    --bg: 14 17 22;
    --surface: 23 27 34;
    --ink: 232 236 242;
    --muted: 154 164 178;
    --subtle: 125 136 152;
    --line: 42 48 58;
    --accent: 255 107 94;      /* red, from the {} icon */
    --accent-ink: 40 8 6;
    --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
:root[data-theme="light"] {
    color-scheme: light;
    --bg: 242 240 235;
    --surface: 255 255 255;
    --ink: 20 22 26;
    --muted: 91 98 112;
    --subtle: 100 106 118;
    --line: 217 214 206;
    --accent: 200 32 22;
    --accent-ink: 255 255 255;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: rgb(var(--bg)); -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: rgb(var(--bg));
    color: rgb(var(--ink));
    font-family: var(--font);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color .3s ease, color .3s ease;
}
a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; height: auto; display: block; }
h1, h2, h3, h4 { margin: 0; }
p { margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 1152px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .wrap { padding: 0 24px; } }
.narrow { max-width: 780px; margin: 0 auto; }
main { padding-top: 32px; padding-bottom: 32px; display: flex; flex-direction: column; gap: 16px; min-height: 60vh; }
@media (min-width: 768px) { main { padding-top: 48px; } }

.mono { font-family: var(--mono); font-size: 12px; letter-spacing: .08em; color: rgb(var(--subtle)); text-transform: uppercase; }
.muted { color: rgb(var(--muted)); }

/* --- Nav --- */
.nav { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 20px 16px 0; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.02em; }
.nav { flex-wrap: nowrap; }
@media (max-width: 480px) { .brand-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } }
.brand img { width: 26px; height: 26px; border-radius: 7px; }
.pill { display: inline-flex; gap: 4px; padding: 5px; border-radius: 999px; background: rgb(var(--surface)); font-size: 14px; font-weight: 600; }
.pill a { padding: 8px 16px; border-radius: 999px; color: rgb(var(--muted)); transition: color .2s, background .2s; }
.pill a:hover { color: rgb(var(--ink)); }
.pill a[aria-current="page"] { background: rgb(var(--ink)); color: rgb(var(--bg)); }
.icon-btn { width: 42px; height: 42px; border-radius: 999px; border: 0; background: rgb(var(--surface)); color: rgb(var(--ink)); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { opacity: .8; }
.icon-btn svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
:root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }

/* --- Tiles and chips --- */
.tile { background: rgb(var(--surface)); border-radius: 28px; padding: 28px; }
@media (min-width: 640px) { .tile { padding: 36px; } }
.tile-hover { transition: transform .35s cubic-bezier(.22, 1, .36, 1); display: block; }
.tile-hover:hover { transform: translateY(-4px); }
.chip { display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 999px; background: rgb(var(--bg)); font-size: 13px; font-weight: 500; }
/* Chips sitting on the page background (not on a tile) need their own fill */
.post-head .chip, .hero .chip { background: rgb(var(--bg)); }
.post-head .chip { background: rgb(var(--surface)); }
a.chip:hover { color: rgb(var(--accent)); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 20px; border-radius: 999px; font-size: 15px; font-weight: 700; border: 0; cursor: pointer; background: rgb(var(--accent)); color: rgb(var(--accent-ink)); font-family: inherit; }
.btn:hover { opacity: .9; }
.btn.ghost { background: transparent; border: 1.5px solid rgb(var(--line)); color: rgb(var(--ink)); }
.link { color: rgb(var(--accent)); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }

/* --- Home --- */
.hero { display: flex; flex-direction: column; gap: 22px; }
.hero h1 { font-size: clamp(2.6rem, 8vw, 4.5rem); line-height: .98; font-weight: 800; letter-spacing: -.04em; }
.hero h1 .accent { color: rgb(var(--accent)); }
.hero p.lead { font-size: 17px; max-width: 640px; line-height: 1.6; }
.hero-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: rgb(var(--bg)); gap: 2px; }
.seg button { border: 0; background: transparent; color: rgb(var(--muted)); font: 600 13px var(--font); padding: 8px 14px; border-radius: 999px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: rgb(var(--ink)); color: rgb(var(--bg)); }

.posts { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 768px) { .posts { grid-template-columns: 1fr 1fr; } }
/* A lone post takes the whole row */
.posts > .post-card:only-child { grid-column: 1 / -1; min-height: 0; }
.post-card { display: flex; flex-direction: column; gap: 14px; min-height: 260px; }
.post-card h2 { font-size: 28px; font-weight: 800; letter-spacing: -.03em; line-height: 1.08; }
.post-card p { color: rgb(var(--muted)); line-height: 1.55; }
.post-card .chips { margin-top: auto; }
.meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.badge { font: 700 11px var(--mono); letter-spacing: .08em; padding: 3px 8px; border-radius: 999px; background: rgb(var(--accent)); color: rgb(var(--accent-ink)); }
.empty { display: none; }
.empty.show { display: block; }

/* Language filter: a post is hidden when its language is not the selected one */
:root[data-filter="it"] [data-lang="en"].post-card,
:root[data-filter="en"] [data-lang="it"].post-card { display: none; }
/* Interface text in the visitor's language: Italian when filtered on Italian, else English */
:root[data-ui="it"] [data-t="en"],
:root:not([data-ui="it"]) [data-t="it"] { display: none; }

/* --- Post page --- */
.post-head { display: flex; flex-direction: column; gap: 18px; }
.post-head h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); line-height: 1; font-weight: 800; letter-spacing: -.04em; text-wrap: balance; }
.post-head .lead { font-size: 19px; color: rgb(var(--muted)); line-height: 1.55; max-width: 680px; }
.back { font: 500 12px var(--mono); letter-spacing: .08em; color: rgb(var(--muted)); text-transform: uppercase; align-self: flex-start; }
.back:hover { color: rgb(var(--ink)); }

.prose { font-size: 18px; line-height: 1.75; }
.prose > * + * { margin-top: 1.1em; }
.prose h2 { font-size: 1.7rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; margin-top: 2em; }
.prose h3 { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; margin-top: 1.8em; }
.prose h2 .anchor, .prose h3 .anchor { color: rgb(var(--subtle)); margin-left: .4em; font-weight: 400; opacity: 0; text-decoration: none; }
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }
.prose a { color: rgb(var(--accent)); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: .35em; }
.prose blockquote { margin-left: 0; padding: 4px 0 4px 20px; border-left: 3px solid rgb(var(--accent)); color: rgb(var(--muted)); }
.prose hr { border: 0; border-top: 1px solid rgb(var(--line)); margin: 2em 0; }
.prose :not(pre) > code { font: 500 .86em var(--mono); background: rgb(var(--bg)); padding: .15em .45em; border-radius: 7px; }
.prose img, .prose video { border-radius: 18px; margin: 1.6em 0; width: 100%; background: rgb(var(--bg)); }
.prose table { width: 100%; border-collapse: collapse; font-size: 16px; }
.prose th, .prose td { text-align: left; padding: 10px 12px; border-bottom: 1px solid rgb(var(--line)); }

/* Plain code blocks (the editor preview does not run Shiki) */
.prose pre:not(.shiki) { margin: 1.5em 0; padding: 20px 22px; overflow-x: auto; border-radius: 18px; background: rgb(var(--bg)); font: 400 14px/1.65 var(--mono); }
.prose pre:not(.shiki) code { font: inherit; background: none; padding: 0; }

/* Code blocks (Shiki writes both theme colours as variables) */
.code { position: relative; margin: 1.5em 0; border-radius: 18px; background: rgb(var(--bg)); overflow: hidden; }
.code pre { margin: 0; padding: 20px 22px; overflow-x: auto; font: 400 14px/1.65 var(--mono); tab-size: 4; background: transparent !important; }
.code pre code { font: inherit; background: none; padding: 0; }
.shiki span { color: var(--shiki-dark); }
:root[data-theme="light"] .shiki span { color: var(--shiki-light); }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px 0 22px; font: 500 11px var(--mono); letter-spacing: .08em; color: rgb(var(--subtle)); text-transform: uppercase; }
.copy { border: 0; background: rgb(var(--surface)); color: rgb(var(--muted)); font: 600 12px var(--font); padding: 5px 11px; border-radius: 999px; cursor: pointer; }
.copy:hover { color: rgb(var(--ink)); }

.post-foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }

/* --- Footer --- */
.footer { margin-top: 24px; padding-top: 8px; padding-bottom: 40px; }
.footer .tile { display: flex; flex-wrap: wrap; gap: 16px 32px; align-items: center; justify-content: space-between; padding: 24px 28px; }
.footer a:hover { color: rgb(var(--accent)); }
.footer .links { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 14px; font-weight: 600; }
.footer small { color: rgb(var(--subtle)); font: 400 12px var(--mono); }

/* --- Motion --- */
@keyframes tileIn { from { opacity: 0; transform: translateY(28px) scale(.97); } to { opacity: 1; transform: none; } }
.enter { animation: tileIn .8s cubic-bezier(.22, 1, .36, 1) backwards; }
.stagger:not(.is-visible) > * { opacity: 0; }
.stagger.is-visible > * { animation: tileIn .8s cubic-bezier(.22, 1, .36, 1) backwards; animation-delay: calc(min(var(--i, 0), 6) * 90ms); }

:focus:not(:focus-visible) { outline: none; }
a:focus-visible, button:focus-visible { outline: 2px solid rgb(var(--accent)); outline-offset: 3px; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    body { transition: none; }
    .enter, .stagger > * { opacity: 1 !important; animation: none !important; }
    .tile-hover:hover { transform: none; }
}
