:root {
    /* Palette del terminale — gerarchia per leggibilità
       (accento verde = prompt/banner, comando digitato = brillante,
        risposte = verde-grigio soffuso, link = ciano) */
    --term-bg: #0a0e0a;      /* sfondo quasi nero */
    --term-text: #bcd2bc;    /* testo/risposte: soffuso e leggibile */
    --term-bright: #eafff0;  /* comandi digitati / input: brillante */
    --term-accent: #33ff33;  /* prompt, banner, cursore */
    --term-link: #56d3ec;    /* link (ciano) */
    --term-dim: #7f947f;     /* etichette/testo attenuato */
    --accent-rgb: 51, 255, 51; /* accento in formato RGB per rgba(...) */
  }

  /* Tema ambra (vecchio monitor) — attivato dal toggle in titlebar */
  html[data-theme="amber"] {
    --term-bg: #0f0b04;
    --term-text: #d8bd85;
    --term-bright: #fff0cf;
    --term-accent: #ffb000;
    --term-link: #6fd0ff;
    --term-dim: #9a8355;
    --accent-rgb: 255, 176, 0;
  }

body {
    margin: 0;
    font-family: monospace;
    background: var(--term-bg);
    color: var(--term-text);
    text-shadow: 0 0 1px currentColor;
    font-size: 1rem;
    --mouse-x: 0px;
    --mouse-y: 0px;
    --mouse-opacity: 1;
  }

  /* Custom mouse glow effect - very small, light and blurred */
  body::after {
    content: "";
    position: fixed;
    top: var(--mouse-y);
    left: var(--mouse-x);
    width: 40px;
    height: 40px;
    background: radial-gradient(circle, rgba(var(--accent-rgb), 0.05) 0%, rgba(var(--accent-rgb), 0.02) 50%, transparent 100%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
    transform: translate(-50%, -50%);
    opacity: var(--mouse-opacity);
    transition: opacity 0.5s ease;
    mix-blend-mode: screen;
    filter: blur(3px);
  }

body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background:
        repeating-linear-gradient(
            rgba(255, 255, 255, 0.02) 0px,
            rgba(255, 255, 255, 0.02) 2px,
            rgba(0, 0, 0, 0) 2px,
            rgba(0, 0, 0, 0) 4px
        ),
        radial-gradient(circle at center, rgba(var(--accent-rgb), 0.04), rgba(0, 0, 0, 0.75));
    mix-blend-mode: screen;
    animation: flicker 4s ease-in-out infinite;
    z-index: 1;
  }

