/* CyberOS — CRT phosphor workstation */

:root {
  --bg-void: #030504;
  --bezel: #121612;
  --bezel-edge: #2a322a;
  --screen: #050806;
  --phosphor: #3dff7a;
  --phosphor-dim: #1a8f45;
  --phosphor-fade: rgba(61, 255, 122, 0.12);
  --phosphor-glow: 0 0 8px rgba(61, 255, 122, 0.45), 0 0 24px rgba(61, 255, 122, 0.15);
  --danger: #ff5a5a;
  --warn: #ffc857;
  --font-display: "VT323", "IBM Plex Mono", monospace;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, monospace;
  --radius-win: 2px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-phosphor="amber"] {
  --phosphor: #ffb347;
  --phosphor-dim: #a86c1c;
  --phosphor-fade: rgba(255, 179, 71, 0.14);
  --phosphor-glow: 0 0 8px rgba(255, 179, 71, 0.5), 0 0 24px rgba(255, 179, 71, 0.18);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, #0c140e 0%, var(--bg-void) 70%),
    var(--bg-void);
  color: var(--phosphor);
  font-family: var(--font-mono);
  overflow-x: hidden;
  padding: 0 !important;
  align-items: stretch !important;
}

body .container {
  max-width: none;
}

/* Shared header overrides inside CRT */
.crt-screen > header[data-lab-header] {
  margin: 0;
  padding: 0.45rem 0.75rem;
  max-width: none;
  width: 100%;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "back logo actions";
  gap: 0.5rem;
  border-bottom: 1px solid var(--phosphor-fade);
  background: rgba(0, 0, 0, 0.35);
  z-index: 5;
}

.crt-screen .back-link,
.crt-screen .app-logo,
.crt-screen .subtitle {
  color: var(--phosphor) !important;
  text-shadow: var(--phosphor-glow);
}

.crt-screen .back-link {
  opacity: 0.85;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  background: transparent !important;
  border: 1px solid var(--phosphor-fade) !important;
  box-shadow: none !important;
  color: var(--phosphor) !important;
  border-radius: 2px !important;
  padding: 0.3rem 0.55rem !important;
  backdrop-filter: none !important;
}

.crt-screen .back-link:hover {
  opacity: 1;
  background: var(--phosphor-fade) !important;
  border-color: var(--phosphor-dim) !important;
}

.crt-screen .os-brand {
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: 0.08em;
  gap: 0.4rem;
}

.brand-glyph {
  animation: pulse-glyph 2.4s ease-in-out infinite;
}

.brand-ver {
  font-size: 0.7rem;
  opacity: 0.55;
  letter-spacing: 0.12em;
  font-family: var(--font-mono);
}

.crt-screen .theme-toggle {
  display: none !important;
}

.crt-screen .header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.phosphor-switch {
  display: inline-flex;
  gap: 0.25rem;
  border: 1px solid var(--phosphor-fade);
  padding: 0.15rem 0.35rem;
  border-radius: 999px;
}

.phos-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.15rem 0.25rem;
  opacity: 0.35;
  transition: opacity 0.2s, transform 0.2s;
}

.phos-btn[data-phosphor="green"] {
  color: #3dff7a;
}

.phos-btn[data-phosphor="amber"] {
  color: #ffb347;
}

.phos-btn.is-active,
.phos-btn:hover {
  opacity: 1;
  transform: scale(1.15);
}

/* Foco visível consistente para todos os controles do CyberOS */
.crt-screen :is(button, a, select, textarea, input, [tabindex]):focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 2px;
  border-radius: 2px;
}

.phos-btn:focus-visible {
  opacity: 1;
}

/* Boot */
.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: #000;
  padding: 2rem;
}

.boot-log {
  width: min(640px, 100%);
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(0.75rem, 2.2vw, 0.9rem);
  line-height: 1.55;
  color: var(--phosphor);
  text-shadow: var(--phosphor-glow);
  white-space: pre-wrap;
}

.boot-screen.is-done {
  animation: crt-off 0.55s var(--ease-out) forwards;
  pointer-events: none;
}

/* CRT hardware */
.crt-frame {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(0.75rem, 2vw, 1.75rem);
  padding-bottom: 0.5rem;
  animation: crt-on 0.7s var(--ease-out);
}

