:root {
  --bg: #f3f7fb;
  --bg-grad-1: #dbe7ff;
  --bg-grad-2: #ffebd1;
  --ink: #112132;
  --muted: #5d6f7f;
  --panel: rgba(255, 255, 255, 0.88);
  --line: #d8e3ec;
  --card-bg: #ffffff;
  --code-bg: #f6f9fc;
  --field-bg: #ffffff;
  --btn-bg: #ffffff;
  --btn-border: #b8cadb;
  --btn-hover-shadow: rgba(10, 24, 40, 0.12);
  --chart-line: #1b79ff;
  --chart-grid: rgba(83, 112, 140, 0.25);
  --ok: #0f8a5f;
  --warn: #b97817;
  --bad: #be3a2c;
  --accent: #005fcc;
  --accent-soft: #d8e8ff;
  --shadow: 0 18px 40px rgba(11, 28, 45, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Space Grotesk", "IBM Plex Sans", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 5% 10%, var(--bg-grad-1) 0, transparent 40%),
    radial-gradient(circle at 90% 0, var(--bg-grad-2) 0, transparent 35%),
    var(--bg);
  transition: background-color 200ms ease, color 200ms ease;
}

body.theme-dark {
  --bg: #0b1322;
  --bg-grad-1: #17355e;
  --bg-grad-2: #2a1d42;
  --ink: #d8e5f6;
  --muted: #8ea5bf;
  --panel: rgba(15, 27, 43, 0.92);
  --line: #29415c;
  --card-bg: #102236;
  --code-bg: #0b1a2b;
  --field-bg: #0d2136;
  --btn-bg: #10263d;
  --btn-border: #37547a;
  --btn-hover-shadow: rgba(0, 0, 0, 0.35);
  --chart-line: #7ab4ff;
  --chart-grid: rgba(122, 180, 255, 0.25);
  --accent: #4d8fff;
  --accent-soft: #163663;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.45;
  background-image: linear-gradient(to right, rgba(9, 32, 53, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(9, 32, 53, 0.05) 1px, transparent 1px);
  background-size: 36px 36px;
}

.page {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 16px;
}

.page > * {
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  animation: reveal 420ms ease;
}

.navbar {
  display: grid;
  gap: 12px;
  position: sticky;
  top: 10px;
  z-index: 30;
  backdrop-filter: blur(10px);
}

.navbar-title {
  display: grid;
  gap: 2px;
}

.navbar-title h1 {
  margin: 4px 0 0;
  font-size: 24px;
}

.nav-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 92ch;
  font-size: 13px;
}

.navbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.nav-update {
  margin: 0;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.08em;
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
}

h1,
h2 {
  margin: 8px 0;
}

.token-input {
  display: grid;
  gap: 6px;
  min-width: 240px;
}

.token-input span,
.muted {
  font-size: 12px;
  color: var(--muted);
}

.cards {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.card {
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 12px;
  background: var(--card-bg);
}

.card p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.tone-ok {
  border-left: 5px solid var(--ok);
}

.tone-warn {
  border-left: 5px solid var(--warn);
}

.tone-bad {
  border-left: 5px solid var(--bad);
}

.tone-accent {
  border-left: 5px solid var(--accent);
  background: linear-gradient(to bottom, var(--accent-soft), var(--card-bg));
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-2 > * {
  min-width: 0;
}

.key-value {
  display: grid;
  gap: 8px;
  margin: 8px 0 10px;
}

.key-value div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 6px;
}

.key-value span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.code-block {
  margin: 0;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
}

.code-block.tall {
  max-height: 360px;
}

.form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 10px;
}

.form-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 9px;
  min-height: 40px;
  background: var(--field-bg);
  color: var(--ink);
}

.btn {
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--ink);
  padding: 10px 12px;
  cursor: pointer;
  transition: all 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--btn-hover-shadow);
}

.btn-accent {
  background: linear-gradient(135deg, #0a6bda, #005fcc);
  border-color: #0050ac;
  color: #fff;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.market-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.market-head {
  align-items: end;
}

.positions-head {
  align-items: end;
}

.positions-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.market-field {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 124px;
  text-transform: none;
  letter-spacing: 0;
}

.market-field select {
  min-width: 118px;
}

.market-controls .btn,
.positions-controls .btn {
  min-height: 40px;
}

.market-ticker {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  margin-bottom: 12px;
}

.price-chart {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 8px;
  font-size: 12px;
}

.pnl-up {
  color: var(--ok);
  font-weight: 700;
}

.pnl-down {
  color: var(--bad);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .form-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .page {
    padding: 12px;
  }

  .navbar {
    top: 0;
  }

  .navbar-actions {
    align-items: stretch;
  }

  .token-input {
    min-width: 0;
    width: 100%;
  }

  .market-controls {
    width: 100%;
  }

  .positions-controls {
    width: 100%;
  }

  .market-field {
    min-width: 0;
    flex: 1 1 140px;
  }

  .market-controls .btn,
  .positions-controls .btn {
    flex: 1 1 120px;
  }

  .grid-2,
  .form-grid,
  .form-grid.compact {
    grid-template-columns: 1fr;
  }

  .market-ticker {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}
