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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  min-height: 100vh;
  color: #333;
  display: flex;
  flex-direction: column;
}

.app-container {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  width: 100%;
}

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

.header h1 {
  color: white;
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.header p {
  color: rgba(255,255,255,0.85);
  font-size: 1.1rem;
}

.main-content {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 2rem;
}

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

.left-panel, .right-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.table-section,
.controls-section,
.transitions-section,
.state-section,
.log-section,
.explainer-section {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

h3 {
  font-size: 1.1rem;
  color: #333;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Table SVG */
.table-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.table-container svg {
  width: 100%;
  height: auto;
}

/* Deadlock alert */
.deadlock-alert {
  margin-top: 1rem;
  padding: 1rem;
  background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
  border: 2px solid #dc3545;
  border-radius: 8px;
  color: #721c24;
  font-weight: 700;
  text-align: center;
  font-size: 0.95rem;
  animation: pulse 1s ease-in-out infinite;
}

.deadlock-alert.hidden {
  display: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Controls */
.control-buttons {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.btn {
  flex: 1;
  padding: 0.65rem 0.75rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

.btn-warning {
  background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
  color: white;
}

.btn-danger {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: white;
}

.btn-danger:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.4);
}

.btn-secondary {
  background: #e9ecef;
  color: #495057;
}

.btn-secondary:hover {
  background: #dee2e6;
}

.speed-control {
  margin-top: 0.5rem;
}

.speed-control label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.25rem;
}

.speed-control input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #e0e0e0;
  border-radius: 3px;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #3498db;
  cursor: pointer;
}

/* Transitions grid */
.transitions-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.philosopher-transitions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pt-name {
  width: 80px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
}

.pt-buttons {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.btn-transition {
  flex: 1;
  padding: 0.4rem 0.5rem;
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-transition.enabled {
  background: #e8f4fd;
  color: #2980b9;
  border: 1px solid #bee5eb;
}

.btn-transition.enabled:hover {
  background: #3498db;
  color: white;
}

.btn-transition.disabled {
  background: #f5f5f5;
  color: #ccc;
  cursor: not-allowed;
  border: 1px solid #eee;
}

/* State grid */
.state-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.state-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: #f8f9fa;
  border-radius: 8px;
}

.state-name {
  font-weight: 600;
  font-size: 0.95rem;
  width: 100px;
}

.state-status {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  flex: 1;
}

.state-forks {
  display: flex;
  gap: 0.75rem;
  font-size: 0.8rem;
}

.fork-held {
  color: #27ae60;
  font-weight: 600;
}

.fork-free {
  color: #ccc;
}

/* Event log */
.log-section h3 {
  display: flex;
  justify-content: space-between;
}

.btn-clear {
  background: none;
  border: none;
  color: #888;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-clear:hover {
  color: #333;
}

.event-log {
  max-height: 300px;
  overflow-y: auto;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.8rem;
  line-height: 1.6;
}

.log-entry {
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 2px;
}

.log-entry.action {
  background: #f0f7ff;
  color: #2c5282;
}

.log-entry.danger {
  background: #fff5f5;
  color: #c53030;
  font-weight: 600;
}

.log-entry.info {
  background: #f0fff4;
  color: #276749;
}

/* Explainer */
.explainer-content {
  font-size: 0.9rem;
  line-height: 1.7;
  color: #555;
}

.explainer-content p {
  margin-bottom: 0.75rem;
}

.explainer-content ul {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}

.explainer-content li {
  margin-bottom: 0.5rem;
}

.explainer-content strong {
  color: #333;
}
