/* ===== Temi ===== */
:root, [data-theme="green"] {
  --bg: #0c0f0a;
  --panel: #12160f;
  --fg: #b8f5a0;
  --dim: #6c8a60;
  --accent: #7CFC00;
  --accent2: #4fd1c5;
  --warn: #f6c177;
  --err: #ff6b6b;
  --sel-bg: #7CFC00;
  --sel-fg: #0c0f0a;
}
[data-theme="amber"] {
  --bg: #0f0b05; --panel: #161007; --fg: #ffcc80; --dim: #9c7a45;
  --accent: #ffb000; --accent2: #ffd27a; --warn: #ffe0a0; --err: #ff7b54;
  --sel-bg: #ffb000; --sel-fg: #0f0b05;
}
[data-theme="ubuntu"] {
  --bg: #2c001e; --panel: #3a0a2b; --fg: #f2f2f2; --dim: #b39aa9;
  --accent: #8ae234; --accent2: #729fcf; --warn: #fce94f; --err: #ef2929;
  --sel-bg: #e95420; --sel-fg: #ffffff;
}
[data-theme="mono"] {
  --bg: #111; --panel: #1a1a1a; --fg: #e6e6e6; --dim: #888;
  --accent: #fff; --accent2: #ccc; --warn: #ddd; --err: #fff;
  --sel-bg: #e6e6e6; --sel-fg: #111;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #050505;
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.5;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ===== Finestra ===== */
.window {
  width: 100%;
  max-width: 1000px;
  height: min(88vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  position: relative;
}

/* leggero effetto CRT */
.window::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.025) 0 1px, transparent 1px 3px);
}

.titlebar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #1c1c1c;
  border-bottom: 1px solid #2a2a2a;
  color: #aaa;
  font-size: 13px;
  user-select: none;
}
.dots { display: flex; gap: 8px; width: 70px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.red { background: #ff5f56; } .yellow { background: #ffbd2e; } .green { background: #27c93f; }
.title { flex: 1; text-align: center; }
.spacer { width: 70px; }

/* ===== Menu in alto ===== */
.menu {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px dashed var(--dim);
}
.menu button {
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: transparent;
  border: none;
  padding: 2px 10px;
  cursor: pointer;
}
.menu button .key { color: var(--accent); }
.menu button:hover, .menu button:focus-visible {
  background: var(--sel-bg);
  color: var(--sel-fg);
  outline: none;
}
.menu button:hover .key, .menu button:focus-visible .key { color: var(--sel-fg); }

/* ===== Terminale ===== */
.terminal {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  cursor: text;
  scrollbar-width: thin;
  scrollbar-color: var(--dim) transparent;
}

#output .line { white-space: pre-wrap; word-break: break-word; min-height: 1.5em; }

.prompt { color: var(--accent); white-space: pre; }
.prompt .path { color: var(--accent2); }

.input-line { display: flex; flex-wrap: wrap; }
.input-wrap { position: relative; flex: 1; min-width: 40px; }
#typed { white-space: pre-wrap; word-break: break-all; }
#cmd {
  position: absolute; left: 0; top: 0;
  width: 100%; height: 100%;
  opacity: 0;
  border: none; outline: none;
  font: inherit; color: transparent; background: transparent;
  caret-color: transparent;
}
.cursor {
  background: var(--fg);
  color: var(--bg);
  animation: blink 1s steps(1) infinite;
}
.terminal:not(.focused) .cursor { background: transparent; outline: 1px solid var(--fg); animation: none; }
@keyframes blink { 50% { background: transparent; } }

/* colori output */
.c-accent { color: var(--accent); }
.c-accent2 { color: var(--accent2); }
.c-dim { color: var(--dim); }
.c-warn { color: var(--warn); }
.c-err { color: var(--err); }
.c-bold { font-weight: 700; }

.terminal a { color: var(--accent2); text-decoration: underline; }
.terminal a:hover { background: var(--accent2); color: var(--bg); }

.cmd-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline dotted;
}
.cmd-link:hover { background: var(--accent); color: var(--bg); }

/* menu interattivo nel terminale */
.tui-menu .item { cursor: pointer; }
.tui-menu .item.active { background: var(--sel-bg); color: var(--sel-fg); }
.tui-box { color: var(--dim); }

/* ===== Statusbar (stile tmux) ===== */
.statusbar {
  display: flex;
  justify-content: space-between;
  padding: 3px 12px;
  background: var(--sel-bg);
  color: var(--sel-fg);
  font-size: 12px;
}