.crt-bezel {
  position: relative;
  width: min(1120px, 100%);
  aspect-ratio: 16 / 10;
  max-height: calc(100dvh - 5.5rem);
  background:
    linear-gradient(145deg, #1c221c 0%, var(--bezel) 40%, #0a0d0a 100%);
  border-radius: 28px;
  padding: clamp(14px, 2.2vw, 28px);
  box-shadow:
    0 0 0 2px var(--bezel-edge),
    0 24px 60px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.crt-screen {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: var(--screen);
  display: flex;
  flex-direction: column;
  isolation: isolate;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.55);
  /* mild CRT curvature feel via clip + scale */
  transform: perspective(1200px) rotateX(0.6deg) scale(1.002);
}

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 40;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.12) 2px,
    rgba(0, 0, 0, 0.12) 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.55;
}

.crt-glow {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 39;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.35) 100%);
  animation: phosphor-flicker 4.5s infinite;
}

.crt-vignette {
  pointer-events: none;
  position: absolute;
  inset: -2%;
  z-index: 38;
  border-radius: 22px;
  box-shadow: inset 0 0 60px 18px rgba(0, 0, 0, 0.55);
}

.crt-power {
  position: absolute;
  right: clamp(18px, 3vw, 32px);
  bottom: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--phosphor);
  box-shadow: var(--phosphor-glow);
  animation: pulse-glyph 2s ease-in-out infinite;
}

/* Desktop */
.desktop {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.dock {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.45rem;
  border: 1px solid var(--phosphor-fade);
  background: rgba(0, 8, 4, 0.72);
  backdrop-filter: blur(4px);
}

.dock-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 3.25rem;
  padding: 0.45rem 0.35rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--phosphor);
  font-family: var(--font-mono);
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.dock-icon:hover,
.dock-icon:focus-visible {
  border-color: var(--phosphor-dim);
  background: var(--phosphor-fade);
  box-shadow: var(--phosphor-glow);
  outline: none;
}

.dock-glyph {
  font-family: var(--font-display);
  font-size: 1.35rem;
  line-height: 1;
}

/* Windows */
.window[hidden] {
  display: none !important;
}

.window {
  position: absolute;
  left: var(--wx, 10%);
  top: var(--wy, 10%);
  width: var(--ww, 50%);
  height: var(--wh, 55%);
  min-width: 240px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--phosphor-dim);
  background: rgba(2, 10, 5, 0.92);
  box-shadow: var(--phosphor-glow), 0 12px 40px rgba(0, 0, 0, 0.45);
  border-radius: var(--radius-win);
  z-index: 10;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition:
    opacity 0.28s var(--ease-out),
    transform 0.28s var(--ease-out),
    box-shadow 0.2s;
}

.window.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.window.is-focused {
  z-index: 20;
  border-color: var(--phosphor);
}

.win-titlebar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
  border-bottom: 1px solid var(--phosphor-fade);
  background: linear-gradient(180deg, rgba(61, 255, 122, 0.1), transparent);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.win-titlebar:active {
  cursor: grabbing;
}

.win-dots {
  display: inline-flex;
  gap: 4px;
}

.win-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid var(--phosphor-dim);
  display: block;
}

.win-dots i:nth-child(3) {
  background: var(--phosphor-fade);
}

.win-title {
  flex: 1;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win-close {
  border: 0;
  background: transparent;
  color: var(--phosphor);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  padding: 0 0.2rem;
  /* O glifo continua pequeno (é uma barra de título retrô), mas a área tocável
     cresce por pseudo-elemento até 44px. */
  position: relative;
}

.win-close::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: var(--touch-target);
  height: var(--touch-target);
  transform: translate(-50%, -50%);
}

.win-close:hover {
  opacity: 1;
  color: var(--danger);
}

.win-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
  font-size: 0.78rem;
  line-height: 1.5;
}

/* Terminal */
.terminal-body {
  display: flex;
  flex-direction: column;
  padding: 0.55rem 0.7rem 0.65rem;
  gap: 0.35rem;
}

.term-output {
  flex: 1;
  min-height: 0;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: clamp(0.7rem, 1.4vw, 0.82rem);
  white-space: pre-wrap;
  word-break: break-word;
}

.term-output .line-cmd {
  color: var(--phosphor);
  opacity: 0.95;
}

