:root {
  --bg: #0b0e14;
  --bg-soft: #111725;
  --card: #141b2b;
  --card-2: #182034;
  --line: #24304a;
  --text: #e6ecf7;
  --muted: #8391ab;
  --accent: #4f8cff;
  --accent-2: #22d3a6;
  --danger: #ff5d6c;
  --warn: #ffb020;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #16213a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  min-height: 100%;
}

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: .35rem 0; line-height: 1.5; }
code { background: #0f1522; padding: .1rem .35rem; border-radius: 6px; font-size: .85em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hint { color: var(--muted); font-size: .78rem; }
.error { color: var(--danger); font-size: .85rem; }
.note { color: var(--accent-2); font-size: .85rem; }
.mt { margin-top: 1.2rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .8rem 1.4rem;
  background: rgba(11, 14, 20, .82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: .55rem; }
.brand em { font-style: normal; font-weight: 400; color: var(--muted); font-size: .78rem; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(34, 211, 166, .15);
}
#main-nav { display: flex; gap: .3rem; margin-left: auto; }
#main-nav button {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: .45rem .8rem; border-radius: 9px; cursor: pointer; font-size: .86rem;
}
#main-nav button:hover { color: var(--text); background: var(--bg-soft); }
#main-nav button.active { color: var(--text); background: var(--card-2); border-color: var(--line); }
.userbox { display: flex; align-items: center; gap: .8rem; margin-left: auto; font-size: .85rem; }
#main-nav:not(.hidden) ~ .userbox { margin-left: 0; }

main { max-width: 1280px; margin: 0 auto; padding: 1.6rem 1.4rem 4rem; }

/* ---------- cards & grid ---------- */
.card {
  background: linear-gradient(180deg, var(--card) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 1rem; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { display: flex; flex-direction: column; gap: .15rem; }
.stat span { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.stat strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .75rem; }
.badge {
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  padding: .15rem .55rem; border-radius: 999px; font-size: .72rem;
}

/* ---------- auth ---------- */
.auth { display: grid; place-items: center; min-height: 72vh; }
.auth-card { width: min(430px, 94vw); }
.auth-card h1 { background: linear-gradient(90deg, #fff, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.tabs { display: flex; gap: .4rem; margin: 1rem 0 .8rem; }
.tab {
  flex: 1; background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--muted); padding: .5rem; border-radius: 9px; cursor: pointer;
}
.tab.active { color: var(--text); background: var(--card-2); border-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: .7rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
input, select {
  background: #0d1320; color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: .6rem .7rem; font-size: .9rem; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 140, 255, .15); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

button {
  font: inherit; cursor: pointer; border-radius: 9px;
  padding: .58rem .95rem; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); transition: .15s ease;
}
button:hover { border-color: var(--accent); }
button.primary { background: linear-gradient(180deg, #5b93ff, #3f74e6); border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.small { padding: .3rem .6rem; font-size: .78rem; }
button.danger { border-color: rgba(255, 93, 108, .5); color: var(--danger); background: rgba(255, 93, 108, .07); }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-height: 420px; border-radius: 10px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th, td { padding: .5rem .65rem; text-align: left; white-space: nowrap; border-bottom: 1px solid rgba(36, 48, 74, .6); }
th { position: sticky; top: 0; background: var(--bg-soft); color: var(--muted); font-weight: 500; z-index: 1; }
tbody tr:hover { background: rgba(79, 140, 255, .06); }
td.num, .num { font-variant-numeric: tabular-nums; }
.pos { color: var(--accent-2); }
.neg { color: var(--danger); }
.pill { padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; border: 1px solid var(--line); }
.pill.live { color: var(--danger); border-color: rgba(255, 93, 108, .4); background: rgba(255, 93, 108, .08); }
.pill.paper { color: var(--accent); border-color: rgba(79, 140, 255, .4); background: rgba(79, 140, 255, .08); }
.pill.running { color: var(--accent-2); border-color: rgba(34, 211, 166, .4); }
.pill.stopped { color: var(--muted); }
.pill.error, .pill.halted { color: var(--danger); border-color: rgba(255, 93, 108, .4); }
.pill.pending { color: var(--warn); border-color: rgba(255, 176, 32, .4); }

/* ---------- profiles ---------- */
.profiles { display: flex; flex-direction: column; gap: .65rem; }
.profile {
  border: 1px solid var(--line); border-radius: 11px; padding: .75rem .85rem;
  background: var(--card-2); display: flex; flex-direction: column; gap: .5rem;
}
.profile-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.profile-title { font-weight: 600; display: flex; align-items: center; gap: .5rem; }
.profile-meta { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .78rem; }
.profile-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.profile .mini { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; font-size: .76rem; }
.profile .mini div { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; }
.profile .mini span { color: var(--muted); display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; }

.kv { display: flex; justify-content: space-between; border-bottom: 1px dashed rgba(36, 48, 74, .8); padding: .4rem 0; font-size: .85rem; }
.kv span { color: var(--muted); }

/* ---------- training progress ---------- */
.training {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem .65rem;
  background: var(--bg);
  margin-top: .35rem;
}
.training-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .76rem; color: var(--muted); margin-bottom: .35rem;
}
.training-head b { color: var(--text); font-variant-numeric: tabular-nums; }
.progress {
  height: 7px; border-radius: 999px; background: rgba(36, 48, 74, .85);
  overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, #4f8cff, #22d3a6);
  transition: width .45s ease;
}
.training-msg { font-size: .72rem; color: var(--muted); margin-top: .35rem; }
.training.done .progress-bar { background: linear-gradient(90deg, #22d3a6, #2fe0b2); }
.training.error { border-color: rgba(255, 93, 108, .45); }
.training.error .training-msg { color: var(--danger); }

/* ---------- canvas ---------- */
canvas { width: 100%; display: block; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 7, 12, .7); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 1rem;
}
.modal-card { width: min(520px, 96vw); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 1.4rem; right: 1.4rem; z-index: 60;
  background: var(--card-2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 10px;
  padding: .75rem 1rem; max-width: 380px; font-size: .85rem;
  box-shadow: var(--shadow);
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--accent-2); }

/* ---------- live cards ---------- */
.live-card { border: 1px solid var(--line); border-radius: 12px; padding: .9rem; background: var(--card-2); }
.live-card .lc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.live-card .price { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.live-card .lc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .45rem; margin-top: .6rem; font-size: .78rem; }
.live-card .lc-grid div { background: var(--bg); padding: .4rem .5rem; border-radius: 8px; border: 1px solid var(--line); }
.live-card .lc-grid span { color: var(--muted); display: block; font-size: .68rem; }

@media (max-width: 980px) {
  .grid.two, .grid.stats { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  #main-nav { order: 3; width: 100%; overflow-x: auto; }
}
