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

:root {
  --bg:           #F9FAFB;
  --surface:      #FFFFFF;
  --border:       #E5E7EB;
  --border-2:     #D1D5DB;
  --text:         #111827;
  --text-muted:   #6B7280;
  --text-subtle:  #9CA3AF;
  --confirmer:    #F97316;
  --confirmer-bg: #FFF7ED;
  --confirmer-bdr:#FED7AA;
  --falsifier:    #0EA5E9;
  --falsifier-bg: #F0F9FF;
  --falsifier-bdr:#BAE6FD;
  --green:        #10B981;
  --green-bg:     #ECFDF5;
  --red:          #EF4444;
  --red-bg:       #FEF2F2;
  --amber:        #F59E0B;
  --amber-bg:     #FFFBEB;
  --blue:         #3B82F6;
  --blue-bg:      #EFF6FF;
  --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.07);
}

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

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -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 28px;
}

.about-grid {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 28px;
  max-width: 1300px;
  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.79rem;
  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.77rem;
  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; }
}

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

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

.header-icon { font-size: 1.6rem; flex-shrink: 0; margin-top: 2px; }

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

.header-text p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  max-width: 620px;
  line-height: 1.5;
}

/* ─── App Body ──────────────────────────────────────────────────────────────────── */

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

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

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

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

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

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

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

.ctrl-val {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 7px;
  font-family: 'SF Mono', monospace;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: var(--border-2);
  outline: none;
  cursor: pointer;
}

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

select, input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  padding: 6px 10px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
select:hover { border-color: var(--border-2); }
select:focus { border-color: var(--blue); }

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

/* Speed options */
.speed-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.speed-btn {
  font-size: 0.65rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 2px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-muted);
  text-align: center;
  transition: all 0.15s;
  font-family: inherit;
}
.speed-btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

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

.btn {
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s, background 0.15s;
  text-align: center;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-run {
  background: #1D4ED8;
  color: #fff;
  border-color: #1E40AF;
}
.btn-run:hover:not(:disabled) { opacity: 0.88; }

.btn-pause {
  background: #FEF3C7;
  color: #92400E;
  border-color: #FDE68A;
}
.btn-pause:hover { background: #FDE68A; }

.btn-step {
  background: var(--surface);
  color: var(--text-muted);
  border-color: var(--border-2);
}
.btn-step:hover:not(:disabled) { color: var(--text); border-color: var(--border-2); }

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

.btn-row { display: flex; gap: 6px; }
.btn-row .btn { flex: 1; }

/* Agent colour chips */
.colour-chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

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

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

.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.76rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

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

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

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

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

.progress-text { font-size: 0.72rem; 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: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  background: var(--bg);
}

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

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

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

.log-info       { color: var(--text-muted); }
.log-milestone  { color: var(--blue); background: var(--blue-bg); }
.log-surprising { color: #92400E; background: var(--amber-bg); }
.log-insight    { color: #065F46; background: var(--green-bg); font-weight: 600; }
.log-warn       { color: var(--red); background: var(--red-bg); }

/* ─── Agent Feed ─────────────────────────────────────────────────────────────────── */

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

.feed-header-bar {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  background: var(--bg);
}

#agent-feed {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
}

.feed-item {
  background: var(--surface);
  padding: 12px 14px;
  font-size: 0.76rem;
  line-height: 1.5;
}

.feed-confirmer { border-left: 3px solid var(--confirmer); }
.feed-falsifier { border-left: 3px solid var(--falsifier); }

.feed-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.feed-label {
  font-weight: 700;
  font-size: 0.72rem;
}

.feed-label-confirmer { color: var(--confirmer); }
.feed-label-falsifier { color: var(--falsifier); }

.feed-conf { font-size: 0.68rem; color: var(--text-subtle); }

.feed-hyp { color: var(--text-muted); margin-bottom: 4px; }
.feed-hyp em { color: var(--text); font-style: normal; }

.feed-test { color: var(--text-muted); font-size: 0.72rem; }

.feed-result { font-family: monospace; font-weight: 700; }
.feed-result-true  { color: var(--green); }
.feed-result-false { color: var(--red); }

.feed-surprise { color: var(--amber); font-weight: 600; margin-left: 4px; }
.feed-revised  { color: var(--falsifier); font-size: 0.7rem; display: block; margin-top: 2px; }
.feed-no-revision { color: var(--text-subtle); font-size: 0.7rem; }

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

.results-section {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 20px 56px;
}

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

.results-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

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

.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.c-card { border-color: var(--confirmer-bdr); background: var(--confirmer-bg); }
.stat-card.f-card { border-color: var(--falsifier-bdr); background: var(--falsifier-bg); }

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

.c-card .stat-label { color: #9A3412; }
.f-card .stat-label { color: #0C4A6E; }

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

.c-card .stat-value { color: var(--confirmer); }
.f-card .stat-value { color: var(--falsifier); }

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

/* Killer stat */
.killer-stat-box {
  background: #FEF9C3;
  border: 1px solid #FDE047;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  font-size: 0.85rem;
  color: #713F12;
  line-height: 1.6;
}

.killer-stat-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #92400E;
  margin-bottom: 6px;
  display: block;
}

/* Insight text */
.insight-box {
  background: var(--green-bg);
  border: 1px solid #A7F3D0;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 20px;
  font-size: 0.82rem;
  color: #065F46;
  line-height: 1.7;
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────────── */

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

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

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

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

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