/* terminal.css — "fabio@cv" interactive terminal: modalità opzionale del CV.
   Estetica console: monospace, accento oro coerente col brand, scanline CRT sottili. */

/* Toggle nell'header (riusa lo stile .button del sito) con alone RGB animato stile Siri. */
/* Angolo animabile per ruotare i colori del gradiente (non il box). */
@property --term-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

.term-toggle-wrap {
  position: relative;
  display: inline-flex;
  border-radius: 10px;
  isolation: isolate;
}
.term-toggle-wrap::before,
.term-toggle-wrap::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  background: conic-gradient(
    from var(--term-angle),
    #ff2d55, #ff9500, #ffe000, #34ffb0, #00c3ff, #5b5bff, #d04bff, #ff2d55
  );
  z-index: -1;
  animation: term-glow-spin 4s linear infinite;
}
/* Alone sfocato morbido. */
.term-toggle-wrap::before {
  filter: blur(12px);
  opacity: 0.85;
}
/* Anello nitido che disegna il bordo colorato. */
.term-toggle-wrap::after {
  inset: -2px;
  filter: blur(1px);
  opacity: 0.75;
}
.term-toggle-wrap:hover::before {
  opacity: 1;
  filter: blur(16px);
}
.term-toggle-wrap:hover::after {
  opacity: 1;
}

.term-toggle {
  position: relative;
  z-index: 1;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.02em;
  cursor: pointer;
}

/* Ruota l'angolo del gradiente: i colori girano, la forma resta quella del bottone. */
@keyframes term-glow-spin {
  to { --term-angle: 360deg; }
}

body.term-active {
  overflow: hidden;
}

/* ---------------------------------------------------------------- *
 * Overlay + finestra
 * ---------------------------------------------------------------- */
#term-root[hidden] {
  display: none;
}

#term-root {
  --term-fg: #f0c987;
  --term-fg-dim: #b7b0a4;
  --term-accent: #d6a15d;
  --term-ok: #6fcf97;
  --term-err: #e57373;
  --term-bg: #0c0d10;
  --term-glow: rgba(214, 161, 93, 0.45);

  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;        /* fallback per browser senza dvh */
  height: 100dvh;       /* segue la viewport dinamica (chrome mobile) */
  z-index: 1000;
  display: flex;
  background: radial-gradient(circle at 50% 0%, #16171b 0%, #08090b 100%);
  font-family: "IBM Plex Mono", monospace;
}

#term-root[data-theme="green"] {
  --term-fg: #7dffb0;
  --term-accent: #33ff77;
  --term-glow: rgba(51, 255, 119, 0.4);
}
#term-root[data-theme="amber"] {
  --term-fg: #ffcf6b;
  --term-accent: #ffb000;
  --term-glow: rgba(255, 176, 0, 0.4);
}
#term-root[data-theme="ice"] {
  --term-fg: #aee3ff;
  --term-accent: #6fb1d6;
  --term-glow: rgba(111, 177, 214, 0.4);
}

.term-window {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: rgba(10, 11, 14, 0.96);
  border: none;
  border-radius: 0;
  overflow: hidden;
}

/* Scanline CRT sottili + vignettatura. */
.term-window::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.025) 0px,
      rgba(255, 255, 255, 0.025) 1px,
      transparent 2px,
      transparent 3px
    ),
    radial-gradient(circle at 50% 50%, transparent 60%, rgba(0, 0, 0, 0.35) 100%);
  z-index: 3;
}

/* ---------------------------------------------------------------- *
 * Barra titolo
 * ---------------------------------------------------------------- */
.term-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(23, 25, 29, 0.95);
  border-bottom: 1px solid var(--line, #34302b);
  z-index: 4;
}