.term-output .line-out {
  color: var(--phosphor);
  opacity: 0.78;
}

.term-output .line-err {
  color: var(--danger);
}

.term-output .line-ok {
  color: var(--warn);
}

.term-input-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border-top: 1px solid var(--phosphor-fade);
  padding-top: 0.45rem;
}

.term-prompt {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--phosphor);
  text-shadow: var(--phosphor-glow);
}

#termInput,
#oracleInput,
textarea,
select {
  font: inherit;
  color: var(--phosphor);
  background: transparent;
  border: 1px solid var(--phosphor-fade);
  border-radius: 2px;
  outline: none;
}

#termInput {
  flex: 1;
  border: 0;
  padding: 0.2rem 0;
  caret-color: var(--phosphor);
  min-width: 0;
}

#termInput:focus {
  outline: none;
}

/* Shared controls */
.os-btn {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--screen);
  background: var(--phosphor);
  border: 1px solid var(--phosphor);
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  box-shadow: var(--phosphor-glow);
  transition: transform 0.15s, filter 0.15s, background 0.15s;
}

.os-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.os-btn.ghost,
.os-btn:not(.is-active).ghost {
  background: transparent;
  color: var(--phosphor);
  box-shadow: none;
}

.os-btn.is-active {
  background: var(--phosphor);
  color: var(--screen);
}

.app-lead {
  margin: 0 0 0.75rem;
  opacity: 0.8;
}

.fw-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.85;
}

.fw-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  margin-bottom: 0.9rem;
  max-width: 280px;
}

.fw-node {
  aspect-ratio: 1;
  border: 1px solid var(--phosphor-dim);
  background: rgba(0, 0, 0, 0.35);
  color: var(--phosphor);
  font-family: var(--font-display);
  font-size: 1.6rem;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.15s;
}

.fw-node:disabled {
  cursor: default;
  opacity: 0.5;
}

.fw-node.is-lit {
  background: var(--phosphor);
  color: var(--screen);
  box-shadow: var(--phosphor-glow);
  transform: scale(1.04);
}

.fw-node.is-ok {
  border-color: var(--warn);
  box-shadow: 0 0 12px rgba(255, 200, 87, 0.45);
}

.fw-node.is-bad {
  border-color: var(--danger);
  animation: shake 0.35s ease;
}

.fw-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

/* Oracle */
.oracle-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.oracle-log {
  flex: 1;
  min-height: 140px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--phosphor-fade);
  padding: 0.65rem;
  background: rgba(0, 0, 0, 0.25);
}

.oracle-msg {
  margin-bottom: 0.65rem;
}

.oracle-msg.user {
  opacity: 0.7;
}

.oracle-msg.bot::before {
  content: "ORACLE › ";
  color: var(--warn);
}

.oracle-form {
  display: flex;
  gap: 0.4rem;
}

#oracleInput {
  flex: 1;
  padding: 0.45rem 0.55rem;
  min-width: 0;
}

.oracle-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chip {
  border: 1px solid var(--phosphor-fade);
  background: transparent;
  color: var(--phosphor);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--phosphor-dim);
  background: var(--phosphor-fade);
}

.chip:active,
.os-btn:active,
.dock-icon:active {
  transform: scale(0.97);
}

/* Cipher */
.cipher-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.cipher-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
  justify-content: space-between;
}

.cipher-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
}

.cipher-controls select {
  padding: 0.4rem 0.5rem;
  min-width: 11rem;
}

.cipher-mode {
  display: flex;
  gap: 0.35rem;
}

.cipher-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.9;
}

.cipher-field textarea {
  padding: 0.55rem;
  resize: vertical;
  opacity: 1;
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.78rem;
  line-height: 1.45;
}

#cipherOut {
  background: rgba(61, 255, 122, 0.05);
}

/* Status bar */
.os-statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  border-top: 1px solid var(--phosphor-fade);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.8;
  background: rgba(0, 0, 0, 0.4);
  z-index: 5;
}

.status-sep {
  opacity: 0.35;
}

.os-statusbar kbd {
  font-family: inherit;
  border: 1px solid var(--phosphor-dim);
  padding: 0 0.25rem;
  text-transform: none;
}

.cyber-lab-footer {
  width: 100%;
  max-width: 1120px;
  margin: 0.35rem auto 0.75rem !important;
  padding: 0 1rem !important;
  opacity: 0.55;
  font-size: 0.75rem;
}

