/* Conservation of Energy Virtual Physics Laboratory Stylesheet */
:root {
  --primary-color: #1e3a8a;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --accent-color: #2563eb;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border-color: #e2e8f0;
  --border-dark: #cbd5e1;

  /* Energy colors */
  --pe-color: #2563eb;
  --pe-bg: #dbeafe;
  --ke-color: #059669;
  --ke-bg: #d1fae5;
  --thermal-color: #ea580c;
  --thermal-bg: #ffedd5;
  --total-color: #7c3aed;
  --total-bg: #ede9fe;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.1), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  padding: 1.5rem;
  max-width: 1440px;
  margin: 0 auto;
}

/* Header */
.lab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  background: var(--card-bg);
  padding: 1.25rem 1.75rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.lab-title-area {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.lab-badge {
  background: var(--primary-light);
  color: var(--primary-color);
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid #bfdbfe;
}

.lab-title-area h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.lab-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.mode-selector {
  display: flex;
  gap: 0.5rem;
  background: #f1f5f9;
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.mode-btn {
  padding: 0.5rem 1.25rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn.active {
  background: var(--card-bg);
  color: var(--primary-color);
  box-shadow: var(--shadow-sm);
}

.mode-btn:hover:not(.active) {
  color: var(--text-main);
}

/* Layout Grid */
.lab-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

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

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-header h2 svg {
  color: var(--accent-color);
}

/* Main Visual Simulation Area */
.sim-container {
  position: relative;
  width: 100%;
  height: 420px;
  background: linear-gradient(180deg, #f8fafc 0%, #edf2f7 100%);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

canvas#simCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Verification Badge overlay on Canvas */
.verification-overlay {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  font-weight: 700;
  transition: all 0.3s ease;
}

.verification-overlay.ideal {
  color: #047857;
  border-color: #a7f3d0;
  background: rgba(236, 253, 245, 0.95);
}

.verification-overlay.friction {
  color: #c2410c;
  border-color: #fed7aa;
  background: rgba(255, 247, 237, 0.95);
}

.badge-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: white;
  background: currentColor;
}

/* Playback Control Bar */
.sim-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  background: #f1f5f9;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.btn-group {
  display: flex;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--text-main);
  border-color: var(--border-dark);
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: var(--primary-color);
}

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-accent {
  background: var(--accent-color);
  color: white;
}

.btn-accent:hover {
  background: #1d4ed8;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.speed-btn {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-color);
  background: white;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
}

.speed-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Control Panel Inputs */
.control-group {
  margin-bottom: 1.25rem;
}

.control-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.control-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-main);
}

.control-val-badge {
  font-size: 0.875rem;
  font-weight: 800;
  color: var(--primary-color);
  background: var(--primary-light);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid #bfdbfe;
}

.slider-input {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #cbd5e1;
  outline: none;
  appearance: none;
  cursor: pointer;
}

.slider-input::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  transition: transform 0.1s ease;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.slider-input::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.range-limits {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Real-time Energy Readout Grid */
.energy-readout-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.metric-box {
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: #f8fafc;
}

.metric-box.pe {
  background: var(--pe-bg);
  border-color: #bfdbfe;
}

.metric-box.ke {
  background: var(--ke-bg);
  border-color: #a7f3d0;
}

.metric-box.thermal {
  background: var(--thermal-bg);
  border-color: #fed7aa;
}

.metric-box.total {
  background: var(--total-bg);
  border-color: #ddd6fe;
}

.metric-name {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.metric-val {
  font-size: 1.25rem;
  font-weight: 800;
  margin-top: 0.2rem;
  font-family: 'JetBrains Mono', monospace, sans-serif;
}

.metric-box.pe .metric-val { color: var(--pe-color); }
.metric-box.ke .metric-val { color: var(--ke-color); }
.metric-box.thermal .metric-val { color: var(--thermal-color); }
.metric-box.total .metric-val { color: var(--total-color); }

/* Energy Bars Visualization */
.energy-bars-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: #f8fafc;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.bar-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
}

.bar-track {
  width: 100%;
  height: 12px;
  background: #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.05s linear;
}

.bar-fill.pe { background: var(--pe-color); }
.bar-fill.ke { background: var(--ke-color); }
.bar-fill.thermal { background: var(--thermal-color); }
.bar-fill.total { background: var(--total-color); }

/* Second Section Grid: Graph + Observation Table */
.secondary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

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

.graph-container {
  position: relative;
  width: 100%;
  height: 300px;
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

canvas#graphCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.graph-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

/* Observation Table */
.table-wrapper {
  overflow-x: auto;
  max-height: 280px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.obs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.obs-table th {
  background: #f1f5f9;
  color: var(--text-main);
  font-weight: 700;
  padding: 0.6rem 0.75rem;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.obs-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-muted);
  white-space: nowrap;
  font-family: monospace;
}

.obs-table tr:nth-child(even) {
  background: #f8fafc;
}

.obs-table tr:hover {
  background: var(--primary-light);
}

.table-empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Educational / Theory Section */
.theory-card {
  margin-bottom: 1.5rem;
}

.theory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.theory-box {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.theory-box h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.theory-box p, .theory-box ul {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.theory-box ul {
  padding-left: 1.2rem;
  margin-top: 0.5rem;
}

.theory-box li {
  margin-bottom: 0.35rem;
}

.formula-card {
  background: #eff6ff;
  border-left: 4px solid var(--primary-color);
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: var(--primary-color);
  font-weight: 700;
}

/* Footer */
footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
}

/* Responsive adjustments */
@media (max-width: 640px) {
  body {
    padding: 0.75rem;
  }
  .lab-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .sim-controls-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-group {
    flex-direction: column;
  }
  .energy-readout-grid {
    grid-template-columns: 1fr;
  }
}