/* ===== Mobile ===== */
@media (max-width: 640px) {
  body { padding: 0; }
  .window { height: 100vh; height: 100dvh; max-width: none; border-radius: 0; border: none; }
  html, body { font-size: 13px; }
  .titlebar .dots, .spacer { width: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
}

/* ===== IslAI ===== */
.ai-line {
  border-left: 2px solid var(--accent2);
  padding-left: 1.5ch;
  margin-left: .5ch;
}
body.busy .input-line { opacity: 0; } /* non usare visibility: farebbe perdere il focus */
body.chat .statusbar { background: var(--accent2); }

/* ===== password ===== */
.copy {
  color: var(--fg);
  background: rgba(127,127,127,.12);
  padding: 0 .5ch;
  cursor: copy;
  word-break: break-all;
}
.copy:hover { background: var(--accent); color: var(--bg); }
.copy-note { white-space: nowrap; }

/* ===== area privata ===== */
body.auth .statusbar { background: var(--err); color: #fff; }

/* ===== Chat in stile GPT ===== */
.gpt {
  --g-bg: #212121; --g-fg: #ececec; --g-dim: #9b9b9b;
  --g-bubble: #303030; --g-border: #3d3d3d; --g-hover: #2f2f2f;
  display: none;
  flex: 1; min-height: 0;
  flex-direction: column;
  background: var(--g-bg); color: var(--g-fg);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.65;
}
.window.gpt-open .gpt { display: flex; }
.window.gpt-open .menu,
.window.gpt-open .terminal,
.window.gpt-open .statusbar { display: none; }
.window.gpt-open::after { display: none; }

.gpt-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--g-border);
}
.gpt-model { font-weight: 600; font-size: 16px; }
.gpt-badge {
  font-size: 11px; font-weight: 500; color: var(--g-dim);
  border: 1px solid var(--g-border); border-radius: 999px; padding: 1px 8px; margin-left: 4px; vertical-align: 2px;
}
.gpt-btn, .gpt-actions button, .gpt-chips button, .gpt-card {
  font: inherit; color: var(--g-fg); background: transparent; cursor: pointer;
}
.gpt-btn { border: 0; border-radius: 8px; padding: 6px 10px; font-size: 13px; color: var(--g-dim); }
.gpt-btn:hover { background: var(--g-hover); color: var(--g-fg); }

.gpt-scroll { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--g-border) transparent; }
.gpt-log { max-width: 760px; margin: 0 auto; padding: 20px 20px 8px; min-height: 100%; display: flex; flex-direction: column; }

.gpt-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px 0; }
.gpt-logo { font-size: 30px; color: var(--accent); width: 56px; height: 56px; border: 1px solid var(--g-border); border-radius: 50%; display: grid; place-items: center; }
.gpt-empty h1 { font-size: 26px; font-weight: 600; margin: 0 0 10px; }
.gpt-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 560px; }
.gpt-card { text-align: left; border: 1px solid var(--g-border); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.gpt-card b { font-weight: 500; }
.gpt-card span { color: var(--g-dim); font-size: 13px; }
.gpt-card:hover { background: var(--g-hover); }

.msg { margin: 14px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--g-bubble); padding: 9px 16px; border-radius: 20px; max-width: 75%; white-space: pre-wrap; word-break: break-word; }
.msg.assistant { display: flex; gap: 14px; }
.msg .avatar { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--g-border); display: grid; place-items: center; color: var(--accent); font-size: 13px; margin-top: 2px; }
.msg .body { flex: 1; min-width: 0; }
.msg .content p { margin: 0 0 10px; }
.msg .content ul { margin: 0 0 10px; padding-left: 20px; }
.msg .content li { margin: 2px 0; }
.msg .content a { color: #8ab4f8; }
.msg .content .gpt-note { color: var(--g-dim); font-style: italic; }
.streaming::after { content: "●"; margin-left: 3px; font-size: 11px; animation: gpt-pulse 1s infinite; }
@keyframes gpt-pulse { 50% { opacity: .2; } }

.thinking { display: flex; gap: 5px; padding: 10px 0; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--g-dim); animation: gpt-dot 1.2s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes gpt-dot { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.gpt-actions { display: flex; flex-wrap: wrap; gap: 2px; margin: -4px 0 0 -8px; }
.gpt-actions button { border: 0; border-radius: 8px; padding: 3px 8px; font-size: 12px; color: var(--g-dim); }
.gpt-actions button:hover { background: var(--g-hover); color: var(--g-fg); }
.gpt-actions button.run { color: var(--accent); border: 1px solid var(--g-border); margin-left: 4px; font-family: "JetBrains Mono", monospace; }

.gpt-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px 42px; }
.gpt-chips button { border: 1px solid var(--g-border); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.gpt-chips button:hover { background: var(--g-hover); }

.gpt-composer { padding: 6px 20px 12px; }
.gpt-box { max-width: 760px; margin: 0 auto; background: var(--g-bubble); border-radius: 26px; display: flex; align-items: flex-end; gap: 8px; padding: 7px 7px 7px 18px; }
.gpt-box:focus-within { box-shadow: 0 0 0 1px var(--g-border); }
.gpt-box textarea { flex: 1; background: transparent; border: 0; outline: 0; resize: none; color: var(--g-fg); font: inherit; line-height: 1.5; padding: 7px 0; max-height: 200px; }
.gpt-box textarea::placeholder { color: var(--g-dim); }
.gpt-send { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--g-fg); color: #111; font-size: 17px; font-weight: 700; cursor: pointer; }
.gpt-send:disabled { opacity: .3; cursor: default; }
.gpt-foot { text-align: center; font-size: 12px; color: var(--g-dim); margin-top: 8px; }

@media (max-width: 640px) {
  .gpt-cards { grid-template-columns: 1fr; }
  .msg.user .bubble { max-width: 88%; }
  .gpt-chips { margin-left: 0; }
  .gpt-log, .gpt-composer { padding-left: 12px; padding-right: 12px; }
  .gpt-foot { display: none; }
}

/* ===== Matrix ===== */
.matrix-banner {
  position: relative;
  height: 170px;
  margin: 0 -18px 10px;          /* a filo dei bordi del terminale */
  overflow: hidden;
  border-bottom: 1px solid var(--dim);
  white-space: normal !important;
}
.matrix-banner canvas, .matrix-full canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mb-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--bg) 85%, transparent) 0%, color-mix(in srgb, var(--bg) 55%, transparent) 45%, transparent 75%);
  pointer-events: none;
}
.mb-title {
  font-size: clamp(22px, 5vw, 40px);
  font-weight: 700;
  letter-spacing: .25em;
  color: var(--accent);
  text-shadow: 0 0 6px var(--accent), 0 0 22px var(--accent);
  white-space: pre;
}
.mb-sub { font-size: 12px; color: var(--fg); opacity: .85; min-height: 1.5em; text-align: center; padding: 0 12px; }
.mb-caret { animation: blink 1s steps(1) infinite; }

