/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

/* === Theme tokens === */
:root {
  --bg: #fafafa;
  --fg: #0a0a0a;
  --muted: #8a8a8a;
  --line: rgba(0,0,0,0.07);
  --line-strong: rgba(0,0,0,0.13);
  --dot: #1ab574;
  --radius: 10px;
}

html[data-theme="dark"] {
  --bg: #0a0a0a;
  --fg: #f5f5f5;
  --muted: #707070;
  --line: rgba(255,255,255,0.08);
  --line-strong: rgba(255,255,255,0.15);
  --dot: #2dd698;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0a0a0a;
    --fg: #f5f5f5;
    --muted: #707070;
    --line: rgba(255,255,255,0.08);
    --line-strong: rgba(255,255,255,0.15);
    --dot: #2dd698;
  }
}

/* === Theme switch transition (only while toggling) === */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color .35s ease, color .35s ease,
              border-color .35s ease, fill .35s ease, stroke .35s ease !important;
}
@media (prefers-reduced-motion: reduce) {
  html.theme-transition,
  html.theme-transition *,
  html.theme-transition *::before,
  html.theme-transition *::after { transition: none !important; }
}

/* === Lock page scroll === */
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, -apple-system, "Inter", BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  font-weight: 400;
  letter-spacing: -0.011em;
  font-feature-settings: "ss01", "cv11";
  display: flex;
  flex-direction: column;
}

::selection { background: var(--fg); color: var(--bg); }
a { color: inherit; text-decoration: none; }

/* === Shell — same column for header, content, footer === */
.shell {
  flex: 1;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  flex-direction: column;
  min-height: 0;             /* allow inner flex to shrink for scroll */
  animation: enter .6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* === Header === */
.site-header {
  flex-shrink: 0;
  padding: 24px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-header .logo {
  font-weight: 500;
  font-size: 14px;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.site-header .logo .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--dot) 60%, transparent);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dot) 50%, transparent); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.site-header .right {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13.5px;
  color: var(--muted);
}
.site-header .right a {
  padding: 6px 10px;
  border-radius: 100px;
  white-space: nowrap;
}
.site-header .right a:hover { color: var(--fg); background: var(--line); }

.theme-toggle {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin-left: 4px;
}
.theme-toggle:hover { color: var(--fg); background: var(--line); }
.theme-toggle svg { width: 15px; height: 15px; }
html[data-theme="dark"] .theme-toggle .sun,
html:not([data-theme="dark"]) .theme-toggle .moon { display: block; }
html[data-theme="dark"] .theme-toggle .moon,
html:not([data-theme="dark"]) .theme-toggle .sun { display: none; }

/* === Scroll area — the only thing that scrolls === */
.scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* IE/Edge */
  padding-top: 32px;
  padding-bottom: 56px;
  /* Fade mask at top/bottom edges so content fades into header/footer */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
}
.scroll-area::-webkit-scrollbar { display: none; }

/* === Views === */
.view { display: none; flex-direction: column; }
.view[data-active="true"] {
  display: flex;
  animation: viewIn .35s ease both;
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* === Intro === */
.intro { margin-bottom: clamp(64px, 10vw, 96px); }
.intro .lede {
  font-size: clamp(24px, 4.2vw, 32px);
  line-height: 1.18;
  letter-spacing: -0.025em;
  font-weight: 500;
  margin-bottom: 20px;
  max-width: 520px;
}
.intro .lede em { color: var(--muted); font-style: normal; }
.intro .bio {
  font-size: 15px;
  color: var(--muted);
  max-width: 480px;
  line-height: 1.65;
}
.intro .status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 28px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 5px 12px 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 100px;
}
.intro .status .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--dot);
}

