:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1f2937;
  --accent: #58a6ff;
  --accent2: #3fb950;
  --text: #e6edf3;
  --muted: #8b949e;
  --border: #30363d;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-sans: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── SELEZIONE TESTO ── */
::selection { background: rgba(88,166,255,0.32); color: var(--text); }

/* ── READING PROGRESS ── */
.read-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  z-index: 300;
  transition: width 0.1s linear;
}

/* ── NAV ── */
nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: rgba(13,17,23,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 2rem;
  list-style: none;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.2s;
}

.nav-links a:hover { color: var(--text); }

.nav-num {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.78rem;
  margin-right: 0.25rem;
}

.nav-links a:not(.nav-social)::before {
  content: '>';
  color: var(--accent2);
  font-family: var(--font-mono);
  margin-right: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.nav-links a.active::before { opacity: 1; }
.nav-links a.active { color: var(--text); }

/* ── HERO ── */
#hero {
  min-height: 100vh;
  max-width: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6rem 2rem 4rem;
  position: relative;
  overflow: hidden;
}

.hero-terminal {
  position: absolute;
  inset: 0;
  z-index: 1;
  font-family: var(--font-mono);
  font-size: clamp(0.72rem, 1.4vw, 0.95rem);
  line-height: 2.1;
  color: var(--muted);
  opacity: 0.28;
  padding: 7rem 6% 4rem 2rem;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  white-space: pre;
}

.hero-terminal .pu { color: var(--accent2); }
.hero-terminal .pp { color: var(--accent); }
.hero-terminal .ok { color: var(--accent2); }
.hero-terminal .cm { color: var(--muted); opacity: 0.8; }

.term-cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  background: var(--accent);
  vertical-align: -2px;
  margin-left: 3px;
  animation: blink 1s infinite;
}


.hero-content {
  position: relative;
  z-index: 3;
  max-width: 760px;
  text-align: center;
}

.hero-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent2);
  border: 1px solid var(--accent2);
  border-radius: 20px;
  padding: 0.3rem 0.9rem;
  margin-bottom: 1.5rem;
  opacity: 0;
  animation: fadeUp 0.6s 0.2s forwards;
}

.hero-title {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
  opacity: 0;
  text-shadow: 0 2px 10px rgba(13,17,23,0.95), 0 0 24px rgba(13,17,23,0.85);
  animation: fadeUp 0.6s 0.4s forwards;
}

.hero-title span { color: var(--accent); }

.hero-typing {
  font-family: var(--font-mono);
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  color: var(--muted);
  margin-bottom: 2rem;
  min-height: 1.6em;
  opacity: 0;
  text-shadow: 0 1px 8px rgba(13,17,23,0.95);
  animation: fadeUp 0.6s 0.6s forwards;
}

.cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s infinite;
}

.hero-cta {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  opacity: 0;
  animation: fadeUp 0.6s 0.8s forwards;
}

.btn {
  position: relative;
  padding: 0.7rem 1.6rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
}

.btn::after {
  content: '_';
  font-family: var(--font-mono);
  margin-left: 0.2rem;
  opacity: 0;
}

.btn:hover::after {
  opacity: 1;
  animation: blink 1s infinite;
}

.btn-primary {
  background: var(--accent);
  color: #0d1117;
}

.btn-primary:hover {
  background: #79b8ff;
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ── SECTIONS ── */
section {
  max-width: 900px;
  margin: 0 auto;
  padding: 5rem 2rem;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.section-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 2.5rem;
}

.divider {
  width: 40px;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  margin: 0.75rem 0 2.5rem;
}

.section-cmd {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  margin: -1.6rem 0 2.2rem;
}

.section-cmd .pr { color: var(--accent2); }
.section-cmd .term-cursor { width: 6px; height: 0.95em; }

/* ── ABOUT ── */
#about p {
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 640px;
  line-height: 1.8;
}

#about p strong { color: var(--text); }

/* ── SKILLS ── */
.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.skill-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  transition: border-color 0.2s, transform 0.2s;
}

.skill-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.skill-card h4 {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent2);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

.skill-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--bg3);
  color: var(--text);
  border-radius: 5px;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  transition: border-color 0.2s, color 0.2s, transform 0.2s;
  cursor: default;
}

.tag:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ── TIMELINE ── */
.timeline {
  position: relative;
  padding-left: 1.5rem;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, var(--accent), var(--accent2));
  border-radius: 2px;
}

.timeline-item {
  position: relative;
  margin-bottom: 2.5rem;
  padding-left: 1.5rem;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -1.95rem;
  top: 0.4rem;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 3px rgba(88,166,255,0.2);
  animation: pulseDot 2.6s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(88,166,255,0.22); }
  50%      { box-shadow: 0 0 0 7px rgba(88,166,255,0.04); }
}

.timeline-date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  margin-bottom: 0.3rem;
}

.commit-hash {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent2);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  margin-left: 0.55rem;
  vertical-align: middle;
}

.timeline-role {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.timeline-company {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.timeline-desc {
  color: var(--muted);
  font-size: 0.9rem;
}

.timeline-desc li {
  margin-bottom: 0.3rem;
  padding-left: 1rem;
  position: relative;
}

.timeline-desc li::before {
  content: '›';
  position: absolute;
  left: 0;
  color: var(--accent2);
}

/* ── EDUCATION ── */
.edu-grid {
  display: grid;
  gap: 1rem;
}

.edu-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  transition: border-color 0.2s;
}

.edu-card:hover { border-color: var(--accent2); }

.edu-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.edu-date {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent2);
  margin-bottom: 0.3rem;
}

