/* ===================================================================
   Handy Control Panel — Dark Glassmorphism Design
   =================================================================== */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-hover: rgba(255, 255, 255, 0.06);

  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;

  --accent-primary: #6c5ce7;
  --accent-secondary: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.3);

  --success: #00cec9;
  --success-glow: rgba(0, 206, 201, 0.3);
  --danger: #ff6b6b;
  --danger-glow: rgba(255, 107, 107, 0.3);
  --warning: #feca57;
  --warning-glow: rgba(254, 202, 87, 0.3);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(108, 92, 231, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(0, 206, 201, 0.06) 0%, transparent 50%);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: 20px;
}

/* === Glass Effect === */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* === Header === */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  margin-bottom: 16px;
}

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

.logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-sm);
  color: white;
}

.header h1 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.status-indicator:hover {
  background: rgba(255, 255, 255, 0.08);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}

.status-indicator.online .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success-glow);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-indicator.offline .status-dot {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger-glow);
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

/* === Info Bar === */
.info-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
}

.info-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 500;
}

.info-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* === Controls Grid === */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  align-items: start;
}

@media (max-width: 700px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .info-bar {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

/* === Control Cards === */
.control-card {
  border-radius: var(--radius-xl);
  padding: 24px;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

.control-card.collapsed-card {
  /* When the wrapper is collapsed, allow the card to shrink naturally */
  justify-content: flex-start;
}

.control-card:hover {
  background: var(--glass-hover);
  border-color: rgba(255, 255, 255, 0.1);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s;
}

.card-header:hover {
  opacity: 0.8;
}

.card-header .chevron {
  transition: transform 0.3s ease;
  color: var(--text-muted);
}

.card-header.collapsed .chevron {
  transform: rotate(-90deg);
}

.card-body-wrapper {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease;
  opacity: 1;
}

.card-body-inner {
  overflow: hidden;
  padding-top: 6px;
}

.card-body-wrapper.collapsed {
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
}

.card-body-wrapper.collapsed .card-body-inner {
  padding-top: 0;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.card-header h2 svg {
  color: var(--accent-secondary);
}

.card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.4;
}

.card-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 100px;
  background: rgba(0, 206, 201, 0.12);
  color: var(--success);
  border: 1px solid rgba(0, 206, 201, 0.2);
}

.card-badge.badge-alt {
  background: rgba(108, 92, 231, 0.12);
  color: var(--accent-secondary);
  border-color: rgba(108, 92, 231, 0.2);
}

.card-badge.active {
  background: rgba(0, 206, 201, 0.2);
  box-shadow: 0 0 12px var(--success-glow);
}

/* === Control Groups === */
.control-group {
  margin-bottom: 18px;
}

.toggle-row {
  display: flex;
  gap: 10px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-start {
  flex: 1;
  background: linear-gradient(135deg, rgba(0, 206, 201, 0.15), rgba(0, 206, 201, 0.08));
  color: var(--success);
  border: 1px solid rgba(0, 206, 201, 0.25);
}

.btn-start:hover {
  background: linear-gradient(135deg, rgba(0, 206, 201, 0.25), rgba(0, 206, 201, 0.15));
  box-shadow: 0 0 20px var(--success-glow);
}

.btn-stop {
  flex: 1;
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.15), rgba(255, 107, 107, 0.08));
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.25);
}

.btn-stop:hover {
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.25), rgba(255, 107, 107, 0.15));
  box-shadow: 0 0 20px var(--danger-glow);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent-primary), #5a4bd1);
  color: white;
  border: 1px solid rgba(108, 92, 231, 0.4);
}

.btn-accent:hover {
  box-shadow: 0 0 24px var(--accent-glow);
  filter: brightness(1.1);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}

.btn-outline:hover {
  background: var(--glass-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-full {
  width: 100%;
}

/* === Sliders === */
.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.slider-value {
  font-weight: 700;
  color: var(--accent-secondary);
  font-variant-numeric: tabular-nums;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.06);
  outline: none;
  transition: var(--transition);
}

.slider:hover {
  background: rgba(255, 255, 255, 0.1);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 10px var(--accent-glow);
  transition: var(--transition);
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 18px var(--accent-glow);
}

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 10px var(--accent-glow);
}