.term-dots {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.term-dots > * {
  width: 13px;
  height: 13px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #3a3d44;
}
.term-dots > *:nth-child(1) { background: #e57373; }
.term-dots > *:nth-child(2) { background: #e0b85f; }
.term-dots > *:nth-child(3) { background: #6fcf97; }

/* Il pallino rosso è il pulsante di chiusura (stile macOS). */
.term-dot-close {
  position: relative;
  cursor: pointer;
}
.term-dot-close::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  color: rgba(60, 0, 0, 0.7);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.term-dots:hover .term-dot-close::after,
.term-dot-close:focus-visible::after {
  opacity: 1;
}
.term-dot-close:focus-visible {
  outline: 2px solid var(--term-accent);
  outline-offset: 2px;
}

.term-bar-title {
  flex: 1;
  font-size: 0.82rem;
  color: var(--term-fg-dim);
  letter-spacing: 0.03em;
}

.term-stats {
  font-size: 0.78rem;
  color: var(--term-fg-dim);
}
.term-stats b {
  color: var(--term-fg);
}

.term-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line, #34302b);
  border-radius: 6px;
  background: transparent;
  color: var(--term-fg-dim);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.term-x:hover,
.term-x:focus-visible {
  border-color: var(--term-accent);
  color: var(--term-fg);
}

/* ---------------------------------------------------------------- *
 * Output
 * ---------------------------------------------------------------- */
.term-output {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 18px 8px;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--term-fg-dim);
  text-shadow: 0 0 6px var(--term-glow);
  z-index: 2;
  scrollbar-width: thin;
  scrollbar-color: var(--term-accent) transparent;
}
.term-output::-webkit-scrollbar { width: 8px; }
.term-output::-webkit-scrollbar-thumb {
  background: var(--term-accent);
  border-radius: 8px;
}

.term-ln {
  white-space: pre-wrap;
  word-break: break-word;
}
.term-ln.dim { color: #827b70; }
.term-ln.accent { color: var(--term-fg); }
.term-ln.ok { color: var(--term-ok); }
.term-ln.err { color: var(--term-err); }
.term-ln.banner {
  color: var(--term-accent);
  text-shadow: 0 0 10px var(--term-glow);
}

/* ASCII art: niente a-capo, scroll orizzontale se troppo larga. */
.term-art {
  overflow-x: auto;
  margin: 4px 0;
  scrollbar-width: thin;
}
.term-ln.art {
  white-space: pre;
  line-height: 1.05;
}
.term-ln .cmd-echo { color: var(--term-fg); }
.term-ln a {
  color: var(--term-fg);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.term-ln a:hover { color: #fff; }

.term-ln .k { color: var(--term-fg); }
.term-ln .v { color: var(--term-fg-dim); }

/* ---------------------------------------------------------------- *
 * Riga di input
 * ---------------------------------------------------------------- */
.term-inputline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px 16px;
  z-index: 2;
}

.term-prompt {
  color: var(--term-accent);
  font-size: 0.92rem;
  white-space: nowrap;
  text-shadow: 0 0 6px var(--term-glow);
}

#term-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--term-fg);
  font: inherit;
  font-size: 0.92rem;
  caret-color: var(--term-accent);
  text-shadow: 0 0 6px var(--term-glow);
}

/* Cursore a blocco lampeggiante quando l'input è vuoto/focus. */
.term-cursor {
  display: inline-block;
  width: 9px;
  height: 1.05em;
  margin-left: 2px;
  background: var(--term-accent);
  vertical-align: -2px;
  animation: term-blink 1.05s step-end infinite;
}
@keyframes term-blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* Tasti rapidi (mobile / accesso veloce). */
.term-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 14px;
  z-index: 2;
}
.term-quick button {
  padding: 5px 11px;
  border: 1px solid var(--line, #34302b);
  border-radius: 999px;
  background: rgba(23, 25, 29, 0.9);
  color: var(--term-fg-dim);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.term-quick button:hover,
.term-quick button:active {
  border-color: var(--term-accent);
  color: var(--term-fg);
}

/* Toast achievement. */
.term-toast {
  position: absolute;
  top: 54px;
  left: 50%;
  transform: translate(-50%, -10px);
  z-index: 6;
  padding: 9px 16px;
  border: 1px solid var(--term-accent);
  border-radius: 8px;
  background: rgba(12, 13, 16, 0.97);
  color: var(--term-fg);
  font-size: 0.82rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.term-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------------------------------------------------------- *
 * Snake — overlay mini-gioco
 * ---------------------------------------------------------------- */
#term-snake[hidden] { display: none; }

.term-snake {
  position: absolute;
  top: 42px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: var(--term-bg);
}

.snake-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line, #34302b);
}
.snake-title {
  flex: 1;
  color: var(--term-fg);
  font-size: 0.85rem;
}
.snake-score-wrap {
  color: var(--term-fg-dim);
  font-size: 0.82rem;
}
.snake-score-wrap b { color: var(--term-fg); }

.snake-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#snake-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 1px solid var(--line, #34302b);
  border-radius: 4px;
  box-shadow: 0 0 24px var(--term-glow);
  touch-action: none;
}

/* D-pad: solo su touch. */
.snake-dpad {
  display: none;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(2, 48px);
  gap: 6px;
  justify-content: center;
  padding: 12px 0 18px;
}
.snake-dpad button {
  border: 1px solid var(--line, #34302b);
  border-radius: 8px;
  background: rgba(23, 25, 29, 0.9);
  color: var(--term-fg);
  font-size: 1.2rem;
  cursor: pointer;
  touch-action: manipulation;
}
.snake-dpad button:active {
  background: var(--term-accent);
  color: #18140f;
}
.snake-dpad [data-sndir="up"] { grid-area: 1 / 2; }
.snake-dpad [data-sndir="left"] { grid-area: 2 / 1; }
.snake-dpad [data-sndir="right"] { grid-area: 2 / 3; }
.snake-dpad [data-sndir="down"] { grid-area: 2 / 2; }

@media (hover: none) and (pointer: coarse) {
  .snake-dpad { display: grid; }
}

/* Controlli Tetris (touch). */
#term-tetris[hidden] { display: none; }
.term-tetris {
  position: absolute;
  top: 42px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: var(--term-bg);
}
.tt-dpad {
  display: none;
  gap: 8px;
  justify-content: center;
  padding: 12px 0 18px;
}
.tt-dpad button {
  width: 56px;
  height: 50px;
  border: 1px solid var(--line, #34302b);
  border-radius: 8px;
  background: rgba(23, 25, 29, 0.9);
  color: var(--term-fg);
  font-size: 1.2rem;
  cursor: pointer;
  touch-action: manipulation;
}
.tt-dpad button:active {
  background: var(--term-accent);
  color: #18140f;
}
@media (hover: none) and (pointer: coarse) {
  .tt-dpad { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  .term-cursor { animation: none; }
  .term-toast { transition: none; }
  .term-toggle-wrap::before,
  .term-toggle-wrap::after { animation: none; }
}

@media (max-width: 600px) {
  .term-output { font-size: 0.82rem; }
  .term-prompt { font-size: 0.82rem; }
  /* 16px sull'input evita lo zoom automatico di iOS al focus. */
  #term-input { font-size: 16px; }
  .term-bar-title { display: none; }
  /* Tasti rapidi: scroll orizzontale invece di occupare metà schermo. */
  .term-quick {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .term-quick::-webkit-scrollbar { display: none; }
  .term-quick button { flex: 0 0 auto; }
}
