:root {
  --bg: #08080c;
  --surface: #111118;
  --surface-2: #1a1a24;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f4f6;
  --muted: #8b8b9a;
  --accent: #7c6cf0;
  --positive: #3dd68c;
  --negative: #f87171;
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --font-display: "Instrument Serif", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.header {
  margin-bottom: 2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c6cf0, #3dd68c);
  box-shadow: 0 0 12px rgba(124, 108, 240, 0.6);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.header-desc {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.field span {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
}

.field input:focus {
  outline: none;
  border-color: rgba(124, 108, 240, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 108, 240, 0.15);
}

.btn {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: none;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, #6d5ce7, #5b8def);
  color: white;
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  margin-top: 0.5rem;
}

.status {
  min-height: 1.25rem;
  margin: 0.75rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.status.error {
  color: var(--negative);
}

.status.ok {
  color: var(--positive);
}

.hidden {
  display: none !important;
}

.position-list {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

#positions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: min(70vh, 560px);
  overflow-y: auto;
}

.pos-item {
  width: 100%;
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  transition: border-color 0.15s, background 0.15s;
}

.pos-item:hover {
  border-color: rgba(124, 108, 240, 0.35);
}

.pos-item.active {
  border-color: var(--accent);
  background: rgba(124, 108, 240, 0.1);
}

.pos-item-summary {
  border-color: rgba(61, 214, 140, 0.25);
  background: rgba(61, 214, 140, 0.06);
}

.pos-item-summary:hover {
  border-color: rgba(61, 214, 140, 0.45);
}

.pos-item-summary.active {
  border-color: var(--positive);
  background: rgba(61, 214, 140, 0.12);
}

.pos-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.88rem;
}

.pos-item-pnl {
  font-size: 0.8rem;
  font-weight: 600;
}

.pos-item-pnl.positive { color: var(--positive); }
.pos-item-pnl.negative { color: var(--negative); }

.pos-item-meta {
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.card-controls .card-toolbar {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.card-preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

.copy-bar {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s, color 0.15s, opacity 0.15s;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(124, 108, 240, 0.45);
}

.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn.is-copying {
  color: var(--accent);
  border-color: rgba(124, 108, 240, 0.45);
}

.card-toolbar {
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem 1rem;
}

.toolbar-block {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.toolbar-block-bg {
  flex: 1;
  min-width: 0;
}

.toolbar-label {
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chip {
  padding: 0.32rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
  transition: border-color 0.15s, background 0.15s;
}

.chip:hover:not(:disabled) {
  border-color: rgba(124, 108, 240, 0.4);
}

.chip.active {
  border-color: var(--accent);
  background: rgba(124, 108, 240, 0.14);
}

.chip-swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chip-upload {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.swatch-mini {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  display: block;
}

.swatch-mini.bg-aurora {
  background: linear-gradient(135deg, #1a1035, #2d1b4e, #1e3a5f);
}

.swatch-mini.bg-emerald {
  background: linear-gradient(135deg, #0a1f1a, #134e3a, #0c1222);
}

.swatch-mini.bg-sunset {
  background: linear-gradient(135deg, #2d1515, #5c2e1a, #1a1028);
}

.eth-rate-note {
  margin: 0.5rem 0 0;
  font-size: 0.68rem;
  color: var(--muted);
}

.bg-opt:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.preview {
  min-height: 420px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, rgba(124, 108, 240, 0.06), transparent 60%);
}

.preview-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  padding: 0.5rem 0 1rem;
}

.card-controls {
  width: 100%;
  max-width: 720px;
}

.detail-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 1rem;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.detail-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.detail-value {
  font-size: 0.9rem;
  font-weight: 600;
}

.hide-toggle {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.84rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.hide-toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.empty-preview {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

.empty-icon {
  font-size: 2.5rem;
  opacity: 0.35;
  margin-bottom: 0.75rem;
}

.card-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.pnl-card.hide-stats-on-card .card-stats {
  display: none !important;
}

.pnl-card.hide-stats-on-card.card-mode-position .card-id {
  display: none !important;
}

.pnl-card {
  position: relative;
  width: 100%;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  transition: max-width 0.2s ease;
}

.pnl-card.ratio-portrait {
  max-width: 400px;
  aspect-ratio: 4 / 5;
}

.pnl-card.ratio-landscape {
  max-width: 720px;
  aspect-ratio: 16 / 9;
}

.card-noise {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.pnl-card.bg-aurora {
  background: linear-gradient(145deg, #1a1035 0%, #2d1b4e 35%, #1e3a5f 70%, #0f172a 100%);
}

.pnl-card.bg-emerald {
  background: linear-gradient(145deg, #0a1f1a 0%, #134e3a 40%, #1e4d3b 65%, #0c1222 100%);
}

.pnl-card.bg-sunset {
  background: linear-gradient(145deg, #2d1515 0%, #5c2e1a 35%, #4a2c4a 65%, #1a1028 100%);
}

.pnl-card.bg-custom {
  background-color: #0f172a;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.pnl-card.has-custom-bg .card-overlay {
  background: linear-gradient(180deg, rgba(8, 8, 12, 0.25) 0%, rgba(8, 8, 12, 0.62) 100%);
}

.card-overlay {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.swatch.bg-custom-swatch {
  background: linear-gradient(135deg, #1a1a24, #2a2a38);
  background-size: cover;
  background-position: center;
}

.custom-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.55rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.custom-upload:hover {
  border-color: rgba(124, 108, 240, 0.45);
  color: var(--text);
}

.bg-opt:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.card-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  padding: 1.75rem 1.6rem;
  display: flex;
  flex-direction: column;
}

.card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card-top {
  position: relative;
  flex-shrink: 0;
  min-height: 3.25rem;
  margin-bottom: 0.15rem;
}

.card-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: 17px;
  width: auto;
  filter: brightness(0) invert(1);
  opacity: 0.92;
  pointer-events: none;
}

.card-protocol {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 0.68rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
}

.card-pair {
  margin: 0 0 0.15rem;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-align: left;
}

.card-id {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.45);
  text-align: left;
}

.card-pnl {
  margin: auto 0 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  text-align: left;
}

.card-pnl span:first-child {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.card-pnl-pct {
  font-size: 1.1rem;
  font-weight: 600;
  opacity: 0.85;
}

.card-pnl.positive span { color: #6ee7b7; }
.card-pnl.negative span { color: #fca5a5; }

.card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.65rem;
  padding: 1rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: rgba(255, 255, 255, 0.45);
}

.stat-value {
  font-size: 0.88rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
}

.card-footer {
  margin-top: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.75rem;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.4);
}

.card-brand {
  color: rgba(255, 255, 255, 0.55);
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

#card-dates {
  text-align: right;
}

.pnl-card.ratio-landscape .card-inner {
  padding: 1.35rem 1.75rem;
}

.pnl-card.ratio-landscape .card-content {
  display: grid;
  grid-template-columns: 1fr minmax(148px, 0.72fr);
  grid-template-areas:
    "top top"
    "pair stats"
    "id stats"
    "pnl stats";
  column-gap: 2rem;
  row-gap: 0.15rem;
  align-content: center;
  flex: 1;
}

.pnl-card.ratio-landscape .card-top {
  grid-area: top;
  min-height: 2.75rem;
  margin-bottom: 0.35rem;
}

.pnl-card.ratio-landscape .card-logo {
  height: 18px;
  top: 20%;
  transform: translate(-50%, -50%);
}

.pnl-card.ratio-landscape .card-pair {
  grid-area: pair;
  justify-self: start;
  text-align: left;
  margin: 0;
  font-size: 2.85rem;
  line-height: 1.05;
}

.pnl-card.ratio-landscape .card-id {
  grid-area: id;
  justify-self: start;
  text-align: left;
  margin: 0;
  font-size: 0.82rem;
}

.pnl-card.ratio-landscape .card-pnl {
  grid-area: pnl;
  justify-self: start;
  text-align: left;
  align-items: flex-start;
  margin: 0.55rem 0 0;
}

.pnl-card.ratio-landscape .card-pnl span:first-child {
  font-size: 3.5rem;
}

.pnl-card.ratio-landscape .card-pnl-pct {
  font-size: 1.35rem;
}

.pnl-card.ratio-landscape .card-stats {
  grid-area: stats;
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.85rem 0 0.85rem 1.25rem;
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
}

.pnl-card.ratio-landscape .card-stats .stat-value {
  font-size: 0.95rem;
}

.pnl-card.ratio-landscape .card-footer {
  margin-top: 0.75rem;
}

.pnl-card.card-mode-summary .card-pair {
  font-size: 1.85rem;
}

.pnl-card.card-mode-summary .card-pnl span:first-child {
  font-size: 2.85rem;
}

.pnl-card.card-mode-summary.ratio-landscape .card-pair {
  font-size: 2.5rem;
}

.pnl-card.card-mode-summary.ratio-landscape .card-pnl span:first-child {
  font-size: 3.25rem;
}

.pnl-card.ratio-landscape.hide-stats-on-card .card-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.pnl-card.ratio-landscape.hide-stats-on-card .card-top {
  flex-shrink: 0;
  min-height: 4.25rem;
  margin-top: 40px;
  margin-bottom: 0;
  padding-bottom: 0.85rem;
}

.pnl-card.ratio-landscape.hide-stats-on-card .card-logo {
  top: 18%;
}

.pnl-card.ratio-landscape.hide-stats-on-card .card-pair {
  margin-top: auto;
  margin-bottom: 0.35rem;
  align-self: flex-start;
  text-align: left;
  width: auto;
  transform: translateY(-30px);
}

.pnl-card.ratio-landscape.hide-stats-on-card .card-pnl {
  margin-bottom: auto;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  justify-content: flex-start;
  min-height: 0;
  transform: translateY(-30px);
}

.pnl-card.ratio-portrait.hide-stats-on-card .card-content {
  flex: 1;
  min-height: 0;
}

.pnl-card.ratio-portrait.hide-stats-on-card .card-pnl {
  margin: 0;
  flex: 1;
  justify-content: center;
}