:root {
  --bg: #0A0E0F;
  --bg-elevated: #12181A;
  --bg-card: #161D20;
  --line: #232B2E;
  --text: #E8E8E3;
  --text-muted: #8A9199;
  --green: #3DDC84;
  --red: #FF5C5C;
  --gold: #E3B341;
  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- TICKER SUPERIOR ---------- */
.ticker-bar {
  background: #050706;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  white-space: nowrap;
  height: 34px;
  display: flex;
  align-items: center;
}
.ticker-track {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 13px;
  padding-left: 100%;
  animation: scroll-left 40s linear infinite;
}
.ticker-track span.up { color: var(--green); }
.ticker-track span.down { color: var(--red); }
@keyframes scroll-left {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

/* ---------- BRAND ---------- */
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: -0.5px;
  margin: 0;
  color: var(--text);
}
.brand span { color: var(--green); }
.brand.small { font-size: 20px; }

/* ---------- AUTH SCREEN ---------- */
.auth-screen {
  min-height: calc(100vh - 34px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(61,220,132,0.06), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(227,179,65,0.05), transparent 40%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 36px 32px;
}
.tagline {
  color: var(--text-muted);
  font-size: 14px;
  margin: 6px 0 28px;
}
.auth-tabs {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 14px;
  cursor: pointer;
}
.auth-tab.active { background: var(--bg-elevated); color: var(--text); }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
input {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
}
input:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.btn-primary {
  background: var(--green);
  color: #06110A;
  border: none;
  border-radius: 3px;
  padding: 12px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  margin-top: 6px;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 3px;
  padding: 12px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-muted);
  border-radius: 3px;
  padding: 8px 14px;
  font-family: var(--font-display);
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-discord {
  display: inline-block;
  background: transparent;
  border: 1px solid #5865F2;
  color: #8891FF;
  border-radius: 3px;
  padding: 8px 14px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
}
.btn-discord:hover { background: rgba(88,101,242,0.12); }
.auth-discord {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: #8891FF;
  font-size: 13px;
}
.auth-discord:hover { color: #A6ADFF; }
.auth-error { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 14px; }

/* ---------- APP SHELL ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  gap: 24px;
  flex-wrap: wrap;
}
.stats { display: flex; gap: 28px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.stat { display: flex; flex-direction: column; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: none; }
.stat-value { font-family: var(--font-mono); font-size: 17px; font-weight: 600; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 14px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab.active { color: var(--text); border-bottom-color: var(--green); }
.tab-icon { font-size: 15px; line-height: 1; }
.tab-label { font-size: 13px; }

/* ---------- AJUSTES SEGÚN DISPOSITIVO DETECTADO (ver app.js) ---------- */

/* Celular: barra de navegación fija abajo, estilo app nativa */
.device-mobile .topbar { position: sticky; top: 0; z-index: 30; background: var(--bg); }
.device-mobile .tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  justify-content: space-between;
  background: var(--bg-card);
  border-top: 1px solid var(--line);
  border-bottom: none;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  overflow-x: visible;
  z-index: 40;
}
.device-mobile .tab {
  flex: 1;
  flex-direction: column;
  gap: 2px;
  padding: 6px 2px;
  border-bottom: none;
  min-height: 48px;
}
.device-mobile .tab.active { color: var(--green); }
.device-mobile .tab-icon { font-size: 19px; }
.device-mobile .tab-label { font-size: 9.5px; }
.device-mobile .content { padding-bottom: 92px; }
.device-mobile .stats { gap: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.device-mobile .asset-grid { grid-template-columns: 1fr; }
.device-mobile input,
.device-mobile .btn-primary,
.device-mobile .btn-danger,
.device-mobile .upgrade-card button { min-height: 46px; }
.device-mobile .modal { align-items: flex-end; padding: 0; }
.device-mobile .modal-card {
  max-width: 100%;
  width: 100%;
  border-radius: 14px 14px 0 0;
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
}

/* Computador: barra superior normal (comportamiento por defecto, sin cambios) */
.device-desktop .tab { flex-direction: row; }

.content { padding: 28px; max-width: 1100px; margin: 0 auto; }
.content h2 { margin: 0 0 4px; font-size: 22px; }
.hint { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }
.subheading { font-size: 15px; color: var(--text-muted); margin: 24px 0 10px; font-weight: 500; }

.view { display: none; }
.view.active { display: block; }

.stat-value.gold { color: var(--gold); }

/* ---------- ASSET CARDS ---------- */
.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.asset-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 16px;
  cursor: pointer;
  transition: border-color .15s ease;
}
.asset-card:hover { border-color: var(--text-muted); }
.asset-card .symbol { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.asset-card .name { font-size: 15px; font-weight: 600; margin: 2px 0 10px; }
.asset-card .price { font-family: var(--font-mono); font-size: 20px; font-weight: 600; }
.mini-chart { display: block; width: 100%; height: 44px; margin: 4px 0 8px; cursor: pointer; }
.trade-chart { display: block; width: 100%; height: 140px; border-radius: 3px; margin-bottom: 4px; }
.asset-card .delta { font-family: var(--font-mono); font-size: 12px; margin-top: 4px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }

.asset-card.company { border-left: 3px solid var(--gold); }
.asset-card.company .price { color: var(--gold); }
.asset-card.company .income { font-family: var(--font-mono); font-size: 12px; color: var(--green); margin-top: 6px; }
.asset-card.owned { opacity: 0.55; cursor: default; }
.badge-owned {
  display: inline-block;
  font-size: 11px;
  color: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 2px;
  padding: 2px 6px;
  margin-top: 8px;
}

/* ---------- TABLES ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; }
.empty-note { color: var(--text-muted); font-size: 13px; padding: 12px 0; }

/* ---------- RENACIMIENTO ---------- */
.rebirth-card {
  background: var(--bg-card);
  border: 1px solid var(--gold);
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 24px;
}
.rebirth-progress-bar {
  height: 10px;
  background: var(--bg-elevated);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.rebirth-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold));
  width: 0%;
  transition: width .4s ease;
}
.rebirth-coins-row {
  display: flex;
  gap: 24px;
  font-family: var(--font-mono);
  font-size: 13px;
  margin: 14px 0;
  flex-wrap: wrap;
}
.rebirth-coins-row strong { color: var(--gold); }
#rebirthBtn:disabled { opacity: 0.4; cursor: not-allowed; border-color: var(--line); color: var(--text-muted); }

.upgrade-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.upgrade-card .name { font-size: 15px; font-weight: 600; margin: 0; }
.upgrade-card .desc { font-size: 12px; color: var(--text-muted); margin: 0; }
.upgrade-card .level { font-family: var(--font-mono); font-size: 12px; color: var(--green); }
.upgrade-card button {
  margin-top: 6px;
  background: var(--gold);
  color: #1a1200;
  border: none;
  border-radius: 3px;
  padding: 9px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.upgrade-card button:disabled {
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ---------- RANKINGS ---------- */
.ranking-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 32px; }
.ranking-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.ranking-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 13px;
}
.ranking-list li .rank-pos { color: var(--text-muted); margin-right: 10px; }
@media (max-width: 640px) {
  .ranking-columns { grid-template-columns: 1fr; }
}

/* ---------- MODAL ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 20px;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 28px;
  width: 100%;
  max-width: 400px;
  position: relative;
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer; line-height: 1;
}
.modal-card h3 { margin: 0 0 4px; }
.modal-card label {
  display: flex; flex-direction: column; gap: 6px; font-size: 13px;
  color: var(--text-muted); margin: 16px 0;
}
.trade-total { font-family: var(--font-mono); font-size: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 10px; }
.modal-actions button { flex: 1; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); border: 1px solid var(--line);
  padding: 12px 20px; border-radius: 4px; font-size: 13px; z-index: 60;
}
.toast.error { border-color: var(--red); color: var(--red); }
.toast.success { border-color: var(--green); color: var(--green); }

@media (max-width: 700px) {
  .topbar { padding: 14px 16px; }
  .content { padding: 18px; }
  .stats { gap: 16px; }
}
