/* Terminal / pixel identity: phosphor-green accent, Silkscreen for display text, JetBrains Mono for UI. */

/* Self-hosted fonts (SIL Open Font License 1.1, see fonts/LICENSE.md): no request to third-party servers. */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 400 500; font-display: swap;
  src: url("fonts/inter-latin.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 400 500; font-display: swap;
  src: url("fonts/jetbrains-mono-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Silkscreen"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("fonts/silkscreen-latin.woff2") format("woff2");
}

:root {
  --bg: #121412;
  --bg-2: #1a1d1a;
  --fg: #e9eee8;
  --muted: #8a938a;
  --dim: #4b524b;
  --line: #2c322c;
  --accent: #7dff9b;
  --accent-dim: rgba(125, 255, 155, .35);
  --pixel: "Silkscreen", "JetBrains Mono", ui-monospace, monospace;
  --sans: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --gutter: clamp(16px, 4vw, 64px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
/* faint dot grid + CRT scanlines instead of film grain */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 1px, transparent 1px 3px);
  opacity: .5;
}
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background-image: radial-gradient(rgba(125,255,155,.07) 1px, transparent 1px);
  background-size: 24px 24px;
}
a { color: inherit; text-decoration: none; }
/* the hidden attribute must win over display:grid/flex set on .exam, .row, ... (used by the exam search) */
[hidden] { display: none !important; }
ul { list-style: none; }
::selection { background: var(--accent); color: var(--bg); }
.mono { font-family: var(--mono); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- i18n: show only the active language ---------- */
html[lang="it"] [data-l="en"], html[lang="en"] [data-l="it"] { display: none !important; }
.lang-toggle {
  font-family: var(--mono); font-size: 11px; letter-spacing: .04em; cursor: pointer;
  background: transparent; color: var(--dim); border: 1px solid var(--line); padding: 3px 8px;
  transition: border-color .2s;
}
.lang-toggle:hover { border-color: var(--accent-dim); }
.lang-toggle .lt-sep { margin: 0 3px; color: var(--dim); }
html[lang="it"] .lang-toggle .lt-it, html[lang="en"] .lang-toggle .lt-en { color: var(--accent); }

/* ---------- header ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px var(--gutter);
  background: rgba(18, 20, 18, .78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 18px; white-space: nowrap; }
.logo { font-family: var(--pixel); font-size: 13px; letter-spacing: .04em; }
.logo::before { content: "▮ "; color: var(--accent); }
.clock { color: var(--muted); font-size: 10px; }
.nav { display: flex; align-items: center; gap: clamp(14px, 2.4vw, 28px); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.nav-caret { color: var(--accent); font-weight: 500; animation: caret 1s steps(1) infinite; }
.nav a:not(.pill):hover { color: var(--accent); }
.nav a[aria-current="page"] { color: var(--accent); }
.pill { border: 1px solid var(--accent-dim); color: var(--accent); padding: 3px 9px; transition: background .2s, color .2s; }
.pill:hover { background: var(--accent); color: var(--bg); }
@media (max-width: 900px) { .clock { display: none; } }

/* ---------- hero ---------- */
.hero {
  position: relative; min-height: 100vh; min-height: 100svh;
  padding: 110px var(--gutter) 40px;
  display: flex; flex-direction: column; justify-content: space-between;
}
#particles { position: absolute; inset: 0; width: 100%; height: 100%; }
.hero-head { position: relative; z-index: 2; pointer-events: none; }
.prompt { color: var(--muted); text-transform: none; font-size: 12px; margin-bottom: 10px; }
.prompt .ps { color: var(--accent); }
.prompt .path { color: #8ab4ff; }
.pixel-title {
  font-family: var(--pixel); font-weight: 400;
  font-size: clamp(18px, 4vw, 54px); line-height: 1.05; letter-spacing: .01em;
  text-transform: uppercase; white-space: nowrap;
}
.cursor {
  display: inline-block; width: .55em; height: .9em; margin-left: .15em; vertical-align: -.05em;
  background: var(--accent); animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* typewriter (About) */
[data-typewriter] { cursor: text; }
.tw-typed { color: inherit; }
.tw-rest { color: transparent; }
.tw-caret {
  display: inline-block; width: .5em; height: 1em; margin: 0 1px; vertical-align: -.12em;
  background: var(--accent); animation: caret 1s steps(1) infinite;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hero-meta { position: relative; z-index: 2; display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; }
.hero-meta p { color: var(--muted); font-family: var(--pixel); font-size: 12px; letter-spacing: .04em; line-height: 1.7; }
.hint { animation: blink 2.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- sections ---------- */
.row {
  display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 40px;
  padding: 120px var(--gutter) 40px;
}
.label { font-family: var(--pixel); font-size: 13px; font-weight: 400; letter-spacing: .04em; position: sticky; top: 90px; align-self: start; }
.label .sl { color: var(--accent); }
.lead { font-size: clamp(20px, 2.2vw, 28px); line-height: 1.4; color: var(--muted); max-width: 30em; }

.entry { padding: 28px 0 32px; border-bottom: 1px dashed var(--line); }
.entry:first-child { padding-top: 0; }
.entry header { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; margin-bottom: 12px; }
.entry h3 { font-size: 15px; font-weight: 500; }
.entry time { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.entry p { color: var(--muted); font-size: 13px; max-width: 46em; }
.entry-link { display: inline-block; margin-top: 10px; font-family: var(--mono); font-size: 12px; color: var(--accent); }
.entry-link::before { content: "→ "; }
.entry-link:hover { text-decoration: underline; }
/* tags: outlined, terminal-flag style */
.tag {
  display: inline-block; font-family: var(--mono); font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent); border: 1px solid var(--accent-dim); padding: 0 6px; margin-left: 6px;
  line-height: 1.7; vertical-align: 1px;
}
.tag::before { content: "--"; opacity: .6; }

/* project cards */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.card {
  position: relative; background: var(--bg-2); border: 1px solid var(--line);
  padding: 22px 22px 20px; display: flex; flex-direction: column; gap: 10px;
  transition: border-color .25s, transform .25s;
}
.card::before { content: "● ● ●"; font-size: 7px; letter-spacing: 2px; color: var(--dim); }
.card:hover { border-color: var(--accent-dim); transform: translateY(-2px); }
.card .tag { margin-left: 0; align-self: flex-start; }
.card h3 { font-family: var(--pixel); font-weight: 400; font-size: 17px; line-height: 1.3; letter-spacing: .02em; }
.card p { color: var(--muted); font-size: 13px; flex: 1; }
.card.featured { grid-column: 1 / -1; }
.card.featured h3 { font-family: var(--pixel); font-weight: 400; font-size: clamp(20px, 2.4vw, 30px); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chips li { font-family: var(--mono); font-size: 10px; text-transform: lowercase; color: var(--muted); }
.chips li::before { content: "#"; color: var(--accent); }
.chips li + li { margin-left: 4px; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); }
.mini-stats b { font-family: var(--pixel); font-weight: 400; font-size: 18px; color: var(--accent); margin-right: 4px; }
.more { margin-top: 18px; color: var(--muted); text-transform: none; line-height: 1.7; }
.entry em { color: var(--fg); font-style: italic; }

/* Paper, Esperienze, Formazione: same boxed look as the Ricerca cards, CSS only (markup unchanged in both languages) */
#paper .content, #esperienze .content, #formazione .content { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
#paper .entry, #esperienze .entry, #formazione .entry {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--line); padding: 22px 22px 20px;
  transition: border-color .25s, transform .25s;
}
#paper .entry::before, #esperienze .entry::before, #formazione .entry::before { content: "● ● ●"; font-size: 7px; letter-spacing: 2px; color: var(--dim); }
#paper .entry:hover, #esperienze .entry:hover, #formazione .entry:hover { border-color: var(--accent-dim); transform: translateY(-2px); }
#formazione .entry:first-child { grid-column: 1 / -1; }
:is(#paper, #esperienze, #formazione) .entry header { display: block; margin: 0; }
/* the tag is the last child of the title: column-reverse lifts it above the title, like on the cards */
:is(#paper, #esperienze, #formazione) .entry h3 {
  display: flex; flex-direction: column-reverse; align-items: flex-start; gap: 10px;
  font-family: var(--pixel); font-weight: 400; font-size: 17px; line-height: 1.3; letter-spacing: .02em;
}
:is(#paper, #esperienze, #formazione) .entry h3 .tag { margin-left: 0; }
#formazione .entry:first-child h3 { font-size: clamp(20px, 2.4vw, 30px); }
:is(#paper, #esperienze, #formazione) .entry time { position: absolute; top: 18px; right: 22px; font-size: 11px; }
:is(#paper, #esperienze, #formazione) .entry p { flex: 1; }
:is(#paper, #esperienze, #formazione) .entry-link { margin-top: 0; }
@media (max-width: 860px) {
  #paper .content, #esperienze .content, #formazione .content { grid-template-columns: 1fr; }
}

/* skills */
.skills { display: flex; flex-wrap: wrap; gap: 6px 20px; font-family: var(--pixel); text-transform: uppercase; font-size: clamp(18px, 2.6vw, 34px); line-height: 1.3; }
.skills li { color: var(--dim); transition: color .25s; cursor: default; }
.skills li.lit, .skills li:hover { color: var(--accent); }
.skill-notes { margin-top: 40px; display: grid; gap: 12px; }
.skill-notes p { color: var(--muted); font-size: 13px; }
.skill-notes .tag { margin: 0 8px 0 0; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.stat { display: flex; flex-direction: column; gap: 10px; border-top: 1px dashed var(--line); padding-top: 18px; }
.stat .num { font-family: var(--pixel); font-size: clamp(48px, 6vw, 88px); line-height: 1; color: var(--accent); }
.stat .mono { color: var(--muted); line-height: 1.7; }
.stat a { color: var(--fg); border-bottom: 1px solid var(--line); }

/* contact */
.contact { padding: 160px var(--gutter) 80px; text-align: center; }
.contact > .mono { color: var(--muted); }
.contact-big { display: block; margin: 24px 0 32px; line-height: 1; }
.pixel-big { font-family: var(--pixel); font-size: clamp(40px, 9vw, 120px); }
.links { display: flex; justify-content: center; gap: 32px; flex-wrap: wrap; }
.links a:hover { color: var(--accent); }

.footer { display: flex; justify-content: space-between; padding: 24px var(--gutter); border-top: 1px solid var(--line); color: var(--muted); }

/* ---------- exams page ---------- */
.page-hero { padding: 120px var(--gutter) 20px; }
.page-hero .lead { margin-top: 28px; }
.back { color: var(--muted); display: inline-block; margin-bottom: 28px; }
.back:hover { color: var(--accent); }
.exam-tools { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; margin-top: 48px; border-top: 1px solid var(--line); padding-top: 18px; }
.search { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 240px; max-width: 480px; }
.search .mono { color: var(--accent); }
.search input {
  flex: 1; background: transparent; border: 0; border-bottom: 1px solid var(--line);
  color: var(--fg); font: 14px var(--mono); padding: 6px 0; outline: none; caret-color: var(--accent);
}
.search input:focus { border-color: var(--accent); }
.search input::placeholder { color: var(--dim); }
.count { color: var(--muted); }
.label .sub { color: var(--muted); font-family: var(--mono); font-size: 10px; display: inline-block; margin-top: 8px; line-height: 1.6; }

.exams { border-top: 1px solid var(--line); }
.exam {
  display: grid; grid-template-columns: 36px 1fr auto auto; align-items: center; gap: 18px;
  padding: 16px 0; border-bottom: 1px dashed var(--line); transition: background .2s, padding .2s;
}
.exam:hover { background: var(--bg-2); padding-left: 10px; padding-right: 10px; }
.exam .idx { color: var(--dim); }
.exam h3 { font-size: 15px; font-weight: 500; line-height: 1.35; }
.exam .code { color: var(--muted); font-size: 10px; }
.exam .status { color: var(--accent); font-size: 10px; }
.exam .status.pending { color: #ffcf6b; }
.notes { font-size: 10px; border: 1px dashed var(--line); padding: 3px 10px; color: var(--dim); white-space: nowrap; }
.notes.on { border: 1px solid var(--accent-dim); color: var(--accent); transition: background .2s, color .2s; }
.notes.on:hover { background: var(--accent); color: var(--bg); }
.empty { text-align: center; color: var(--muted); padding: 80px var(--gutter); }
@media (max-width: 600px) {
  .exam { grid-template-columns: 28px 1fr; row-gap: 8px; }
  .exam .status { display: none; }
  .exam .notes { grid-column: 2; justify-self: start; }
}

/* ---------- legal page ---------- */
.legal { max-width: 46em; color: var(--muted); font-size: 14px; }
.legal p + p, .legal ul + p, .legal p + ul { margin-top: 12px; }
.legal h3 { font-family: var(--mono); font-size: 13px; font-weight: 500; color: var(--fg); margin: 26px 0 10px; text-transform: uppercase; letter-spacing: .04em; }
.legal h3:first-child { margin-top: 0; }
.legal ul { list-style: none; display: grid; gap: 6px; }
.legal li::before { content: "> "; color: var(--accent); font-family: var(--mono); }
.legal strong { color: var(--fg); font-weight: 500; }
.legal a { color: var(--accent); }
.legal a:hover { text-decoration: underline; }
.legal code { font-family: var(--mono); font-size: 12px; color: var(--fg); }
.legal .todo { color: #ffcf6b; font-family: var(--mono); font-size: 12px; }
.legal-meta { color: var(--muted); margin-top: 18px; }
.footer a:hover { color: var(--accent); }

/* ---------- motion ---------- */
:root { --ease-out: cubic-bezier(.16, 1, .3, 1); }

/* reveal: rise + un-blur + fade, staggered by --d (set in script.js) */
.reveal {
  opacity: 0;
  transform: translate3d(0, 28px, 0) scale(.985);
  filter: blur(6px);
  /* !important: .card / #section .entry set their own (hover) transition with higher specificity; the reveal is a
     short-lived state and script.js removes the class when it ends, so the hover transition takes over again */
  transition:
    opacity .9s var(--ease-out) var(--d, 0ms),
    transform .9s var(--ease-out) var(--d, 0ms),
    filter .9s var(--ease-out) var(--d, 0ms) !important;
  will-change: opacity, transform;
}
.reveal.in { opacity: 1; transform: none; filter: none; }
/* skill words pop slightly instead of rising */
.skills li.reveal { transform: translate3d(0, 10px, 0) scale(.92); }

/* thin progress bar under the top edge */
.scroll-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 60;
  background: linear-gradient(90deg, rgba(125,255,155,.2), var(--accent));
  transform: scaleX(0); transform-origin: 0 50%;
  box-shadow: 0 0 8px rgba(125,255,155,.5);
  pointer-events: none;
}

/* header gets a touch more presence once the page has scrolled */
.topbar { transition: background .4s var(--ease-out), padding .4s var(--ease-out), box-shadow .4s var(--ease-out); }
.topbar.scrolled { padding-top: 12px; padding-bottom: 12px; background: rgba(18, 20, 18, .9); box-shadow: 0 8px 24px rgba(0,0,0,.35); }

/* hero parallax layers (transforms set in script.js) */
.hero-head, .hero-meta, #particles { will-change: transform, opacity; }

/* section labels: accent line draws in when the label enters the viewport */
.label::after {
  content: ""; display: block; width: 56px; height: 2px; margin-top: 12px;
  background: var(--accent); box-shadow: 0 0 6px rgba(125,255,155,.5);
  transform: scaleX(0); transform-origin: 0 50%;
  transition: transform 1.1s var(--ease-out) .15s;
}
.label.drawn::after { transform: scaleX(1); }

/* boxed elements: smoother hover lift and a soft spotlight that follows the pointer (--mx/--my from script.js) */
.card, :is(#paper, #esperienze, #formazione) .entry {
  background:
    radial-gradient(380px circle at var(--mx, -500px) var(--my, -500px), rgba(125,255,155,.07), transparent 60%),
    var(--bg-2);
  transition: border-color .35s var(--ease-out), transform .45s var(--ease-out), box-shadow .45s var(--ease-out);
}
.card:hover, :is(#paper, #esperienze, #formazione) .entry:hover {
  transform: translate3d(0, -4px, 0);
  box-shadow: 0 14px 30px -12px rgba(0,0,0,.6), 0 0 0 1px rgba(125,255,155,.08);
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .row { grid-template-columns: 1fr; gap: 24px; padding-top: 90px; }
  .label { position: static; }
  .cards { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
}
/* header: drop the caret first, then the section links, so logo + IT/EN + Contatti always fit */
@media (max-width: 1080px) { .nav .nav-caret { display: none; } .nav { gap: 16px; } }
@media (max-width: 600px) {
  .logo { font-size: 11px; letter-spacing: 0; }
  .entry header { flex-direction: column; gap: 2px; }
  .hero-meta { flex-direction: column; align-items: flex-start; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .nav-caret, .cursor, .hint { animation: none; }
  .reveal { opacity: 1; transform: none; filter: none; transition: none; }
  .label::after { transform: scaleX(1); transition: none; }
  .card:hover, :is(#paper, #esperienze, #formazione) .entry:hover { transform: none; }
}

/* ---------- header layout + hamburger menu (phones / narrow screens) ---------- */
.nav { margin-left: auto; }
.header-tools { display: flex; align-items: center; gap: 12px; margin-left: clamp(14px, 2.4vw, 28px); }
.menu-toggle { display: none; }

@media (max-width: 860px) {
  .header-tools { margin-left: auto; }
  .menu-toggle {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 38px; height: 30px; padding: 0 9px; cursor: pointer;
    background: transparent; border: 1px solid var(--line); transition: border-color .2s;
  }
  .menu-toggle:hover, .menu-toggle:focus-visible { border-color: var(--accent-dim); }
  .menu-toggle .bar {
    display: block; height: 2px; background: var(--fg);
    transition: transform .35s var(--ease-out), opacity .2s, background .2s;
  }
  /* bars are children 2-4 (child 1 is the screen-reader label): morph into an X */
  .topbar.menu-open .menu-toggle .bar { background: var(--accent); }
  .topbar.menu-open .menu-toggle .bar:nth-child(2) { transform: translateY(6px) rotate(45deg); }
  .topbar.menu-open .menu-toggle .bar:nth-child(3) { opacity: 0; }
  .topbar.menu-open .menu-toggle .bar:nth-child(4) { transform: translateY(-6px) rotate(-45deg); }

  /* the nav becomes a drop-down panel under the header */
  .nav {
    position: absolute; top: 100%; left: 0; right: 0; margin: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    padding: 6px var(--gutter) 22px;
    background: var(--bg); border-bottom: 1px solid var(--line);
    box-shadow: 0 18px 30px -10px rgba(0, 0, 0, .6);
    opacity: 0; visibility: hidden; transform: translateY(-10px);
    transition: opacity .25s, transform .35s var(--ease-out), visibility 0s linear .35s;
  }
  .topbar.menu-open .nav { opacity: 1; visibility: visible; transform: none; transition: opacity .25s, transform .35s var(--ease-out); }
  .nav .nav-caret { display: none; }
  .nav a {
    display: block; font-family: var(--pixel); font-size: 17px; letter-spacing: .04em;
    padding: 14px 0; border-bottom: 1px dashed var(--line);
  }
  .nav a:not(.pill)::before { content: "> "; color: var(--accent); }
  .nav a[aria-current="page"] { color: var(--accent); }
  .nav .pill { margin-top: 18px; text-align: center; border: 1px solid var(--accent-dim); }
  /* links slide in one after another when the menu opens */
  .topbar.menu-open .nav a { animation: menu-in .45s var(--ease-out) both; }
  .topbar.menu-open .nav a:nth-of-type(2) { animation-delay: .04s; }
  .topbar.menu-open .nav a:nth-of-type(3) { animation-delay: .08s; }
  .topbar.menu-open .nav a:nth-of-type(4) { animation-delay: .12s; }
  .topbar.menu-open .nav a:nth-of-type(5) { animation-delay: .16s; }
  .topbar.menu-open .nav a:nth-of-type(6) { animation-delay: .20s; }
}
@keyframes menu-in { from { opacity: 0; transform: translate3d(-12px, 0, 0); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .topbar.menu-open .nav a { animation: none; }
  .nav, .menu-toggle .bar { transition: none; }
}

/* phones: the status column is hidden, but "in progress" must stay visible */
@media (max-width: 600px) { .exam .status.pending { display: block; grid-column: 2; } }
