* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #070a12;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #4ade80;
  --danger: #f87171;
  --glass: rgba(16, 22, 36, 0.72);
  --border: rgba(120, 160, 255, 0.16);
}
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
.accent { color: var(--accent); }

/* ---------- fondo animado ---------- */
.bg-gradient {
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(60% 80% at 70% 40%, rgba(45, 80, 190, 0.22), transparent 60%),
    radial-gradient(50% 60% at 20% 80%, rgba(74, 222, 128, 0.08), transparent 60%),
    radial-gradient(40% 50% at 85% 85%, rgba(248, 113, 113, 0.07), transparent 60%),
    var(--bg);
  animation: drift 18s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(0,0,0) scale(1); }
  to   { transform: translate3d(-2%, -1%, 0) scale(1.06); }
}
.bg-grid {
  position: fixed; inset: -50%; z-index: -1;
  background-image:
    linear-gradient(rgba(120,160,255,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,160,255,0.05) 1px, transparent 1px);
  background-size: 60px 60px;
  transform: perspective(600px) rotateX(55deg);
  animation: gridmove 14s linear infinite;
}
@keyframes gridmove { from { background-position-y: 0; } to { background-position-y: 60px; } }

.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.45);
}

.screen { height: 100vh; height: 100dvh; position: relative; }

/* ---------- auth + landing ---------- */
#auth-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  height: auto; min-height: 100vh; min-height: 100dvh;
  overflow-y: auto; padding: max(2.5rem, 6vh) 0 3rem;
}
#auth-brain { position: fixed; inset: 0; width: 100%; height: 100%; }

/* contenido indexable de la portada */
.landing {
  position: relative; z-index: 2;
  width: min(940px, 92vw); margin: 2.6rem auto 0;
  color: var(--text); line-height: 1.65;
}
.landing h2 {
  font-size: 1.35rem; margin: 2rem 0 0.8rem; text-align: center;
  letter-spacing: -0.01em;
}
.landing > p { color: #b9c0cf; font-size: 0.95rem; max-width: 720px; margin: 0 auto; text-align: center; }
.landing strong { color: var(--text); }
.landing-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px; margin: 1.6rem 0 0.5rem;
}
.landing-grid article {
  background: var(--glass); border: 1px solid var(--border); border-radius: 14px;
  padding: 1rem 1.1rem; backdrop-filter: blur(10px);
}
.landing-grid h3 { font-size: 0.98rem; margin-bottom: 0.4rem; }
.landing-grid p { font-size: 0.87rem; color: #a8b0c0; line-height: 1.55; }
.faq { max-width: 760px; margin: 0 auto; }
.faq details {
  background: rgba(16, 22, 36, 0.6); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.75rem 1rem; margin-bottom: 0.6rem;
}
.faq summary { cursor: pointer; font-weight: 600; font-size: 0.93rem; }
.faq summary::marker { color: var(--accent); }
.faq details p { margin-top: 0.6rem; font-size: 0.87rem; color: #a8b0c0; }
.landing a { color: var(--accent); }
.landing-foot { text-align: center; margin-top: 2rem; display: flex; flex-direction: column; gap: 0.9rem; }
.landing-foot > a { font-size: 0.92rem; font-weight: 600; text-decoration: none; }
.landing-legal { color: var(--muted); font-size: 0.72rem; max-width: 620px; margin: 0 auto; }
.auth-card { position: relative; z-index: 2; padding: 2.2rem 2.4rem; width: min(410px, 92vw); text-align: center; }
.auth-card h1 { font-size: 2.2rem; letter-spacing: 0.02em; margin-top: 0.4rem; }
.logo { width: 84px; height: 84px; filter: drop-shadow(0 0 14px rgba(74,222,128,0.25)); }
.brand-motto { color: var(--text); font-size: 0.95rem; font-style: italic; opacity: 0.9; margin-top: 0.1rem; }
.tagline { color: var(--muted); font-size: 0.8rem; margin: 0.5rem 0 1.4rem; }
.tabs { display: flex; margin-bottom: 1rem; border-radius: 9px; overflow: hidden; border: 1px solid var(--border); }
.tab { flex: 1; padding: 0.6rem; background: transparent; color: var(--muted); border: 0; cursor: pointer; font-size: 0.9rem; }
.tab.active { background: var(--accent); color: #06220f; font-weight: 700; }
#auth-form { display: flex; flex-direction: column; gap: 0.7rem; }
#auth-form input {
  padding: 0.75rem 0.9rem; border-radius: 9px; border: 1px solid var(--border);
  background: rgba(10, 14, 24, 0.8); color: var(--text); font-size: 0.95rem;
}
#auth-form button[type=submit] {
  padding: 0.75rem; border-radius: 9px; border: 0; background: var(--accent);
  color: #06220f; font-weight: 800; font-size: 1rem; cursor: pointer;
  box-shadow: 0 0 24px rgba(74, 222, 128, 0.35);
}
.error { color: var(--danger); font-size: 0.85rem; min-height: 1em; }
.disclaimer { color: var(--muted); font-size: 0.68rem; margin-top: 1.2rem; }

/* ---------- cerebro ---------- */
#brain-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- barra superior ---------- */
.top-bar {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  width: min(1100px, calc(100vw - 28px));
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 1.1rem; z-index: 20;
}
.top-bar button {
  background: rgba(10,14,24,0.6); color: var(--text); border: 1px solid var(--border);
  padding: 0.4rem 0.8rem; border-radius: 8px; cursor: pointer; margin-left: 0.5rem;
}
.user-email { color: var(--muted); font-size: 0.8rem; margin-left: 0.6rem; }
#oro-btn.active {
  background: rgba(255, 199, 44, 0.16);
  border-color: rgba(255, 199, 44, 0.55);
  box-shadow: 0 0 14px rgba(255, 199, 44, 0.25);
}

