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

body {
  font-family: 'din-2014', sans-serif;
  font-style: italic;
  line-height: 1.5;
  color: #111;
  background-color: #b0b2ba;
  height: 100vh;
  overflow: hidden;
  text-transform: uppercase;
  position: relative;
  letter-spacing: 0.5px;
}

.app-container {
  width: 100%;
  height: 100vh;
  position: relative;
}

/* Connection screen */
#connection-screen {
  position: absolute;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #b0b2ba;
  z-index: 10;
  transition: opacity 0.5s ease-in-out;
}

.connection-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 24px;
}

.logo {
  width: 80px;
  height: auto;
  color: #111;
}

#connection-status {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 3px;
  opacity: 0.5;
}

#connection-details {
  font-size: 10px;
  color: #555;
  letter-spacing: 1px;
  margin-top: -16px;
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 1.5px solid rgba(0, 0, 0, 0.08);
  border-radius: 50%;
  border-top-color: #111;
  animation: spin 1s ease-in-out infinite;
}

.debug-section {
  margin-top: 16px;
}

#debug-button {
  background: none;
  color: #111;
  border: 1px solid rgba(17, 17, 17, 0.15);
  padding: 5px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 9px;
  letter-spacing: 1.5px;
  opacity: 0.35;
  transition: all 0.3s ease;
}

#debug-button:hover {
  opacity: 1;
  border-color: #111;
  background: none;
}

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

/* Main application */
#app-screen {
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px;
  position: absolute;
  width: 100%;
  top: 0;
  left: 0;
  overflow: hidden;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(17, 17, 17, 0.15);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-small {
  width: 48px;
  height: auto;
  color: #111;
  display: block;
}

.header-divider {
  width: 1px;
  height: 18px;
  background-color: rgba(17, 17, 17, 0.25);
}

h1 {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 3px;
}

h3 {
  font-size: 13px;
}

.connection-indicator {
  font-size: 9px;
  padding: 3px 10px;
  background: none;
  color: #111;
  border: 1px solid rgba(17, 17, 17, 0.25);
  border-radius: 20px;
  letter-spacing: 1.5px;
  opacity: 0.5;
}

/* Controls */
.controls {
  display: flex;
  gap: 15px;
  margin-bottom: 16px;
}

button {
  padding: 7px 14px;
  background-color: #111;
  color: #fff;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  transition: all 0.3s ease;
  letter-spacing: 1px;
}

button:hover {
  background-color: #333;
}

/* Parameters — inline row layout */
#parameters-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  padding: 0 40px;
  padding-bottom: 20px;
  flex: 1;
  max-width: 700px;
  height: 100%;
  scrollbar-width: none;
}

#parameters-container::-webkit-scrollbar {
  display: none;
}

.parameter {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(17, 17, 17, 0.12);
  background: none;
  box-shadow: none;
  border-radius: 0;
}

.parameter:last-child {
  border-bottom: none;
}

.parameter-label {
  width: 35%;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  margin-bottom: 0;
}

.parameter-label .parameter-description {
  display: none;
}

.parameter-input {
  flex: 1;
  min-width: 0;
}

/* Pill toggle controls for selects */
.pill-control {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.pill-btn {
  padding: 3px 10px;
  font-size: 9px;
  font-family: inherit;
  font-style: italic;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  background: none;
  color: rgba(17, 17, 17, 0.4);
  border: 1px solid rgba(17, 17, 17, 0.15);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.pill-btn:hover {
  color: #111;
  border-color: #111;
  background: none;
}

.pill-btn.active {
  background: #111;
  color: #c4c4c4;
  border-color: #111;
}

/* Hidden select (value tracking only) */
.parameter-input select {
  display: none;
}

/* Range input styling */
.parameter-input input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 16px;
  background: transparent;
  margin: 4px 0;
}

.parameter-input input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 2px;
  cursor: pointer;
  background: #111;
  border-radius: 2px;
}

.parameter-input input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 12px;
  width: 12px;
  border-radius: 50%;
  background: #111;
  cursor: pointer;
  margin-top: -5px;
}

.parameter-input input[type="range"]:focus {
  outline: none;
}

.parameter-input input[type="number"] {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid #111;
  background-color: rgba(255, 255, 255, 0.1);
  font-family: inherit;
  font-size: 11px;
  border-radius: 4px;
  transition: border-color 0.3s ease;
}

.parameter-input input[type="number"]:focus {
  outline: none;
  border-color: #3a5b81;
}

