/* Maurizio Carlini · portfolio
   One stylesheet, tokens first. Light and dark follow the OS setting. */

/* Self-hosted fonts (SIL Open Font License), no requests to third parties */
@font-face { font-family: "Hanken Grotesk"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("fonts/hanken-grotesk-latin.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/jetbrains-mono-500-latin.woff2") format("woff2"); }

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #eeece6;
  --ink: #16181a;
  --muted: #53575c;
  --line: #dcd9d1;
  --accent: #ad1a5c;
  --accent-ink: #ffffff;
  --focus: #1f5fd1;
  /* Accent for inverted surfaces (contact block): the other theme's values */
  --accent-inverse: #ff7eb4;
  --accent-ink-inverse: #2a0a18;
  --focus-inverse: #8fb4ff;

  --font: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --wrap: 1180px;
  --gutter: clamp(16px, 4vw, 40px);
  --radius: 14px;
  --space-section: clamp(72px, 10vw, 136px);
  color-scheme: light dark;
}

:root[data-theme="dark"] {
  --bg: #111214;
  --surface: #191b1e;
  --surface-2: #202327;
  --ink: #edebe6;
  --muted: #a5a8ad;
  --line: #2e3136;
  --accent: #ff7eb4;
  --accent-ink: #2a0a18;
  --focus: #8fb4ff;
  --accent-inverse: #ad1a5c;
  --accent-ink-inverse: #ffffff;
  --focus-inverse: #1f5fd1;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #191b1e;
    --surface-2: #202327;
    --ink: #edebe6;
    --muted: #a5a8ad;
    --line: #2e3136;
    --accent: #ff7eb4;
    --accent-ink: #2a0a18;
    --focus: #8fb4ff;
    --accent-inverse: #ad1a5c;
    --accent-ink-inverse: #ffffff;
    --focus-inverse: #1f5fd1;
  }
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1.0625rem/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { display: block; max-width: 100%; height: auto; }
a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 4px; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }

.wrap { width: 100%; max-width: calc(var(--wrap) + var(--gutter) * 2); margin: 0 auto; padding: 0 var(--gutter); }

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 10;
  padding: 10px 14px; background: var(--ink); color: var(--bg); border-radius: 8px;
}
.skip:focus { top: 12px; }

.eyebrow {
  font: 500 0.78rem/1.4 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Header ---------- */
.site-header { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid transparent; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 64px; }
.brand { font-weight: 600; text-decoration: none; letter-spacing: -0.01em; }
.nav { display: flex; align-items: center; gap: clamp(14px, 2.4vw, 28px); font-size: 0.95rem; }
.nav a { text-decoration: none; color: var(--muted); }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }
.nav .btn { color: var(--accent-ink); }
@media (max-width: 640px) { .nav .hide-sm { display: none; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--ink);
  font-weight: 600; font-size: 0.95rem; text-decoration: none;
  background: var(--ink); color: var(--bg);
  transition: background .15s, color .15s, border-color .15s;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: transparent; color: var(--accent); border-color: var(--accent); }