.edu-title {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.edu-school {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.edu-thesis {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  border-left: 2px solid var(--accent);
  padding-left: 0.75rem;
  margin-top: 0.5rem;
}

.edu-tree {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.85;
  color: #484f58;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.4rem 1.6rem;
  overflow-x: auto;
  white-space: pre;
}

.edu-tree .et-root { color: var(--accent); }
.edu-tree .et-dir { color: var(--text); }
.edu-tree .et-key { color: var(--accent2); }
.edu-tree .et-val { color: var(--muted); }
.edu-tree .et-sub { color: #c9d1d9; }

@media (max-width: 600px) {
  .edu-tree {
    font-size: 0.7rem;
    padding: 1.1rem 0.9rem;
    line-height: 1.9;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 400px) {
  .edu-tree { font-size: 0.6rem; line-height: 2; }
}

/* ── CONTACT ── */
#contact {
  text-align: center;
}

#contact p {
  color: var(--muted);
  max-width: 480px;
  margin: 0 auto 2rem;
}

.contact-links {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── FOOTER ── */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
}

/* ── BACK TO TOP ── */
.back-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  background: rgba(22,27,34,0.9);
  backdrop-filter: blur(8px);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  transition: opacity 0.3s, transform 0.3s, border-color 0.2s, color 0.2s;
}

.back-top.show { opacity: 1; visibility: visible; transform: translateY(0); }

.back-top:hover {
  border-color: var(--accent);
  color: var(--accent2);
  transform: translateY(-2px);
}

.back-top .bt-label { color: var(--muted); }
.back-top:hover .bt-label { color: var(--text); }

@media (max-width: 600px) {
  .back-top .bt-label { display: none; }
  .back-top { padding: 0.7rem 0.8rem; }
}

/* ── ANIMATIONS ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-item {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.reveal-item.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .reveal, .reveal-item { opacity: 1; transform: none; transition: none; }
}

/* ── LANG TOGGLE ── */
.lang-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.lang-toggle:hover { border-color: var(--accent); color: var(--text); }
.lang-toggle #langCur { color: var(--accent2); text-transform: uppercase; }

/* ── MINI TERMINAL ── */
.mini-term {
  max-width: 540px;
  margin: 2.75rem auto 0;
  text-align: left;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  font-family: var(--font-mono);
  box-shadow: 0 10px 40px rgba(0,0,0,0.35);
}

.mt-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}

.mt-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.mt-title { margin-left: 0.5rem; font-size: 0.78rem; color: var(--muted); }

.mt-body {
  padding: 0.9rem 1rem 0.3rem;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text);
  min-height: 96px;
  max-height: 220px;
  overflow-y: auto;
}

.mt-body .mt-in { color: var(--muted); }
.mt-body .mt-in b { color: var(--accent); font-weight: 600; }
.mt-body a { color: var(--accent); text-decoration: none; }
.mt-body a:hover { text-decoration: underline; }
.mt-err { color: #ff7b72; }
.mt-ok { color: var(--accent2); }

.mt-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0.9rem;
  font-size: 0.82rem;
}

.mt-prompt { color: var(--accent2); white-space: nowrap; }

.mt-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  caret-color: var(--accent);
}

/* ── NAV TOGGLE (mobile) ── */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}

/* ── RESPONSIVE ── */
@media (max-width: 760px) {
  nav { padding: 0.9rem 1.25rem; }
  .nav-logo { font-size: 0.9rem; }
  .nav-toggle { display: block; }

  .nav-links {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0;
    background: rgba(13,17,23,0.98);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .nav-links.open { max-height: 70vh; }
  .nav-links li { width: 100%; }

  .nav-links li a {
    display: block;
    padding: 0.85rem 1.5rem;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
  }

  .nav-links a:not(.nav-social)::before { content: none; }
  .nav-links a.active { color: var(--accent); }
  .nav-links .lang-toggle { margin: 0.75rem 1.5rem; }
}

@media (max-width: 600px) {
  section { padding: 4rem 1.25rem; }
  #hero { padding: 6rem 1.25rem 3rem; }
  .hero-terminal { font-size: 0.62rem; padding-left: 1.25rem; padding-right: 1rem; }
  .hero-cta { gap: 0.6rem; }
  .btn { padding: 0.65rem 1.2rem; font-size: 0.85rem; }
  .skills-grid { grid-template-columns: 1fr 1fr; }
  .edu-card { flex-direction: column; gap: 0.85rem; }
  .contact-links { flex-direction: column; align-items: stretch; }
  .contact-links .btn { display: block; text-align: center; }
  .back-top { bottom: 1rem; right: 1rem; }

  .mini-term { margin-top: 2rem; border-radius: 8px; }
  .mt-title { font-size: 0.7rem; }
  .mt-body { font-size: 0.76rem; padding: 0.8rem 0.85rem 0.25rem; min-height: 84px; }
  .mt-input-row { padding: 0.45rem 0.85rem 0.8rem; font-size: 0.76rem; }
  .mt-input { font-size: 0.76rem; }
  .mt-prompt .mt-host { display: none; }
}

@media (max-width: 380px) {
  .skills-grid { grid-template-columns: 1fr; }
  .nav-logo { font-size: 0.8rem; }
}