/* Value display — inline */
.parameter-value {
  position: static;
  flex-shrink: 0;
  width: 55px;
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  color: #111;
  opacity: 0.7;
}

/* Bipolar range styling */
.range-wrapper {
  position: relative;
  width: 100%;
  padding: 0;
}

.bipolar-wrapper {
  margin-top: 4px;
}

.center-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 1px;
  height: 10px;
  background-color: #555;
  z-index: 1;
}

.bipolar-range::-webkit-slider-runnable-track {
  background: linear-gradient(to right, #555 0%, #555 49.5%, #111 50.5%, #111 100%);
}

/* Editor Tabs */
.editor-tabs {
  display: flex;
  margin-bottom: 12px;
  border-bottom: 1px solid #111;
}

.tab-button {
  background: none;
  border: none;
  padding: 8px 16px;
  margin-right: 10px;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  color: #111;
  text-transform: uppercase;
  position: relative;
  letter-spacing: 2px;
}

.tab-button:hover {
  background: none;
  color: #3a5b81;
}

.tab-button.active {
  font-weight: bold;
}

.tab-button.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #111;
}

.editors-container {
  position: relative;
  flex: 1;
  height: calc(100vh - 170px);
  overflow: hidden;
}

.editor-section {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  flex: 1;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.editor-section.active {
  display: flex;
  flex-direction: column;
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
}

/* Scale Editor */
.scale-editor-layout {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  flex: 0 0 auto;
}

.scale-left-panel {
  width: 220px;
  flex-shrink: 0;
  padding: 15px;
  background-color: #9da1ad;
  border-radius: 6px;
}

.scale-right-panel {
  flex-grow: 1;
}

.bank-selection, .scale-selection {
  margin-bottom: 20px;
  text-align: center;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 5px;
  margin-top: 10px;
}

.button-grid button {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 16px;
  background-color: transparent;
  border: 1px solid #111;
  color: #111;
  border-radius: 6px;
}

.button-grid button:hover {
  background-color: rgba(17, 17, 17, 0.1);
}

.button-grid button.active {
  background-color: #111;
  color: white;
}

.scale-edit-controls {
  display: flex;
  flex-direction: row;
  gap: 10px;
  margin-bottom: 20px;
  justify-content: center;
  padding: 10px 0;
  background-color: #9da1ad;
  border-radius: 6px;
}

.scale-edit-controls button {
  padding: 7px 14px;
  flex: 0 1 auto;
  background: transparent;
  border: 1px solid #111;
  color: #111;
}

.scale-edit-controls button:hover {
  background-color: #111;
  color: #c4c4c4;
}

.sliders-container {
  display: flex;
  justify-content: center;
  gap: 24px;
  height: 300px;
  padding: 20px 10px;
  background-color: #9da1ad;
  border-radius: 6px;
}

.slider-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 30px;
}

.slider-label {
  margin-bottom: 5px;
  font-weight: 700;
  font-size: 14px;
}

.slider-track {
  position: relative;
  width: 2px;
  height: 220px;
  background-color: #111;
  margin-bottom: 10px;
}

.slider-handle {
  width: 16px;
  height: 2px;
  background-color: #111;
  position: absolute;
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
}

.slider-endpoint {
  position: absolute;
  left: 0;
  width: 100%;
  height: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  z-index: 2;
}

.slider-endpoint-lower {
  top: 0;
  transform: translateY(-85%);
}

.slider-endpoint-upper {
  bottom: 0;
  transform: translateY(85%);
}

.slider-endpoint-marker {
  width: 12px;
  height: 12px;
  background-color: #111;
  border-radius: 50%;
  box-sizing: border-box;
  border: 1px solid #444;
}

