/* Terminal de fósforo — a pele das telas de crt.epius.com.br.

   Monocromático de verdade: existe UMA cor (o fósforo) e o resto é brilho. A hierarquia vem de onde
   vinha num tubo — texto apagado (dim), texto normal, texto forte e VÍDEO REVERSO para o que grita.
   Sem vermelho, sem verde de "ok": um tubo P1 não tinha como.

   O efeito é montado em camadas sobre .tubo: varredura (scanline), máscara de grade de abertura,
   vinheta do vidro curvo, reflexo e o brilho de fósforo (text-shadow). Tudo puramente decorativo e
   inerte ao ponteiro; `prefers-reduced-motion` desliga o que se mexe.

   Dois fósforos (D: escolha do Léo em 14/09): P1 verde e P3 âmbar, na tecla C, lembrados no navegador. */

:root,
[data-fosforo="verde"] {
  --fosforo: #33ff5e;          /* P1 — o verde do VT100/Apple II */
  --fosforo-forte: #b6ffc8;
  --fundo: #060a07;
  --fundo-tinta: #0c140d;      /* o vidro nunca é preto puro: tem a tinta do fósforo em repouso */
  --brilho: rgba(51, 255, 94, .55);
}

[data-fosforo="ambar"] {
  --fosforo: #ffb02e;          /* P3 — o âmbar do IBM 3279 e dos VT220 tardios */
  --fosforo-forte: #ffe5b0;
  --fundo: #0a0703;
  --fundo-tinta: #150d04;
  --brilho: rgba(255, 176, 46, .5);
}

* { box-sizing: border-box; }

/* o user-agent dá fonte própria a pre/input/button — no tubo tudo é a mesma matriz de caracteres */
pre, input, button, table { font: inherit; }
pre { margin: 0; white-space: pre-wrap; }

html, body {
  height: 100%;
  margin: 0;
  background: #050605;
  color: var(--fosforo);
  font-family: "VT323", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(15px, 1.05vw + 11px, 21px);
  line-height: 1.28;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeSpeed;
}

body { overflow: hidden; }

/* ---------- o tubo ---------- */

.tubo {
  position: relative;
  height: 100%;
  padding: clamp(8px, 1.6vmin, 22px);
  background:
    radial-gradient(120% 120% at 50% 45%, var(--fundo-tinta) 0%, var(--fundo) 55%, #000 100%);
  overflow: hidden;
}

/* varredura + grade de abertura: as duas linhas que dão a textura do tubo */
.tubo::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, .38) 0 1px, rgba(0, 0, 0, 0) 1px 3px),
    repeating-linear-gradient(to right, rgba(255, 255, 255, .025) 0 1px, rgba(0, 0, 0, 0) 1px 3px);
  mix-blend-mode: multiply;
  opacity: .9;
}

/* vinheta do vidro curvo + reflexo da sala */
.tubo::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  background:
    radial-gradient(130% 115% at 50% 50%, rgba(0, 0, 0, 0) 52%, rgba(0, 0, 0, .55) 82%, rgba(0, 0, 0, .9) 100%),
    linear-gradient(148deg, rgba(255, 255, 255, .055) 0%, rgba(255, 255, 255, 0) 38%);
  border-radius: clamp(10px, 2.6vmin, 30px);
}

/* o feixe: uma banda clara descendo devagar, como a varredura do quadro */
.feixe {
  position: absolute;
  left: 0;
  right: 0;
  height: 28vh;
  pointer-events: none;
  z-index: 2;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, .028), transparent);
  animation: varre 7.5s linear infinite;
}

@keyframes varre {
  from { transform: translateY(-30vh); }
  to { transform: translateY(105vh); }
}

.quadro {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  text-shadow: 0 0 1px var(--brilho), 0 0 7px var(--brilho), 0 0 18px rgba(255, 255, 255, .05);
  animation: cintila 5.5s ease-in-out infinite;
}

/* o ganho do tubo nunca ficava exatamente parado */
@keyframes cintila {
  0%, 100% { opacity: 1; }
  47% { opacity: .985; }
  48% { opacity: .955; }
  49% { opacity: .99; }
}

/* ---------- hierarquia por brilho (é tudo a mesma cor) ---------- */

.dim { opacity: .5; }
.forte { color: var(--fosforo-forte); }
.rev,
.erro {
  background: var(--fosforo);
  color: var(--fundo);
  text-shadow: none;
  padding: 0 .35ch;
}

/* a tarja é do texto, não da célula: dentro de tabela ela vai num <span> (ver `tabela()` em crt.js) */
td.rev, th.rev { background: none; color: inherit; padding: 0 1ch 0 0; }
.pisca { animation: pisca 1.05s steps(1) infinite; }
@keyframes pisca { 50% { opacity: .25; } }

