/* Estilos generales */
* { box-sizing: border-box; }
html, body { height: 100%; }

:root {
  --bg: #000;
  --fg: #fff;
  --fg-dim: #cfcfcf;
  --line: #2a2a2a;
  --accent: #7e7e7e;
  --shadow: rgba(0,0,0,0.5);
  --bot: #9ae6b4;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden; /* desactivar scroll general de la página */
}

/* Pantalla de arranque */
.boot-screen {
  position: fixed;
  inset: 0;
  background: #000;
  display: grid;
  place-items: center;
  z-index: 10;
  transition: opacity 600ms ease, visibility 600ms ease;
}
.boot-screen.hidden {
  opacity: 0;
  visibility: hidden;
}
.boot-inner {
  width: min(860px, calc(100% - 48px));
  color: var(--fg);
}
.boot-log {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.6;
}
.boot-cursor {
  display: inline-block;
  margin-left: 8px;
  animation: blink 1s steps(1, end) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Terminal principal */
.terminal {
  position: relative;
  min-height: 100svh; /* ajusta al viewport visible en móviles (sin barra) */
  height: 100dvh; /* reserva altura completa con soporte de dynamic viewport */
  display: flex;
  flex-direction: column;
  overflow: hidden; /* el scroll queda dentro de .chat */
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.035) 0px,
    rgba(255,255,255,0.035) 1px,
    transparent 3px,
    transparent 5px
  );
  mix-blend-mode: screen;
  opacity: 0.08;
  animation: scanmove 12s linear infinite;
}
@keyframes scanmove {
  0% { background-position: 0 0; }
  100% { background-position: 0 1000px; }
}

.chat {
  flex: 1;
  padding: 16px;
  overflow-y: auto; /* scroll solo aquí */
  scroll-behavior: smooth;
  overscroll-behavior: contain; /* evita rebote y scrolling del body */
  scrollbar-gutter: stable; /* evita saltos al aparecer/desaparecer scrollbar */
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 500ms ease, transform 500ms ease;
}
body.started .chat { opacity: 1; transform: none; }

/* Línea de mensaje estilo terminal */
.line {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 6px 4px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 300ms ease, transform 300ms ease;
}
.line.show { opacity: 1; transform: none; }
.line .prefix { color: var(--fg-dim); min-width: 20px; user-select: none; }
.line.user .prefix { color: var(--fg); }
.line .content { color: var(--fg); word-break: break-word; }
.line.bot .prefix { display: none; }
.line.bot .content { color: var(--bot); }

.line.bot.thinking .content {
  opacity: 0.85;
}

/* Enlaces dentro del contenido del chat */
.line .content a {
  color: inherit;
  text-decoration: underline;
}
.line .content a:visited { color: inherit; }
.line .content a:hover { text-decoration: none; }

/* Dock de entrada */
.input-form { position: relative; }
.input-dock {
  position: static; /* deja de ser overlay, se integra en el flujo */
  width: auto;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  /* añadir espacio para notch / barras en móviles */
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
  margin: 8px 16px calc(16px + env(safe-area-inset-bottom)); /* separación del borde inferior + safe area */
}
.input-dock.centered, .input-dock.docked {
  top: auto;
  bottom: auto;
  transform: none; /* anular transformaciones del modo overlay */
}

/* Fila estilo bash: prefijo + input */
.prompt-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.prompt-prefix {
  color: var(--fg);
  opacity: 0.95;
  user-select: none;
  white-space: pre;
}
.send-button {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--fg);
  font: inherit;
  border-radius: 8px;
  min-width: 48px;
  padding: 0 16px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03), 0 6px 18px rgba(0,0,0,0.55);
  transition: background 180ms ease, border-color 180ms ease, box-shadow 220ms ease, transform 120ms ease;
}
.send-button__icon {
  font-size: 1rem;
  line-height: 1;
  transform: translateY(1px);
  letter-spacing: -0.06em;
}
.send-button:hover {
  background: rgba(255,255,255,0.1);
  border-color: #6c6c6c;
}
.send-button:active { transform: translateY(1px); }
.send-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.25), 0 4px 18px rgba(0,0,0,0.65);
}
.send-button.armed {
  border-color: #6cffc8;
  background: rgba(108,255,200,0.12);
  box-shadow: 0 0 22px rgba(108,255,200,0.35), inset 0 0 0 1px rgba(255,255,255,0.06);
}
.send-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
  background: rgba(255,255,255,0.02);
}

/* Campo de entrada */
.prompt-symbol {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg);
  opacity: 0.9;
}
#prompt-input {
  width: 100%;
  padding: 12px 8px 12px 34px;
  background: transparent;
  color: var(--fg);
  border: none;
  border-bottom: none;
  border-radius: 0;
  outline: none;
  caret-color: var(--fg);
  box-shadow: none;
  transition: background 180ms ease, text-shadow 180ms ease;
  font: inherit;
  font-size: inherit; /* asegurar coincidencia con .line .content */
  line-height: inherit; /* mantener proporción visual */
}
.prompt-row #prompt-input { padding-left: 0; flex: 1; min-width: 0; }
#prompt-input::placeholder { color: #808080; }
#prompt-input:focus {
  border-bottom: none;
  background: transparent;
  text-shadow: 0 0 6px rgba(255,255,255,0.08);
}
#prompt-input:disabled { opacity: 0.8; cursor: progress; }

/* Chips de sugerencias */
.suggestions {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(820px, calc(100% - 32px));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0;
  z-index: 2;
  transition: opacity 250ms ease, transform 250ms ease;
}
.suggestions.fading { opacity: 0; transform: translate(-50%, calc(-50% - 4px)); }
.chip {
  background: rgba(0,0,0,0.3);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}
.chip:hover { transform: translateY(-1px); border-color: #5a5a5a; }
.chip:active { transform: translateY(0); }
.chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.24);
}

/* Responsividad */
@media (max-width: 480px) {
  html, body { font-size: 14px; }
  .chat { padding: 12px; }
  #prompt-input { font-size: 14px; padding: 12px 12px 12px 30px; }
  .prompt-symbol { left: 10px; }
  .send-button {
    min-width: 40px;
    padding: 0 12px;
    height: 38px;
  }
  .input-dock {
    margin: 8px env(safe-area-inset-left) calc(16px + env(safe-area-inset-bottom)) env(safe-area-inset-right);
  }
}

/* Muy pequeñas (teléfonos <= 360px) */
@media (max-width: 360px) {
  html, body { font-size: 13px; }
  #prompt-input { font-size: 13px; padding: 11px 11px 11px 28px; }
}

/* Extra pequeñas (teléfonos <= 320px) */
@media (max-width: 320px) {
  html, body { font-size: 12px; }
  #prompt-input { font-size: 12px; padding: 10px 10px 10px 26px; }
}

/* Scrollbar sutil (webkit) */
.chat::-webkit-scrollbar { width: 10px; }
.chat::-webkit-scrollbar-thumb { background: #1d1d1d; border-radius: 8px; }
.chat::-webkit-scrollbar-thumb:hover { background: #262626; }
/* Firefox */
.chat { scrollbar-width: thin; scrollbar-color: #1d1d1d transparent; }
