:root {
  --bg: #0b1220;
  --panel: #111826;
  --line: #1f2a3d;
  --text: #d9e2f2;
  --muted: #8da2c0;
  --accent: #2d7ff9;
  --green: #abb2c0;
  --red: #1a7a94;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body.loading-active {
  cursor: progress;
}

.page-loader {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 18%, rgba(45, 127, 249, 0.24), transparent 34%),
    radial-gradient(circle at 80% 80%, rgba(73, 148, 236, 0.14), transparent 28%),
    linear-gradient(135deg, rgba(4, 12, 24, 0.98) 0%, rgba(10, 18, 32, 0.98) 46%, rgba(17, 24, 38, 0.98) 100%);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

.page-loader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.page-loader-card {
  position: relative;
  width: min(420px, 100%);
  display: grid;
  gap: 20px;
  justify-items: center;
  padding: 36px 28px 28px;
  border: 1px solid rgba(116, 149, 201, 0.18);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(13, 22, 37, 0.94) 0%, rgba(9, 16, 28, 0.92) 100%);
  box-shadow: 0 28px 72px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(18px);
}

.page-loader-logo-shell {
  position: relative;
  width: 108px;
  height: 108px;
  display: grid;
  place-items: center;
  border-radius: 30px;
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.28) 0%, rgba(15, 23, 36, 0.72) 100%);
  box-shadow: 0 18px 40px rgba(14, 65, 171, 0.34);
}

.page-loader-logo-shell::before {
  content: '';
  position: absolute;
  inset: -14px;
  border: 1px solid rgba(59, 130, 246, 0.28);
  border-radius: 40px;
  animation: loaderPulse 1.9s ease-in-out infinite;
}

.page-loader-logo {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  object-fit: cover;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
}

.page-loader-copy {
  display: grid;
  gap: 8px;
  text-align: center;
}

.page-loader-kicker {
  color: #7eb2ff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.page-loader-title {
  margin: 0;
  color: #eef4ff;
  font-size: clamp(28px, 4vw, 34px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.page-loader-text {
  margin: 0;
  color: #93a7c6;
  font-size: 14px;
  line-height: 1.5;
}

.page-loader-line {
  position: relative;
  width: min(250px, 100%);
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(116, 149, 201, 0.14);
}

.page-loader-line::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 42%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0) 0%, rgba(59, 130, 246, 0.78) 42%, rgba(147, 197, 253, 1) 100%);
  animation: loaderSlide 1.2s ease-in-out infinite;
}

@keyframes loaderPulse {
  0%,
  100% {
    opacity: 0.4;
    transform: scale(0.96);
  }

  50% {
    opacity: 1;
    transform: scale(1.02);
  }
}

@keyframes loaderSlide {
  0% {
    transform: translateX(-130%);
  }

  100% {
    transform: translateX(300%);
  }
}

.topbar {
  min-height: 56px;
  height: auto;
  background: #0f1724;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 8px 12px 10px;
  gap: 8px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  order: 1;
  min-height: 36px;
}

.brand-logo {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  object-fit: cover;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px 10px;
  flex-wrap: wrap;
  flex: 1 1 100%;
  width: 100%;
  min-width: 0;
  order: 3;
}

.controls-cipher {
  align-items: center;
}

.page-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px;
  border: 1px solid #253149;
  border-radius: 10px;
  background: #101926;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.nav-link.active {
  background: var(--accent);
  color: #fff;
}

.promo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid #3b82f6;
  background: linear-gradient(180deg, #3b82f6 0%, #1d4ed8 100%);
  color: #fff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}

.promo-btn:visited {
  color: #fff;
}

.promo-btn:hover {
  filter: brightness(1.05);
}

.select-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.interval-select {
  min-width: 76px;
  font-weight: 700;
}

.cipher-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  user-select: none;
}

.cipher-toggle input {
  width: 16px;
  height: 16px;
  accent-color: #2d7ff9;
}

button,
input[type='date'],
select {
  background: #182235;
  border: 1px solid #253149;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
}

.symbol-select {
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  min-width: 60px;
}

.replay-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 2px;
  border: 1px solid #253149;
  border-radius: 10px;
  background: #101926;
}

.replay-controls.hidden {
  display: none;
}

button.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

#btn-step-back,
#btn-run-toggle,
#btn-step-forward {
  min-width: 40px;
  padding: 7px 8px;
  font-weight: 700;
}

.status {
  color: var(--muted);
  font-size: 12px;
  flex: 0 1 auto;
  width: auto;
  margin-left: auto;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  order: 2;
  min-height: 36px;
  display: flex;
  align-items: center;
}

.help-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  padding: 0;
  font-weight: 700;
  line-height: 1;
  margin-left: auto;
}

.layout {
  height: calc(100vh - var(--topbar-h, 56px));
  display: grid;
  grid-template-rows: 58% 21% 21%;
  position: relative;
}

.layout.cipher-wt-visible {
  grid-template-rows: 44% 18% 18% 20%;
}

.pane-cipher-wt {
  background: #131722;
  position: relative;
}

