:root {
  --bg-primary: #0a0d14;
  --bg-secondary: #111726;
  --bg-card: #1a2234;
  --bg-card-hover: #222d44;
  --border-color: #2a364f;
  --border-subtle: #1e283d;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-crank: #ef4444;      /* Red */
  --accent-coupler: #3b82f6;    /* Blue */
  --accent-follower: #f59e0b;   /* Amber */
  --accent-ground: #94a3b8;     /* Slate */
  --accent-tracer: #10b981;     /* Emerald green */
  --accent-target: #06b6d4;     /* Cyan */
  --accent-primary: #6366f1;    /* Indigo */
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.65rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 50;
  flex-shrink: 0;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 1.4rem;
  background: linear-gradient(135deg, #6366f1, #10b981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* App Main Layout: Hero Stage (Left) + Diagnostics Sidebar (Right) */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 0;
  height: calc(100vh - 58px);
  overflow: hidden;
}

@media (max-width: 1100px) {
  main {
    grid-template-columns: 1fr 320px;
  }
}

@media (max-width: 860px) {
  main {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
}

/* Main Interactive Canvas Area */
.main-stage-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: #060911;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

canvas#mainCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* Floating HUD Controls on Main Canvas */
.canvas-hud-top {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 20;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  pointer-events: auto;
  background: rgba(17, 23, 38, 0.88);
  padding: 0.35rem 0.65rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.hud-pill {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Floating Bottom Playback & View Bar */
.canvas-hud-bottom {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  z-index: 20;
}

.playback-hud {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: rgba(17, 23, 38, 0.92);
  border: 1px solid var(--border-color);
  border-radius: 0.6rem;
  backdrop-filter: blur(10px);
  pointer-events: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.scrubber-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.angle-badge {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 55px;
  text-align: right;
  color: #38bdf8;
}

/* Viewport Info Overlay */
.viewport-hint {
  position: absolute;
  top: 4.2rem;
  left: 1rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: rgba(11, 15, 25, 0.82);
  padding: 0.4rem 0.75rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(6px);
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.viewport-hint .highlight {
  color: #38bdf8;
  font-weight: 600;
}

/* Sidebar Panel */
.sidebar {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Cards & Control Groups */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 0.55rem;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.control-label span.val {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-primary);
  height: 5px;
  background: #0f172a;
  border-radius: 3px;
  cursor: pointer;
}

select, input[type="text"], input[type="number"] {
  background: #0f172a;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.45rem 0.65rem;
  border-radius: 0.35rem;
  font-size: 0.82rem;
  outline: none;
}

select:focus, input:focus {
  border-color: var(--accent-primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.85rem;
  border-radius: 0.45rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease-in-out;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  color: white;
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
}

.btn-success {
  background: linear-gradient(135deg, #059669, #047857);
  color: white;
}

.btn-success:hover {
  background: linear-gradient(135deg, #10b981, #059669);
}

.btn-outline {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

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

.btn-sm {
  padding: 0.3rem 0.55rem;
  font-size: 0.74rem;
}

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

/* Metrics Grid */
.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.metric-card {
  background: #0f172a;
  border: 1px solid var(--border-subtle);
  border-radius: 0.4rem;
  padding: 0.55rem 0.7rem;
  display: flex;
  flex-direction: column;
}

.metric-title {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-value {
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-mono);
  margin-top: 0.2rem;
  color: var(--text-primary);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Cognates Tabs */
.cognate-tabs {
  display: flex;
  background: #0f172a;
  border-radius: 0.4rem;
  padding: 0.2rem;
  gap: 0.2rem;
}

.cognate-tab {
  flex: 1;
  text-align: center;
  padding: 0.4rem 0.2rem;
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 0.3rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cognate-tab.active {
  background: var(--accent-primary);
  color: white;
}

/* Parameters Table */
.param-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
  font-family: var(--font-mono);
}

.param-table td {
  padding: 0.28rem 0.45rem;
  border-bottom: 1px solid var(--border-subtle);
}

.param-table tr:last-child td {
  border-bottom: none;
}

.param-name {
  color: var(--text-secondary);
}

.param-val {
  text-align: right;
  color: var(--text-primary);
  font-weight: 600;
}

/* Checklist */
.checklist {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.75rem;
}

.check-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0.45rem;
  background: #0f172a;
  border-radius: 0.35rem;
}

.check-icon {
  font-size: 0.8rem;
  margin-right: 0.45rem;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.72rem;
  padding: 0.4rem 0.75rem;
  background: rgba(17, 23, 38, 0.92);
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
