/* ============================================================================
   SCENEMAKER — CSS TOKENS & COMPONENT STYLES
   Dark-themed wizard UI for X Air preset generator
   ========================================================================== */

/* ============================================================================
   CSS VARIABLES (Design Tokens)
   ========================================================================== */

:root {
  /* Colors */
  --bg: #0e0e0e;
  --bg-card: #1a1a1a;
  --bg-input: #111;
  --border: #333;
  --border-active: #4a9eff;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #4a9eff;
  --accent-green: #9eff4a;
  --accent-orange: #ff9e4a;
  --accent-red: #ff4a4a;
  --accent-yellow: #ffde4a;

  /* Spacing & Sizing */
  --radius: 8px;
  --radius-sm: 4px;

  /* Typography */
  --font: system-ui, -apple-system, sans-serif;
  --mono: 'Courier New', monospace;

  /* Transitions */
  --transition: 200ms ease;
}

/* ============================================================================
   RESET
   ========================================================================== */

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

html, body {
  width: 100%;
}

/* ============================================================================
   BODY & GENERAL
   ========================================================================== */

body {
  background-color: var(--bg);
  color: var(--text);
  font: 14px / 1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ============================================================================
   PROGRESS BAR (Header)
   ========================================================================== */

#progress-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 16px;
  min-height: 60px;
}

.progress-steps {
  grid-column: 2;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.lang-toggle {
  grid-column: 3;
  justify-self: end;
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.lang-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 6px 10px;
  font: 600 12px var(--font);
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all var(--transition);
}

.lang-btn + .lang-btn {
  border-left: 1px solid var(--border);
}

.lang-btn:hover:not(.active) {
  background-color: rgba(74, 158, 255, 0.1);
  color: var(--text);
}

.lang-btn.active {
  background-color: var(--accent);
  color: var(--bg);
}

/* ============================================================================
   PROGRESS STEP INDICATORS
   ========================================================================== */

.progress-step {
  display: flex;
  align-items: center;
  gap: 6px;
}

.progress-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  transition: all var(--transition);
  cursor: pointer;
}

.progress-dot:hover {
  border-color: var(--accent);
}

.progress-dot.active {
  background-color: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.progress-dot.completed {
  background-color: var(--accent-green);
  color: var(--bg);
  border-color: var(--accent-green);
}

.progress-dot.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.progress-sep {
  width: 20px;
  height: 2px;
  background-color: var(--border);
  transition: background-color var(--transition);
}

.progress-sep.active {
  background-color: var(--accent);
}

/* ============================================================================
   MAIN APP CONTAINER
   ========================================================================== */

#app {
  flex: 1;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 16px;
}

/* ============================================================================
   TYPOGRAPHY
   ========================================================================== */

h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

/* ============================================================================
   CARDS & GRID (Selection Cards)
   ========================================================================== */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background-color: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  position: relative;
}

.card:hover:not(.disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(74, 158, 255, 0.2);
}

.card.selected {
  background-color: rgba(74, 158, 255, 0.15);
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(74, 158, 255, 0.3);
}

.card.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.card-icon {
  font-size: 32px;
  margin-bottom: 8px;
  display: block;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================================
   CHANNEL ROWS (Channel Configuration)
   ========================================================================== */

.channel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  transition: all var(--transition);
}

.channel-row:hover {
  border-color: var(--border-active);
  background-color: rgba(74, 158, 255, 0.05);
}