.pane-cipher-wt.hidden {
  display: none;
}

.layout-cipher {
  grid-template-rows: 58% 42%;
}

.cipher-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #131722;
}

.pane-cipher-price {
  background: #131722;
}

.pane-cipher {
  border-bottom: none;
}

.pane-cipher-main {
  width: 100%;
  height: 100%;
  border-bottom: none;
  background: #131722;
}

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

.cipher-legend {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  max-width: calc(100% - 24px);
  font-size: 12px;
  line-height: 1.2;
  color: #d9e2f2;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.cipher-legend-title {
  color: #d9e2f2;
  font-weight: 700;
}

.cipher-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #aeb9cf;
}

.cipher-legend-item strong {
  font-weight: 700;
}

.pane {
  border-bottom: 1px solid #1b2639;
  position: relative;
  touch-action: none;
}

.pane-watermark {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 28px;
  height: 28px;
  z-index: 4;
  pointer-events: none;
  object-fit: cover;
  border-radius: 8px;
  opacity: 0.95;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14), 0 6px 16px rgba(0, 0, 0, 0.32);
}

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

.trade-overlay.editing {
  pointer-events: auto;
}

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

/* ── Heatmap hover tooltip ── */
.heatmap-tooltip {
  position: absolute;
  z-index: 25;
  pointer-events: none;
  background: rgba(10, 14, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 4px 2px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  color: #c8cdd4;
  white-space: nowrap;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.heatmap-tooltip table {
  border-collapse: collapse;
  border-spacing: 0;
}

.heatmap-tooltip td {
  padding: 2px 8px;
  text-align: right;
}

.heatmap-tooltip .hm-vol { color: #c8cdd4; }
.heatmap-tooltip .hm-cur { font-weight: 600; }
.heatmap-tooltip .hm-price { color: #8a8f9a; font-size: 10px; }
.heatmap-tooltip .hm-zero span { color: #3a3e47; }

/* Row where cursor is positioned */
.heatmap-tooltip tr.hm-cursor {
  background: rgba(80, 180, 220, 0.14);
}
.heatmap-tooltip tr.hm-cursor .hm-price { color: #d0d0d0; }

/* High-volume rows */
.heatmap-tooltip tr.hm-hot {
  background: rgba(200, 200, 50, 0.12);
}
.heatmap-tooltip tr.hm-hot .hm-vol   { color: #e8e850; }
.heatmap-tooltip tr.hm-hot .hm-cur   { color: #e8e850; font-size: 13px; }
.heatmap-tooltip tr.hm-hot .hm-price { color: #d0d0d0; }

/* Very high-volume rows */
.heatmap-tooltip tr.hm-mega {
  background: rgba(255, 230, 50, 0.22);
}
.heatmap-tooltip tr.hm-mega .hm-vol   { color: #fff840; }
.heatmap-tooltip tr.hm-mega .hm-cur   { color: #fff840; font-size: 14px; font-weight: 700; }
.heatmap-tooltip tr.hm-mega .hm-price { color: #f0f0e0; font-weight: 600; }

/* Cursor + hot/mega combined */
.heatmap-tooltip tr.hm-cursor.hm-hot {
  background: rgba(200, 200, 50, 0.20);
}
.heatmap-tooltip tr.hm-cursor.hm-mega {
  background: rgba(255, 230, 50, 0.32);
}

.prompt {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 40;
}

.prompt.hidden {
  display: none;
}

.prompt-card {
  background: rgba(8, 14, 24, 0.95);
  border: 1px solid #2a3956;
  border-radius: 12px;
  padding: 12px;
  width: 280px;
}

.prompt-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.prompt-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.prompt-actions {
  display: flex;
  gap: 8px;
}

.about-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(3, 7, 13, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.about-overlay.hidden {
  display: none;
}

.about-card {
  width: min(620px, 100%);
  background: rgba(8, 14, 24, 0.98);
  border: 1px solid #2a3956;
  border-radius: 12px;
  padding: 16px;
}

.about-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.about-card p {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.5;
}

.about-actions {
  display: flex;
  justify-content: flex-end;
}

.tf-group {
  display: flex;
  gap: 2px;
  background: #111826;
  border-radius: 8px;
  border: 1px solid #253149;
  padding: 2px;
  margin: 0 4px;
}

.tf-btn {
  border: none !important;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  min-width: 36px;
}

.tf-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: none;
  border-color: transparent !important;
}

.config-toggle-btn {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.config-toggle-btn:not(.active) {
  opacity: 0.72;
}

.signal-config-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1 1 100%;
  order: 30;
  padding: 4px 8px;
  border: 1px solid #253149;
  border-radius: 10px;
  background: #101926;
}

.signal-config-controls.hidden {
  display: none;
}

.config-checkbox-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #d1d4dc;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.config-checkbox-label input[type="checkbox"] {
  accent-color: #2962ff;
  cursor: pointer;
}

.signal-config-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.signal-config-inner.hidden {
  display: none;
}

.signal-slider-control,
.signal-select-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.signal-slider-control {
  margin-left: auto;
}

#btn-long,
#btn-short {
  min-width: 68px;
}

.signal-control-label,
.signal-control-value {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.signal-control-value {
  min-width: 38px;
  text-align: right;
}

.signal-range {
  width: 132px;
  accent-color: #7ee0dd;
}

.signal-control-select-input {
  min-width: 58px;
  font-weight: 600;
}

/* ─── Mobile Responsive ─── */
@media (max-width: 768px) {
  .topbar {
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 6px;
  }

  .brand {
    font-size: 13px;
    gap: 5px;
    order: 0;
  }

  .brand-logo {
    width: 20px;
    height: 20px;
  }

  .promo-btn {
    width: 100%;
  }

  .pane-watermark {
    left: 8px;
    bottom: 8px;
    width: 24px;
    height: 24px;
    border-radius: 7px;
  }

  .help-btn {
    order: 1;
    margin-left: auto;
  }

  .status {
    order: 2;
    flex: 1 1 100%;
    text-align: center;
    font-size: 11px;
    padding: 2px 0;
    width: auto;
  }

  .controls {
    order: 3;
    flex: 1 1 100%;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
  }

  .controls button,
  .controls input[type='date'],
  .controls select {
    padding: 6px 7px;
    font-size: 11px;
    min-height: 34px;
  }

  .replay-controls {
    flex: 1 1 100%;
    justify-content: center;
    gap: 4px;
    order: 10;
  }

  #btn-step-back,
  #btn-run-toggle,
  #btn-step-forward {
    min-width: 34px;
    padding: 6px 6px;
  }

  .tf-group {
    margin: 0 2px;
  }

  .page-nav {
    order: 1;
  }

  .nav-link {
    min-width: 56px;
    min-height: 32px;
    padding: 6px 10px;
    font-size: 11px;
  }

  .select-label {
    font-size: 11px;
  }

  .interval-select {
    min-width: 68px;
  }

  .cipher-toggle {
    font-size: 11px;
  }

  .tf-btn {
    padding: 4px 10px;
    font-size: 11px;
    min-width: 30px;
  }

  .config-toggle-btn {
    font-size: 11px;
    padding: 6px 8px;
  }

  .signal-config-controls {
    justify-content: center;
    width: 100%;
  }

  .signal-slider-control,
  .signal-select-control {
    min-height: 30px;
  }

  .signal-control-label,
  .signal-control-value {
    font-size: 11px;
  }

  .signal-range {
    width: 110px;
  }

  input[type='date'] {
    max-width: 120px;
  }

  .layout {
    height: calc(100vh - var(--topbar-h, 100px));
    grid-template-rows: 60% 20% 20%;
  }

  .layout.cipher-wt-visible {
    grid-template-rows: 42% 18% 18% 22%;
  }

  .layout-cipher {
    grid-template-rows: 55% 45%;
  }

  .cipher-legend {
    top: 8px;
    left: 8px;
    gap: 6px 8px;
    font-size: 11px;
    max-width: calc(100% - 16px);
  }

  .prompt-card {
    width: 240px;
    padding: 10px;
  }

  .prompt-card h3 {
    font-size: 13px;
  }

  .prompt-card p {
    font-size: 11px;
  }

  .about-card {
    padding: 14px;
  }

  .about-card h3 {
    font-size: 14px;
  }

  .about-card p {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .controls {
    gap: 3px;
  }

  .controls button,
  .controls input[type='date'],
  .controls select {
    padding: 5px 5px;
    font-size: 10px;
    min-height: 30px;
  }

  .replay-controls {
    gap: 3px;
  }

  #btn-step-back,
  #btn-run-toggle,
  #btn-step-forward {
    min-width: 30px;
    font-size: 13px;
  }

  .tf-btn {
    padding: 3px 8px;
    font-size: 10px;
  }

  .nav-link {
    min-width: 50px;
    min-height: 30px;
    padding: 5px 8px;
    font-size: 10px;
  }

  .interval-select {
    min-width: 62px;
  }

  .cipher-toggle {
    font-size: 10px;
    gap: 4px;
  }

  .cipher-legend {
    font-size: 10px;
  }

  .config-toggle-btn {
    font-size: 10px;
    padding: 5px 6px;
  }

  .signal-config-controls {
    gap: 6px;
    padding: 4px 6px;
  }

  .signal-control-label,
  .signal-control-value {
    font-size: 10px;
  }

  .signal-range {
    width: 86px;
  }

  .signal-control-select-input {
    min-width: 52px;
  }

  input[type='date'] {
    max-width: 105px;
    font-size: 10px;
  }

  .brand span {
    display: none;
  }
}

/* ── Delete trade button ── */
.btn-delete-trade {
  display: block;
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(220, 38, 38, 0.92);
  color: #fff;
  border: 1px solid rgba(255, 80, 80, 0.7);
  border-radius: 10px;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  -webkit-tap-highlight-color: transparent;
}

.btn-delete-trade.hidden {
  display: none;
}