@keyframes flicker {
    0% { opacity: 0.98; }
    50% { opacity: 1; }
    100% { opacity: 0.99; }
  }
  
  .terminal {
    height: 92dvh;
    max-width: 1040px;
    margin: 4dvh auto;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    position: relative;
    z-index: 2;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(var(--accent-rgb), 0.28);
    border-radius: 10px;
    box-shadow: 0 0 40px rgba(var(--accent-rgb), 0.07), 0 24px 60px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    backdrop-filter: blur(1px);
  }

  /* Barra del titolo stile finestra terminale */
  .titlebar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.85rem;
    background: rgba(var(--accent-rgb), 0.06);
    border-bottom: 1px solid rgba(var(--accent-rgb), 0.16);
  }
  .titlebar .dots {
    display: flex;
    gap: 0.45rem;
  }
  .titlebar .dots span {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
  }
  .titlebar .dots span:nth-child(1) { background: #ff5f56; }
  .titlebar .dots span:nth-child(2) { background: #ffbd2e; }
  .titlebar .dots span:nth-child(3) { background: #27c93f; }
  .titlebar .title {
    flex: 1;
    min-width: 0;              /* può restringersi: non spinge i bottoni fuori dalla barra */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    font-size: 0.8rem;
    color: var(--term-dim);
    opacity: 0.9;
    text-shadow: none;
    letter-spacing: 0.3px;
  }

  /* Bottone nella titlebar (toggle tema) */
  .titlebar-btn {
    flex: 0 0 auto;
    background: transparent;
    border: 1px solid rgba(var(--accent-rgb), 0.4);
    color: var(--term-accent);
    border-radius: 6px;
    width: 26px;
    height: 22px;
    line-height: 1;
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-shadow: none;
    transition: background 0.15s, border-color 0.15s;
  }
  .titlebar-btn:hover {
    background: rgba(var(--accent-rgb), 0.15);
    border-color: var(--term-accent);
  }
  .titlebar-btn:focus-visible {
    outline: 2px solid var(--term-link);
    outline-offset: 2px;
  }

  /* Corpo del terminale (area scrollabile + input) */
  .term-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 1rem 1.1rem;
    box-sizing: border-box;
  }
  
  /* area di output del terminale */
  #output {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    font-family: monospace;
    white-space: pre-wrap;     /* consente l'andare a capo automatico */
    word-break: break-word;    /* evita la scroll orizzontale */
    line-height: 1.5;          /* più aria tra le righe = più leggibile */
    text-shadow: 0 0 1px currentColor; /* glow più leggero per nitidezza */
  }

  /* Stacca visivamente ogni comando eseguito dal precedente */
  #output > .line {
    margin-top: 1rem;
  }
  #output > .line:first-child {
    margin-top: 0;
  }

  /* Risposte del terminale - testo soffuso e leggibile */
  #output > div:not(.line),
  #output > pre {
    color: var(--term-text);
  }

  /* ASCII art nel colore accento */
  #output > pre#ascii-art {
    color: var(--term-accent);
    overflow: hidden;
    white-space: pre;
  }
  
  .input-line {
    display: flex;
    align-items: center;
    gap: 0.5rem; /* spazio tra prompt e input */
    background: transparent;
    position: relative; /* contesto per il cursore assoluto; resta in fondo grazie al flex */
    flex: 0 0 auto;
  }
  
  .input-line .prompt {
    white-space: nowrap; /* evita che vada a capo */
  }
  
  #input {
    flex-grow: 1; /* occupa il resto dello spazio disponibile */
    background: transparent !important;
    color: var(--term-bright) !important;
    border: none;
    outline: none;
    font-family: monospace;
    font-size: inherit;
    caret-color: transparent; /* nasconde il cursore normale */
  }

  /* Cursore a blocco stile terminale anni '90 */
  .cursor {
    position: absolute;
    width: 0.6em;
    height: 1em;
    background: var(--term-accent);
    animation: blink 1s step-end infinite;
    pointer-events: none;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    transition: left 0.05s;
  }

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

  .prompt {
    color: var(--term-accent);
  }

  /* Linea del comando inviato - testo brillante per distinguerlo dall'output */
  .line {
    color: var(--term-bright);
  }
  
  pre {
    font-family: monospace;
    font-size: clamp(0.25rem, 1.5vw, 1.2rem);
    margin: 0;
    padding: 0;
    line-height: 1.1;
    overflow-x: auto;
    max-width: 100%;
  }
  
  a[data-cmd] {
    color: var(--term-link);
    text-decoration: underline;
    cursor: pointer;
  }

  a[data-cmd]:hover {
    color: var(--term-link);
  }

  a {
    text-shadow: 0 0 2px currentColor;
  }

  a:link {
    text-decoration: none;
  }
  a:visited { 
    text-decoration: none; 
  } 
  a:hover { 
    text-decoration: none; 
  } 
  a:active { 
    text-decoration: none; 
  }

  a.gh-link {
    color: var(--term-link);
    text-decoration: none;
  }

  a.gh-link:hover {
    color: var(--term-link);
    text-decoration: underline;
  }

  /* ------ AI Level Tags ------ */
  .ai-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    margin-left: 6px;
    text-shadow: 0 0 3px currentColor;
  }

  .ai-tag.ai-low {
    background: rgba(100, 200, 255, 0.2);
    color: #64c8ff;
    border: 1px solid #64c8ff;
  }

  .ai-tag.ai-medium {
    background: rgba(255, 200, 0, 0.2);
    color: #ffc800;
    border: 1px solid #ffc800;
  }

  .ai-tag.ai-high {
    background: rgba(255, 100, 0, 0.2);
    color: #ff6400;
    border: 1px solid #ff6400;
  }

  .ai-tag.ai-none {
    background: rgba(128, 128, 128, 0.2);
    color: #888888;
    border: 1px solid #888888;
  }

  .ai-tag.ai-vibecoded {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid;
    animation: vibecoded-rainbow 3s linear infinite, vibecoded-wiggle 0.5s ease-in-out infinite;
    font-weight: 900;
    letter-spacing: 1px;
  }

  /* ------ Project Year Tag ------ */
  .project-year {
    color: var(--term-dim);
    font-size: 0.9em;
    margin-left: 4px;
  }

  /* ------ Utility ------ */
  .field-label { color: var(--term-accent); }
  .muted { color: var(--term-dim); }
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  @keyframes vibecoded-rainbow {
    0% {
      color: #ff0000;
      border-color: #ff0000;
      text-shadow: 0 0 10px #ff0000;
    }
    16.66% {
      color: #ff7700;
      border-color: #ff7700;
      text-shadow: 0 0 10px #ff7700;
    }
    33.33% {
      color: #ffff00;
      border-color: #ffff00;
      text-shadow: 0 0 10px #ffff00;
    }
    50% {
      color: #00ff00;
      border-color: #00ff00;
      text-shadow: 0 0 10px #00ff00;
    }
    66.66% {
      color: #0099ff;
      border-color: #0099ff;
      text-shadow: 0 0 10px #0099ff;
    }
    83.33% {
      color: #9900ff;
      border-color: #9900ff;
      text-shadow: 0 0 10px #9900ff;
    }
    100% {
      color: #ff0000;
      border-color: #ff0000;
      text-shadow: 0 0 10px #ff0000;
    }
  }

  @keyframes vibecoded-wiggle {
    0%, 100% {
      transform: rotate(0deg) translateY(0px);
    }
    25% {
      transform: rotate(-2deg) translateY(-1px);
    }
    50% {
      transform: rotate(0deg) translateY(0px);
    }
    75% {
      transform: rotate(2deg) translateY(1px);
    }
  }

  /* ------ Compact banner (mobile) ------ */
  pre.banner-compact {
    color: var(--term-accent);
    line-height: 1.15;
    overflow: hidden;
    white-space: pre;
  }

  /* ------ Quick command bar (chips) ------ */
  #cmdbar {
    display: flex;
    gap: 0.5rem;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0.7rem 0 0.55rem;
    margin-top: 0.3rem;
    border-top: 1px solid rgba(var(--accent-rgb), 0.14);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #cmdbar::-webkit-scrollbar { display: none; }

  .cmd-chip {
    flex: 0 0 auto;
    background: rgba(var(--accent-rgb), 0.07);
    color: var(--term-accent);
    border: 1px solid rgba(var(--accent-rgb), 0.35);
    border-radius: 999px;
    padding: 6px 15px;
    font-family: monospace;
    font-size: 0.85em;
    cursor: pointer;
    text-shadow: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }
  .cmd-chip:hover {
    background: rgba(var(--accent-rgb), 0.18);
    border-color: var(--term-accent);
    color: var(--term-bright);
  }
  .cmd-chip:focus-visible {
    background: rgba(var(--accent-rgb), 0.18);
    border-color: var(--term-accent);
    color: var(--term-bright);
    outline: 2px solid var(--term-link);
    outline-offset: 2px;
  }

  /* Bottone "copy" accanto all'email */
  .copy-btn {
    background: transparent;
    border: 1px solid rgba(var(--accent-rgb), 0.4);
    color: var(--term-accent);
    border-radius: 5px;
    padding: 1px 8px;
    margin-left: 6px;
    font-family: monospace;
    font-size: 0.8em;
    cursor: pointer;
    text-shadow: none;
    transition: background 0.15s, border-color 0.15s;
  }
  .copy-btn:hover {
    background: rgba(var(--accent-rgb), 0.15);
    border-color: var(--term-accent);
  }
  .copy-btn:focus-visible {
    outline: 2px solid var(--term-link);
    outline-offset: 2px;
  }
  .copy-btn.copied {
    color: var(--term-bright);
    border-color: var(--term-accent);
  }

  /* ------ Mobile adjustments ------ */
  @media (max-width: 700px) {
    html, body {
      height: 100%;
      overflow: hidden; /* la pagina non scrolla: il terminale è ancorato al viewport visibile */
    }
    body {
      font-size: 0.9rem;
    }
    #input {
      font-size: 1rem; /* >=16px: evita lo zoom automatico di iOS Safari sul focus */
    }
    /* Su telefono la finestra occupa tutto lo schermo (niente chrome flottante) */
    .terminal {
      height: 100dvh;
      max-width: none;
      margin: 0;
      border: none;
      border-radius: 0;
      box-shadow: none;
    }
    .term-body {
      padding: 0.7rem;
    }
    .cmd-chip {
      padding: 8px 14px; /* target touch più comodo */
    }
  }

  /* ------ Touch devices: usa il caret nativo (il blocco custom sfasa a metà testo) ------ */
  @media (hover: none) and (pointer: coarse) {
    #input {
      caret-color: var(--term-accent) !important;
    }
    .cursor {
      display: none;
    }
  }

  /* ------ Rispetta le preferenze di riduzione del movimento ------ */
  @media (prefers-reduced-motion: reduce) {
    body::before {
      animation: none; /* niente flicker CRT a schermo intero */
    }
    body::after {
      display: none; /* niente glow del mouse */
    }
    .cursor {
      animation: none;
      opacity: 1;
    }
    .ai-tag.ai-vibecoded {
      animation: none;
      border-color: #ff00ff;
      color: #ff00ff;
    }
  }

  /* ============================================================
     Readable CV view — documento chiaro e stampabile per gli HR
     ============================================================ */
  .titlebar .cv-toggle {
    flex: 0 0 auto;
    width: auto;
    height: 22px;
    padding: 0 10px;
    gap: 6px;
    font-size: 0.78rem;
    letter-spacing: 0.3px;
    white-space: nowrap;
    line-height: 1;
  }

  #cv-view {
    position: fixed;
    inset: 0;
    z-index: 3000;
    overflow-y: auto;
    background: #f6f7f6;
    color: #1c1f1c;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    text-shadow: none;
    -webkit-overflow-scrolling: touch;
  }
  #cv-view[hidden] { display: none; }
  body.cv-open .terminal { display: none; }

  .cv-bar {
    position: sticky;
    top: 0;
    display: flex;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    background: #ffffff;
    border-bottom: 1px solid #e2e6e2;
  }
  .cv-btn {
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid #cbd5cb;
    background: #fff;
    color: #1c1f1c;
    border-radius: 8px;
    padding: 6px 12px;
    text-shadow: none;
  }
  .cv-btn:hover { background: #eef2ee; }
  .cv-btn:focus-visible { outline: 2px solid #178a2e; outline-offset: 2px; }

  .cv-content {
    max-width: 820px;
    margin: 0 auto;
    padding: 2.2rem 1.5rem 4rem;
    line-height: 1.6;
  }
  .cv-header h1 { margin: 0 0 0.15rem; font-size: 2.1rem; letter-spacing: -0.5px; }
  .cv-role { margin: 0; font-size: 1.15rem; color: #178a2e; font-weight: 600; }
  .cv-sub { margin: 0.15rem 0 0.5rem; color: #555; }
  .cv-contact { margin: 0.4rem 0 0; font-size: 0.95rem; }
  .cv-contact a, .cv-links a, .cv-list a { color: #0b6bcb; text-decoration: none; }
  .cv-contact a:hover, .cv-links a:hover, .cv-list a:hover { text-decoration: underline; }
  /* Nessun glow sui link in modalità CV (a differenza del terminale) */
  #cv-view a { text-shadow: none; }
  .cv-sep { margin: 0 0.5rem; color: #b0b6b0; }

  .cv-section { margin-top: 1.8rem; }
  .cv-section h2 {
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #178a2e;
    border-bottom: 2px solid #e2e6e2;
    padding-bottom: 0.3rem;
    margin: 0 0 0.8rem;
  }
  .cv-skill { margin: 0.25rem 0; }
  .cv-entry { margin: 0 0 1rem; }
  .cv-entry-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: baseline;
  }
  .cv-entry-title { font-weight: 600; }
  .cv-date, .cv-year { color: #666; font-weight: 400; font-size: 0.9rem; white-space: nowrap; }
  .cv-entry p { margin: 0.2rem 0 0; }
  .cv-links { margin: 0.3rem 0 0; font-size: 0.92rem; }
  .cv-list { margin: 0; padding-left: 1.2rem; }
  .cv-list li { margin: 0.2rem 0; }
  .cv-tag {
    display: inline-block;
    font-size: 0.72rem;
    padding: 1px 8px;
    border-radius: 999px;
    background: #eef2ee;
    color: #566;
    border: 1px solid #d5ddd5;
    vertical-align: middle;
    font-weight: 600;
  }

  @media (max-width: 700px) {
    .cv-toggle-label { display: none; }
    .titlebar .cv-toggle { padding: 0 8px; }
  }

  /* Stampa / salva PDF: solo il CV, colori neutri */
  @media print {
    body::before, body::after { display: none !important; }
    .cv-bar { display: none; }
    #cv-view { position: static; overflow: visible; background: #fff; }
    .cv-content { max-width: none; padding: 0; }
    .cv-role, .cv-section h2 { color: #000; }
    .cv-contact a, .cv-links a, .cv-list a { color: #000; }
  }