/* Drag handle (grip dots) */
.drag-handle {
  display: flex;
  align-items: center;
  cursor: grab;
  padding: 4px 2px;
  opacity: 0.3;
  transition: opacity 0.15s;
  flex-shrink: 0;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
.instrument-group:hover .drag-handle { opacity: 0.7; }
.drag-handle-spacer { width: 16px; flex-shrink: 0; }

/* Instrument group (draggable) */
.instrument-group {
  border-radius: var(--radius-sm);
  transition: opacity 0.2s, transform 0.2s;
  margin-bottom: 2px;
}
.instrument-group.dragging {
  opacity: 0.3;
  transform: scale(0.98);
}

/* Drop indicator (animated gap) */
.drop-indicator {
  height: 0;
  transition: height 0.2s ease, opacity 0.2s ease;
  overflow: hidden;
  position: relative;
}
.drop-indicator.active {
  height: 40px;
}
.drop-indicator.active::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 10%;
  right: 10%;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  transform: translateY(-50%);
  animation: dropPulse 1s ease infinite;
}
@keyframes dropPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.channel-num {
  font-weight: 700;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  min-width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.channel-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.channel-icon svg { width: 20px; height: 20px; color: var(--text-muted); }

.channel-name {
  flex: 1;
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-subtype {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.channel-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.channel-row:hover .channel-actions { opacity: 0.8; }
.channel-actions svg { width: 16px; height: 16px; }

/* Explicit remove button (replaces bare X icon) */
.btn-remove-channel {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--accent-red);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent-red);
  font: 11px var(--font);
  cursor: pointer;
  opacity: 0.6;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-remove-channel:hover {
  opacity: 1;
  background: rgba(255, 74, 74, 0.1);
}
.channel-row:hover .btn-remove-channel,
.instrument-group:hover .btn-remove-channel {
  opacity: 1;
}

/* Inline scenario preview (inside badge card) */
.scenario-detail {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  text-align: left;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
}
.scenario-detail ul {
  margin: 4px 0 0;
  padding-left: 16px;
}
.scenario-detail strong {
  color: var(--text);
  font-size: 12px;
}

/* ============================================================================
   FX TOGGLE (Tri-state Button Group)
   ========================================================================== */

.fx-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
}

.fx-toggle button {
  flex: 1;
  padding: 10px 12px;
  background-color: transparent;
  color: var(--text-muted);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: all var(--transition);
}

.fx-toggle button:last-child {
  border-right: none;
}

.fx-toggle button:hover {
  background-color: rgba(74, 158, 255, 0.1);
  color: var(--text);
}

.fx-toggle button.active {
  background-color: var(--accent);
  color: var(--bg);
}

/* ============================================================================
   AUX SECTION & SLIDERS
   ========================================================================== */

.aux-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}

.aux-header {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.slider-row {
  display: grid;
  grid-template-columns: 80px 1fr 50px;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

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

.slider-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  text-align: right;
}

.slider-range {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background-color: var(--border);
  appearance: none;
  cursor: pointer;
}

.slider-range::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--accent);
  cursor: pointer;
  transition: all var(--transition);
  border: 2px solid var(--bg-card);
}

.slider-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--accent);
  cursor: pointer;
  transition: all var(--transition);
  border: 2px solid var(--bg-card);
}

.slider-range::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

.slider-range::-moz-range-thumb:hover {
  transform: scale(1.25);
}

.slider-value {
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  font-size: 13px;
  font-family: var(--mono);
  min-width: 40px;
}

/* ============================================================================
   BUTTONS
   ========================================================================== */

