/* ==========================================================================
   AI Quant Strategy Lab — Backtest Simulator
   Trading terminal dark theme · mobile-first H5 · zero dependencies
   ========================================================================== */

:root {
  /* Terminal palette (locked by spec) */
  --bg: #131722;
  --panel: #1E222D;
  --panel-deep: #181C26;
  --border: #2A2E39;
  --text: #D6D9E0;
  --text-strong: #FFFFFF;
  --muted: #787B86;
  --muted-2: #9AA0AC;
  --green: #089981;
  --green-text: #3ECFA6;
  --green-soft: rgba(8, 153, 129, 0.12);
  --red: #F23645;
  --red-text: #FF5C6A;
  --amber: #E8A33D;
  --radius: 12px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, "Roboto Mono", "Courier New", monospace;
}

/* --------------------------------------------------------------------------
   Reset & base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  /* Deep-screen glow: same-hue green only, kept subtle */
  background:
    radial-gradient(1100px 480px at 50% -8%, rgba(8, 153, 129, 0.07), transparent 62%),
    radial-gradient(820px 400px at 88% 108%, rgba(8, 153, 129, 0.045), transparent 58%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

::selection {
  background: rgba(8, 153, 129, 0.35);
  color: #fff;
}

/* App shell: locked single column, iOS safe areas */
.app {
  max-width: 440px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  display: block;
  filter: drop-shadow(0 0 6px rgba(8, 153, 129, 0.35));
}

.brand-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: 0.01em;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--green-text);
  background: var(--green-soft);
  border: 1px solid rgba(8, 153, 129, 0.35);
  border-radius: 999px;
  padding: 5px 10px;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: dotPulse 1.6s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Funnel stepper
   -------------------------------------------------------------------------- */
.stepper {
  display: flex;
  gap: 8px;
  list-style: none;
  margin-bottom: 20px;
}

.step-chip {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(30, 34, 45, 0.55);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
  transition: border-color 0.25s ease, background 0.25s ease, color 0.25s ease;
}

.chip-num {
  width: 16px;
  height: 16px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #262B38;
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.step-chip.is-active {
  border-color: rgba(8, 153, 129, 0.5);
  background: var(--green-soft);
  color: var(--text);
}

.step-chip.is-active .chip-num {
  background: var(--green);
  color: #fff;
  box-shadow: 0 0 10px rgba(8, 153, 129, 0.5);
}

.step-chip.is-done {
  color: var(--muted-2);
}

.step-chip.is-done .chip-num {
  background: rgba(8, 153, 129, 0.22);
  color: var(--green-text);
}

/* --------------------------------------------------------------------------
   Screens
   -------------------------------------------------------------------------- */
main {
  flex: 1;
}

.screen {
  display: none;
  padding-bottom: 26px;
}

.screen.is-active {
  display: block;
  animation: screenIn 450ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* --------------------------------------------------------------------------
   Step 1 · Configuration
   -------------------------------------------------------------------------- */
.hero-title {
  font-size: 25px;
  line-height: 1.22;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}

.hero-sub {
  margin-top: 10px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted-2);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.config-card {
  margin-top: 20px;
}

.field + .field {
  margin-top: 18px;
}

.field-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 9px;
}

.seg {
  display: flex;
  gap: 8px;
}

.seg-btn {
  flex: 1;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 6px;
  background: var(--panel-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted-2);
  font-size: 13px;
  font-weight: 600;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

.seg-btn:active {
  transform: scale(0.97);
}

.seg-btn.is-selected {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-text);
  box-shadow: inset 0 0 0 1px rgba(8, 153, 129, 0.3), 0 0 14px rgba(8, 153, 129, 0.12);
}

.seg-col {
  flex-direction: column;
}

.seg-col .seg-btn {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  min-height: 52px;
  padding: 12px 14px;
  text-align: left;
}

.seg-main {
  font-size: 14px;
  font-weight: 700;
}

.seg-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  transition: color 0.18s ease;
}

.seg-btn.is-selected .seg-sub {
  color: rgba(62, 207, 166, 0.75);
}

.seg-check {
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.18s ease, transform 0.18s ease;
  color: var(--green-text);
  font-size: 13px;
  line-height: 1;
}