/* === Sections === */
section + section { margin-top: clamp(48px, 8vw, 72px); }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.section-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.section-right {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.section-meta {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Per-section order toggle — arrow up = newest first, flips down for oldest.
   Hover background is an inset circle so it's never clipped at the content edge. */
.sort-toggle {
  position: relative;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sort-toggle::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: transparent;
  transition: background .2s ease;
}
.sort-toggle:hover { color: var(--fg); }
.sort-toggle:hover::before { background: var(--line); }
.sort-toggle svg {
  position: relative;
  width: 15px;
  height: 15px;
  transition: transform .35s cubic-bezier(0.16, 1, 0.3, 1);
}
.sort-toggle[data-dir="asc"] svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
  .sort-toggle svg { transition: none; }
}

/* === Lists === */
.list { list-style: none; }
.list-item a {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 16px;
  padding: 14px 0;
  font-size: 14.5px;
  color: var(--fg);
  border-bottom: 1px solid var(--line);
}
.list-item:last-child a { border-bottom: none; }

/* Collapsed items (beyond the home limit) and their reveal animation */
.list-item.is-collapsed { display: none; }
.list-item.revealing {
  animation: itemReveal .42s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: var(--reveal-delay, 0ms);
}
@keyframes itemReveal {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* "Vedi altri" button */
.list-more { display: flex; padding-top: 16px; }
.more-btn {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 100px;
  padding: 6px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color .2s ease, background .2s ease;
}
.more-btn:hover { color: var(--fg); background: var(--line); }
.more-btn .more-count { font-variant-numeric: tabular-nums; opacity: .65; }
@media (prefers-reduced-motion: reduce) {
  .list-item.revealing { animation: none; }
}

.list-item .item-title {
  font-weight: 400;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.list-item .item-title::after {
  content: "→";
  opacity: 0;
  color: var(--muted);
  transform: translateX(-4px);
  transition: opacity .2s ease, transform .2s ease;
  font-size: 13px;
}
.list-item a:hover .item-title::after { opacity: 1; transform: translateX(0); }
.list-item .item-date {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* === Detail views === */
.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 40px;
  padding: 6px 10px;
  border-radius: 100px;
  width: max-content;
  transition: gap .2s ease;
}
.back:hover { color: var(--fg); background: var(--line); gap: 8px; }

.cover {
  aspect-ratio: 16 / 9;
  margin-bottom: 40px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--line);
}
.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.post-header { margin-bottom: 36px; }
.post-header h1 {
  font-size: clamp(22px, 3.2vw, 26px);
  line-height: 1.25;
  letter-spacing: -0.022em;
  margin-bottom: 14px;
  font-weight: 500;
  max-width: 560px;
}
.post-meta {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  gap: 14px;
  font-variant-numeric: tabular-nums;
}
.post-meta > *:not(:first-child)::before {
  content: "·";
  margin-right: 14px;
  color: var(--line-strong);
}

.post-body { font-size: 15.5px; line-height: 1.75; }
.post-body p { margin-bottom: 1.25em; }
.post-body em { font-style: italic; }
.post-body h2 {
  font-size: 16px;
  font-weight: 500;
  margin: 2.5em 0 0.75em;
  letter-spacing: -0.015em;
}
.post-body blockquote {
  margin: 2em 0;
  padding-left: 18px;
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
}
.post-body blockquote strong { color: inherit; font-weight: 500; }
.post-body blockquote br { line-height: 2; }
.post-body img {
  max-width: 100%;
  display: block;
  margin: 2em 0;
  border-radius: var(--radius);
}
.post-body ol {
  margin: 1.6em 0;
  padding-left: 1.5em;
  display: flex;
  flex-direction: column;
  gap: 0.55em;
}
.post-body ol li { padding-left: 0.3em; }
.post-body ol li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }
/* A quote directly followed by a list reads as one block (e.g. a manifesto) */
.post-body blockquote + ol { margin-top: -0.8em; }
.post-body .post-caption {
  font-size: 13px;
  color: var(--muted);
  margin: -0.4em 0 2em;
}
.post-body .post-caption a {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.post-body .post-caption a:hover { color: var(--fg); }

.project-summary {
  font-size: 17px;
  color: var(--muted);
  max-width: 520px;
  margin-bottom: 36px;
  line-height: 1.55;
  letter-spacing: -0.01em;
}

.project-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 12px 40px;
  margin-bottom: 48px;
  padding: 22px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.project-meta dt { color: var(--muted); font-size: 13px; }
.project-meta dd { color: var(--fg); }

.project-section { margin-bottom: 40px; }
.project-section .section-label { margin-bottom: 14px; }

.process-list { list-style: none; }
.process-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 24px;
  padding: 16px 0;
  font-size: 14.5px;
  border-bottom: 1px solid var(--line);
}
.process-item:last-child { border-bottom: none; }
.process-item .step-name { color: var(--muted); font-size: 13px; padding-top: 1px; }
.process-item .step-body { line-height: 1.6; }

.outcomes { list-style: none; font-size: 14.5px; }
.outcomes li {
  padding: 10px 0;
  display: flex;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}
.outcomes li:last-child { border-bottom: none; }
.outcomes li::before { content: "→"; color: var(--muted); font-size: 13px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 12.5px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 100px;
}

.gallery {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gallery figure { margin: 0; }
.gallery img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
  background: var(--line);
}
.gallery figcaption {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 8px;
}

/* === Footer === */
.site-footer {
  flex-shrink: 0;
  padding: 18px 0 22px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-variant-numeric: tabular-nums;
  border-top: 1px solid var(--line);
}
.site-footer a {
  padding: 4px 10px;
  margin: -4px -10px;
  border-radius: 100px;
}
.site-footer a:hover { color: var(--fg); background: var(--line); }

/* === Responsive === */
@media (max-width: 560px) {
  .shell { padding: 0 20px; }
  .site-header { padding: 18px 0; }
  /* Section links don't fit next to the logo on small screens — the
     sections are still reachable by scrolling the home. */
  .site-header .right a { display: none; }
  .scroll-area { padding-top: 24px; padding-bottom: 40px; }
  .list-item a { grid-template-columns: 1fr auto; gap: 12px; font-size: 14px; }
  .process-item { grid-template-columns: 1fr; gap: 4px; }
  .process-item .step-name { font-size: 12px; }
  .intro .status { font-size: 12px; }
  .project-meta { grid-template-columns: max-content 1fr; gap: 10px 24px; }
}

/* === Loading === */
.loading {
  font-size: 13px;
  color: var(--muted);
  padding: 14px 0;
}
