:root {
  --bg: #0b0d10;
  --bg-2: #101419;
  --panel: #151a20;
  --panel-2: #1a2027;
  --border: #2b3440;
  --border-strong: #3d4855;
  --text: #eef3f8;
  --muted: #9aa7b4;
  --faint: #657282;
  --amber: #f59e0b;
  --cyan: #22d3ee;
  --green: #22c55e;
  --red: #ef4444;
  --purple: #8b5cf6;
  --focus: #fbbf24;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at 18% -10%, rgba(34, 211, 238, 0.13), transparent 30rem),
    linear-gradient(135deg, #0b0d10 0%, #101419 50%, #120f13 100%);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
label:has(input:focus-visible) span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.icons {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid rgba(61, 72, 85, 0.72);
  background: rgba(11, 13, 16, 0.9);
  backdrop-filter: blur(16px);
}

.brand,
.top-actions,
.panel-head,
.range-row,
.input-row {
  display: flex;
  align-items: center;
}

.brand {
  min-width: 0;
  gap: 0.85rem;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(245, 158, 11, 0.42);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(34, 211, 238, 0.12));
}

.brand-mark svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.brand h1,
.panel h2 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(1.05rem, 2vw, 1.35rem);
}

.eyebrow {
  display: block;
  color: var(--amber);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
}

.icon-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.58rem 0.85rem;
  color: var(--text);
  background: var(--panel-2);
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease;
}

.icon-button:hover {
  border-color: var(--border-strong);
  background: #202832;
}

.icon-button.primary {
  border-color: rgba(245, 158, 11, 0.7);
  background: #f59e0b;
  color: #17110a;
  font-weight: 800;
}

.icon-button.primary:hover {
  background: #fbbf24;
}

.icon-button.positive {
  border-color: rgba(34, 197, 94, 0.5);
  color: #bbf7d0;
}

.icon-button.danger {
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
}

.icon-button.secondary {
  border-color: var(--border);
}

.status-chip {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.status-chip::before {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--faint);
  content: "";
}

.status-online {
  border-color: rgba(34, 197, 94, 0.42);
  color: #bbf7d0;
}

.status-online::before {
  background: var(--green);
}

.status-offline {
  border-color: rgba(239, 68, 68, 0.36);
  color: #fecaca;
}

.status-offline::before {
  background: var(--red);
}

.shell {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 1.1rem clamp(1rem, 3vw, 2rem) 2rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.85rem;
}

.metric,
.panel {
  border: 1px solid rgba(61, 72, 85, 0.78);
  border-radius: 8px;
  background: rgba(21, 26, 32, 0.9);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 118px;
  padding: 1rem;
}

.metric.accent {
  border-color: rgba(245, 158, 11, 0.5);
  background:
    linear-gradient(135deg, rgba(245, 158, 11, 0.14), transparent),
    rgba(21, 26, 32, 0.92);
}

.metric-label,
.metric-note,
.panel-meta {
  color: var(--muted);
}

.metric-label,
.metric-note {
  display: block;
  font-size: 0.85rem;
}

.metric strong {
  display: block;
  min-height: 2.4rem;
  margin: 0.35rem 0 0.1rem;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1.15;
  letter-spacing: 0;
}

.positive-text {
  color: #86efac;
}

.negative-text {
  color: #fca5a5;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(350px, 0.85fr);
  gap: 1rem;
  margin-top: 1rem;
}

.layout.lower {
  grid-template-columns: minmax(0, 1fr) minmax(420px, 0.7fr);
}

.panel {
  min-width: 0;
  padding: 1rem;
}

.panel-head {
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.panel h2 {
  margin-top: 0.15rem;
  font-size: 1.05rem;
}

.panel-meta {
  font-size: 0.85rem;
  text-align: right;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.chart-panel {
  margin-top: 1rem;
}

.chart-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
}

select {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 2rem 0.55rem 0.7rem;
  color: var(--text);
  background: #0e1217;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid rgba(43, 52, 64, 0.75);
  border-radius: 8px;
  background: #080a0d;
}

#klineCanvas {
  display: block;
  width: 100%;
  height: 420px;
}

.chart-legend {
  display: flex;
  min-height: 30px;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.65rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.legend-dot {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot::before {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid rgba(43, 52, 64, 0.75);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  padding: 0.72rem 0.75rem;
  border-bottom: 1px solid rgba(43, 52, 64, 0.65);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(26, 32, 39, 0.94);
}

td {
  color: var(--text);
  font-size: 0.92rem;
}

tr:last-child td {
  border-bottom: 0;
}

.empty {
  color: var(--faint);
  text-align: center;
}

.badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge.long,
.badge.open,
.badge.buy {
  border-color: rgba(34, 197, 94, 0.38);
  color: #bbf7d0;
}

.badge.short,
.badge.close,
.badge.sell {
  border-color: rgba(239, 68, 68, 0.38);
  color: #fecaca;
}

.badge.hold {
  border-color: rgba(154, 167, 180, 0.38);
  color: #d1d9e2;
}

.config-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.field,
.segmented {
  min-width: 0;
}

.span-2 {
  grid-column: span 2;
}

label,
legend {
  display: block;
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

input[type="number"],
input[type="text"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  background: #0e1217;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--amber);
}

.range-row {
  gap: 0.6rem;
}

.range-row input[type="number"] {
  width: 94px;
  flex: 0 0 auto;
}

.input-row {
  gap: 0.45rem;
}

.unit {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0;
  border: 0;
  padding: 0;
}

.segmented legend {
  grid-column: span 2;
}

.segmented label {
  margin: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #0e1217;
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease;
}

.segmented input:checked + span {
  border-color: rgba(245, 158, 11, 0.72);
  color: #ffe8b4;
  background: rgba(245, 158, 11, 0.14);
}

.log-panel {
  margin-top: 1rem;
}

.learning-panel {
  margin-top: 1rem;
}

pre {
  min-height: 120px;
  max-height: 260px;
  margin: 0;
  overflow: auto;
  border: 1px solid rgba(43, 52, 64, 0.75);
  border-radius: 8px;
  padding: 0.85rem;
  color: #cbd5e1;
  background: #080a0d;
  font-family: "Cascadia Code", Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
  line-height: 1.6;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  max-width: min(420px, calc(100vw - 2rem));
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  color: var(--text);
  background: #111820;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .layout,
  .layout.lower {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .config-form {
    grid-template-columns: 1fr;
  }

  .span-2,
  .segmented legend {
    grid-column: span 1;
  }

  .segmented {
    grid-template-columns: 1fr 1fr;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .icon-button {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
