/* CSS Variables and Dark Mode Theme */
:root {
  /* Colors */
  --bg: #f7f8fa;
  --panel: #fff;
  --ink: #1f2937;
  --muted: #6b7280;
  --brand: #16a34a;
  --cue: #10b981;
  --stim-primary: #2563eb;
  --stim-distractor: #93c5fd;
  --go: #f59e0b;
  --danger: #dc2626;
  
  /* Spacing & Layout */
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 6px 20px rgba(0,0,0,.08);
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --gap: 24px;
  --gap-sm: 16px;
  --gap-xs: 8px;
  
  /* Borders */
  --border: 2px solid #e5e7eb;
  --border-focus: 2px solid var(--brand);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d11;
    --panel: #1f2937;
    --ink: #e5e7eb;
    --muted: #9ca3af;
    --brand: #22c55e;
    --cue: #34d399;
    --stim-primary: #60a5fa;
    --stim-distractor: #93c5fd;
    --go: #fbbf24;
    --danger: #ef4444;
    --border: 2px solid #374151;
    --border-focus: 2px solid var(--brand);
  }
}

/* Base Styles */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 20px;
  background-color: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  background-color: var(--panel);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

h1 {
  color: var(--ink);
  text-align: center;
  margin-bottom: var(--gap);
}

/* Card Components */
.card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--gap-sm);
}

/* Controls */
.controls {
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: var(--gap-sm);
}

.select-group {
  display: flex;
  flex-direction: column;
}

/* Align button with the select input, not the label */
#start-experiment {
  align-self: end;
  margin-bottom: 15px; /* Match the select's margin-bottom */
}

@media (max-width: 768px) {
  .controls {
    grid-template-columns: 1fr;
    gap: var(--gap-sm);
  }
}

label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
  color: var(--ink);
}

select {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
  border: var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background-color: var(--panel);
  color: var(--ink);
  transition: border-color 0.3s ease;
}

select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

/* Layout */
.content {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--gap);
}

@media (max-width: 768px) {
  .content {
    grid-template-columns: 1fr;
  }
}

.left-panel {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.right-panel {
  position: sticky;
  top: 16px;
  align-self: start;
}

/* Canvas Container */
#canvas-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
  background-color: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--gap-sm);
}

@media (max-width: 768px) {
  #canvas-container {
    min-height: 300px;
  }
}

/* Info Panel */
#info-panel {
  background-color: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--gap-sm);
}

#info-panel h3 {
  margin-top: 0;
  color: var(--ink);
  border-bottom: 2px solid var(--muted);
  padding-bottom: var(--gap-xs);
}

#info-panel dl {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: var(--gap-xs);
  align-items: baseline;
}

#info-panel dt {
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

#info-panel dd {
  margin: 0;
  color: var(--muted);
}

#info-panel p {
  margin: var(--gap-xs) 0;
  padding: 4px 0;
}

#info-panel strong {
  color: var(--ink);
  font-weight: 600;
}

/* Timeline */
#timeline-svg {
  width: 100%;
  height: 300px;
  border-radius: var(--radius);
  background-color: var(--panel);
  box-shadow: var(--shadow);
}

@media (max-width: 768px) {
  #timeline-svg {
    height: 250px;
  }
}

/* Timeline Legend */
.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-sm);
  margin-top: var(--gap-xs);
  padding: var(--gap-xs);
  background-color: var(--panel);
  border-radius: var(--radius-sm);
  border: 1px solid var(--muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink);
}

.legend-swatch {
  width: 16px;
  height: 12px;
  border-radius: 3px;
  box-shadow: var(--shadow-sm);
}

/* Trial Status */
.trial-status {
  text-align: center;
  padding: var(--gap-xs);
  margin-top: var(--gap-xs);
  background-color: var(--panel);
  border-radius: var(--radius-sm);
  border: 1px solid var(--muted);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

/* Button */
#start-experiment {
  padding: 10px 20px;
  background-color: var(--brand);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

#start-experiment:hover:not(:disabled) {
  background-color: #15803d;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

#start-experiment:disabled {
  background-color: var(--muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-sm);
}

/* Canvas */
canvas {
  background: black;
  border-radius: var(--radius-sm);
}

/* States */
.placeholder, .loading, .error, .success {
  text-align: center;
  padding: 20px;
  border-radius: var(--radius-sm);
}

.placeholder {
  color: var(--muted);
  font-style: italic;
}

.loading {
  color: var(--stim-primary);
  font-weight: 500;
}

.error {
  color: var(--danger);
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger);
  font-weight: 500;
}

.success {
  color: var(--brand);
  background-color: rgba(34, 197, 94, 0.1);
  border: 1px solid var(--brand);
  font-weight: 500;
}

/* Skeleton Loading States */
.skeleton {
  background: linear-gradient(90deg, var(--muted) 25%, rgba(255,255,255,0.3) 50%, var(--muted) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-timeline {
  height: 300px;
  margin: var(--gap-xs) 0;
}

.skeleton-info {
  height: 200px;
  margin: var(--gap-xs) 0;
}

.skeleton-canvas {
  height: 400px;
  margin: var(--gap-xs) 0;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Animation for smooth state changes */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Focus and accessibility */
#canvas-container:focus {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

/* SVG Timeline Styles */
.timeline-grid {
  stroke: var(--muted);
  opacity: 0.08;
}

.timeline-grid.major {
  opacity: 0.18;
}

.timeline-bar {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.timeline-label {
  fill: var(--ink);
  font-family: inherit;
  font-size: 10px;
}

.timeline-tag {
  fill: var(--panel);
  stroke: var(--muted);
  stroke-width: 1;
}

/* Nav Header & Back Link */
.nav-header {
  margin-bottom: var(--gap-sm);
  display: flex;
  justify-content: flex-start;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: var(--brand);
}