/* ==========================================================================
   Polymarket 5m Bot — neon desk
   Mobile-first. Breakpoints go up, never down.
   ========================================================================== */
:root {
  --bg: #04070c;
  --surface: rgba(14, 19, 27, 0.86);
  --surface-2: rgba(20, 26, 36, 0.94);
  --line: rgba(120, 160, 255, 0.14);
  --line-strong: rgba(120, 160, 255, 0.28);
  --text: #eef3fa;
  --text-dim: #93a0b4;
  --text-faint: #5f6b7d;
  --cyan: #59d8ff;
  --green: #22e07a;
  --red: #ff5b77;
  --amber: #f0b90b;
  --purple: #b39dff;
  --r: 16px;
  --r-sm: 10px;
  --gap: 12px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Orbitron", var(--sans);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  background:
    radial-gradient(circle at 12% 0%, rgba(79, 140, 255, .10), transparent 32%),
    radial-gradient(circle at 88% 12%, rgba(34, 224, 122, .08), transparent 28%),
    linear-gradient(180deg, #03060a 0%, #070b12 55%, #020407 100%);
  background-attachment: fixed;
}

/* ---- Fondo decorativo ---- */
.app-bg, .bg-grid, .bg-glow { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.bg-grid {
  opacity: .2;
  background-image:
    linear-gradient(rgba(120,160,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,160,255,.05) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 0%, #000 10%, transparent 78%);
}
.bg-glow { filter: blur(90px); opacity: .40; }
.bg-glow-a { background: radial-gradient(circle at 18% 12%, rgba(79,140,255,.30), transparent 42%); }
.bg-glow-b { background: radial-gradient(circle at 82% 22%, rgba(34,224,122,.20), transparent 40%); }
.bg-glow-c { background: radial-gradient(circle at 50% 92%, rgba(179,157,255,.16), transparent 44%); }

/* ==========================================================================
   Glow verde perimetral: señal inequívoca de que hay plata real operando.
   Se activa con .live-running en <body> (lo pone app.js).
   ========================================================================== */
.live-edge {
  position: fixed; inset: 0; z-index: 60; pointer-events: none;
  opacity: 0; transition: opacity .5s ease;
}
body.live-running .live-edge { opacity: 1; animation: livePulse 2.6s ease-in-out infinite; }
.live-edge::before {
  content: ""; position: absolute; inset: 0;
  box-shadow:
    inset 0 0 0 2px rgba(34, 224, 122, .55),
    inset 0 0 26px rgba(34, 224, 122, .30),
    inset 0 0 70px rgba(34, 224, 122, .14);
}
@keyframes livePulse {
  0%, 100% { opacity: .55; }
  50%      { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  body.live-running .live-edge { animation: none; opacity: .8; }
}

/* ---- Layout ---- */
.shell {
  position: relative; z-index: 1;
  max-width: 1500px; margin: 0 auto;
  /* safe-area: installed on an iPhone home screen, the notch and the bottom
     bar eat the edges unless they are accounted for. */
  padding: calc(14px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
           calc(40px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: var(--gap);
}

/* ---- Topbar ---- */
.topbar {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); backdrop-filter: blur(10px);
}
.brand-kicker {
  font-size: .62rem; letter-spacing: .18em; text-transform: uppercase;
  color: var(--amber); opacity: .8; margin-bottom: 6px;
}
.brand-line { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.topbar-title { font-family: var(--display); font-size: 1.05rem; font-weight: 800; letter-spacing: .01em; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
  background: var(--text-faint); box-shadow: 0 0 8px currentColor;
}
.status-dot.ok { background: var(--green); box-shadow: 0 0 10px rgba(34,224,122,.8); }
.mode-pill, .asset-pill {
  padding: 3px 10px; border-radius: 999px; font-size: .62rem;
  letter-spacing: .09em; text-transform: uppercase; white-space: nowrap;
  background: rgba(240,185,11,.10); border: 1px solid rgba(240,185,11,.28); color: var(--amber);
}
.asset-pill { background: rgba(120,160,255,.09); border-color: rgba(120,160,255,.22); color: #9fb6e8; }
.clock-chip { font-family: var(--mono); font-size: .95rem; color: var(--cyan); }
.clock-chip small { display: block; font-size: .62rem; color: var(--text-faint); letter-spacing: .04em; }

/* ---- Control bar ---- */
.control-bar {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
body.live-running .control-bar { border-color: rgba(34,224,122,.34); }
.control-state { display: flex; align-items: center; gap: 10px; }
.control-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--text-faint); flex: 0 0 auto; }
.control-dot.on { background: var(--green); box-shadow: 0 0 12px rgba(34,224,122,.9); }
.control-dot.off { background: var(--red); box-shadow: 0 0 12px rgba(255,91,119,.8); }
#control-label { font-weight: 700; letter-spacing: .03em; font-size: .9rem; }
.control-state small { display: block; font-size: .68rem; color: var(--text-faint); }
.control-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.control-model { display: flex; align-items: center; gap: 7px; font-size: .66rem;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-dim); }
.control-model select, .control-actions input {
  background: rgba(0,0,0,.5); border: 1px solid var(--line-strong); color: var(--text);
  border-radius: var(--r-sm); padding: 10px 12px; font-family: inherit; font-size: .85rem;
  min-height: 42px;
}
.control-actions input { flex: 1 1 150px; min-width: 0; }
.control-model select:focus, .control-actions input:focus { outline: none; border-color: rgba(120,160,255,.7); }
.btn {
  border: none; border-radius: var(--r-sm); padding: 11px 18px; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: .8rem; letter-spacing: .04em;
  min-height: 42px; flex: 1 1 auto; transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn-start { background: linear-gradient(135deg, #12a355, #22e07a); color: #04140a; }
.btn-stop  { background: linear-gradient(135deg, #b0202f, #ff5b77); color: #1a0406; }
.control-msg { font-size: .76rem; min-height: 1em; color: var(--text-dim); }
.control-msg.err { color: #ff8a95; }
.control-msg.ok  { color: var(--green); }

/* ---- Metrics ---- */
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.metric-card {
  padding: 13px 14px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line);
}
.metric-label { font-size: .6rem; letter-spacing: .13em; text-transform: uppercase; color: var(--text-faint); }
.metric-value { font-family: var(--mono); font-size: 1.32rem; font-weight: 700; margin-top: 5px; word-break: break-word; }
.metric-sub { font-size: .66rem; color: var(--text-faint); margin-top: 3px; }

/* ---- Panels ---- */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; backdrop-filter: blur(10px);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.014);
}
.panel-title { font-family: var(--display); font-size: .82rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; }
.panel-badge { font-family: var(--mono); font-size: .68rem; color: var(--cyan); white-space: nowrap; }
.panel-body { padding: 14px 16px; }
.panel-caption { font-size: .72rem; color: var(--text-faint); margin-bottom: 10px; }
.section-title {
  font-size: .62rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--text-faint); margin: 16px 0 8px;
}
.panel-live { border-color: rgba(255,91,119,.38); box-shadow: 0 0 28px rgba(255,91,119,.09); }
.panel-live .panel-title { color: #ff8a95; }
body.live-running .panel-live { border-color: rgba(34,224,122,.45); box-shadow: 0 0 30px rgba(34,224,122,.14); }

/* One book per model. With three of them, fixing two columns left the third
   alone on a whole row: auto-fit lays out 1/2/3 columns by real width. */
.dual-grid { display: grid; grid-template-columns: 1fr; gap: var(--gap); }
/* One accent per model, so the three books are told apart at a glance. */
.panel-v1 { border-color: rgba(240,185,11,.30); }
.panel-v1 .panel-title { color: var(--amber); }
.panel-v2 { border-color: rgba(179,157,255,.30); }
.panel-v2 .panel-title { color: var(--purple); }
.panel-v3 { border-color: rgba(89,216,255,.30); }
.panel-v3 .panel-title { color: var(--cyan); }

/* ---- Tables: on mobile each row becomes a card ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .8rem; }
thead th {
  text-align: left; font-size: .6rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-faint); font-weight: 600; padding: 8px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 10px; border-bottom: 1px solid rgba(120,160,255,.07); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
td.countdown, td .mono { font-family: var(--mono); }
.title-cell { max-width: 240px; }
.empty { text-align: center; color: var(--text-faint); padding: 22px 10px !important; font-size: .78rem; }
.muted { color: var(--text-faint); }
.cyan { color: var(--cyan); } .purple { color: var(--purple); }
.pos { color: var(--green); } .neg { color: var(--red); } .warn { color: var(--amber); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .62rem; letter-spacing: .05em; font-weight: 700;
}
.badge.up { background: rgba(34,224,122,.14); color: var(--green); border: 1px solid rgba(34,224,122,.3); }
.badge.down { background: rgba(255,91,119,.14); color: var(--red); border: 1px solid rgba(255,91,119,.3); }
.band {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .62rem;
  background: rgba(89,216,255,.12); color: var(--cyan); border: 1px solid rgba(89,216,255,.26);
}
.footer { text-align: center; font-size: .68rem; color: var(--text-faint); padding: 6px 0 0; }

/* ==========================================================================
   Números vivos: todo lo que se mueve con el order book.
   El tween lo hace app.js; acá solo el destello de dirección y el ancho fijo
   de los dígitos, para que un número que cambia no empuje al de al lado.
   ========================================================================== */
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.metric-value .num { font-family: var(--mono); }

@keyframes tickUp {
  0%   { color: var(--green); text-shadow: 0 0 14px rgba(34,224,122,.75); transform: translateY(2px); }
  100% { text-shadow: none; transform: translateY(0); }
}
@keyframes tickDown {
  0%   { color: var(--red); text-shadow: 0 0 14px rgba(255,91,119,.75); transform: translateY(-2px); }
  100% { text-shadow: none; transform: translateY(0); }
}
.num.tick-up   { animation: tickUp .75s ease-out; }
.num.tick-down { animation: tickDown .75s ease-out; }

/* Card with open positions: the border breathes so a glance tells you that
   number is not standing still. */
.metric-card.marking {
  border-color: rgba(89,216,255,.30);
  animation: markingPulse 3.4s ease-in-out infinite;
}
@keyframes markingPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(89,216,255,0); }
  50%      { box-shadow: 0 0 18px rgba(89,216,255,.16); }
}
.tag-live {
  font-size: .5rem; letter-spacing: .12em; padding: 1px 5px; border-radius: 4px;
  background: rgba(89,216,255,.14); color: var(--cyan); border: 1px solid rgba(89,216,255,.3);
  vertical-align: middle;
}
.arrow { color: var(--text-faint); padding: 0 2px; }
.cell-sub { font-size: .62rem; color: var(--text-faint); margin-top: 2px; font-family: var(--sans); }
td.mono { font-family: var(--mono); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .num.tick-up, .num.tick-down { animation: none; }
  .metric-card.marking { animation: none; }
}

/* On mobile the stacked row puts the label left and the value right: the
   price sub-line must sit with the value, not under the whole row. */
@media (max-width: 760px) {
  table.stack td .cell-sub { text-align: right; }
}



/* ==========================================================================
   Móvil: las tablas anchas se apilan como tarjetas etiquetadas.
   ========================================================================== */
@media (max-width: 760px) {
  table.stack, table.stack thead, table.stack tbody,
  table.stack tr, table.stack th, table.stack td { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr {
    border: 1px solid var(--line); border-radius: var(--r-sm);
    margin-bottom: 8px; padding: 8px 10px; background: rgba(255,255,255,.016);
  }
  table.stack td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 5px 0; border: none; text-align: right;
  }
  table.stack td::before {
    content: attr(data-label);
    font-size: .6rem; letter-spacing: .1em; text-transform: uppercase;
    color: var(--text-faint); text-align: left; flex: 0 0 auto;
  }
  table.stack td.empty { display: block; text-align: center; }
  table.stack td.empty::before { content: none; }
  .title-cell { max-width: none; }
}

/* ---- Tablet ---- */
@media (min-width: 640px) {
  body { font-size: 15.5px; }
  .shell { padding: 18px 16px 48px; }
  .topbar { flex-direction: row; align-items: center; justify-content: space-between; }
  .clock-chip { text-align: right; font-size: 1.05rem; }
  .topbar-title { font-size: 1.2rem; }
  .control-bar { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .control-state { min-width: 210px; }
  .control-actions { margin-left: auto; }
  .control-actions input { flex: 0 0 175px; }
  .btn { flex: 0 0 auto; }
  .control-msg { flex-basis: 100%; }
  .metric-value { font-size: 1.5rem; }
}

/* ---- Desktop ---- */
@media (min-width: 1024px) {
  :root { --gap: 14px; }
  .metrics { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .dual-grid { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
  .panel-body { padding: 16px 18px; }
}

/* ==========================================================================
   Densidad en móvil: la primera versión medía 5600px de alto y había que
   scrollear muchísimo antes de llegar a los datos.
   ========================================================================== */
@media (max-width: 760px) {
  :root { --gap: 10px; }
  body { font-size: 14px; }

  .topbar { padding: 12px 14px; gap: 8px; }
  .brand-kicker { font-size: .55rem; letter-spacing: .12em; margin-bottom: 4px; }
  .topbar-title { font-size: .98rem; }
  .clock-chip { font-size: .88rem; }
  .clock-chip small { font-size: .58rem; }

  .control-bar { padding: 12px 14px; gap: 10px; }
  .control-state { flex-wrap: wrap; }
  #control-label { font-size: .84rem; }
  .control-state small { flex-basis: 100%; }
  /* input on one row, the two buttons sharing the next */
  .control-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .control-model { grid-column: 1 / -1; }
  .control-actions input { grid-column: 1 / -1; width: 100%; }
  .btn { width: 100%; padding: 11px 10px; }

  .metric-card { padding: 11px 12px; }
  .metric-value { font-size: 1.06rem; }
  .metric-label { font-size: .55rem; }
  .metric-sub { font-size: .6rem; }

  .panel-header { padding: 11px 14px; }
  .panel-title { font-size: .72rem; letter-spacing: .06em; }
  .panel-badge { font-size: .62rem; }
  .panel-body { padding: 12px 14px; }
  .panel-caption { font-size: .66rem; }

  /* The opening window is redundant next to "Ends": hiding it takes the card
     from six rows down to five. */
  .hide-sm { display: none !important; }

  table.stack tr { padding: 7px 10px; margin-bottom: 7px; }
  table.stack td { padding: 4px 0; font-size: .78rem; }
  .section-title { margin: 12px 0 6px; }
}

.mode-value { font-size: 1rem; line-height: 1.25; }
@media (max-width: 760px) { .mode-value { font-size: .8rem; } }

/* Pantallas muy angostas */
@media (max-width: 380px) {
  .topbar-title { font-size: .9rem; }
  .metric-value { font-size: .98rem; }
}