.slider-accent::-webkit-slider-thumb {
  background: linear-gradient(135deg, #00cec9, #00b894);
  box-shadow: 0 0 10px var(--success-glow);
}

.slider-accent::-moz-range-thumb {
  background: linear-gradient(135deg, #00cec9, #00b894);
  box-shadow: 0 0 10px var(--success-glow);
}

.slider-range::-webkit-slider-thumb {
  background: linear-gradient(135deg, #feca57, #f39c12);
  box-shadow: 0 0 10px var(--warning-glow);
}

.slider-range::-moz-range-thumb {
  background: linear-gradient(135deg, #feca57, #f39c12);
  box-shadow: 0 0 10px var(--warning-glow);
}

.slider-marks {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 8px;
  aspect-ratio: 1 / 1;
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.preset-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.preset-btn:active {
  transform: translateY(0) scale(0.97);
}

.preset-btn.active {
  background: rgba(108, 92, 231, 0.2);
  border-color: var(--accent-secondary);
  box-shadow: 0 0 12px rgba(108, 92, 231, 0.4);
}

.preset-icon {
  font-size: 2.2rem;
}

.preset-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.preset-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.preset-pattern {
  border-color: rgba(108, 92, 231, 0.2);
}

.preset-pattern:hover {
  border-color: rgba(108, 92, 231, 0.4);
  box-shadow: 0 0 15px var(--accent-glow);
}

.preset-stop {
  border-color: rgba(255, 107, 107, 0.4);
  background: rgba(255, 107, 107, 0.15);
  grid-column: span 1;
}

.preset-stop:hover {
  border-color: rgba(255, 107, 107, 0.5);
  box-shadow: 0 0 15px var(--danger-glow);
  background: rgba(255, 107, 107, 0.08);
}

/* === Toast Notifications === */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 1000;
  max-width: 340px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 500;
  animation: toast-in 0.3s ease-out;
  border: 1px solid;
}

.toast-success {
  background: rgba(0, 206, 201, 0.12);
  color: var(--success);
  border-color: rgba(0, 206, 201, 0.2);
}

.toast-error {
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.2);
}

.toast-info {
  background: rgba(108, 92, 231, 0.12);
  color: var(--accent-secondary);
  border-color: rgba(108, 92, 231, 0.2);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.toast-exit {
  animation: toast-out 0.2s ease-in forwards;
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-5px) scale(0.95);
  }
}

/* === Loading Shimmer === */
.shimmer {
  background: linear-gradient(90deg,
      rgba(255, 255, 255, 0.03) 25%,
      rgba(255, 255, 255, 0.08) 50%,
      rgba(255, 255, 255, 0.03) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* === Disabled state === */
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* === Responsive fine-tuning === */
@media (max-width: 500px) {
  .app {
    padding: 12px;
  }

  .header h1 {
    font-size: 1.15rem;
  }

  .control-card {
    padding: 18px;
  }

  .preset-grid {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
  }

  .preset-btn {
    padding: 10px 4px;
  }

  .preset-icon {
    font-size: 1.8rem;
  }
}

/* ===================================================================
   Focus Mode (Quick Presets Full Screen)
   =================================================================== */

body.focus-mode {
  overflow: hidden;
  /* Prevent scrolling outside the grid */
}

/* Hide everything else when in focus mode */
body.focus-mode .header,
body.focus-mode .info-bar,
body.focus-mode #hampCard,
body.focus-mode .control-card:not([style*="grid-column: 1 / -1;"]),
body.focus-mode .timeline-section,
body.focus-mode .card-header,
body.focus-mode .card-body-wrapper.collapsed .card-body-inner

/* Ensure it's not collapsed even if state says so */
  {
  display: none !important;
}

/* Expand the Quick Presets section */
body.focus-mode .control-card[style*="grid-column: 1 / -1;"] {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  border-radius: 0;
  border: none;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  padding: 70px 24px 16px 24px;
  /* 70px top padding clears the floating exit button */
  overflow-y: hidden;
  /* Prevent scrolling inside the card */
}

body.focus-mode .control-card[style*="grid-column: 1 / -1;"] .card-body-wrapper {
  grid-template-rows: 1fr;
  opacity: 1;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-height: 0;
  /* Important for flex shrink */
}

body.focus-mode .control-card[style*="grid-column: 1 / -1;"] .card-body-inner {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-height: 0;
  padding-top: 16px;
}

body.focus-mode .preset-grid {
  flex-grow: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(0, 1fr);
  /* Distribute height evenly, prevent row overflow */
  gap: 12px;
  align-content: stretch;
  min-height: 0;
  height: 100%;
}

body.focus-mode .preset-btn {
  aspect-ratio: unset;
  /* Let it shrink to be rectangular if needed */
  min-height: 0;
  height: 100%;
  padding: 8px 4px;
}

body.focus-mode .preset-icon {
  font-size: min(2.5rem, 5vh);
}

body.focus-mode .preset-name {
  font-size: min(1.1rem, 2.3vh);
}

body.focus-mode .preset-detail {
  font-size: min(0.85rem, 2vh);
}

/* Floating Exit Button */
.floating-exit-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  /* Respect iOS notch/dynamic island */
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 107, 107, 0.15);
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.3);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: var(--transition);
}

.floating-exit-btn:hover {
  background: rgba(255, 107, 107, 0.25);
  box-shadow: 0 0 15px var(--danger-glow);
  transform: scale(1.05);
}

.floating-exit-btn:active {
  transform: scale(0.95);
}

body.focus-mode .floating-exit-btn {
  display: flex;
}

#floatingRandomStrokeBtn {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 70px;
  height: 44px;
  border-radius: var(--radius-md);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 0.85rem;
  font-family: var(--font);
  font-weight: 500;
  z-index: 1000;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: var(--transition);
  border-width: 1px;
  border-style: solid;
}

