@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Share+Tech+Mono&display=swap');

:root {
  --bg-dark: #080a0f;
  --bg-panel: rgba(13, 17, 28, 0.7);
  --bg-panel-solid: #0d111c;
  --border-color: rgba(0, 240, 255, 0.15);
  --border-light: rgba(255, 255, 255, 0.08);
  --accent-cyan: #00f0ff;
  --accent-blue: #0088ff;
  --accent-green: #39ff14;
  --accent-red: #ff3838;
  --accent-amber: #ff9f00;
  --text-main: #e2e8f0;
  --text-muted: #64748b;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'Share Tech Mono', monospace;
  --glow-cyan: 0 0 10px rgba(0, 240, 255, 0.4);
  --glow-green: 0 0 10px rgba(57, 255, 20, 0.4);
  --glow-red: 0 0 10px rgba(255, 56, 56, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

/* Scrollbar styles */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-cyan);
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  display: grid;
  grid-template-rows: 60px 1fr 140px;
  grid-template-columns: 340px 1fr 340px;
  grid-template-areas:
    "top top top"
    "left center right"
    "bottom bottom bottom";
}

/* Glassmorphism utility */
.glass-panel {
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  z-index: 10;
  transition: all 0.3s ease;
}

.glass-panel:hover {
  border-color: rgba(0, 240, 255, 0.25);
}

/* --- TOP BAR --- */
header {
  grid-area: top;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  background: linear-gradient(180deg, rgba(13, 17, 28, 0.95) 0%, rgba(13, 17, 28, 0.7) 100%);
  border-bottom: 1px solid var(--border-light);
  z-index: 20;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 24px;
  height: 24px;
  border: 2px solid var(--accent-cyan);
  border-radius: 4px;
  position: relative;
  box-shadow: var(--glow-cyan);
  animation: pulse 2s infinite alternate;
}

.logo-icon::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  right: 4px;
  bottom: 4px;
  background: var(--accent-cyan);
}

@keyframes pulse {
  0% { transform: scale(1); box-shadow: 0 0 5px rgba(0, 240, 255, 0.2); }
  100% { transform: scale(1.05); box-shadow: 0 0 15px rgba(0, 240, 255, 0.6); }
}

