* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

body {
  min-height: 100vh;
  color: #f1f5f9;
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow-x: hidden;
}

/* Dynamic State Themes with High-Contrast Pulsing */
body.state-serene {
  background-color: #0b1329;
  animation: pulse-serene 6s ease-in-out infinite alternate;
}

body.state-happy {
  background-color: #064e3b;
  animation: pulse-happy 2.5s ease-in-out infinite alternate;
}

body.state-crying {
  background-color: #7f1d1d;
  animation: pulse-crying 0.9s cubic-bezier(0.4, 0, 0.6, 1) infinite alternate;
}

@keyframes pulse-serene {
  0% { background-color: #070e20; }
  100% { background-color: #0f1c3f; }
}

@keyframes pulse-happy {
  0% { background-color: #043d2e; }
  100% { background-color: #065f46; }
}

@keyframes pulse-crying {
  0% { background-color: #5c0f0f; box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.8); }
  100% { background-color: #b91c1c; box-shadow: inset 0 0 200px rgba(255, 0, 0, 0.5); }
}

.app-container {
  width: 100%;
  max-width: 1000px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.7);
  padding: 16px 24px;
  border-radius: 12px;
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.branding {
  display: flex;
  align-items: center;
  gap: 12px;
}

.branding h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #64748b;
}

.status-indicator.active {
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
}

.header-controls {
  display: flex;
  gap: 10px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
}

.primary-btn {
  background: #3b82f6;
  color: #ffffff;
}

.primary-btn:hover {
  background: #2563eb;
}

.primary-btn.stop {
  background: #ef4444;
}

.primary-btn.stop:hover {
  background: #dc2626;
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Settings Drawer */
.settings-panel {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 20px;
}

.settings-panel.hidden {
  display: none;
}

.panel-content h3 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.panel-content .subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-bottom: 16px;
}

.input-group {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.input-group input {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 10px 12px;
  color: #fff;
  font-size: 0.9rem;
}

.panel-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

/* Main Display */
.main-display {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.state-card {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden;
}

.state-label {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: #94a3b8;
  display: block;
  margin-bottom: 8px;
}

#stateDisplay {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}

.state-sub {
  font-size: 0.95rem;
  color: #cbd5e1;
  margin-bottom: 24px;
}

.meter-wrapper {
  max-width: 500px;
  margin: 0 auto;
}

#waveformCanvas {
  width: 100%;
  height: 70px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.db-readout {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 6px;
}

/* Metrics Row */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.metric-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 18px;
  backdrop-filter: blur(8px);
}

.metric-card h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.metric-value {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.top-class-name {
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 8px;
}

.top-class-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.bar-fill {
  height: 100%;
  background: #38bdf8;
  transition: width 0.2s ease;
}

.top-class-confidence {
  font-size: 0.8rem;
  color: #94a3b8;
  text-align: right;
}

.threshold-marker {
  font-size: 0.75rem;
  color: #64748b;
}

/* Timeline Logger */
.timeline-section {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 20px;
  backdrop-filter: blur(8px);
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.timeline-header h3 {
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.clear-btn {
  background: transparent;
  color: #94a3b8;
  font-size: 0.8rem;
  padding: 4px 8px;
}

.clear-btn:hover {
  color: #ffffff;
}

.timeline-scroller {
  max-height: 220px;
  overflow-y: auto;
  padding-right: 6px;
}

.timeline-scroller::-webkit-scrollbar {
  width: 6px;
}

.timeline-scroller::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.timeline-entry .timestamp {
  color: #64748b;
  font-family: monospace;
  font-size: 0.8rem;
}

.badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-crying { background: #dc2626; color: #fff; }
.badge-happy { background: #059669; color: #fff; }
.badge-serene { background: #2563eb; color: #fff; }
.badge-system { background: #475569; color: #fff; }

.timeline-entry .message {
  color: #e2e8f0;
}