.nav .btn { min-height: 38px; padding: 0 14px; background: var(--accent); border-color: var(--accent); }
.nav .btn:hover { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* ---------- Hero ---------- */
.hero { padding: clamp(48px, 8vw, 104px) 0 clamp(48px, 7vw, 88px); }
.hero-grid { display: grid; grid-template-columns: 1fr; gap: 40px; align-items: center; }
@media (min-width: 900px) { .hero-grid { grid-template-columns: minmax(0, 1fr) 280px; gap: 64px; } }
.hero h1 { font-size: clamp(2.4rem, 6.2vw, 4.6rem); line-height: 1.02; letter-spacing: -0.035em; font-weight: 600; max-width: 17ch; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero .lede { margin-top: 28px; max-width: 58ch; font-size: clamp(1.08rem, 1.6vw, 1.25rem); color: var(--muted); }
.hero .lede strong { color: var(--ink); font-weight: 600; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 36px; }
.status { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 28px; font-size: 0.95rem; color: var(--muted); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #2f9e5a; box-shadow: 0 0 0 4px color-mix(in srgb, #2f9e5a 22%, transparent); }
.portrait { margin: 0; }
.portrait img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; object-position: 50% 20%; border-radius: var(--radius); filter: grayscale(1) contrast(1.05); }
.portrait figcaption { margin-top: 12px; font-size: 0.88rem; color: var(--muted); }
@media (max-width: 899px) { .portrait { max-width: 112px; order: -1; } .portrait img { aspect-ratio: 1; border-radius: 50%; } .hero-grid { gap: 24px; } }

/* ---------- Proof strip ---------- */
.proof { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.proof ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 800px) { .proof ul { grid-template-columns: repeat(4, 1fr); } }
.proof li { padding: 26px 20px 26px 0; }
.proof li + li { border-left: 1px solid var(--line); padding-left: 20px; }
@media (max-width: 799px) {
  .proof li:nth-child(3) { border-left: 0; padding-left: 0; }
  .proof li:nth-child(n+3) { border-top: 1px solid var(--line); }
}
.proof b { display: block; font-size: clamp(1.8rem, 3.4vw, 2.5rem); font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; }
.proof span { display: block; margin-top: 6px; font-size: 0.92rem; color: var(--muted); max-width: 22ch; }

/* ---------- Sections ---------- */
.section { padding: var(--space-section) 0 0; }
.section-head { display: grid; gap: 14px; margin-bottom: clamp(32px, 5vw, 56px); max-width: 62ch; }
.section-head h2 { font-size: clamp(1.9rem, 3.6vw, 2.75rem); }
.section-head p { color: var(--muted); font-size: 1.08rem; }

/* ---------- Work cards ---------- */
.work-list { display: grid; gap: clamp(20px, 3vw, 32px); }
.work-card {
  position: relative; display: grid; grid-template-columns: 1fr; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px);
  transition: border-color .2s, transform .2s;
}
@media (min-width: 900px) { .work-card { grid-template-columns: 1.15fr 1fr; } .work-card:nth-child(even) .work-media { order: 2; } }
.work-card:hover { border-color: var(--accent); }
@media (prefers-reduced-motion: no-preference) { .work-card:hover { transform: translateY(-2px); } }
.work-media { background: var(--surface-2); position: relative; aspect-ratio: 32 / 21; overflow: hidden; }
@media (max-width: 899px) { .work-media { aspect-ratio: 32 / 23; } }
@media (min-width: 900px) { .work-media { aspect-ratio: auto; min-height: 100%; } }
.work-media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center; }
.work-body { padding: clamp(24px, 3.5vw, 44px); display: flex; flex-direction: column; gap: 16px; }
.work-body h3 { font-size: clamp(1.55rem, 2.6vw, 2rem); }
.work-body h3 a { text-decoration: none; }
.work-body h3 a::after { content: ""; position: absolute; inset: 0; }
.work-body .summary { color: var(--muted); }
.work-points { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 10px; font-size: 0.97rem; }
.work-points li { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.work-points li > span:first-child { font: 500 0.74rem/1.9 var(--mono); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.work-more { margin-top: auto; padding-top: 8px; font-weight: 600; color: var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.tags li { font: 500 0.74rem/1 var(--mono); padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }

/* ---------- Principles ---------- */
.principles { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
@media (min-width: 760px) { .principles { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1080px) { .principles { grid-template-columns: repeat(4, 1fr); } }
.principle { background: var(--bg); padding: 28px 24px 32px; display: grid; gap: 10px; align-content: start; }
.principle .num { font: 500 0.8rem var(--mono); color: var(--accent); }
.principle h3 { font-size: 1.2rem; letter-spacing: -0.01em; }
.principle p { color: var(--muted); font-size: 0.98rem; }

/* ---------- Experience ---------- */
.about-grid { display: grid; gap: 48px; }
@media (min-width: 900px) { .about-grid { grid-template-columns: 1fr 1.4fr; gap: 80px; } }
.about-copy { display: grid; gap: 18px; font-size: 1.1rem; }
.about-copy p:not(:first-child) { color: var(--muted); }
.skills { margin-top: 10px; }
.skills h3 { margin-bottom: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.timeline li { display: grid; grid-template-columns: 1fr; gap: 4px 24px; padding: 20px 0; border-bottom: 1px solid var(--line); }
@media (min-width: 640px) { .timeline li { grid-template-columns: 120px 1fr; } }
.timeline .when { font: 500 0.82rem/1.9 var(--mono); color: var(--muted); }
.timeline h3 { font-size: 1.1rem; letter-spacing: -0.01em; }
.timeline h3 span { font-weight: 400; color: var(--muted); }
.timeline p { color: var(--muted); font-size: 0.97rem; margin-top: 4px; }
.timeline .earlier p { margin: 0; }

/* ---------- Contact ---------- */
.contact { --accent: var(--accent-inverse); --accent-ink: var(--accent-ink-inverse); --focus: var(--focus-inverse); margin-top: var(--space-section); padding: clamp(56px, 8vw, 104px) 0; background: var(--ink); color: var(--bg); }
.contact h2 { font-size: clamp(2.2rem, 5.6vw, 4.2rem); line-height: 1.02; letter-spacing: -0.035em; max-width: 16ch; }
.contact p { margin-top: 20px; max-width: 52ch; color: color-mix(in srgb, var(--bg) 72%, var(--ink)); font-size: 1.1rem; }
.contact .hero-actions .btn { background: var(--bg); color: var(--ink); border-color: var(--bg); }
.contact .hero-actions .btn:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.contact .hero-actions .btn-ghost { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 35%, var(--ink)); }
.mail { display: inline-block; margin-top: 28px; font-size: clamp(1.1rem, 2.4vw, 1.6rem); font-weight: 500; color: var(--bg); word-break: break-all; }
.mail:hover { color: var(--accent); }

.site-footer { padding: 28px 0 40px; font-size: 0.9rem; color: var(--muted); }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; }
.site-footer a { color: var(--muted); }

/* ================= Case study ================= */
.case-hero { padding: clamp(36px, 6vw, 72px) 0 clamp(32px, 5vw, 56px); }
.crumb { display: inline-block; margin-bottom: 36px; font-size: 0.95rem; color: var(--muted); text-decoration: none; }
.case-hero h1 { margin-top: 14px; font-size: clamp(2.4rem, 6vw, 4.4rem); line-height: 1.02; letter-spacing: -0.035em; max-width: 18ch; }
.case-hero .lede { margin-top: 24px; max-width: 60ch; font-size: clamp(1.1rem, 1.7vw, 1.3rem); color: var(--muted); }

.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; margin: 40px 0 0; padding: 24px 0 0; border-top: 1px solid var(--line); }
@media (min-width: 860px) { .facts { grid-template-columns: repeat(4, 1fr); } }
.facts dt { font: 500 0.74rem/1.5 var(--mono); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.facts dd { margin: 6px 0 0; font-size: 0.98rem; }

.cover { margin: 0; }
.cover img { width: 100%; border-radius: calc(var(--radius) + 4px); border: 1px solid var(--line); }

.tldr { display: grid; gap: 1px; margin-top: clamp(40px, 6vw, 72px); background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
@media (min-width: 860px) { .tldr { grid-template-columns: repeat(3, 1fr); } }
.tldr > div { background: var(--surface); padding: 26px 24px 28px; }
.tldr h2 { font: 500 0.78rem/1.4 var(--mono); text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); margin-bottom: 10px; }
.tldr p { font-size: 1rem; }

.chapter { padding-top: clamp(64px, 9vw, 112px); display: grid; gap: 28px; }
@media (min-width: 960px) { .chapter { grid-template-columns: 240px minmax(0, 1fr); gap: 56px; } }
.chapter > header .eyebrow { color: var(--accent); }
.chapter > header h2 { margin-top: 10px; font-size: clamp(1.6rem, 2.8vw, 2.1rem); }
@media (min-width: 960px) { .chapter > header { position: sticky; top: 96px; align-self: start; } }
.prose { display: grid; gap: 18px; max-width: 68ch; font-size: 1.08rem; }
.prose p { color: var(--muted); }
.prose p strong { color: var(--ink); font-weight: 600; }
.prose ul { margin: 0; padding-left: 1.2em; color: var(--muted); display: grid; gap: 8px; }
.prose li strong { color: var(--ink); }
.prose h3 { margin-top: 18px; font-size: 1.3rem; letter-spacing: -0.015em; }

.figure { margin: 12px 0 8px; }
.figure a { display: block; }
.figure img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); }
.figure figcaption { margin-top: 10px; font-size: 0.9rem; color: var(--muted); }

.decisions { display: grid; gap: 16px; }
.decision { padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: grid; gap: 10px; }
.decision h3 { margin: 0; font-size: 1.15rem; }
.decision p { font-size: 1rem; }
.decision .why { font-size: 0.95rem; }
.decision .why b { font: 500 0.74rem var(--mono); text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); margin-right: 6px; }

.quote { margin: 8px 0; padding: 4px 0 4px 20px; border-left: 3px solid var(--accent); font-size: 1.2rem; line-height: 1.45; color: var(--ink); }

.next { margin-top: clamp(72px, 10vw, 120px); padding-top: 32px; border-top: 1px solid var(--line); }
.next a { display: grid; gap: 8px; text-decoration: none; }
.next b { font-size: clamp(1.8rem, 4vw, 3rem); letter-spacing: -0.03em; font-weight: 600; line-height: 1.05; }
.next a:hover b { color: var(--accent); }
.next a span:last-child { color: var(--muted); }

/* ---------- Live figures (HTML instead of images) ---------- */
.panel { margin: 12px 0 8px; padding: clamp(18px, 3vw, 28px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-cap { margin-top: 10px; font-size: 0.9rem; color: var(--muted); }

.code { margin: 0; padding: 18px 20px; overflow-x: auto; background: var(--surface-2); border-radius: 10px; font: 500 0.82rem/1.65 var(--mono); color: var(--ink); white-space: pre-wrap; }
.code .c { color: var(--muted); }
.code .k { color: var(--accent); }

.flow { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; counter-reset: flow; }
@media (min-width: 640px) { .flow { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1240px) { .flow { grid-template-columns: repeat(4, 1fr); } }
.flow li { position: relative; padding: 16px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; counter-increment: flow; }
.flow li::before { content: counter(flow, decimal-leading-zero); display: block; margin-bottom: 8px; font: 500 0.74rem var(--mono); color: var(--accent); }
.flow b { display: block; font-size: 0.98rem; }
.flow span { display: block; margin-top: 4px; font-size: 0.9rem; color: var(--muted); }

.layers { display: grid; gap: 10px; }
.layer { display: grid; gap: 4px 16px; padding: 14px 16px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
@media (min-width: 720px) { .layer { grid-template-columns: 150px 1fr; align-items: baseline; } }
.layer b { font: 500 0.78rem var(--mono); text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.layer span { font-size: 0.95rem; color: var(--muted); }
.layer code { font: 500 0.82rem var(--mono); color: var(--ink); }
.layer-arrow { justify-self: center; color: var(--muted); font-size: 0.9rem; line-height: 1; }

.owners { display: grid; gap: 12px; }
@media (min-width: 720px) { .owners { grid-template-columns: repeat(3, 1fr); } }
.owner { padding: 16px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.owner h4 { margin: 0 0 10px; font-size: 1rem; }
.owner ul { margin: 0; padding-left: 1.1em; display: grid; gap: 6px; font-size: 0.92rem; color: var(--muted); }

.ratios { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.ratios caption { text-align: left; margin-bottom: 12px; font-size: 0.9rem; color: var(--muted); }
.ratios th, .ratios td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.ratios thead th { font: 500 0.74rem var(--mono); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.ratios td.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.ratios th.num { text-align: right; }
.swatch { display: inline-flex; align-items: center; justify-content: center; min-width: 52px; padding: 3px 8px; border-radius: 6px; font: 600 0.82rem var(--font); border: 1px solid var(--line); }
@media (max-width: 560px) { .ratios .hide-xs { display: none; } }

.pair { display: grid; gap: 12px; }
@media (min-width: 720px) { .pair { grid-template-columns: 1fr 1fr; } }
.pair .figure { margin: 0; }

.ratios .note { display: block; font: 500 0.72rem var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.swatch svg { display: block; }

/* ---------- Theme toggle ---------- */
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--ink); cursor: pointer; }
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: block; }
}

/* ---------- Lightbox ---------- */
.figure a { cursor: zoom-in; }
.lightbox { width: min(96vw, 1600px); max-width: none; max-height: 94vh; margin: auto; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); overflow: hidden; }
.lightbox::backdrop { background: rgb(10 10 14 / .78); }
.lightbox-inner { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-height: 94vh; }
.lightbox-bar { display: flex; justify-content: flex-end; padding: 10px; }
.lightbox-close { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--ink); font: 600 0.92rem var(--font); cursor: pointer; }
.lightbox-close:hover { border-color: var(--accent); color: var(--accent); }
.lightbox-body { overflow: auto; padding: 0 16px; }
.lightbox-body img { width: 100%; height: auto; border-radius: 10px; }
.lightbox-cap { padding: 12px 16px 16px; font-size: 0.92rem; color: var(--muted); }
.lightbox-cap:empty { display: none; }
@media (prefers-reduced-motion: no-preference) { .lightbox[open] { animation: lb-in .16s ease-out; } @keyframes lb-in { from { opacity: 0; transform: scale(.98); } } }