.logo h1 {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  letter-spacing: 2px;
  font-weight: 500;
  background: linear-gradient(90deg, var(--accent-cyan) 0%, var(--accent-blue) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

.btn {
  background: rgba(0, 240, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn:hover {
  background: rgba(0, 240, 255, 0.2);
  border-color: var(--accent-cyan);
  box-shadow: var(--glow-cyan);
  text-shadow: 0 0 4px var(--accent-cyan);
}

.btn-danger:hover {
  background: rgba(255, 56, 56, 0.2);
  border-color: var(--accent-red);
  box-shadow: var(--glow-red);
  text-shadow: 0 0 4px var(--accent-red);
}

.btn-active {
  background: rgba(0, 240, 255, 0.2);
  border-color: var(--accent-cyan);
  box-shadow: var(--glow-cyan);
}

/* Toggle Switches */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 12px;
  border-left: 1px solid var(--border-light);
  padding-left: 15px;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-item input {
  display: none;
}

.toggle-switch {
  width: 32px;
  height: 16px;
  background: #1a202c;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  position: relative;
  transition: background 0.3s;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: left 0.3s, background 0.3s;
}

.toggle-item input:checked + .toggle-switch {
  background: rgba(0, 240, 255, 0.25);
  border-color: var(--accent-cyan);
}

.toggle-item input:checked + .toggle-switch::after {
  left: 18px;
  background: var(--accent-cyan);
  box-shadow: var(--glow-cyan);
}

.toggle-item input:checked ~ span {
  color: var(--accent-cyan);
}


/* --- LEFT PANEL: JOINT CONTROLS --- */
#left-panel {
  grid-area: left;
  margin: 15px 0 15px 15px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 15px;
  border-bottom: 1px solid var(--border-light);
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  letter-spacing: 1px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header-badge {
  font-size: 0.7rem;
  background: rgba(0, 240, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

.scroll-content {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.control-group {
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: rgba(8, 10, 15, 0.4);
  overflow: hidden;
  flex-shrink: 0; /* Prevent parent flex column from squishing the categories */
}

.group-title {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-light);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.group-title::after {
  content: '▼';
  font-size: 0.6rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.control-group.collapsed .group-title::after {
  transform: rotate(-90deg);
}

.group-content {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 500px;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.control-group.collapsed .group-content {
  max-height: 0;
  padding: 0;
  overflow: hidden;
  border-bottom-width: 0;
}

.joint-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.joint-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
}

.joint-name {
  color: var(--text-main);
  font-family: var(--font-mono);
}

.joint-val {
  color: var(--accent-cyan);
  font-family: var(--font-mono);
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.joint-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: #1a202c;
  outline: none;
  border: 1px solid var(--border-light);
}

.joint-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: var(--glow-cyan);
  transition: transform 0.1s;
}

.joint-slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

.joint-slider:focus::-webkit-slider-thumb {
  background: #fff;
  box-shadow: 0 0 12px var(--accent-cyan);
}

.joint-reset-btn {
  font-family: var(--font-mono);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.65rem;
  padding: 2px;
}

.joint-reset-btn:hover {
  color: var(--accent-red);
}


/* --- CENTER VIEWPORT --- */
#viewport-container {
  grid-area: center;
  margin: 15px;
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  background: radial-gradient(circle at center, #111827 0%, #030712 100%);
}

#canvas-container {
  width: 100%;
  height: 100%;
}

.viewport-overlay {
  position: absolute;
  top: 15px;
  left: 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.status-badge {
  background: rgba(13, 17, 28, 0.85);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.active {
  background-color: var(--accent-green);
  box-shadow: var(--glow-green);
}

.status-dot.alert {
  background-color: var(--accent-red);
  box-shadow: var(--glow-red);
  animation: blink 0.5s infinite alternate;
}

@keyframes blink {
  0% { opacity: 0.3; }
  100% { opacity: 1; }
}

.viewport-tools {
  position: absolute;
  top: 15px;
  right: 15px;
  display: flex;
  gap: 8px;
}


/* --- RIGHT PANEL: DIAGNOSTICS & TELEMETRY --- */
#right-panel {
  grid-area: right;
  margin: 15px 15px 15px 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.telemetry-section {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0; /* Prevent stability matrix and chart from being squished */
}

.telemetry-section h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.stability-card {
  background: rgba(8, 10, 15, 0.4);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stab-item {
  display: flex;
  flex-direction: column;
}

.stab-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.stab-val {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-main);
  margin-top: 2px;
}

.stab-status {
  font-weight: 600;
}

.stab-status.stable {
  color: var(--accent-green);
  text-shadow: 0 0 5px rgba(57, 255, 20, 0.3);
}

.stab-status.unstable {
  color: var(--accent-red);
  text-shadow: 0 0 5px rgba(255, 56, 56, 0.3);
}

/* Telemetry Chart Canvas */
.chart-container {
  height: 120px;
  background: rgba(8, 10, 15, 0.5);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

#telemetry-chart {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-legend {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-color {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

/* Console Scripting Window */
.console-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Important for flex child scrolling */
}

.console-controls {
  padding: 8px 15px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.console-editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.console-textarea {
  flex: 1;
  background: #06080c;
  color: var(--accent-amber);
  border: none;
  border-bottom: 1px solid var(--border-light);
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  resize: none;
  outline: none;
}

.console-textarea:focus {
  background: #080b11;
}

.console-log {
  height: 100px;
  background: #040507;
  border-top: 1px solid var(--border-light);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 8px;
  overflow-y: auto;
}

.log-entry {
  margin-bottom: 4px;
  line-height: 1.3;
}

.log-entry.info { color: var(--text-muted); }
.log-entry.success { color: var(--accent-green); }
.log-entry.error { color: var(--accent-red); }
.log-entry.output { color: var(--accent-cyan); }


/* --- BOTTOM PANEL: TIMELINE & SEQUENCER --- */
footer {
  grid-area: bottom;
  margin: 0 15px 15px 15px;
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  grid-template-areas: "timeline-play timeline-scrub timeline-presets";
  gap: 15px;
  padding: 12px 15px;
  align-items: center;
}

.timeline-play-container {
  grid-area: timeline-play;
  display: flex;
  align-items: center;
  gap: 10px;
}

.play-controls {
  display: flex;
  gap: 6px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  font-size: 0.9rem;
}

.speed-control {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.speed-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.timeline-scrub-container {
  grid-area: timeline-scrub;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.timeline-scrub-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.timeline-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: #1a202c;
  outline: none;
  border: 1px solid var(--border-light);
  position: relative;
}

.timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: var(--glow-cyan);
  z-index: 5;
  position: relative;
}

.timeline-ticks {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 6px;
  transform: translateY(-50%);
  pointer-events: none;
  display: flex;
  justify-content: space-between;
}

.timeline-tick-mark {
  width: 1px;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
}

.timeline-tick-mark.keyframe {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-amber);
  box-shadow: 0 0 5px var(--accent-amber);
  transform: translateX(-3px);
}

.timeline-info {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.current-frame-readout {
  color: var(--accent-cyan);
  font-weight: 600;
}

.timeline-presets-container {
  grid-area: timeline-presets;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.select-wrapper {
  position: relative;
}

.gait-select {
  background: rgba(13, 17, 28, 0.9);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 30px 6px 12px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.select-wrapper::after {
  content: '▼';
  font-size: 0.6rem;
  color: var(--accent-cyan);
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.timeline-actions {
  display: flex;
  gap: 6px;
}

/* Utility to override visibility */
.hidden {
  display: none !important;
}

/* Joint Chart custom styling */
.chart-tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid var(--accent-cyan);
  padding: 4px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  pointer-events: none;
}