body.focus-mode #floatingRandomStrokeBtn {
  display: flex;
}

#floatingRandomStrokeBtn.active {
  background: rgba(108, 92, 231, 0.25);
  border-color: var(--accent-secondary);
  color: var(--accent-secondary);
  box-shadow: 0 0 15px var(--accent-glow);
}

#floatingRandomStrokeBtn:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.02);
}

#floatingRandomStrokeBtn.active:hover {
  background: rgba(108, 92, 231, 0.35);
}

#floatingRandomStrokeBtn:active {
  transform: scale(0.98);
}

/* Responsive adjustment for focus mode */
@media (max-width: 500px) {
  body.focus-mode .preset-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ===================================================================
   Timeline
   =================================================================== */

.timeline-section {
  margin-top: 24px;
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 20px;
}

.timeline-section .card-header {
  margin-bottom: 12px;
}

.timeline-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.palette-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 100px;
  cursor: grab;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  transition: var(--transition);
  user-select: none;
}

.palette-chip:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.palette-chip:active {
  cursor: grabbing;
}

.palette-chip .chip-icon {
  font-size: 0.9rem;
}

.timeline-track {
  display: flex;
  align-items: stretch;
  min-height: 56px;
  border: 2px dashed rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.2);
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  transition: border-color 0.2s;
  padding-top: 16px;

  /* Hide scrollbar */
  scrollbar-width: none;
  /* Firefox */
  -ms-overflow-style: none;
  /* IE/Edge */
}

.timeline-track::-webkit-scrollbar {
  display: none;
  /* Chrome/Safari */
}

.timeline-markers {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 14px;
  pointer-events: none;
}

.tl-marker {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  padding-left: 3px;
  line-height: 14px;
}

.timeline-track.drag-over {
  border-color: var(--accent-secondary);
  background: rgba(108, 92, 231, 0.06);
}

.timeline-track.empty::after {
  content: 'Drag presets here to build a sequence';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  pointer-events: none;
}

.timeline-segment {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  border-radius: 6px;
  margin: 4px 2px;
  cursor: default;
  user-select: none;
  overflow: hidden;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.timeline-segment .seg-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.timeline-segment .seg-dur {
  font-size: 0.6rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 2px;
}

.seg-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 2;
  background: transparent;
  transition: background 0.15s;
}

.seg-handle:hover,
.seg-handle.active {
  background: rgba(255, 255, 255, 0.2);
}

.seg-handle-left {
  left: 0;
  border-radius: 6px 0 0 6px;
}

.seg-handle-right {
  right: 0;
  border-radius: 0 6px 6px 0;
}

.seg-delete {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.7);
  border: none;
  font-size: 0.55rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 3;
  line-height: 1;
  padding: 0;
  font-family: var(--font);
}

.timeline-segment:hover .seg-delete {
  display: flex;
}

.timeline-segment .seg-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.15);
  pointer-events: none;
  width: 0;
  transition: none;
}

.timeline-segment.active-seg {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: -1px;
}

.seg-drop-indicator {
  position: absolute;
  top: 4px;
  bottom: 8px;
  width: 3px;
  background: var(--accent-secondary);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--accent-glow);
  pointer-events: none;
  z-index: 10;
}

.timeline-segment[draggable="true"] {
  cursor: grab;
}

.timeline-segment[draggable="true"]:active {
  cursor: grabbing;
}

.timeline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.tl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.tl-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.tl-btn:active {
  transform: scale(0.96);
}

.tl-btn.tl-play {
  background: linear-gradient(135deg, rgba(0, 206, 201, 0.15), rgba(0, 206, 201, 0.08));
  color: var(--success);
  border-color: rgba(0, 206, 201, 0.25);
}

.tl-btn.tl-play:hover {
  box-shadow: 0 0 16px var(--success-glow);
}

.tl-btn.tl-stop {
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.15), rgba(255, 107, 107, 0.08));
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.25);
}

.tl-btn.tl-repeat {
  opacity: 0.5;
  border-style: dashed;
}

.tl-btn.tl-repeat.active {
  opacity: 1;
  border-style: solid;
  background: rgba(108, 92, 231, 0.2);
  color: var(--accent-secondary);
  border-color: rgba(108, 92, 231, 0.5);
  box-shadow: 0 0 12px var(--accent-glow);
}

.tl-duration-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  font-family: var(--font);
}

.tl-duration-input {
  width: 48px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  outline: none;
}

.tl-duration-input:focus {
  border-color: var(--accent-secondary);
}

.tl-total-time {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 500px) {
  .timeline-section {
    padding: 16px;
  }

  .timeline-track {
    min-height: 48px;
  }

  .palette-chip {
    font-size: 0.7rem;
    padding: 4px 8px;
  }
}

/* === Settings Modal === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 9999;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  width: 90%;
  max-width: 400px;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-overlay.active .modal-content {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--glass-border);
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.settings-btn:hover {
  color: var(--text-primary) !important;
}