.matrix-full {
  position: absolute; inset: 0; z-index: 20;
  background: var(--bg);
  cursor: pointer;
}
.mf-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: clamp(18px, 4vw, 30px); font-weight: 700; color: var(--accent);
  text-shadow: 0 0 8px var(--accent), 0 0 26px var(--accent);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  padding: 12px 22px; white-space: pre;
}
.mf-hint {
  position: absolute; bottom: 14px; width: 100%; text-align: center;
  font-size: 12px; color: var(--fg); opacity: .7;
}
@media (max-width: 640px) {
  .matrix-banner { height: 140px; margin: 0 -18px 8px; }
  .mb-title { letter-spacing: .12em; }
}

/* ===== foto ASCII ===== */
.ascii-photo {
  font-size: 7px;
  line-height: 1;
  letter-spacing: 0;
  white-space: pre !important;
  color: var(--fg);
  margin: 6px 0;
  overflow: hidden;
}
@media (max-width: 640px) { .ascii-photo { font-size: 5px; } }

/* ===== utility ===== */
.hl { background: var(--accent); color: var(--bg); }
.qr {
  display: inline-block;
  background: #fff; color: #000;
  font-size: 10px; line-height: 1; letter-spacing: 0;
  white-space: pre; padding: 6px 4px; margin: 4px 2px;
}
.gpt-term {
  background: #0d0d0d; border: 1px solid var(--g-border); border-radius: 10px;
  padding: 10px 14px; margin: 4px 0 10px; overflow-x: auto;
  font-family: "JetBrains Mono", monospace; font-size: 12.5px; line-height: 1.5; color: #d6f5c8;
}
.gpt-term .line { white-space: pre-wrap; }
.gpt-term-cmd { color: var(--g-dim); margin-bottom: 4px; }
.gpt-term .copy { color: #fff; }
.gpt-run-big {
  font: inherit; cursor: pointer; color: var(--accent); background: transparent;
  border: 1px solid var(--g-border); border-radius: 10px; padding: 6px 12px; font-family: "JetBrains Mono", monospace;
}
.gpt-run-big:hover { background: var(--g-hover); }

/* ===== app interattive (giochi, frattali, simulazioni) ===== */
.app { white-space: pre !important; line-height: 1.15; overflow-x: auto; }
.gpt-term .app { line-height: 1.1; font-size: 11px; }

/* ===== sicurezza / CTF ===== */
.ctf-img { max-width: 240px; image-rendering: pixelated; border: 1px solid var(--dim); margin: 6px 0; display: block; }

/* ===== calendario ===== */
.cal-preview { display: block; width: 100%; max-width: 980px; margin: 6px 0; border-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,.4); }
