:root {
  --bg: #0a0f1c;
  --surface: #111827;
  --surface-2: #1f2937;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-light: #a5b4fc;
  --accent-dark: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --border: rgba(99, 102, 241, 0.18);
  --glow: 0 0 18px rgba(99, 102, 241, 0.22);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Container & Header ──────────────────────────────── */
.simulator-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 4rem 1.5rem 6rem;
}

.simulator-header {
  text-align: center;
  margin-bottom: 4.5rem;
}

.simulator-header h1 {
  font-size: clamp(2.8rem, 6.5vw, 4.5rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  background: linear-gradient(90deg, #c4b5fd, #a78bfa, #818cf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 1.25rem;
}

.simulator-header p {
  font-size: 1.25rem;
  color: var(--text-muted);
  max-width: 680px;
  margin: 0 auto;
}

/* ── Form ──────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 2rem 1.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 2.8rem 2.4rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.03);
  backdrop-filter: blur(8px);
  position: relative;
  overflow: hidden;
}

.form-grid::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(99,102,241,0.06) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.form-group {
  position: relative;
  z-index: 1;
}

label {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 0.6rem;
}

input,
select {
  width: 100%;
  padding: 0.95rem 1.1rem;
  font-size: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  color: var(--text);
  transition: all 0.22s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}

small {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.45rem;
}

.btn-primary {
  grid-column: 1 / -1;
  justify-self: center;
  min-width: 240px;
  padding: 1.1rem 2.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  color: white;
  border: none;
  border-radius: 0.9rem;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(99,102,241,0.3);
  transition: all 0.35s cubic-bezier(0.23,1,0.32,1);
  margin-top: 1.2rem;
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 40px rgba(99,102,241,0.45);
}

.btn-primary:active {
  transform: translateY(-1px);
}

/* ── Presets ───────────────────────────────────────────── */
.presets {
  margin: 0 auto 2.5rem;
  max-width: 1280px;
  text-align: center;
}

.presets h3 {
  font-size: 1.2rem;
  color: var(--accent-light);
  margin-bottom: 1rem;
  font-weight: 600;
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.8rem;
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.6rem;
  border-radius: 9999px;
  font-size: 0.95rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.23,1,0.32,1);
  white-space: nowrap;
}

.preset-btn:hover {
  background: linear-gradient(135deg, #6366f1, #a78bfa);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: var(--glow);
}

/* ── Results ───────────────────────────────────────────── */
.results-panel {
  margin-top: 4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 2.5rem;
  min-height: 320px;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}

.results-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 320px;
  color: var(--accent-light);
  font-size: 1.15rem;
  gap: 1.2rem;
}

.results-loading i {
  font-size: 4.5rem;
  animation: spin 1.4s linear infinite;
  color: var(--accent);
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-visual {
  position: relative;
  width: 90px;
  height: 90px;
  margin-bottom: 1.2rem;
}

.loading-visual i {
  font-size: 4.5rem;
  color: var(--accent);
}

.turtle-emoji {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(40%, -50%); /* beside the spinner */
  font-size: 2.8rem;
  animation: turtleBounce 1.4s ease-in-out infinite;
}

@keyframes turtleBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.loading-text {
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.loading-sub {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 320px;
  text-align: center;
}

#results-content h3 {
  font-size: 1.65rem;
  color: var(--accent-light);
  margin-bottom: 1.4rem;
}

#results-pre {
  background: #0f172a;
  padding: 1.6rem;
  border-radius: 0.85rem;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.96rem;
  white-space: pre-wrap;
  line-height: 1.55;
  color: var(--text);
  border: 1px solid #1e293b;
}

#no-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 5rem 1rem;
}

#no-results i {
  font-size: 4.5rem;
  opacity: 0.25;
  margin-bottom: 1.5rem;
}

/* ── Metrics cards ───────────────────────────────────── */
.metrics-big {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 1.25rem;
  padding: 2rem 1.8rem;
  text-align: center;
  transition: all 0.3s cubic-bezier(0.23,1,0.32,1);
  box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

.metric-card:hover {
  transform: translateY(-6px);
  border-color: var(--accent);
  box-shadow: var(--glow);
}

.metric-card span {
  display: block;
  font-size: 1.05rem;
  color: var(--accent-light);
  margin-bottom: 0.6rem;
  font-weight: 600;
}

.metric-card strong {
  display: block;
  font-size: 3.2rem;
  font-weight: 700;
  line-height: 1.05;
}

#final-pnl.positive { color: var(--success); }
#final-pnl.negative { color: var(--danger); }

/* ── Chart ───────────────────────────────────────────── */
.chart-wrapper {
  position: relative;
  height: 260px;
  width: 100%;
  background: #0f172a;
  border-radius: 0.9rem;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.chart-wrapper-price {
  min-height: 420px;
  overflow: hidden;
}

.chart-wrapper-price-inner {
  height: 380px;
  width: 100%;
  overflow: hidden;
  position: relative;
  background: #0f172a;
  border-radius: 0.9rem;
}

.chart-wrapper-price-inner canvas {
  display: block;
  width: 100% !important;
  max-width: 100%;
}

.chart-wrapper .chart-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 0.35rem;
  text-align: center;
}

.chart-legend-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 0.75rem;
}

/* ── Trade log table ───────────────────────────────────── */
.trades-log-wrapper {
  margin: 2rem 0;
  background: var(--surface-2);
  border-radius: 1.05rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.trades-log-scroll {
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
}

.trades-log {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  color: var(--text);
}

.trades-log th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  color: var(--accent-light);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.trades-log td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(99, 102, 241, 0.12);
}

.trades-log tbody tr:hover {
  background: rgba(99, 102, 241, 0.06);
}

.trades-log .pnl-cell.positive { color: var(--success); font-weight: 600; }
.trades-log .pnl-cell.negative { color: var(--danger); font-weight: 600; }

/* Turtle trade tooltip (entry/exit hover) – matches page theme */
.turtle-trade-tooltip {
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  padding: 12px 14px;
  max-width: 320px;
  background: rgba(15, 23, 42, 0.98);
  color: #e2e8f0;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.turtle-trade-tooltip-title {
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 6px;
  font-size: 13px;
}

.turtle-trade-tooltip-line {
  margin-bottom: 2px;
}

.turtle-trade-tooltip-line:last-child {
  margin-bottom: 0;
}

/* ── Raw Data Dropdown ───────────────────────────────── */
.raw-details {
  margin-top: 2.5rem;
  background: #0f172a;
  border-radius: 0.85rem;
  overflow: hidden;
  border: 1px solid #1e293b;
}

.raw-details summary {
  padding: 1rem 1.4rem;
  font-weight: 600;
  color: var(--accent-light);
  cursor: pointer;
  background: #1e293b;
}

.raw-details pre {
  padding: 1.6rem;
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  max-height: 420px;
  overflow: auto;
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
  .simulator-header {
    margin-bottom: 3.5rem;
  }
  .form-grid {
    padding: 2rem 1.6rem;
  }
  .btn-primary {
    min-width: 100%;
  }
}

/* ── Summary Panel ───────────────────────────── */
.summary-panel {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 1.05rem;
  padding: 1.5rem 2rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 1rem;
  color: var(--text);
}

.summary-row span {
  font-weight: 500;
  color: var(--accent-light);
}

.summary-row strong {
  font-weight: 600;
  color: var(--text);
}

#summary-status.positive { color: var(--success); }
#summary-status.negative { color: var(--danger); }
