/* ─── Tokens ─────────────────────────────────────────────────────────────────── */

:root {
  --bg:           #F8F9FA;
  --surface:      #FFFFFF;
  --border:       #E5E7EB;
  --border-2:     #D1D5DB;
  --text:         #111827;
  --text-muted:   #6B7280;
  --text-subtle:  #9CA3AF;
  --accent:       #F59E0B;
  --accent-light: #FEF3C7;
  --accent-dark:  #D97706;
  --blue:         #3B82F6;
  --blue-light:   #EFF6FF;
  --green:        #10B981;
  --green-light:  #ECFDF5;
  --red:          #EF4444;
  --red-light:    #FEF2F2;
  --radius:       10px;
  --radius-sm:    7px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:       0 4px 12px rgba(0,0,0,0.06), 0 2px 6px rgba(0,0,0,0.04);
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── About Banner ───────────────────────────────────────────────────────────── */

.about-banner {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
}

.about-grid {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 28px;
  max-width: 1280px;
  margin: 0 auto;
  align-items: start;
}

.about-divider { background: var(--border); }

.about-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  margin-bottom: 8px;
  display: block;
}

.about-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.75;
}

.about-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.about-list li {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.55;
  padding-left: 14px;
  position: relative;
}

.about-list li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--text-subtle);
  font-size: 0.7rem;
  top: 1px;
}

.about-list strong { color: var(--text); font-weight: 600; }

@media (max-width: 820px) {
  .about-grid { grid-template-columns: 1fr; }
  .about-divider { height: 1px; width: 100%; }
  .about-banner { padding: 16px; }
}

/* ─── App Header ─────────────────────────────────────────────────────────────── */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
  display: flex;
  align-items: flex-start;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
  line-height: 1;
  margin-top: 2px;
}

.header-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-text p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
  max-width: 600px;
}

/* ─── App Body (two-column layout) ───────────────────────────────────────────── */

.app-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
  align-items: start;
}

/* ─── Controls Panel ─────────────────────────────────────────────────────────── */

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: sticky;
  top: 80px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.controls-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  margin-bottom: 16px;
}

/* Control group */
.ctrl-group {
  margin-bottom: 16px;
}

.ctrl-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.ctrl-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.ctrl-val {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 7px;
}

/* Sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border-2);
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}

input[type="range"]:hover { background: #C9D0D8; }

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: pointer;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: pointer;
}

/* Sub-label row under luck slider */
.ctrl-sublabel {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--text-subtle);
}

.ctrl-sublabel span:last-child { color: var(--blue); font-weight: 500; }

/* Select */
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  padding: 6px 10px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
select:hover { border-color: var(--border-2); }
select:focus { border-color: var(--accent); }

/* Text input */
input[type="number"],
input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="number"]:focus,
input[type="text"]:focus { border-color: var(--accent); }

.ctrl-hint {
  font-size: 0.68rem;
  color: var(--text-subtle);
  margin-top: 4px;
}

/* Divider */
.ctrl-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* Buttons */
.ctrl-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s, transform 0.1s;
  text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-run {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
}
.btn-run:hover:not(:disabled) { opacity: 0.88; }

.btn-stop {
  background: var(--red-light);
  color: var(--red);
  border-color: var(--red);
}
.btn-stop:hover { background: var(--red); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-2);
}
.btn-ghost:hover:not(:disabled) {
  border-color: var(--border-2);
  color: var(--text);
  background: var(--bg);
}

.btn-compare {
  background: var(--blue-light);
  color: var(--blue);
  border-color: var(--blue);
  font-weight: 500;
}
.btn-compare:hover:not(:disabled) { background: var(--blue); color: #fff; }

/* ─── Visualization Panel ────────────────────────────────────────────────────── */

.viz-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Live charts row */
.live-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
  box-shadow: var(--shadow-sm);
}

.chart-card-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.chart-container {
  position: relative;
  height: 220px;
}

/* Progress bar */
.progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Status log */
.log-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.log-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  background: var(--bg);
}

#log-panel {
  height: 180px;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.log-msg {
  font-size: 0.76rem;
  line-height: 1.5;
  padding: 3px 6px;
  border-radius: 4px;
  animation: fadeIn 0.2s ease;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-info     { color: var(--text-muted); }
.log-milestone{ color: var(--blue); background: var(--blue-light); }
.log-result   { color: #92400E; background: var(--accent-light); font-weight: 600; }
.log-warn     { color: var(--red); background: var(--red-light); }

/* ─── Results Section ────────────────────────────────────────────────────────── */

.results-section,
.compare-section {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

.results-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 4px;
}

.results-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* Stat cards row */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-card.accent { border-color: var(--accent); background: var(--accent-light); }

.stat-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  margin-bottom: 6px;
}

.stat-card.accent .stat-label { color: #92400E; }

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
}

.stat-card.accent .stat-value { color: var(--accent-dark); }

.stat-footnote {
  font-size: 0.68rem;
  color: var(--text-subtle);
  margin-top: 4px;
}

/* Result charts */
.result-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.result-chart-tall .chart-container { height: 280px; }

/* Compare section */
.compare-section {
  margin-top: 0;
}

.compare-chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.compare-chart-container .chart-container { height: 300px; }

/* Section divider */
.section-divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .app-body { grid-template-columns: 260px 1fr; }
}

@media (max-width: 820px) {
  .app-body { grid-template-columns: 1fr; }
  .controls { position: static; }
  .live-charts-row { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .result-charts-row { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .app-header { padding: 16px; }
  .app-body, .results-section, .compare-section { padding: 16px; }
  .stat-cards { grid-template-columns: 1fr 1fr; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
