:root {
  --ink: #1b2238;
  --panel: #262f4d;
  --panel-2: #303a5e;
  --line: #414c75;
  --text: #e8ebf5;
  --muted: #a9b0c9;
  --lamp: #f2b33d;
  --lamp-dark: #c98d1f;
  --work: #4fc1a6;
  --wait: #f2b33d;
  --err: #e86a62;
  --paper: #f1e8d4;
  --paper-ink: #2b2a33;
  --pixel: 'Pixelify Sans', ui-monospace, monospace;
  --read: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --gpt: #2f9e86;
  --claude: #d9844f;
  --clipshort: #8f5bd6;
  --publisher: #4a7fd6;
  --analyst: #d9b13b;
  --cm: #e05a8a;
  --iana: #3fb6c9;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--text);
  font: 15px/1.5 var(--read);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }

/* ---------- Botones ---------- */
.btn {
  font: 600 15px/1 var(--pixel);
  border: 0; cursor: pointer; border-radius: 4px;
  padding: 11px 16px;
}
.btn-lamp {
  background: var(--lamp); color: var(--ink);
  box-shadow: 0 3px 0 var(--lamp-dark);
}
.btn-lamp:hover { filter: brightness(1.06); }
.btn-lamp:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--lamp-dark); }
.btn-lamp:disabled { opacity: .6; cursor: wait; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); padding: 7px 10px; font-size: 13px; }
.btn-small { padding: 7px 10px; font-size: 13px; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%);
  background: var(--panel); border: 2px solid var(--line); border-radius: 6px;
  padding: 28px; display: grid; gap: 10px;
}
.login-card h1 { font: 600 30px/1 var(--pixel); margin: 0 0 4px; color: var(--lamp); }
.login-card p { margin: 0 0 8px; color: var(--muted); }
input, textarea {
  width: 100%; font: 15px/1.45 var(--read); color: var(--text);
  background: var(--ink); border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px;
}
textarea { resize: vertical; }
label { font-size: 14px; color: var(--muted); }
.error { color: var(--err); min-height: 1.4em; }