.slider-endpoint-label {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
  color: #fff;
  background-color: #444;
  padding: 2px 5px;
  border-radius: 4px;
  min-width: 34px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.slider-endpoint.editing .slider-endpoint-marker {
  background-color: #ff5500;
  box-shadow: 0 0 5px rgba(255, 85, 0, 0.5);
}

/* Preview mode styling */
.slider-endpoint.preview-active .slider-endpoint-marker {
  background-color: #00cc66;
  box-shadow: 0 0 8px rgba(0, 204, 102, 0.7);
  animation: pulse 0.4s ease-in-out;
}

.slider-endpoint.preview-active .slider-endpoint-label {
  background-color: #00aa55;
  box-shadow: 0 0 8px rgba(0, 204, 102, 0.5);
}

#preview-button.playing {
  background-color: #00cc66;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* Piano Keyboard */
.keyboard-container {
  margin-top: 20px;
  overflow-x: auto;
  padding: 10px;
  width: 100%;
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
}

.piano-keyboard {
  display: flex;
  height: 150px;
  max-width: 600px;
  width: 100%;
  position: relative;
  justify-content: center;
}

.piano-key {
  position: relative;
  border: 1px solid #111;
  box-sizing: border-box;
}

.white-key {
  background-color: white;
  height: 100%;
  z-index: 1;
  width: 20px;
  flex-grow: 1;
  flex-shrink: 1;
}

.black-key {
  background-color: #111;
  width: 12px;
  height: 65%;
  margin-left: -6px;
  margin-right: -6px;
  z-index: 2;
  flex-grow: 0;
  flex-shrink: 0;
}

.piano-key.active {
  background-color: #00cc66;
}

.piano-key.endpoint-lower {
  border-top: 3px solid #0066cc;
}

.piano-key.endpoint-upper {
  border-bottom: 3px solid #ff5500;
}

.key-label.reference-only {
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 8px;
  color: #999;
  pointer-events: none;
  opacity: 0.7;
}

.endpoint-indicator {
  position: absolute;
  font-size: 8px;
  padding: 2px;
  border-radius: 2px;
  background-color: rgba(255, 255, 255, 0.8);
  color: #111;
  white-space: nowrap;
  pointer-events: none;
  z-index: 3;
}

.endpoint-indicator.lower {
  top: 2px;
  color: #0066cc;
}

.endpoint-indicator.upper {
  bottom: 2px;
  color: #ff5500;
}

/* Utility classes */
.visible {
  opacity: 1;
  z-index: 10;
}

.hidden {
  opacity: 0;
  z-index: -1;
  pointer-events: none;
}

/* Firmware Editor Styles */
#firmware-editor {
  display: flex;
  flex-direction: column;
}

.firmware-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

.firmware-section {
  background-color: #9da1ad;
  border-radius: 6px;
  padding: 20px;
}

.firmware-section h3 {
  text-align: center;
  margin-bottom: 15px;
  font-size: 18px;
}

.firmware-description {
  text-align: center;
  margin-bottom: 20px;
  font-size: 14px;
  text-transform: none;
  font-weight: 300;
}

.firmware-selection {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 20px;
}

.firmware-selection h4 {
  font-size: 16px;
  margin-bottom: 10px;
}

#firmware-selector {
  width: 100%;
  padding: 10px;
  font-family: inherit;
  border: 1px solid #111;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  transition: border-color 0.3s ease;
}

#firmware-selector:focus {
  outline: none;
  border-color: #3a5b81;
}

.advanced-options {
  margin-top: 20px;
  padding: 10px;
  border: 1px solid #555;
  border-radius: 6px;
  background-color: #8e92a0;
}

.advanced-options summary {
  cursor: pointer;
  font-weight: 500;
  padding: 5px;
  user-select: none;
}

.advanced-options summary:hover {
  color: #555;
}

.advanced-options summary:focus {
  outline: none;
}

.firmware-upload {
  margin-top: 15px;
}

.option-description {
  font-size: 12px;
  margin-bottom: 10px;
  text-transform: none;
  font-style: italic;
  color: #444;
}

#firmware-file-input {
  width: 100%;
  padding: 10px;
  border: 1px solid #111;
  background-color: rgba(255, 255, 255, 0.1);
  font-family: inherit;
  margin-top: 5px;
  border-radius: 6px;
}

.firmware-actions {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

#update-firmware-button {
  padding: 15px 30px;
  font-size: 16px;
  background-color: #111;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

#update-firmware-button:disabled {
  background-color: #888;
  cursor: not-allowed;
}

.firmware-status {
  background-color: #9da1ad;
  border-radius: 6px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

#firmware-status-message {
  text-align: center;
  font-weight: 500;
  font-size: 16px;
}

#firmware-progress-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#firmware-progress {
  width: 100%;
  height: 15px;
  -webkit-appearance: none;
  appearance: none;
}

#firmware-progress::-webkit-progress-bar {
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}

#firmware-progress::-webkit-progress-value {
  background-color: #111;
  border-radius: 10px;
}

#firmware-progress-text {
  font-size: 14px;
  font-weight: bold;
}

#firmware-log {
  margin-top: 10px;
  max-height: 150px;
  overflow-y: auto;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  font-family: monospace;
  font-size: 12px;
  text-transform: none;
}

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

.log-info {
  color: #111;
}

.log-warning {
  color: #8a4f00;
  background-color: #fff3cd;
}

.log-error {
  color: #721c24;
  background-color: #f8d7da;
}