/* ---------- caja de texto (arriba-izquierda) ---------- */
.composer {
  position: absolute; top: 86px; left: 20px; z-index: 20;
  width: min(520px, calc(100vw - 40px));
  padding: 1rem;
  animation: slideIn 0.6s ease;
}
@keyframes slideIn { from { transform: translateY(-30px); opacity: 0; } to { transform: none; opacity: 1; } }
#input {
  width: 100%; resize: vertical; min-height: 165px;
  padding: 0.9rem 1rem; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(10,14,24,0.8); color: var(--text);
  font-size: 1rem; line-height: 1.5; font-family: inherit;
}
#input:focus { outline: 1px solid rgba(74,222,128,0.5); }
.composer-actions { display: flex; gap: 0.6rem; margin-top: 0.7rem; }
.attach {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-size: 0.95rem; font-weight: 600; cursor: pointer; color: var(--accent);
  border: 1px dashed rgba(74,222,128,0.45); border-radius: 10px;
  padding: 0.7rem 0.9rem;
}
.attach:hover { background: rgba(74,222,128,0.1); border-style: solid; }
#send {
  flex: 1; padding: 0.7rem 1.1rem; border-radius: 10px; border: 0; background: var(--accent);
  color: #06220f; font-weight: 800; cursor: pointer; font-size: 1rem;
  box-shadow: 0 0 18px rgba(74,222,128,0.3);
}
#send:disabled { opacity: 0.5; cursor: wait; }
#image-preview { position: relative; display: inline-block; margin-bottom: 0.5rem; }
#image-preview img { max-height: 80px; border-radius: 8px; }
#remove-img {
  position: absolute; top: -8px; right: -8px; width: 22px; height: 22px;
  border-radius: 50%; border: 0; background: var(--danger); color: #fff; cursor: pointer; font-weight: 700;
}

/* chip del mensaje que "cae" hacia el cerebro */
.falling-chip {
  position: fixed; z-index: 30; pointer-events: none;
  max-width: 300px; padding: 0.5rem 0.8rem; border-radius: 10px;
  background: rgba(35, 64, 102, 0.9); border: 1px solid var(--border);
  font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: fallToBrain 0.9s cubic-bezier(0.5, 0, 0.8, 0.4) forwards;
}
@keyframes fallToBrain {
  0%   { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.15); }
}

/* ---------- burbuja de pensamiento ---------- */
.thought {
  position: absolute; z-index: 15;
  top: 12%; right: 4%;
  width: min(420px, 44vw);
  max-height: 62vh; overflow-y: auto;
  padding: 1rem 1.2rem;
  background: rgba(16, 22, 36, 0.88);
  border: 1px solid rgba(120,160,255,0.3);
  border-radius: 18px;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 40px rgba(74,222,128,0.12), 0 12px 40px rgba(0,0,0,0.5);
  font-size: 0.92rem; line-height: 1.5; white-space: pre-wrap;
  animation: pop 0.35s ease;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }
/* colita de pensamiento: burbujas hacia el cerebro */
.thought::before, .thought::after {
  content: ""; position: absolute; border-radius: 50%;
  background: rgba(16,22,36,0.88); border: 1px solid rgba(120,160,255,0.3);
}
.thought::before { width: 18px; height: 18px; left: -26px; bottom: 18%; }
.thought::after { width: 10px; height: 10px; left: -42px; bottom: 12%; }
#close-thought {
  position: absolute; top: 6px; right: 8px;
  background: none; border: 0; color: var(--muted);
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 4px;
}
#close-thought:hover { color: var(--text); }
.thought { padding-right: 2.2rem; }
.thought .dots { display: inline-block; }
.thought .dots span {
  display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%;
  background: var(--accent); animation: blink 1.2s infinite;
}
.thought .dots span:nth-child(2) { animation-delay: 0.2s; background: var(--danger); }
.thought .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ---------- panel de stats (abajo-izquierda) ---------- */
.stats-panel {
  position: absolute; left: 20px; bottom: 20px; z-index: 20;
  width: min(360px, calc(100vw - 40px));
  padding: 0.9rem 1rem;
}
/* en escritorio el panel siempre está visible: sin pestaña ni cabecera */
#trades-btn { display: none; }
.stats-head { display: none; }
.stats-row { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; }
.stat { flex: 1; text-align: center; background: rgba(10,14,24,0.55); border-radius: 10px; padding: 0.5rem 0.2rem; }
.stat span { font-size: 1.25rem; font-weight: 800; color: var(--accent); display: block; }
.stat label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.last-feedback {
  font-size: 0.8rem; color: var(--muted); line-height: 1.4;
  max-height: 4.2em; overflow: hidden;
  border-left: 2px solid var(--accent); padding-left: 0.6rem;
}

/* ---------- historial ---------- */
.history-drawer {
  position: absolute; top: 80px; right: 14px; bottom: 20px; z-index: 25;
  width: min(400px, calc(100vw - 28px));
  display: flex; flex-direction: column;
  animation: pop 0.25s ease;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
.drawer-head button { background: none; border: 0; color: var(--muted); font-size: 1.3rem; cursor: pointer; }
#history-list { flex: 1; overflow-y: auto; padding: 0.8rem; display: flex; flex-direction: column; gap: 0.6rem; }
.hmsg { padding: 0.55rem 0.8rem; border-radius: 10px; font-size: 0.85rem; white-space: pre-wrap; line-height: 1.4; }
.hmsg.user { align-self: flex-end; background: rgba(35,64,102,0.8); max-width: 88%; }
.hmsg.assistant { align-self: flex-start; background: rgba(20,28,44,0.9); border: 1px solid var(--border); max-width: 92%; }

/* ---------- móvil: todo en una pantalla, sin scroll ---------- */
@media (max-width: 720px) {
  /* barra superior compacta */
  .top-bar { top: 8px; width: calc(100vw - 16px); padding: 0.5rem 0.7rem; }
  .top-bar strong { font-size: 0.95rem; }
  .top-bar button { padding: 0.35rem 0.55rem; margin-left: 0.3rem; font-size: 0.85rem; }
  .btn-label, .user-email { display: none; }

  /* trades: pestaña propia (📊) — oculto hasta que se abre */
  #trades-btn { display: inline-block; }
  .stats-panel { display: none; }
  .stats-panel.open {
    display: block;
    top: 58px; bottom: auto; left: 8px; right: 8px;
    width: auto; padding: 0.8rem; z-index: 25;
    animation: pop 0.25s ease;
  }
  .stats-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.5rem; font-size: 0.9rem;
  }
  .stats-head button {
    background: none; border: 0; color: var(--muted);
    font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 4px;
  }
  .stats-row { gap: 0.3rem; }
  .stat { padding: 0.35rem 0.1rem; }
  .stat span { font-size: 1.05rem; }
  .stat label { font-size: 0.58rem; }
  .last-feedback { font-size: 0.75rem; }

  /* el cerebro respira en el centro (ver brain.js: más grande en móvil) */

  /* burbuja: zona media, sobre el compositor */
  .thought {
    left: 3%; right: 3%; width: auto; top: auto;
    bottom: 142px; max-height: 34vh;
    font-size: 0.85rem; padding: 0.8rem 2rem 0.8rem 0.9rem;
  }
  .thought::before, .thought::after { display: none; }

  /* compositor abajo, compacto */
  .composer {
    top: auto; bottom: 8px; left: 8px;
    width: calc(100vw - 16px); padding: 0.55rem;
  }
  #input { min-height: 0; height: 62px; resize: none; font-size: 0.95rem; padding: 0.55rem 0.7rem; }
  .composer-actions { margin-top: 0.45rem; }
  .attach, #send { padding: 0.5rem 0.5rem; font-size: 0.85rem; }

  /* historial: pestaña propia (🕘) a pantalla casi completa */
  .history-drawer { top: 58px; right: 8px; left: 8px; bottom: 8px; width: auto; }
}

