/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-panel: #16213e;
  --border-color: #0f3460;
  --text-primary: #ecf0f1;
  --text-secondary: #bdc3c7;
  --accent-primary: #f39c12;
  --accent-secondary: #2ecc71;
  --accent-danger: #e74c3c;
  --input-bg: #1a1a2e;
  --input-border: #0f3460;
  --radius: 8px;
  --radius-sm: 4px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-primary);
}

header .subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ── Main layout ──────────────────────────────────────────── */
.main-layout {
  display: flex;
  height: calc(100vh - 60px);
  overflow: hidden;
}

/* ── Control panel (left) ─────────────────────────────────── */
.control-panel {
  width: 280px;
  min-width: 260px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px;
}

.panel-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-primary);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

/* ── Input groups ─────────────────────────────────────────── */
.input-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 8px;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: background 0.2s, box-shadow 0.2s;
}

.input-group.highlighted {
  animation: pulse-highlight 1.2s ease-in-out infinite;
}

@keyframes pulse-highlight {
  0%, 100% {
    background: rgba(243, 156, 18, 0.08);
    box-shadow: 0 0 6px rgba(243, 156, 18, 0.15);
  }
  50% {
    background: rgba(243, 156, 18, 0.2);
    box-shadow: 0 0 14px rgba(243, 156, 18, 0.35);
  }
}

.input-group label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.85rem;
  min-width: 0;
}

.input-group .label-name {
  font-family: 'Consolas', 'Courier New', monospace;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.input-group .label-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.input-group input[type="number"] {
  width: 72px;
  padding: 4px 6px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85rem;
  text-align: right;
  outline: none;
  transition: border-color 0.2s;
}

.input-group input[type="number"]:focus {
  border-color: var(--accent-primary);
}

/* ── Buttons ──────────────────────────────────────────────── */
.button-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.btn {
  padding: 8px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  flex: 1;
  min-width: 60px;
  text-align: center;
}

.btn-primary {
  background: var(--accent-primary);
  color: #1a1a2e;
  border-color: var(--accent-primary);
}
.btn-primary:hover { background: #e67e22; }

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

.btn-accent {
  background: var(--bg-secondary);
  color: var(--accent-secondary);
  border-color: var(--accent-secondary);
}
.btn-accent:hover { background: var(--accent-secondary); color: #1a1a2e; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Section description ──────────────────────────────────── */
.section-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.4;
}

/* ── Gait overlay (above animation panel) ─────────────────── */
.gait-overlay {
  position: fixed;
  bottom: 226px;
  left: 296px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 10px 14px;
  z-index: 20;
  width: 260px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* ── Score rows ───────────────────────────────────────────── */
.score-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 12px;
}

.score-row:last-child {
  margin-bottom: 0;
}

.score-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.score-value {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 50px;
  text-align: right;
}

.score-value.good {
  color: var(--accent-secondary);
}

.score-value.bad {
  color: var(--accent-danger);
}

.score-value.orange {
  color: var(--accent-primary);
}

.score-value.reddish-orange {
  color: #e67e22;
}

.score-value.dark-orange {
  color: #d35400;
}

/* ── Integer approximation warning ────────────────────────── */
.integer-warning {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(231, 76, 60, 0.12);
  border: 1px solid rgba(231, 76, 60, 0.35);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: #e74c3c;
  line-height: 1.4;
}

/* ── Sliders ──────────────────────────────────────────────── */
.slider-group {
  margin-bottom: 10px;
}

.slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.slider-group label span {
  color: var(--accent-primary);
  font-weight: 600;
  font-family: 'Consolas', monospace;
}

.slider-group input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 3px;
  outline: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  border: 2px solid var(--bg-panel);
}

.slider-group input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  border: 2px solid var(--bg-panel);
}

/* ── Checkbox ─────────────────────────────────────────────── */
.checkbox-group {
  margin-top: 4px;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  accent-color: var(--accent-primary);
  width: 16px;
  height: 16px;
}

/* ── Export status ────────────────────────────────────────── */
.export-status {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 6px;
  min-height: 1.2em;
}

/* ── Canvas container (right) ─────────────────────────────── */
.canvas-container {
  flex: 1;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

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

/* ── Solver warning ───────────────────────────────────────── */
.solver-warning {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-danger);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 10;
  white-space: nowrap;
}

/* ── Animation panel (fixed, lower-left, right of sidebar) ── */
.animation-panel {
  position: fixed;
  bottom: 16px;
  left: 296px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px;
  z-index: 20;
  width: 260px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.animation-panel .button-row {
  margin-bottom: 10px;
}

.animation-panel .slider-group {
  margin-bottom: 10px;
}

.animation-panel .checkbox-group {
  margin-top: 0;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .main-layout {
    flex-direction: column;
    height: auto;
    overflow-y: auto;
  }

  .control-panel {
    width: 100%;
    min-width: unset;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .canvas-container {
    min-height: 60vh;
  }

  .animation-panel {
    left: 50%;
    transform: translateX(-50%);
    bottom: 8px;
    width: calc(100% - 16px);
    max-width: 320px;
  }

  .gait-overlay {
    left: 50%;
    transform: translateX(-50%);
    bottom: 212px;
    width: calc(100% - 16px);
    max-width: 320px;
  }

  header h1 {
    font-size: 1.1rem;
  }
}

@media (max-width: 480px) {
  .control-panel {
    padding: 8px;
  }

  .panel-section {
    padding: 8px;
  }

  .input-group input[type="number"] {
    width: 60px;
  }
}

/* ── Scrollbar styling ────────────────────────────────────── */
.control-panel::-webkit-scrollbar {
  width: 6px;
}
.control-panel::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
.control-panel::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
.control-panel::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* ── Flash highlight (one-shot, matches canvas bar crossfade) ── */
@keyframes flash-highlight {
  0%   { background: transparent; box-shadow: none; }
  20%  { background: rgba(243, 156, 18, 0.25); box-shadow: 0 0 16px rgba(243, 156, 18, 0.45); }
  100% { background: transparent;   box-shadow: none; }
}
.flash-highlight {
  animation: flash-highlight 2.5s ease-out forwards;
}

@keyframes flash-button {
  0%   { background: transparent; box-shadow: none; transform: scale(1); }
  20%  { background: rgba(243, 156, 18, 0.25); box-shadow: 0 0 16px rgba(243, 156, 18, 0.45); transform: scale(1.06); }
  100% { background: transparent;   box-shadow: none; transform: scale(1); }
}
.flash-button {
  animation: flash-button 2.5s ease-out forwards;
}

@keyframes flash-value {
  0%   { color: var(--text-primary); text-shadow: none; }
  20%  { color: var(--accent-primary); text-shadow: 0 0 10px rgba(243, 156, 18, 0.6); }
  100% { color: var(--text-primary); text-shadow: none; }
}
.flash-value {
  animation: flash-value 2.5s ease-out forwards;
}