.cursor {
  display: inline-block;
  width: .6em;
  height: 1em;
  margin-left: .08ch;
  vertical-align: -.12em;
  background: var(--fosforo);
  color: transparent;
  box-shadow: 0 0 6px var(--brilho);
  animation: pisca 1.05s steps(1) infinite;
}

.par {
  display: flex;
  align-items: baseline;
  gap: .9ch;
}

.par .pontos {
  flex: 1;
  border-bottom: 1px dotted currentColor;
  opacity: .4;
  transform: translateY(.14em);  /* o item vazio alinha a borda na baseline; desce para o pé das letras */
}

.par .valor { font-style: normal; }

hr.regua {
  border: 0;
  border-top: 1px solid currentColor;
  opacity: .35;
  margin: .15rem 0;
}

/* ---------- barra de status e rodapé de teclas ---------- */

.barra,
.teclas {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem 1.6ch;
  align-items: baseline;
  white-space: nowrap;
}

.barra-topo {
  justify-content: space-between;
  border-bottom: 1px solid currentColor;
  padding-bottom: .15rem;
}

.teclas {
  border-top: 1px solid currentColor;
  padding-top: .2rem;
  opacity: .85;
}

.tecla {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  letter-spacing: inherit;
}

.tecla b {
  background: var(--fosforo);
  color: var(--fundo);
  padding: 0 .4ch;
  font-weight: normal;
  text-shadow: none;
}

.tecla[aria-current="true"] { color: var(--fosforo-forte); }
.tecla:focus-visible { outline: 1px dashed currentColor; outline-offset: 2px; }

/* ---------- corpo rolável ---------- */

.corpo {
  flex: 1;
  overflow: auto;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  scrollbar-color: var(--fosforo) transparent;
}

.corpo::-webkit-scrollbar { width: 8px; height: 8px; }
.corpo::-webkit-scrollbar-thumb { background: var(--fosforo); opacity: .6; }
.corpo::-webkit-scrollbar-track { background: transparent; }

.tela[hidden] { display: none; }

.titulo {
  font-size: 1.5em;
  font-weight: normal;
  letter-spacing: .25ch;
  margin: .1rem 0 .3rem;
}

/* ---------- tabelas: colunas de terminal ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  white-space: pre;
}

th {
  text-align: left;
  font-weight: normal;
  border-bottom: 1px solid currentColor;
  padding: 0 1ch .1rem 0;
  opacity: .75;
}

td {
  padding: 0 1ch 0 0;
  vertical-align: top;
}

tbody tr:hover { background: rgba(255, 255, 255, .05); }
td.num, th.num { text-align: right; padding-right: 2ch; }
.truncar { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; width: 100%; }

/* a lista do log preserva o espaçamento fixo e quebra linha longa */
.log-linha { white-space: pre-wrap; }
.log-linha .tipo { display: inline-block; width: 9ch; padding-right: 1ch; }
.log-linha .alvo { display: inline-block; width: 11ch; padding-right: 1ch; }
.log-linha .tipo b { font-weight: normal; }

/* ---------- tela de login ---------- */

.login {
  font-size: clamp(17px, 1.15vw + 11px, 26px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .1rem;
  max-width: 70ch;
  height: 100%;
  margin: 0 auto;
  white-space: pre-wrap;
}

.campo {
  position: relative;
  display: flex;
  align-items: baseline;
}

.campo label { width: 8ch; }

.campo input {
  position: absolute;
  inset: 0 0 0 8ch;
  width: calc(100% - 8ch);
  background: none;
  border: 0;
  color: transparent;
  caret-color: transparent;
  font: inherit;
  padding: 0;
}

.campo input:focus { outline: none; }
.campo .espelho { min-height: 1em; }
.campo[data-ativo="nao"] .cursor { visibility: hidden; }

.entrar {
  align-self: flex-start;
  margin-top: 1.1em;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  cursor: pointer;
  letter-spacing: .1ch;
}

.entrar:hover,
.entrar:focus-visible { background: var(--fosforo); color: var(--fundo); text-shadow: none; outline: none; }

/* ---------- respeito a quem não quer movimento ---------- */

@media (prefers-reduced-motion: reduce) {
  .feixe, .quadro, .pisca, .cursor { animation: none; }
  .feixe { display: none; }
  .cursor { opacity: .8; }
}

@media (max-width: 640px) {
  .log-linha .alvo { width: 10ch; }
  .barra, .teclas { gap: .15rem 1.1ch; }
}