/* ---------- Layout ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
}
.brand { font: 600 22px/1 var(--pixel); color: var(--lamp); margin: 0; }
.channel { color: var(--muted); font-size: 14px; }
.demo { font: 13px/1 var(--pixel); background: var(--err); color: var(--ink); padding: 5px 8px; border-radius: 3px; }
.conn { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: var(--err); }
.conn.is-on i { background: var(--work); }

.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 0;
  min-height: 0;
}
.stage { padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
#game {
  width: 100%; aspect-ratio: 704 / 480; max-height: calc(100vh - 170px);
  border: 3px solid #0f1424; border-radius: 4px; overflow: hidden; background: var(--ink);
  image-rendering: pixelated;
}
#game canvas { display: block; }

/* Tarjetas de agentes bajo la oficina */
.roster { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.agent {
  background: var(--panel); border-radius: 4px; padding: 10px 12px;
  border-left: 4px solid var(--c); cursor: pointer; min-width: 0;
}
.agent.is-picked { background: var(--panel-2); }
.agent-name { font: 600 15px/1.2 var(--pixel); display: flex; align-items: center; gap: 6px; }
.agent-role { color: var(--muted); font-size: 13px; }
.agent-doing { font-size: 13px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.working { background: var(--work); }
.dot.walking { background: var(--work); opacity: .6; }
.dot.waiting { background: var(--wait); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- Cajón lateral ---------- */
.drawer { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; background: none; border: 0; color: var(--muted); cursor: pointer;
  font: 600 15px/1 var(--pixel); padding: 14px; border-bottom: 3px solid transparent;
}
.tab.is-on { color: var(--text); border-bottom-color: var(--lamp); }
.tab b { background: var(--lamp); color: var(--ink); border-radius: 9px; padding: 1px 6px; font-size: 12px; margin-left: 4px; }
.panel { padding: 18px; overflow-y: auto; flex: 1; }

.modes { border: 0; padding: 0; margin: 0 0 14px; display: grid; gap: 8px; }
.modes legend { font: 600 15px/1 var(--pixel); margin-bottom: 10px; color: var(--text); }
.mode { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 4px; border: 1px solid var(--line); cursor: pointer; }
.mode:has(input:checked) { border-color: var(--lamp); background: rgba(242, 179, 61, .08); }
.mode input { accent-color: var(--lamp); margin-top: 4px; width: auto; flex: none; }
.mode strong { display: block; color: var(--text); font-weight: 700; }
.mode small { display: block; color: var(--muted); font-size: 13px; line-height: 1.35; }
#taskForm > label { display: block; margin-bottom: 6px; }
#taskForm .btn { width: 100%; margin-top: 12px; }
.form-msg { min-height: 1.4em; font-size: 14px; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }

/* Historial */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  background: var(--ink); border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px;
  cursor: pointer; text-align: left; color: var(--text); width: 100%; font: inherit;
}
.item:hover { border-color: var(--muted); }
.item-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.chip { font: 12px/1 var(--pixel); padding: 4px 6px; border-radius: 3px; background: var(--panel-2); color: var(--muted); align-self: start; white-space: nowrap; }
.chip.listo { background: var(--work); color: var(--ink); }
.chip.esperando_video { background: var(--wait); color: var(--ink); }
.chip.error { background: var(--err); color: var(--ink); }
.chip.por_publicar { background: var(--wait); color: var(--ink); }
.chip.publicado { background: var(--publisher); color: #fff; }
.step-box textarea { background: #fffaf0; color: var(--paper-ink); border-color: #b9ad90; }
.step-box h3 { margin-top: 16px; }
.uploads { padding-left: 18px; line-height: 1.7; }
.empty { color: var(--muted); }

/* ---------- Memo (resultado en papel) ---------- */
.memo { border: 0; padding: 0; background: transparent; max-width: min(760px, 94vw); width: 100%; }
.memo::backdrop { background: rgba(10, 13, 26, .7); }
.memo-sheet {
  position: relative; background: var(--paper); color: var(--paper-ink);
  padding: 34px 34px 28px; border-radius: 2px; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 2px 0 #d6cbb2, 0 4px 0 #c3b796, 0 18px 40px rgba(0, 0, 0, .4);
  background-image: linear-gradient(transparent 31px, rgba(43, 42, 51, .06) 32px);
  background-size: 100% 32px;
}
.memo-sheet::before {
  content: ''; position: absolute; top: -10px; left: 50%; width: 70px; height: 20px; transform: translateX(-50%) rotate(-2deg);
  background: rgba(242, 179, 61, .75);
}
.memo-close { position: absolute; top: 8px; right: 12px; background: none; border: 0; font-size: 28px; cursor: pointer; color: var(--paper-ink); }
.memo h2 { font: 600 24px/1.2 var(--pixel); margin: 0 0 6px; }
.memo h3 { font: 600 17px/1.3 var(--pixel); margin: 26px 0 8px; }
.memo .meta { color: #6b6658; font-size: 14px; margin: 0 0 12px; }
.memo .md { max-width: 68ch; line-height: 1.6; }
.memo .md h1, .memo .md h2, .memo .md h3 { font-family: var(--pixel); }
.memo .md a { color: #2a5bb8; }
.memo pre { white-space: pre-wrap; background: rgba(43, 42, 51, .07); padding: 10px; border-radius: 3px; overflow-x: auto; }
.copybox { background: #fffaf0; border: 1px solid #d6cbb2; border-radius: 3px; padding: 12px 14px; white-space: pre-wrap; line-height: 1.55; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.memo .btn-ghost { color: var(--paper-ink); border-color: #b9ad90; }
.memo .settings { font-size: 14px; color: #4b473d; }
.step-box { background: rgba(242, 179, 61, .2); border: 2px dashed var(--lamp-dark); border-radius: 4px; padding: 14px; margin-top: 12px; }
.step-box label { color: #4b473d; }
.step-box input { background: #fffaf0; color: var(--paper-ink); border-color: #b9ad90; }
details summary { cursor: pointer; font: 600 17px/1.3 var(--pixel); margin-top: 22px; }
.err-box { background: #f7d7d3; border-left: 4px solid var(--err); padding: 10px 12px; }

/* ---------- Avisos ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--paper); color: var(--paper-ink); border-left: 5px solid var(--lamp);
  padding: 12px 14px; border-radius: 3px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); cursor: pointer;
  animation: drop .25s ease-out;
}
@keyframes drop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Móvil ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .drawer { border-left: 0; border-top: 1px solid var(--line); }
  .stage { padding: 10px; }
  #game { max-height: none; }
  .roster { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .topbar { padding: 10px 12px; gap: 10px; }
  .memo-sheet { padding: 28px 18px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .toast, .dot.waiting { animation: none; }
}

.preview { display: block; width: min(320px, 100%); aspect-ratio: 9 / 16; background: #000; border-radius: 4px; margin: 6px 0 4px; }
.scenes { padding-left: 22px; line-height: 1.55; }
.scenes li { margin-bottom: 6px; }

/* Analista cripto */
.ccard { background: #fffaf0; border: 1px solid #d6cbb2; border-radius: 4px; padding: 14px 16px; margin: 10px 0 16px; }
.ccard-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.ccard-asset { font: 600 15px/1 var(--pixel); color: #6b6658; }
.ccard-price { font: 600 30px/1.1 var(--pixel); margin: 4px 0; }
.spark { width: 240px; max-width: 100%; height: 48px; }
.ccard-zone { font-weight: 700; margin: 10px 0 8px; padding: 6px 10px; border-radius: 3px; background: #eee6d3; display: inline-block; }
.ccard-zone span { font-weight: 400; color: #6b6658; }
.ccard-zone.z-baja, .ccard-zone.z-baja_fuerte { background: #d7efdf; }
.ccard-zone.z-alta, .ccard-zone.z-alta_fuerte { background: #f6d9d5; }
.ctable { border-collapse: collapse; width: 100%; font-size: 14px; }
.ctable td { padding: 4px 0; border-bottom: 1px solid #ece3cf; }
.ctable td:last-child { text-align: right; font-weight: 700; }
.reasons { margin: 8px 0; padding-left: 20px; font-size: 14px; }
.memo table { border-collapse: collapse; }
.memo .md table td, .memo .md table th { border: 1px solid #d6cbb2; padding: 4px 8px; }

/* Ficha del agente */
.agent-head { display: flex; align-items: center; gap: 12px; border-left: 6px solid var(--c); padding-left: 10px; }
.agent-head h2 { margin: 0; }
.now { background: #fffaf0; border: 1px solid #d6cbb2; border-radius: 4px; padding: 10px 12px; margin: 10px 0; }
.pbar { height: 8px; background: #e6dcc6; border-radius: 4px; overflow: hidden; margin-top: 8px; }
.pbar i { display: block; height: 100%; background: var(--lamp-dark); }
.ahist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.ahist button { width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; background: #fffaf0; border: 1px solid #d6cbb2; border-radius: 4px; padding: 8px 10px; cursor: pointer; font: inherit; color: var(--paper-ink); }
.ahist button:hover { border-color: #9a8f7a; }
.ah-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ah-date { color: #6b6658; font-size: 13px; }
.ah-res { grid-column: 1 / -1; font-size: 13px; color: #4b473d; }
.empty-p { color: #6b6658; }

/* Estadísticas */
.stable { border-collapse: collapse; width: 100%; font-size: 14px; margin: 8px 0 12px; background: #fffaf0; }
.stable th, .stable td { border: 1px solid #e0d6c0; padding: 5px 8px; text-align: left; vertical-align: top; }
.stable th { background: #efe5cf; font-family: var(--pixel); font-weight: 600; }
.stable td:nth-last-child(-n+3) { text-align: right; }
.stable .nodata { color: #8a8270; text-align: left !important; font-size: 13px; }

/* Cancelar y subir video propio */
.btn-stop { background: #c4483f; color: #fff; border: 0; }
.btn-stop:hover { filter: brightness(1.08); }
.cancel-row { margin: 4px 0 10px; }
.upload-box { display: grid; gap: 8px; margin-top: 12px; padding: 12px; border: 1px dashed var(--line); border-radius: 4px; }
.upload-box input[type=file] { padding: 8px; }
.nets { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.nets legend { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.nets label, .lit { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.nets input, .lit input { width: auto; accent-color: var(--lamp); }
.agent { padding: 8px 10px; }
.agent-role { font-size: 12px; }
@media (max-width: 900px) { .roster { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Monitor de créditos */
.stable.credits tr.sub td { padding-top: 0; border-top: 0; font-size: .85rem; text-align: left; }
.bal-input { width: 6.5em; padding: 4px 6px; font: inherit; border: 1px solid #b9c0cb; border-radius: 4px; }
