:root {
  --bg: #050a07;
  --panel: #0a130e;
  --line: #17382a;
  --text: #b9f2cf;
  --dim: #63a07d;
  --green: #3dff88;
  --amber: #ffb454;
  --red: #ff6b5f;
  --cyan: #6fe3ff;
  --bright: #eafff2;
  --top: rgba(5, 10, 7, 0.92);
  --scan: rgba(0, 0, 0, 0.16);
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", "Cascadia Code", Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

/* Temi del "fosforo" (comando `theme`): ridefiniscono solo le variabili. */
:root[data-theme="amber"] {
  --bg: #0b0803;
  --panel: #140f06;
  --line: #3d2c10;
  --text: #ffd59a;
  --dim: #b88a4c;
  --green: #ffb000;
  --amber: #ffe08a;
  --red: #ff6a4d;
  --cyan: #ffc966;
  --bright: #fff2d6;
  --top: rgba(11, 8, 3, 0.92);
}
:root[data-theme="white"] {
  --bg: #08090a;
  --panel: #111214;
  --line: #2f3236;
  --text: #d6d9de;
  --dim: #8b9099;
  --green: #f4f6fa;
  --amber: #e9dfbd;
  --red: #ff7a70;
  --cyan: #bfd4ff;
  --bright: #ffffff;
  --top: rgba(8, 9, 10, 0.92);
}
/* Segreto: il Costrutto, la stanza bianca dove si carica tutto. Si sblocca con tutti gli achievement. */
:root[data-theme="construct"] {
  --bg: #eef1ee;
  --panel: #fbfcfb;
  --line: #c3d0c7;
  --text: #15201a;
  --dim: #4b6455;
  --green: #08703a;
  --amber: #8a5300;
  --red: #b3261e;
  --cyan: #00657d;
  --bright: #000000;
  --top: rgba(238, 241, 238, 0.92);
  --scan: rgba(0, 0, 0, 0.035);
  color-scheme: light;
}

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

html { scroll-behavior: smooth; scroll-padding-top: 4rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 var(--mono);
  -webkit-text-size-adjust: 100%;
}

/* Righe di scansione da tubo catodico: leggere, e mai sopra i clic. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, var(--scan) 2px 3px);
}

a { color: var(--green); text-underline-offset: 3px; }
a:hover { color: var(--bright); }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
::selection { background: var(--green); color: var(--bg); }

.dim { color: var(--dim); }
.small { font-size: 0.82rem; }
code, kbd { font-family: inherit; color: var(--amber); }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 60; background: var(--bg); padding: 0.5rem 1rem; }

/* --- intestazione --- */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1.5rem;
  padding: 0.6rem max(1rem, calc((100vw - 62rem) / 2));
  background: var(--top);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; }
.brand span { color: var(--dim); }
.top nav { display: flex; flex-wrap: wrap; gap: 0.15rem 1.1rem; font-size: 0.9rem; }
.top nav a { color: var(--text); text-decoration: none; }
.top nav a::before { content: "./"; color: var(--dim); }
.top nav a:hover { color: var(--green); }
.top nav a.lang { color: var(--amber); }
.top nav a.lang::before { content: "--lang="; }

main { max-width: 62rem; margin: 0 auto; padding: 0 1rem; }

h1, h2, h3 { line-height: 1.25; text-wrap: balance; }
h1 { font-size: clamp(1.45rem, 4.2vw, 2.3rem); color: var(--green); margin: 0 0 1rem; text-shadow: 0 0 18px color-mix(in srgb, var(--green) 35%, transparent); }
h2 { font-size: 1.25rem; color: var(--green); margin: 0 0 0.5rem; }
h3 { font-size: 1.08rem; margin: 0; }
p { margin: 0 0 1rem; }

/* --- hero e terminale --- */
.hero { padding: 3rem 0 1rem; }
.lede { max-width: 46rem; font-size: 1.05rem; }