.btn {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: var(--text);
  font: 13px / 1 var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.btn:hover:not(:disabled) {
  background-color: rgba(74, 158, 255, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn.primary {
  background-color: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.btn.primary:hover:not(:disabled) {
  background-color: #3a8eef;
  border-color: #3a8eef;
  box-shadow: 0 0 12px rgba(74, 158, 255, 0.4);
}

.btn.primary:active:not(:disabled) {
  background-color: #2a7edf;
}

.btn.danger {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.btn.danger:hover:not(:disabled) {
  background-color: rgba(255, 74, 74, 0.1);
  border-color: var(--accent-red);
}

.btn.success {
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.btn.success:hover:not(:disabled) {
  background-color: rgba(158, 255, 74, 0.1);
  border-color: var(--accent-green);
}

.btn-group {
  display: flex;
  gap: 8px;
  margin-top: 24px;
}

.btn-group .btn {
  flex: 1;
}

/* ============================================================================
   BOTTOM NAVIGATION BAR
   ========================================================================== */

.nav-bar {
  position: sticky;
  bottom: 0;
  background-color: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 99;
  flex-shrink: 0;
}

.nav-bar .btn {
  min-width: 120px;
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */

#toast-container {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border-left: 4px solid;
  background-color: var(--bg-card);
  border-color: var(--border);
  color: var(--text);
  animation: fadeIn 200ms ease;
  pointer-events: auto;
  max-width: 300px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.toast.error {
  border-color: var(--accent-red);
  color: var(--accent-red);
  background-color: rgba(255, 74, 74, 0.1);
}

.toast.warn {
  border-color: var(--accent-orange);
  color: var(--accent-orange);
  background-color: rgba(255, 158, 74, 0.1);
}

.toast.info {
  border-color: var(--accent);
  color: var(--accent);
  background-color: rgba(74, 158, 255, 0.1);
}

.toast.ok {
  border-color: var(--accent-green);
  color: var(--accent-green);
  background-color: rgba(158, 255, 74, 0.1);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================================
   MODAL OVERLAY & DIALOG
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  animation: fadeIn 200ms ease;
}

.modal {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 300ms ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal h2 {
  margin-bottom: 12px;
}

.modal .subtitle {
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 24px;
  justify-content: flex-end;
}

.modal-actions .btn {
  min-width: 100px;
}

/* ============================================================================
   COUNTER (Numeric Badge)
   ========================================================================== */

.counter {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
}

/* ============================================================================
   BANNERS
   ========================================================================== */

.banner {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  margin-bottom: 16px;
  font-size: 13px;
  line-height: 1.5;
}

.banner.warn {
  background-color: rgba(255, 222, 74, 0.1);
  border-color: var(--accent-yellow);
  color: var(--accent-orange);
}

.banner.info {
  background-color: rgba(74, 158, 255, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.banner.error {
  background-color: rgba(255, 74, 74, 0.1);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* ============================================================================
   ADD ROW / LIST ITEM
   ========================================================================== */

.add-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  margin-bottom: 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
}

.add-row:hover {
  border-color: var(--accent);
  background-color: rgba(74, 158, 255, 0.05);
  color: var(--accent);
}

.add-row svg {
  margin-right: 6px;
}

/* ============================================================================
   FORM INPUTS
   ========================================================================== */

input[type="text"],
input[type="number"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: 13px var(--font);
  transition: all var(--transition);
  font-family: inherit;
}

input[type="text"]::placeholder,
input[type="number"]::placeholder,
input[type="email"]::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--bg-card);
  box-shadow: 0 0 8px rgba(74, 158, 255, 0.2);
}

input[type="text"]:disabled,
input[type="number"]:disabled,
input[type="email"]:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--bg-card);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

/* ============================================================================
   LABELS & FORM GROUPS
   ========================================================================== */

label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 13px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ============================================================================
   UTILITY CLASSES
   ========================================================================== */

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.text-muted {
  color: var(--text-muted);
}

.text-accent {
  color: var(--accent);
}

.text-green {
  color: var(--accent-green);
}

.text-orange {
  color: var(--accent-orange);
}

.text-red {
  color: var(--accent-red);
}

.text-yellow {
  color: var(--accent-yellow);
}

.mt-8 {
  margin-top: 8px;
}

.mt-16 {
  margin-top: 16px;
}

.mt-24 {
  margin-top: 24px;
}

.mb-8 {
  margin-bottom: 8px;
}

.mb-16 {
  margin-bottom: 16px;
}

.mb-24 {
  margin-bottom: 24px;
}

.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden;
}

.opacity-50 {
  opacity: 0.5;
}

.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gap-8 {
  gap: 8px;
}

.gap-12 {
  gap: 12px;
}

.gap-16 {
  gap: 16px;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 600px) {
  #app {
    padding: 24px 12px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  /* Progress bar: stack toggle above steps on mobile to avoid overlap */
  #progress-bar {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    padding: 6px 10px 8px;
    min-height: 0;
    gap: 4px;
  }

  .progress-steps {
    grid-column: 1;
    grid-row: 2;
    gap: 6px;
  }

  .lang-toggle {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
  }

  .progress-step {
    gap: 0;
  }

  .progress-step span {
    display: none;
  }

  .progress-dot {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  .progress-sep {
    width: 12px;
  }

  .lang-btn {
    padding: 4px 8px;
    font-size: 11px;
  }

  .slider-row {
    grid-template-columns: 70px 1fr 40px;
  }

  .nav-bar {
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }

  .nav-bar .btn {
    min-width: 80px;
    padding: 10px 12px;
    font-size: 12px;
  }

  .modal {
    width: 95%;
    padding: 20px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  /* Delete button always visible on mobile */
  .channel-actions {
    opacity: 0.8;
  }

  /* Drag handle always visible on mobile */
  .drag-handle {
    opacity: 0.5;
  }
}

/* ============================================================================
   ACCESSIBILITY & FOCUS STATES
   ========================================================================== */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
  #progress-bar,
  .nav-bar,
  .btn,
  #toast-container {
    display: none;
  }

  body {
    background-color: white;
    color: black;
    padding-bottom: 0;
  }

  #app {
    max-width: 100%;
  }
}