.seg-btn.is-selected .seg-check {
  opacity: 1;
  transform: scale(1);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn-primary {
  width: 100%;
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 54px;
  background: var(--green);
  color: #fff;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.05em;
  box-shadow: 0 10px 26px rgba(8, 153, 129, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn-primary:active {
  transform: translateY(1px) scale(0.985);
  box-shadow: 0 6px 16px rgba(8, 153, 129, 0.24);
}

.btn-pulse {
  animation: ctaPulse 1.9s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}

.btn-ghost {
  width: 100%;
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted-2);
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.btn-ghost:active {
  background: rgba(255, 255, 255, 0.04);
}

.micro-trust {
  margin-top: 14px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

#bt-count {
  color: var(--green-text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Step 2 · Live simulation
   -------------------------------------------------------------------------- */
.sim-head {
  margin-bottom: 16px;
}

.sim-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-strong);
}

.sim-ctx {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart-card {
  padding: 14px 14px 12px;
}

.chart-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chart-cap {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.progress-pct {
  font-size: 13px;
  font-weight: 800;
  color: var(--green-text);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: #10141D;
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  position: relative;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #06786A, #089981);
  border-radius: 999px;
  overflow: hidden;
  will-change: width;
}

.progress-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.5s linear infinite;
}

.sim-status {
  margin-top: 9px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.caret {
  color: var(--green-text);
  animation: blink 1s steps(2, start) infinite;
}

#chart {
  display: block;
  width: 100%;
  height: 236px;
  margin-top: 8px;
}

.chart-legend {
  display: flex;
  gap: 14px;
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--muted);
}

.lg-buy {
  color: var(--green-text);
}

.lg-sell {
  color: var(--red-text);
}

.log-window {
  margin-top: 12px;
  height: 132px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.75;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 14px);
  mask-image: linear-gradient(180deg, transparent 0, #000 14px);
  scrollbar-width: none;
}

.log-window::-webkit-scrollbar {
  display: none;
}

.log-line {
  display: flex;
  gap: 8px;
  color: #8B93A3;
}

.log-time {
  flex: none;
  color: #5C6370;
  font-variant-numeric: tabular-nums;
}

.log-tag {
  flex: none;
  width: 40px;
  font-weight: 700;
}

.tag-info { color: #787B86; }
.tag-ok   { color: var(--green-text); }
.tag-risk { color: var(--amber); }
.tag-buy  { color: var(--green-text); }
.tag-sell { color: var(--red-text); }

.log-msg {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

/* --------------------------------------------------------------------------
   Step 3 · Quant report
   -------------------------------------------------------------------------- */
.report-head {
  margin-bottom: 16px;
}

.report-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--green-text);
}

.report-title {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}

.report-ctx {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.report-card {
  margin-top: 16px;
}

.metric-hero {
  text-align: center;
  padding: 4px 0 10px;
}

.metric-hero-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.metric-hero-value {
  margin-top: 6px;
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--green-text);
  text-shadow: 0 0 26px rgba(8, 153, 129, 0.4);
  font-variant-numeric: tabular-nums;
}

.metric-hero-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.equity {
  display: block;
  width: 100%;
  height: 56px;
  margin: 2px 0 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  background: var(--panel-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.metric-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.metric-value {
  margin-top: 6px;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.metric-value.is-win {
  color: var(--green-text);
  text-shadow: 0 0 16px rgba(8, 153, 129, 0.45);
}

.stat-strip {
  display: flex;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--panel-deep);
}

.stat {
  flex: 1;
  text-align: center;
  padding: 10px 4px 9px;
}

.stat + .stat {
  border-left: 1px solid var(--border);
}

.stat-k {
  display: block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-v {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.report-card .btn-primary {
  margin-top: 16px;
}

.report-card .btn-ghost {
  margin-top: 10px;
}

.disclaimer {
  margin-top: 14px;
  font-size: 11px;
  line-height: 1.65;
  color: #676D7A;
}

.footer {
  padding-top: 18px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 10.5px;
  color: #565C68;
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  max-width: calc(100vw - 36px);
  padding: 12px 18px;
  background: var(--panel);
  border: 1px solid rgba(8, 153, 129, 0.55);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 60;
}

.toast.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */
@keyframes screenIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dotPulse {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(8, 153, 129, 0.5);
  }
  50% {
    opacity: 0.7;
    box-shadow: 0 0 0 5px rgba(8, 153, 129, 0);
  }
}

@keyframes ctaPulse {
  0% {
    box-shadow: 0 10px 26px rgba(8, 153, 129, 0.28), 0 0 0 0 rgba(8, 153, 129, 0.45);
  }
  70% {
    box-shadow: 0 10px 26px rgba(8, 153, 129, 0.28), 0 0 0 16px rgba(8, 153, 129, 0);
  }
  100% {
    box-shadow: 0 10px 26px rgba(8, 153, 129, 0.28), 0 0 0 0 rgba(8, 153, 129, 0);
  }
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  60%, 100% { transform: translateX(100%); }
}

/* --------------------------------------------------------------------------
   Responsive & accessibility
   -------------------------------------------------------------------------- */
@media (max-width: 359px) {
  .chip-label {
    display: none;
  }
  .step-chip {
    gap: 0;
  }
  #chart {
    height: 210px;
  }
}

@media (hover: hover) {
  .btn-primary:hover {
    filter: brightness(1.06);
  }
  .seg-btn:hover {
    border-color: #3A3F4D;
  }
  .btn-ghost:hover {
    color: var(--text);
    border-color: #3A3F4D;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