.term {
  margin-top: 1.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--green) 5%, transparent), 0 18px 50px rgba(0, 0, 0, 0.6), 0 0 60px color-mix(in srgb, var(--green) 6%, transparent);
  overflow: hidden;
}
.term-bar { display: flex; align-items: center; gap: 0.4rem; padding: 0.45rem 0.75rem; border-bottom: 1px solid var(--line); font-size: 0.8rem; color: var(--dim); }
.term-bar i { width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--line); }
.term-bar i:first-child { background: var(--red); }
.term-bar i:nth-child(2) { background: var(--amber); }
.term-bar i:nth-child(3) { background: var(--green); }
.term-bar span { margin-left: 0.5rem; }
.term-body { height: 23rem; overflow-y: auto; padding: 0.75rem 0.9rem; font-size: 0.9rem; line-height: 1.5; cursor: text; scrollbar-color: var(--line) transparent; }
.term-out > div { white-space: pre-wrap; overflow-wrap: anywhere; min-height: 1.5em; }
.term-line { display: flex; gap: 0.6ch; }
.term-line[hidden] { display: none; }
.term-line label { color: var(--green); white-space: nowrap; }
.term-line input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; padding: 0; color: var(--text); font: inherit; caret-color: var(--green); }
.hint { margin-top: 0.75rem; font-size: 0.82rem; }

/* colori dell'output del terminale */
.c-g { color: var(--green); }
.c-a { color: var(--amber); }
.c-r { color: var(--red); }
.c-c { color: var(--cyan); }
.c-d { color: var(--dim); }
.c-b { font-weight: 700; color: var(--bright); }
.term-out > .tight { line-height: 1.05; min-height: 0; }
.term-out > .wide { white-space: pre; overflow-x: auto; overflow-wrap: normal; }
.term-stop { display: block; margin-top: 0.3rem; padding: 0; border: 0; background: none; color: var(--dim); font: inherit; font-size: 0.78rem; cursor: pointer; }
.term-stop:hover { color: var(--green); }
.term-stop[hidden] { display: none; }
.term-key { margin-left: 1ch; padding: 0 0.6ch; border: 1px solid var(--line); border-radius: 3px; background: none; color: var(--dim); font: inherit; cursor: pointer; }
.term-body.playing { touch-action: none; overscroll-behavior: contain; }
.term-out > .snake { line-height: 1.15; }
.snake-grid { white-space: pre; overflow: hidden; }
.snake-grid .c-g { font-weight: 700; }

/* --- sezioni e schede --- */
.block { padding: 2.75rem 0 0.5rem; }
.block.narrow { max-width: 42rem; padding-top: 4rem; }
.intro { max-width: 46rem; color: var(--dim); }
#about p { max-width: 46rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr)); gap: 1rem; margin-top: 1.25rem; }
.card { display: flex; flex-direction: column; align-items: flex-start; gap: 0.6rem; padding: 1.1rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); transition: border-color 0.15s, transform 0.15s; }
.card:hover { border-color: var(--green); transform: translateY(-2px); }
.card h3 a { text-decoration: none; }
.card h3 a::before { content: "> "; color: var(--dim); }
.card p { margin: 0; font-size: 0.92rem; }
.card .actions { margin-top: auto; padding-top: 0.75rem; display: flex; flex-direction: column; align-items: flex-start; gap: 0.75rem; width: 100%; font-size: 0.88rem; }

.badge { display: inline-block; padding: 0.28rem 0.6rem 0.16rem; text-wrap: balance; border: 1px solid currentColor; border-radius: 3px; font-size: 0.75rem; line-height: 1.4; color: var(--dim); }
.badge-alpha { color: var(--green); }
.badge-soon { color: var(--amber); }
.badge-done { color: var(--cyan); }

.stack { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; margin: 0; padding: 0; list-style: none; font-size: 0.78rem; color: var(--dim); }
.stack li::before { content: "#"; }

.live { display: grid; gap: 0.3rem; width: 100%; margin: 0; padding: 0.55rem 0.7rem; border: 1px dashed var(--line); border-radius: 4px; list-style: none; font-size: 0.8rem; }
.live[hidden] { display: none; }
.live li { display: flex; flex-wrap: wrap; gap: 0 0.6ch; }
.live .dot { color: var(--dim); }
.live .dot.on { color: var(--green); text-shadow: 0 0 6px var(--green); }
.live .name { color: var(--bright); }

