:root {
  --panel: rgba(14, 16, 22, 0.72);
  --line: rgba(255, 255, 255, 0.07);
  --ok: #9fd0b0;
}

#bgCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: -2;
}

#status-pill.live {
  color: var(--ok);
}

.center-wrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 4;
  pointer-events: none;
  padding: 18px;
}

.stage-card {
  position: relative;
  pointer-events: auto;
  width: min(760px, calc(100vw - 28px));
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: radial-gradient(120% 140% at 50% -20%, rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.07), transparent 55%), linear-gradient(180deg, rgba(14, 16, 22, 0.72), rgba(9, 11, 16, 0.78));
  backdrop-filter: blur(22px) saturate(120%);
  -webkit-backdrop-filter: blur(22px) saturate(120%);
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.025);
  overflow: hidden;
}

.stage-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.03), transparent 35%, rgba(255, 255, 255, 0.015));
  opacity: .9;
  z-index: 0;
}

.stage {
  position: relative;
  height: 320px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.stage * {
  position: relative;
  z-index: 1;
}

.glow {
  position: absolute;
  inset: auto 50% 53% auto;
  width: 420px;
  height: 420px;
  transform: translate(50%, 50%);
  background: radial-gradient(circle, rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.14), rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.05) 35%, rgba(200, 212, 255, 0.00) 70%);
  filter: blur(8px);
  pointer-events: none;
  z-index: 0;
}

.phase-indicator {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 300;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.11);
  pointer-events: none;
}

.orb-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.orb {
  width: 128px;
  height: 128px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03) 42%, rgba(255, 255, 255, 0.015) 58%, rgba(255, 255, 255, 0.00) 75%), radial-gradient(circle, rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.06), rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.015) 60%, rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0) 80%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.03) inset, 0 0 32px rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.08), 0 8px 24px rgba(0, 0, 0, 0.22);
  transform: scale(1);
  opacity: .9;
  transition: transform 1.3s ease, opacity 1.3s ease;
}

.orb.rise {
  transform: scale(1.1);
  opacity: 1;
}

.caption {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 64px;
  text-align: center;
  color: rgba(231, 234, 238, 0.92);
  font-size: 15px;
  letter-spacing: 0.01em;
  min-height: 1.4em;
  transition: opacity 600ms ease;
  text-wrap: balance;
  padding: 0 10px;
  pointer-events: none;
}

.caption.dim {
  opacity: 0.6;
}

canvas#wave {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 62px;
  display: block;
  opacity: .85;
  pointer-events: none;
}

.toggle,
.range-wrap {
  appearance: none;
  font-family: var(--font-main);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.83);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px 13px;
  transition: background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle:hover,
.range-wrap:hover {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.97);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.primary {
  color: #fff !important;
}

.stop {
  color: #f2d8d8 !important;
}

.segment {
  display: inline-flex;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.015);
}

.segment button {
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 0;
  min-width: 58px;
  background: transparent;
  padding: 10px 14px;
}

.segment button:last-child {
  border-right: 0;
}

.segment button.active {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  user-select: none;
  cursor: pointer;
}

.toggle input {
  margin: 0;
}

.range-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: rgba(255, 255, 255, 0.6);
}

.range-wrap .label {
  font-size: 12px;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.38);
}

input[type="range"] {
  width: 124px;
  accent-color: rgb(var(--accent-r), var(--accent-g), var(--accent-b));
}

.status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: rgba(255, 255, 255, 0.46);
  font-size: 12px;
  letter-spacing: .3px;
  margin-top: 2px;
  padding: 0 10px;
}

.status .live {
  color: var(--ok);
}

.hint {
  color: rgba(255, 255, 255, 0.35);
  font-size: 12px;
  line-height: 1.35;
  padding: 0 10px;
}

#top-actions {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 12;
  display: inline-flex;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .6s ease, visibility .6s ease;
}

#top-actions.visible {
  opacity: 1;
  visibility: visible;
}

#top-actions button {
  padding: 9px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.005)), linear-gradient(180deg, rgba(12, 14, 18, 0.62), rgba(8, 10, 14, 0.74));
  border: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(16px) saturate(125%);
  -webkit-backdrop-filter: blur(16px) saturate(125%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

@media (max-width: 820px) {
  .stage {
    height: 300px;
  }

  .controls {
    gap: 8px;
  }
}

@media (max-width: 640px) {
  .stage-card {
    width: min(760px, calc(100vw - 16px));
  }

  .stage {
    height: 286px;
  }

  .phase-indicator {
    font-size: 16px;
    letter-spacing: 2px;
    top: 12px;
  }

  .orb {
    width: 112px;
    height: 112px;
  }

  .caption {
    bottom: 60px;
    font-size: 14px;
  }

  .row {
    gap: 6px;
  }

  .range-wrap {
    width: 100%;
    justify-content: space-between;
  }

  input[type="range"] {
    width: 112px;
  }

  #top-actions {
    top: 10px;
    left: 10px;
  }

  #top-actions button {
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* --- RESPONSIVE OPTIMIERUNGEN --- */

@media (max-width: 600px) {
  /* Abstände der Hauptkarte verringern */
  .center-wrap {
    padding: 10px;
    align-items: center; /* Zentrierung sicherstellen */
  }

  .stage-card {
    width: 100%;
    border-radius: 20px;
    padding: 15px;
  }

  /* Der Orb (Kreis) etwas kleiner auf dem Handy */
  #orb {
    width: 140px;
    height: 140px;
  }

  /* Schriftgrößen anpassen */
  h1, .stage-card h2 {
    font-size: 1.4rem;
  }

  #caption {
    font-size: 1rem;
    min-height: 3em; /* Platz für zweizeiligen Text reservieren */
  }

  /* Die Button-Gitter (Presets, BPM etc.) kompakter machen */
  .segment, .audio-mode, .preset-mode {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 Spalten statt nebeneinander */
    gap: 8px;
  }

  .segment button, .audio-mode button, .preset-mode button {
    padding: 8px 5px;
    font-size: 0.85rem;
    width: 100%;
  }

  /* Footer-Steuerung (Start/Stop) fixieren oder verkleinern */
  .controls-footer {
    flex-direction: column;
    gap: 10px;
  }

  #startBtn, #stopBtn {
    width: 100%;
    padding: 14px;
  }

  /* Verstecke weniger wichtige Infos auf sehr kleinen Screens */
  #status-pill {
    font-size: 0.7rem;
    top: 10px;
  }

  #app-brand {
    font-size: 0.8rem;
    bottom: 10px;
  }
}

/* Spezielle Anpassung für sehr kleine Handys oder Landscape-Modus */
@media (max-height: 500px) and (orientation: landscape) {
  .center-wrap {
    position: relative;
    display: block;
    overflow-y: auto;
  }
  
  .stage-card {
    margin: 20px auto;
  }
}