:root {
  --bg: #0a0e17;
  --bg-2: #0e1420;
  --card: rgba(255, 255, 255, 0.03);
  --border: rgba(120, 160, 255, 0.14);
  --text: #e8edf7;
  --muted: #8b96ad;
  --accent: #4cc9f0;
  --accent-2: #7b5cff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: radial-gradient(120% 80% at 50% -10%, #14203a 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font-family: 'Poppins', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; }

.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- Splash ---------- */
#screen-splash { align-items: center; justify-content: center; gap: 28px; }

.splash-logo, .brand {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  letter-spacing: 0.14em;
  font-size: 15px;
}
.splash-logo span, .brand span {
  display: block;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 11px;
  letter-spacing: 0.42em;
  margin-top: 4px;
}

.loader {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Topbar ---------- */
.topbar {
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 10px;
  border-bottom: 1px solid var(--border);
}

/* ---------- Welcome ---------- */
.welcome-body { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 28px 24px 40px; }

h1 { font-size: 26px; font-weight: 700; line-height: 1.25; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

#tg-user-line { font-size: 14px; margin-bottom: 26px; }

.features { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-bottom: 34px; }
.features li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 13.5px;
  color: var(--muted);
}
.features b { color: var(--text); font-weight: 600; }

.btn-primary {
  align-self: center;
  border: none;
  cursor: pointer;
  padding: 15px 54px;
  border-radius: 14px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #08101c;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 30px rgba(76, 201, 240, 0.25);
  transition: transform 0.12s ease;
}
.btn-primary:active { transform: scale(0.97); }

/* ---------- Dashboard (заглушка) ---------- */
.dash-body { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}
.card-label { font-size: 12px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 8px; }
.card-value { font-family: 'JetBrains Mono', monospace; font-size: 24px; font-weight: 600; }
.card .card-value.small { font-size: 15px; word-break: break-all; }

/* ---------- Поля ввода (вход BinoDex) ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.field input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.btn-block { width: 100%; align-self: stretch; padding: 14px 20px; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-ghost {
  margin-top: 12px;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }

#login-error { margin-top: 4px; min-height: 16px; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---------- Рынки (живые котировки) ---------- */
.topbar-row { display: flex; align-items: center; gap: 12px; }
.back-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.back-btn:active { transform: scale(0.95); }
.markets-status {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.markets-status.ok { color: #3ddc84; }

.card-link { cursor: pointer; transition: border-color 0.15s ease, transform 0.12s ease; }
.card-link:active { transform: scale(0.98); border-color: var(--accent); }
.markets-card-title { color: var(--accent); font-size: 16px; }

.markets-body { flex: 1; overflow-y: auto; padding: 14px 20px calc(env(safe-area-inset-bottom, 0px) + 28px); }
.markets-hint { margin-bottom: 12px; line-height: 1.5; }

#markets-list { display: flex; flex-direction: column; gap: 8px; }
.market-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease;
}
.market-row:active { transform: scale(0.98); border-color: var(--accent); }
.market-sym {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.market-payout {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: #3ddc84;
  background: rgba(61, 220, 132, 0.08);
  border: 1px solid rgba(61, 220, 132, 0.25);
  padding: 3px 9px;
  border-radius: 8px;
}
.market-price {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  min-width: 96px;
  text-align: right;
}

@keyframes flash-up-kf { 0% { color: #3ddc84; } 100% { color: var(--text); } }
@keyframes flash-down-kf { 0% { color: #ff5d7a; } 100% { color: var(--text); } }
.market-price.flash-up { animation: flash-up-kf 0.9s ease-out; }
.market-price.flash-down { animation: flash-down-kf 0.9s ease-out; }

/* ---------- Открытые сделки (дашборд) ---------- */
#open-trades { display: flex; flex-direction: column; gap: 8px; }
.trade-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.trade-dir {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dir-up { color: #3ddc84; }
.dir-down { color: #ff5d7a; }
.trade-amt {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--muted);
}
.trade-cd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  min-width: 42px;
  text-align: right;
}
.trade-close {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.trade-close:active { transform: scale(0.93); color: var(--text); }
#last-closed-line {
  margin-top: 10px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.02em;
}
.pnl-win { color: #3ddc84 !important; }
.pnl-loss { color: #ff5d7a !important; }

/* ---------- Торговая панель (bottom sheet) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 8, 16, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 520px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 18px 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.sheet-price-wrap { text-align: center; padding: 2px 0 6px; }
.sheet-price {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px;
  font-weight: 600;
  margin-top: 2px;
}
.field-label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#trade-amount {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 17px;
  outline: none;
  width: 100%;
}
#trade-amount:focus { border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.chip.active {
  border-color: var(--accent);
  background: rgba(76, 201, 240, 0.12);
  color: var(--accent);
}
.trade-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.btn-down, .btn-up {
  border: none;
  cursor: pointer;
  padding: 16px 0;
  border-radius: 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #fff;
  transition: transform 0.12s ease;
}
.btn-down {
  background: linear-gradient(180deg, #ff5d7a, #c93a55);
  box-shadow: 0 8px 24px rgba(255, 93, 122, 0.25);
}
.btn-up {
  background: linear-gradient(180deg, #3ddc84, #1fa860);
  box-shadow: 0 8px 24px rgba(61, 220, 132, 0.25);
  color: #06130c;
}
.btn-down:active, .btn-up:active { transform: scale(0.97); }
.btn-down:disabled, .btn-up:disabled { opacity: 0.45; cursor: default; }
.sheet-msg {
  font-size: 12.5px;
  color: #ff5d7a;
  text-align: center;
  min-height: 16px;
}