.btn { display: inline-block; padding: 0.45rem 0.95rem; border: 1px solid var(--green); border-radius: 4px; background: color-mix(in srgb, var(--green) 8%, transparent); color: var(--green); font: inherit; font-size: 0.9rem; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--green); color: var(--bg); }

/* --- modulo di iscrizione --- */
.signup { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0.9rem 1rem; align-items: end; max-width: 46rem; margin-top: 1.25rem; padding: 1.1rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.signup label { display: grid; gap: 0.3rem; font-size: 0.82rem; color: var(--dim); }
.signup input, .signup select { width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--text); font: inherit; font-size: 0.95rem; }
.signup input:focus, .signup select:focus { border-color: var(--green); outline: none; }
.signup input::placeholder { color: color-mix(in srgb, var(--dim) 65%, var(--bg)); }
.signup .btn { justify-self: start; }
.signup p { grid-column: 1 / -1; margin: 0; }
.form-msg:empty { display: none; }
.form-msg { color: var(--green); }
.form-msg.err { color: var(--red); }
.hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* --- pagina progetto, impaginata come una man page --- */
.crumbs { padding-top: 1.5rem; font-size: 0.85rem; }
.man { max-width: 48rem; padding: 1.25rem 0 1rem; }
.man-head { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.8rem; margin-bottom: 1.75rem; }
.man section { margin-bottom: 1.6rem; }
.man h2 { font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--amber); margin-bottom: 0.4rem; }
.man h1 { margin-bottom: 0.4rem; }
.man section > :not(h2) { margin-left: clamp(0rem, 4vw, 2.2rem); }
.man .lede { font-size: 1.02rem; }
.features { margin-top: 0; margin-bottom: 0; padding-left: 1.4rem; list-style: "– "; }
.features li { margin-bottom: 0.3rem; }
.shot { display: block; width: min(100%, 26rem); height: auto; margin: 0 0 1.6rem clamp(0rem, 4vw, 2.2rem); border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.man .signup { margin-top: 0.5rem; }

.out { margin: 0 0 1.25rem; padding: 1rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); white-space: pre-wrap; font: inherit; overflow-x: auto; }
.rabbit .out { color: var(--green); }

.foot { max-width: 62rem; margin: 3.5rem auto 0; padding: 1.5rem 1rem 2.5rem; border-top: 1px solid var(--line); font-size: 0.82rem; }
.foot p { margin: 0 0 0.4rem; }

/* --- effetti (easter egg) --- */
.fx-layer { position: fixed; inset: 0; z-index: 100; background: var(--bg); }
.fx-layer canvas { display: block; width: 100%; height: 100%; }
.fx-note { position: absolute; left: 0; right: 0; bottom: 1.25rem; text-align: center; font-size: 0.8rem; color: var(--dim); }
.fx-panic { background: #000; padding: 1.5rem; overflow: hidden; color: #d8d8d8; font-size: 0.85rem; line-height: 1.4; white-space: pre-wrap; }
.fx-wipe main > *, .fx-wipe .top, .fx-wipe .foot { transition: opacity 0.35s, transform 0.35s; }
.fx-gone { opacity: 0 !important; transform: translateY(12px) skewX(-6deg); }
.fx-sl { position: fixed; left: 0; top: 0; z-index: 100; margin: 0; white-space: pre; color: var(--text); font: 0.8rem/1.15 var(--mono); pointer-events: none; }
.fx-glitch { animation: glitch 0.35s steps(2) 3; }
@keyframes glitch {
  0% { transform: translate(0); filter: none; }
  50% { transform: translate(-3px, 1px); filter: hue-rotate(70deg) saturate(2); }
  100% { transform: translate(2px, -1px); filter: none; }
}

@media (max-width: 40rem) {
  body { font-size: 15px; }
  .hero { padding-top: 2rem; }
  .term-body { height: 19rem; font-size: 0.8rem; }
  .top nav { font-size: 0.82rem; gap: 0.1rem 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  body::after, .top, .term, .hint, .signup { display: none; }
  body { background: #fff; color: #000; }
  a, h1, h2 { color: #000; text-shadow: none; }
}