/* ---------- páginas de contenido (guía) ---------- */
body.doc-page { overflow: auto; }
.doc-bar {
  position: sticky; top: 12px; z-index: 20;
  width: min(860px, calc(100vw - 24px)); margin: 12px auto 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.65rem 1.1rem;
}
.doc-brand { font-weight: 800; text-decoration: none; color: var(--text); }
.doc-cta {
  text-decoration: none; color: var(--accent); font-size: 0.88rem; font-weight: 600;
  border: 1px solid rgba(74,222,128,0.4); border-radius: 8px; padding: 0.35rem 0.7rem;
}
.doc-cta.big {
  display: inline-block; background: var(--accent); color: #06220f; border: 0;
  padding: 0.75rem 1.4rem; font-size: 1rem; border-radius: 10px;
  box-shadow: 0 0 24px rgba(74,222,128,0.3);
}
.doc {
  position: relative; z-index: 2;
  width: min(860px, 92vw); margin: 0 auto; padding: 1.6rem 0 4rem;
  color: #c3cad8; line-height: 1.72; font-size: 0.97rem;
}
.doc-crumbs { font-size: 0.78rem; color: var(--muted); margin-bottom: 1rem; }
.doc-crumbs a { color: var(--muted); }
.doc h1 { font-size: clamp(1.6rem, 4.5vw, 2.3rem); line-height: 1.2; color: var(--text); margin-bottom: 0.8rem; letter-spacing: -0.02em; }
.doc-lead { font-size: 1.05rem; color: #b9c0cf; margin-bottom: 1.6rem; }
.doc h2 { font-size: 1.25rem; color: var(--text); margin: 2.4rem 0 0.7rem; letter-spacing: -0.01em; }
.doc h3 { font-size: 1rem; color: var(--text); margin: 1rem 0 0.3rem; }
.doc p { margin-bottom: 0.9rem; }
.doc a { color: var(--accent); }
.doc strong { color: var(--text); }
.doc ul, .doc ol { margin: 0 0 1rem 1.2rem; }
.doc li { margin-bottom: 0.4rem; }
.doc-toc {
  background: rgba(16,22,36,0.65); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem 1.2rem; margin-bottom: 1.6rem;
}
.doc-toc strong { display: block; margin-bottom: 0.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.doc-toc ol { margin: 0 0 0 1.1rem; }
.doc-toc li { margin-bottom: 0.25rem; font-size: 0.9rem; }
.doc-toc a { text-decoration: none; }
.doc-toc a:hover { text-decoration: underline; }
.doc-key {
  background: rgba(74,222,128,0.07); border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0; padding: 0.8rem 1rem; margin: 1.2rem 0;
}
.doc-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 1rem 0; }
.doc-compare > div { background: rgba(16,22,36,0.6); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem 1rem; }
.doc-compare h3 { margin-top: 0; }
.doc-compare p { margin: 0; font-size: 0.9rem; }
@media (max-width: 620px) { .doc-compare { grid-template-columns: 1fr; } }
.doc-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.88rem; display: block; overflow-x: auto; }
.doc-table caption { text-align: left; color: var(--muted); font-size: 0.78rem; margin-bottom: 0.4rem; }
.doc-table th { text-align: left; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.doc-table td { padding: 0.5rem 0.6rem; border-bottom: 1px dashed rgba(120,160,255,0.12); }
.doc-glossary dt { color: var(--accent); font-weight: 700; font-size: 0.9rem; margin-top: 0.7rem; }
.doc-glossary dd { margin: 0.1rem 0 0 0; font-size: 0.9rem; }
.doc-final { margin-top: 2.6rem; border-top: 1px solid var(--border); padding-top: 1.4rem; }
.doc-cta-row { text-align: center; margin: 1.6rem 0; }
.tagline strong { color: #b9c0cf; font-weight: 600; }