.cyber-lab-footer a {
  color: var(--phosphor) !important;
}

/* Motion */
@keyframes pulse-glyph {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

@keyframes phosphor-flicker {
  0%,
  100% {
    opacity: 1;
  }
  92% {
    opacity: 1;
  }
  93% {
    opacity: 0.92;
  }
  94% {
    opacity: 1;
  }
  96% {
    opacity: 0.88;
  }
  97% {
    opacity: 1;
  }
}

@keyframes crt-on {
  0% {
    opacity: 0;
    filter: brightness(3) contrast(0.2);
    transform: scaleY(0.01);
  }
  40% {
    opacity: 1;
    filter: brightness(1.4);
    transform: scaleY(1);
  }
  100% {
    opacity: 1;
    filter: none;
    transform: none;
  }
}

@keyframes crt-off {
  to {
    opacity: 0;
    transform: scaleY(0.02);
    filter: brightness(2);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes type-caret {
  50% {
    opacity: 0;
  }
}

/* Responsive */
@media (max-width: 820px) {
  .crt-bezel {
    aspect-ratio: auto;
    max-height: none;
    min-height: calc(100dvh - 4.5rem);
    border-radius: 18px;
    padding: 12px;
  }

  .crt-screen {
    transform: none;
    border-radius: 12px;
    min-height: calc(100dvh - 6rem);
  }

  .dock {
    top: auto;
    bottom: 2.4rem;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
  }

  .window {
    left: 3% !important;
    right: 3%;
    width: auto !important;
    top: 8% !important;
    height: 58% !important;
  }

  .win-titlebar {
    cursor: default;
  }

  /* Barra de status compacta: separadores quebrariam em linhas soltas */
  .os-statusbar {
    justify-content: center;
    text-align: center;
    font-size: 0.58rem;
    gap: 0.5rem;
  }

  .os-statusbar .status-sep {
    display: none;
  }

  .dock-icon {
    min-width: 3.75rem;
    min-height: 3rem;
  }

  .fw-node {
    min-height: 3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
/* --- lab-responsive-pass --- */
@media (max-width: 480px) {
    .crt-screen > header[data-lab-header] {
        padding-top: max(0.45rem, env(safe-area-inset-top, 0px));
        padding-inline: max(0.75rem, env(safe-area-inset-left, 0px)) max(0.75rem, env(safe-area-inset-right, 0px));
    }
    .crt-screen .back-link {
        min-width: 44px;
        min-height: 44px;
        padding: 0.45rem 0.75rem !important;
    }
    .dock { bottom: max(2.4rem, env(safe-area-inset-bottom, 0px)); }
    .window { height: 52% !important; top: 10% !important; max-width: calc(100% - 1rem); }
    .phos-btn { min-width: 44px; min-height: 44px; padding: 0.35rem 0.5rem; }
}

/* Paisagem curta: o dock virava faixa horizontal no rodapé (regra de ≤820px) e
   caía DENTRO da janela — deitado sobra largura, não altura, então a janela
   ocupava a faixa inteira e os ícones ficavam por baixo, inalcançáveis.

   Aqui o dock volta a ser coluna à esquerda (que é o que a forma da tela pede)
   e a janela recua para começar depois dele. */
@media (max-height: 540px) and (orientation: landscape) {
  .crt-bezel {
    min-height: calc(100dvh - 2rem);
    padding: 8px;
  }

  .crt-screen {
    min-height: calc(100dvh - 3rem);
  }

  .dock {
    top: 50%;
    bottom: auto;
    left: max(0.4rem, env(safe-area-inset-left, 0px));
    transform: translateY(-50%);
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.3rem;
  }

  .dock-icon {
    min-width: 3.1rem;
    min-height: var(--touch-target);
    padding: 0.25rem 0.3rem;
    font-size: 0.54rem;
  }

  .window {
    left: 4.4rem !important;
    right: max(0.6rem, env(safe-area-inset-right, 0px));
    width: auto !important;
    top: 2% !important;
    height: 94% !important;
  }

  .os-statusbar {
    font-size: 0.52rem;
    padding-block: 0.25rem;
  }
}

/* agent-responsive-768 */
@media (max-width: 768px) {
  html, body { overflow-x: clip; }
}
