/* ==========================================================================
   MICHAL BASAR — Sanctuary (8x8 live ritual map)
   Brand guide: two inks, two grounds — Ink #17130F, Cream #EFE3CC,
   Paper #F2EBDD, Black #0B0A09. Night = cream on black (idle),
   Day = ink on cream (active). Tenor Sans for headlines + numerals,
   Jost for body + controls. No shadows, no glows, no recolouring.

   Contents
     1. Tokens + page
     2. Hero (incense)
     3. Transport bar (play · stop · moods · tempo · ½ · menu)
     4. Moods + RANDOM
     5. Settings menu
     6. Workspace + 9-column board
     7. Headers + symbols
     8. Pads + row launches
     9. ECHO / SPACE sends + master echo
    10. Square faders + LOW CUT
    11. Precision view
    12. Touch: no text selection
    13. TRIP / OBE visuals
    14. Tablet (≤ 1100px) · narrow (≤ 880px)
    15. Phone (≤ 680px)
    16. Phone landscape (short screens)
    17. Reduced motion
   ========================================================================== */

/* ==========================================================================
   1. Tokens + page
   ========================================================================== */
:root {
  --mb-ink: #17130F;
  --mb-cream: #EFE3CC;
  --mb-paper: #F2EBDD;
  --mb-black: #0B0A09;

  --mb-line: rgba(239, 227, 204, 0.14);
  --mb-line-strong: rgba(239, 227, 204, 0.36);
  --mb-cream-muted: rgba(239, 227, 204, 0.64);
  --mb-cream-dim: rgba(239, 227, 204, 0.38);

  --font-headline: 'Tenor Sans', sans-serif;
  --font-body: 'Jost', -apple-system, BlinkMacSystemFont, sans-serif;
}

html:has(body.session-body) {
  scroll-snap-type: y proximity;
  scroll-behavior: smooth;
}

body.session-body {
  background-color: var(--mb-black);
  color: var(--mb-cream);
  font-family: var(--font-body);
  font-weight: 300;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input {
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  border-color: var(--mb-cream);
}

/* ==========================================================================
   2. Hero — palo santo with living smoke (drawn by sanctuary-ui.js)
   ========================================================================== */
.sanctuary-hero {
  scroll-snap-align: start;
  padding: 8rem 1.5rem 2.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--mb-black);
}

.sanctuary-palo-santo {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mb-cream);
}

.palo-santo-svg {
  width: 86px;
  height: 152px;
  overflow: visible;
}

/* CSS drift until the live smoke takes over (and when motion is reduced) */
.smoke-plume {
  transform-origin: 60px 150px;
  animation: sanctuarySmokeRise 7.5s ease-in-out infinite alternate;
}

.smoke-plume-2 {
  animation-duration: 9.2s;
  animation-delay: -2.4s;
}

.palo-santo-svg.is-live-smoke .smoke-plume {
  animation: none !important;
  transform: none;
}

.palo-ember {
  animation: sanctuaryEmberBreathe 4.2s ease-in-out infinite alternate;
}

@keyframes sanctuarySmokeRise {
  0% { transform: translateY(0) translateX(-1.5px) scaleX(0.96); opacity: 0.32; }
  50% { transform: translateY(-4px) translateX(1.8px) scaleX(1.04); opacity: 0.72; }
  100% { transform: translateY(-7px) translateX(-1px) scaleX(0.98); opacity: 0.44; }
}

@keyframes sanctuaryEmberBreathe {
  0% { opacity: 0.48; }
  100% { opacity: 1; }
}

.sanctuary-title {
  font-family: var(--font-headline);
  font-size: clamp(1.85rem, 3.5vw, 2.75rem);
  font-weight: 400;
  letter-spacing: 0.36em;
  text-indent: 0.36em;
  text-transform: uppercase;
  color: var(--mb-cream);
  margin-bottom: 0.65rem;
}

.sanctuary-subtitle {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--mb-cream-muted);
  max-width: 460px;
  line-height: 1.6;
}

/* the steam: cream fog rising behind the candle (desktop only) */
.sanctuary-hero { position: relative; overflow: hidden; }

.sanctuary-hero > :not(.mb-fog) { position: relative; z-index: 1; }

.mb-fog {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* in the hero it melts into the black above and below */
.sanctuary-hero .mb-fog {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 22%, #000 70%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, #000 22%, #000 70%, transparent 100%);
}

/* ==========================================================================
   3. Transport bar
   ========================================================================== */
.daw-transport-bar {
  position: relative;
  z-index: 40; /* the settings menu sits above the (floating, 3D) grid */
  width: 100%;
  max-width: 1440px;
  margin: 0 auto 1.1rem;
  background: transparent;
  border-bottom: 1px solid var(--mb-line);
  padding: 0 0 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.transport-group {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.btn-transport-play,
.btn-transport-stop {
  width: 36px;
  height: 36px;
  border: 1px solid var(--mb-line-strong);
  background: var(--mb-black);
  color: var(--mb-cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-transport-play:hover,
.btn-transport-stop:hover {
  border-color: var(--mb-cream);
}

/* Day and Night inversion while playing */
.btn-transport-play.transport-playing {
  background: var(--mb-cream);
  color: var(--mb-ink);
  border-color: var(--mb-cream);
}

/* Tempo */
.daw-bpm-strip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--mb-black);
  border: 1px solid var(--mb-line);
  height: 36px;
  padding: 0 0.75rem;
}

.daw-bpm-strip label {
  font-family: var(--font-headline);
  font-size: 0.6rem;
  color: var(--mb-cream-muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
}

.bpm-display-text {
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--mb-cream);
  min-width: 58px;
  white-space: nowrap;
}

.bpm-slider {
  width: 84px;
}

input[type="range"].bpm-slider {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  height: 20px;
}

input[type="range"].bpm-slider::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--mb-line-strong);
}

input[type="range"].bpm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 8px;
  height: 16px;
  background: var(--mb-cream);
  border: none;
  border-radius: 0;
  margin-top: -7px;
}

input[type="range"].bpm-slider::-moz-range-track {
  height: 2px;
  background: var(--mb-line-strong);
}

input[type="range"].bpm-slider::-moz-range-thumb {
  width: 8px;
  height: 16px;
  background: var(--mb-cream);
  border: none;
  border-radius: 0;
}

/* track symbols respond to their own sound (scale set by JS) */
.track-symbol { transition: transform 0.08s ease-out; }

/* ½ tempo */
.btn-tempo-mod {
  width: 40px;
  height: 36px;
  flex-shrink: 0;
  background: var(--mb-black);
  border: 1px solid var(--mb-line);
  color: var(--mb-cream-muted);
  font-family: var(--font-headline);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-tempo-mod:hover {
  border-color: var(--mb-line-strong);
  color: var(--mb-cream);
}

.btn-tempo-mod.is-on {
  background: var(--mb-cream);
  border-color: var(--mb-cream);
  color: var(--mb-ink);
}

/* Settings button (the night mark) */
.sanctuary-menu-wrap {
  position: relative;
}

.btn-sanctuary-menu {
  width: 36px;
  height: 36px;
  background: var(--mb-black);
  border: 1px solid var(--mb-line);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn-sanctuary-menu img {
  display: block;
  opacity: 0.8;
  transition: opacity 0.15s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.btn-sanctuary-menu:hover,
.btn-sanctuary-menu.is-open {
  border-color: var(--mb-cream);
}

.btn-sanctuary-menu:hover img,
.btn-sanctuary-menu.is-open img {
  opacity: 1;
}

.btn-sanctuary-menu.is-open img {
  transform: rotate(45deg);
}

/* ==========================================================================
   4. Moods + RANDOM
   ========================================================================== */
.mood-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.mood-btn {
  height: 36px;
  padding: 0 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--mb-black);
  border: 1px solid var(--mb-line);
  color: var(--mb-cream-muted);
  font-family: var(--font-headline);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.mood-btn:hover,
.mood-btn.is-on {
  background: var(--mb-cream);
  color: var(--mb-ink);
  border-color: var(--mb-cream);
}

.mood-ico {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.mood-ico svg {
  width: 100%;
  height: 100%;
}

.mood-random { border-style: dashed; }
.mood-random.is-on { border-style: solid; }
.mood-random.is-on .mood-ico { animation: moodRandomSpin 6s linear infinite; }

@keyframes moodRandomSpin {
  0%, 85% { transform: none; }
  100% { transform: rotate(360deg); }
}

/* ==========================================================================
   5. Settings menu (loop warp · RANDOM length · trip)
   ========================================================================== */
.sanctuary-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 100;
  width: 300px;
  max-width: calc(100vw - 32px);
  background: rgba(11, 10, 9, 0.96);
  border: 1px solid var(--mb-line-strong);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sanctuary-menu[hidden] {
  display: none;
}

.sm-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.sm-title {
  font-family: var(--font-headline);
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  color: var(--mb-cream);
}


.sm-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 8px;
}

.sm-track {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-headline);
  font-size: 0.62rem;
  color: var(--mb-cream-muted);
}

.sm-sym img {
  height: 14px !important;
  width: auto !important;
  max-width: 20px !important;
  display: block;
}

.sm-seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

.sm-seg-4 {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.sm-seg button {
  height: 26px;
  background: var(--mb-black);
  border: 1px solid var(--mb-line);
  color: var(--mb-cream-muted);
  font-family: var(--font-body);
  font-size: 0.56rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sm-seg button:hover {
  border-color: var(--mb-line-strong);
  color: var(--mb-cream);
}

.sm-seg button.is-on {
  background: var(--mb-cream);
  border-color: var(--mb-cream);
  color: var(--mb-ink);
}

/* ==========================================================================
   6. Workspace + 9-column board (8 tracks + the master / row column)
   ========================================================================== */
.session-workspace {
  position: relative;
  box-sizing: border-box;
  scroll-snap-align: start;
  scroll-margin-top: 82px;
  flex: 1;
  min-height: calc(100vh - 82px);
  padding: 0.4rem clamp(12px, 2vw, 28px) 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}

.matrix-scroll-shell {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.session-matrix-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 5px;
  width: 100%;
  transform-origin: 50% 50%;
  user-select: none;
  touch-action: none;
}

/* all 8 track columns and the 9th column share the board's grid */
.tracks-container {
  display: contents;
}

.track-column,
.master-scene-column {
  min-width: 0;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.track-column {
  transition: opacity 0.2s ease;
}

.track-column.is-solo-dimmed {
  opacity: 0.36;
}

.master-scene-column {
  padding-left: 8px;
}

/* ==========================================================================
   7. Headers + symbols (hold & sweep a header to solo)
   ========================================================================== */
.track-header,
.scene-header {
  background: transparent;
  padding: 0;
  border: 1px solid var(--mb-line);
  text-align: center;
  height: 46px;
  min-height: 46px;
  max-height: 46px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.track-header {
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

.track-header:hover {
  border-color: var(--mb-line-strong);
}

.track-header.is-soloed {
  background: var(--mb-cream);
  border-color: var(--mb-cream);
  color: var(--mb-ink);
}

.track-header.is-soloed .track-symbol {
  color: var(--mb-ink);
}

.track-header.is-soloed .track-symbol img {
  filter: brightness(0.08) sepia(0.3);
}

.track-symbol {
  color: var(--mb-cream);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 22px;
  flex-shrink: 0;
  pointer-events: none;
}

/* every symbol sits in the same optical box, centred in its frame */
.track-symbol img {
  height: 20px !important;
  width: auto !important;
  max-width: 28px !important;
  object-fit: contain;
  display: block;
}

.track-symbol svg {
  width: 22px;
  height: 22px;
}

/* ==========================================================================
   8. Pads + row launches
   ========================================================================== */
.clips-rack,
.scenes-rack {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  min-width: 0;
}

/* Night state: cream on black */
.clip-slot,
.scene-launch-btn {
  height: clamp(32px, 4.1vh, 40px);
  min-height: clamp(32px, 4.1vh, 40px);
  max-height: clamp(32px, 4.1vh, 40px);
  width: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--mb-black);
  border: 1px solid var(--mb-line);
  padding: 0 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  cursor: pointer;
  transition: background 0.38s cubic-bezier(0.22, 1, 0.36, 1),
              color 0.32s ease,
              border-color 0.38s ease;
  color: var(--mb-cream-muted);
  user-select: none;
  touch-action: none;
}

.scene-launch-btn {
  color: var(--mb-cream);
  border-color: rgba(239, 227, 204, 0.24);
}

.clip-slot:hover {
  border-color: var(--mb-cream);
  color: var(--mb-cream);
}

/* row preview while hovering its ▶ in the 9th column */
.clip-slot.is-row-hovered:not(.is-playing) {
  background: rgba(239, 227, 204, 0.1);
  border-color: var(--mb-line-strong);
  color: var(--mb-cream);
}

.scene-launch-btn:hover,
.scene-launch-btn.is-playing {
  background: var(--mb-cream);
  color: var(--mb-ink);
  border-color: var(--mb-cream);
}

.scene-play-arrow {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  flex-shrink: 0;
  opacity: 0.85;
}

.scene-launch-btn:hover .scene-play-arrow,
.scene-launch-btn.is-playing .scene-play-arrow {
  opacity: 1;
}

/* warm steam trail while cruising across pads */
.clip-slot.is-steaming:not(.is-playing) {
  background: rgba(239, 227, 204, 0.24);
  border-color: var(--mb-cream);
  color: var(--mb-cream);
}

.clip-slot.is-steaming.is-playing {
  background: var(--mb-paper);
  border-color: var(--mb-paper);
  color: var(--mb-ink);
}

.clip-roman {
  font-family: var(--font-headline);
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: inherit;
  white-space: nowrap;
}

/* Day state while playing: ink on cream */
.clip-slot.is-playing {
  background: var(--mb-cream);
  border-color: var(--mb-cream);
  color: var(--mb-ink);
}

.clip-slot.is-playing .clip-roman {
  color: var(--mb-ink);
  opacity: 1;
}

/* waiting for the next bar */
.clip-slot.is-queued {
  border-color: var(--mb-cream);
  animation: clipQueueFlip 0.48s infinite alternate;
}

.clip-slot.is-stopping {
  border-color: var(--mb-line-strong);
  opacity: 0.5;
}

@keyframes clipQueueFlip {
  0% { background: var(--mb-black); color: var(--mb-cream); }
  100% { background: var(--mb-cream); color: var(--mb-ink); }
}

/* pad left empty in the Studio */
.clip-slot.is-empty:not(.is-playing) {
  opacity: 0.32;
}

/* pad waiting for its audio file */
.clip-slot.is-loading {
  animation: mbPadLoading 1.1s ease-in-out infinite alternate;
}

@keyframes mbPadLoading {
  from { opacity: 1; }
  to { opacity: 0.45; }
}

/* ==========================================================================
   9. ECHO / SPACE sends (per column) + master echo character / time / length
   Horizontal cream fill with a crisp cream edge — same language as the faders
   ========================================================================== */
.track-fx-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  min-width: 0;
}

.fx-send,
.fx-master-btn {
  position: relative;
  height: 20px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--mb-black);
  border: 1px solid var(--mb-line);
  display: flex;
  align-items: center;
  justify-content: center;
}

.fx-send {
  cursor: move;
  touch-action: none;
  user-select: none;
  transition: border-color 0.18s ease;
}

.fx-send:hover,
.fx-send.is-dragging {
  border-color: var(--mb-line-strong);
}

/* while turning a send, keep the drag cursor everywhere */
body.is-fx-dragging,
body.is-fx-dragging * {
  cursor: move !important;
}

.fx-send-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0%;
  background: rgba(239, 227, 204, 0.14);
  pointer-events: none;
}

.fx-send.is-dragging .fx-send-fill {
  background: rgba(239, 227, 204, 0.24);
}

.fx-send-cap {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0%;
  width: 1px;
  background: var(--mb-cream);
  pointer-events: none;
  transform: translateX(-1px);
}

.fx-send.is-off .fx-send-cap {
  opacity: 0;
}

.fx-send-label {
  position: relative;
  z-index: 1;
  font-family: var(--font-body);
  font-size: 0.5rem;
  font-weight: 400;
  letter-spacing: 0.16em;
  color: var(--mb-cream-dim);
  pointer-events: none;
  white-space: nowrap;
}

.fx-send.is-dragging .fx-send-label {
  color: var(--mb-cream);
}

.fx-master-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  width: 100%;
  min-width: 0;
}

.fx-master-btn {
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.52rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  color: var(--mb-cream-muted);
  padding: 0;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.fx-master-btn:hover {
  border-color: var(--mb-line-strong);
  color: var(--mb-cream);
}

.fx-master-btn.is-dub {
  background: var(--mb-cream);
  color: var(--mb-ink);
  border-color: var(--mb-cream);
}

/* ==========================================================================
   10. Square faders — the whole square is the control
       (8 track volumes + the master LOW CUT)
   ========================================================================== */
.track-mixer-strip,
.master-strip-rack {
  margin-top: 2px;
  background: var(--mb-black);
  border: 1px solid var(--mb-line);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: clamp(72px, 10.5vh, 100px);
  height: clamp(72px, 10.5vh, 100px);
  width: 100%;
  min-width: 0;
}

.track-mixer-strip {
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  transition: border-color 0.18s ease;
}

.track-mixer-strip:hover,
.track-mixer-strip.is-dragging {
  border-color: var(--mb-cream);
}

.mb-v-fader-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  background: rgba(239, 227, 204, 0.16);
  pointer-events: none;
  transition: background 0.15s ease;
}

.track-mixer-strip:hover .mb-v-fader-fill,
.track-mixer-strip.is-dragging .mb-v-fader-fill {
  background: rgba(239, 227, 204, 0.24);
}

/* the level line */
.mb-v-fader-cap {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  height: 2px;
  background: var(--mb-cream);
  pointer-events: none;
  transform: translateY(50%);
}

/* live audio level breathing inside the square */
.led-meter-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 0%;
  background: rgba(239, 227, 204, 0.18);
  pointer-events: none;
  transition: height 0.06s ease-out;
}

.lowcut-label {
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  text-align: center;
  font-family: var(--font-headline);
  font-size: 0.5rem;
  line-height: 1.3;
  letter-spacing: 0.14em;
  color: var(--mb-cream-muted);
  pointer-events: none;
  mix-blend-mode: difference;
}

/* ==========================================================================
   11. Precision view (hold a fader / send)
   ========================================================================== */
.mb-fine {
  position: fixed;
  left: 50%;
  top: max(84px, env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 2000;
  width: min(420px, calc(100vw - 32px));
  background: rgba(11, 10, 9, 0.96);
  border: 1px solid var(--mb-cream);
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.mb-fine[hidden] { display: none; }


.mb-fine-value {
  font-family: var(--font-headline);
  font-size: 2.6rem;
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--mb-cream);
  font-variant-numeric: tabular-nums;
}

.mb-fine-bar {
  position: relative;
  height: 26px;
  border: 1px solid var(--mb-line-strong);
  background: var(--mb-black);
  overflow: hidden;
}

.mb-fine-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: rgba(239, 227, 204, 0.2);
}

.mb-fine-cap {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0%;
  width: 2px;
  background: var(--mb-cream);
  transform: translateX(-1px);
}


.is-fine {
  border-color: var(--mb-cream) !important;
}

body.is-fine-adjusting,
body.is-fine-adjusting * {
  cursor: ns-resize !important;
}

/* ==========================================================================
   12. Touch: the instrument never selects text or opens the iOS callout
   ========================================================================== */
body.session-body,
body.session-body *:not(input):not(textarea) {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

.session-workspace,
.session-workspace *,
.sanctuary-hero,
.sanctuary-hero * {
  -webkit-tap-highlight-color: transparent;
}

.session-workspace input[type="range"] {
  touch-action: pan-x;
}

/* ==========================================================================
   13. TRIP visuals (desktop only) — liquid melt, breathing grid, afterimages
       OBE (out of body: astral double, 3D float, starfield)
   ========================================================================== */
/* OBE */
.obe-starfield {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

body[data-trip="obe"] .session-workspace > *:not(.obe-starfield) {
  position: relative;
  z-index: 1;
}

body[data-trip] .session-workspace > .daw-transport-bar {
  z-index: 40; /* keep the menu above the floating grid */
}

body[data-trip="obe"] .session-matrix-board {
  filter: url(#mb-obe-filter);
  will-change: transform, filter;
  transform-style: preserve-3d;
}

/* pads let the void through a little, so the stars stream behind them */
body[data-trip="obe"] .clip-slot:not(.is-playing),
body[data-trip="obe"] .scene-launch-btn:not(.is-playing),
body[data-trip="obe"] .fx-send,
body[data-trip="obe"] .track-mixer-strip,
body[data-trip="obe"] .master-strip-rack {
  background: rgba(11, 10, 9, 0.62);
}

body[data-trip="obe"] .clip-slot,
body[data-trip="obe"] .scene-launch-btn {
  transition-duration: 2.6s, 2.6s, 2.6s;
}

body[data-trip="obe"] .track-symbol img {
  animation: mbObeSymbol 5s ease-in-out infinite alternate;
}

@keyframes mbObeSymbol {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  50% { transform: scale(1.25) rotate(12deg); opacity: 0.6; }
  100% { transform: scale(0.92) rotate(-10deg); opacity: 0.9; }
}

/* the rest of the world dissolves while you are out */
body[data-trip="obe"] .sanctuary-hero,
body[data-trip="obe"] .mb-footer {
  opacity: 0.25;
  filter: blur(2px);
  transition: opacity 2s ease, filter 2s ease;
}

body[data-trip="obe"] .smoke-plume {
  animation-duration: 14s !important;
}

/* a piece of the grid detaches, floats out in 3D and glides back */
body[data-trip="obe"] .clips-rack,
body[data-trip="obe"] .track-column,
body[data-trip="obe"] .track-header {
  transform-style: preserve-3d;
}

body[data-trip="obe"] .track-column,
body[data-trip="obe"] .track-header,
body[data-trip="obe"] .scene-header {
  overflow: visible;
}

.obe-float {
  animation: mbObeFloat var(--obe-t, 8s) cubic-bezier(0.45, 0, 0.25, 1) 1 both !important;
  position: relative;
  z-index: 5;
}

@keyframes mbObeFloat {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  45% { transform: translate3d(var(--obe-x), var(--obe-y), var(--obe-z)) rotate(var(--obe-r)); opacity: 0.55; }
  60% { transform: translate3d(var(--obe-x), var(--obe-y), var(--obe-z)) rotate(var(--obe-r)); opacity: 0.55; }
  100% { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
}

/* the settings menu floats along with the trip */
body[data-trip="obe"] .sanctuary-menu {
  animation: mbMenuFloat 7s ease-in-out infinite alternate;
  transform-origin: 90% 0%;
}

@keyframes mbMenuFloat {
  0% { transform: perspective(900px) translate3d(0, 0, 0) rotateX(0deg) rotateY(0deg); }
  33% { transform: perspective(900px) translate3d(-10px, 8px, 30px) rotateX(4deg) rotateY(-6deg); }
  66% { transform: perspective(900px) translate3d(6px, -6px, 10px) rotateX(-3deg) rotateY(5deg); }
  100% { transform: perspective(900px) translate3d(-4px, 4px, 40px) rotateX(2deg) rotateY(-3deg); }
}

/* the transport bar trips too: breathes with the sound (--trip-level), groups drift */
body[data-trip="obe"] .daw-transport-bar {
  transform: translateY(calc(var(--trip-level, 0) * -4px)) scale(calc(1 + var(--trip-level, 0) * 0.008));
  transition: transform 0.25s ease-out;
  border-bottom-color: transparent; /* the hairline becomes a living wave (JS) */
}

body[data-trip="obe"] .daw-transport-bar { perspective: 900px; }
body[data-trip="obe"] .daw-transport-bar > * { animation: mbBarFloat 7s ease-in-out infinite alternate; transform-style: preserve-3d; }
body[data-trip="obe"] .daw-transport-bar > *:nth-child(2) { animation-duration: 9s; animation-delay: -3s; }
body[data-trip="obe"] .daw-transport-bar > *:nth-child(3) { animation-duration: 8s; animation-delay: -5s; }

/* in OBE every button hovers on its own as well */
body[data-trip="obe"] .daw-transport-bar button:not(.obe-float),
body[data-trip="obe"] .daw-bpm-strip {
  animation: mbBtnHover 5s ease-in-out infinite alternate;
}
body[data-trip="obe"] .daw-transport-bar button:nth-of-type(2):not(.obe-float) { animation-duration: 6.2s; animation-delay: -1.5s; }
body[data-trip="obe"] .daw-transport-bar button:nth-of-type(3):not(.obe-float) { animation-duration: 4.4s; animation-delay: -2.7s; }

/* the controls melt like the grid (the dropdown itself stays crisp) */
body[data-trip="obe"] .daw-transport-bar > .transport-group:first-child,
body[data-trip="obe"] .mood-bar,
body[data-trip="obe"] .daw-bpm-strip,
body[data-trip="obe"] .btn-sanctuary-menu {
  filter: url(#mb-ui-filter);
}

.trip-wave-line {
  position: absolute;
  left: 0;
  bottom: -12px;
  width: 100%;
  height: 24px;
  filter: url(#mb-ui-filter);
  pointer-events: none;
  overflow: visible;
  display: none;
}

body[data-trip="obe"] .trip-wave-line {
  display: block;
}

@keyframes mbBarFloat {
  0% { transform: translate3d(0, 0, 0) rotateX(0deg) rotateY(0deg); }
  33% { transform: translate3d(-12px, 8px, 40px) rotateX(8deg) rotateY(-10deg); }
  66% { transform: translate3d(10px, -10px, 15px) rotateX(-6deg) rotateY(9deg); }
  100% { transform: translate3d(-4px, 6px, 55px) rotateX(4deg) rotateY(-5deg); }
}

@keyframes mbBtnHover {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); }
  50% { transform: translate3d(0, -5px, 25px) rotate(-1.5deg); }
  100% { transform: translate3d(0, 3px, 10px) rotate(1.2deg); }
}

/* ==========================================================================
   Opening (phones): the MB logo draws itself on black, nothing written,
   then fades away to the instrument (tap to skip). Hidden everywhere else.
   ========================================================================== */
.mb-opening {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: var(--mb-black);
  display: none;
  align-items: center;
  justify-content: center;
  transition: opacity 0.9s ease;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 680px), (orientation: landscape) and (max-height: 500px) {
  .mb-opening { display: flex; }
}

.mb-opening.is-leaving {
  opacity: 0;
  pointer-events: none;
}

.mb-opening.is-gone { display: none; }

body.is-opening { overflow: hidden; }

body.is-opening .mb-header-wrap {
  opacity: 0;
  pointer-events: none;
}

/* the logo (Michal's animated mark) */
.mbl {
  color: var(--mb-cream);
  line-height: 0;
}

.mbl-svg {
  width: min(190px, 46vw);
  height: auto;
  max-height: 62vh;
  overflow: visible;
}

.mbl-strokes {
  fill: none;
  stroke: currentColor;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mbl-fills { fill: currentColor; }

/* draw in, a little quicker than the demo so the instrument is not kept waiting */
.mbl .in path,
.mbl .in circle {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: mbl-draw 0.8s cubic-bezier(0.5, 0, 0.2, 1) forwards;
  animation-delay: calc(var(--t) * 0.6s);
}

.mbl .dot {
  opacity: 0;
  animation: mbl-pop 0.5s ease-out forwards;
  animation-delay: calc(var(--t) * 0.6s);
}

.mbl .at,
.mbl .rot { transform-origin: 0 0; }

@keyframes mbl-draw { to { stroke-dashoffset: 0; } }
@keyframes mbl-pop { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================================
   14. Tablet (≤ 1100px) · narrow (≤ 880px): all 9 columns still fit
   ========================================================================== */
@media (max-width: 1100px) {
  .daw-transport-bar {
    padding: 0 0 0.85rem;
    gap: 0.65rem;
  }

  .session-workspace {
    padding-top: 0.85rem;
    padding-bottom: 3rem;
  }

  .master-scene-column {
    padding-left: 6px;
  }

  .track-header,
  .scene-header {
    height: 50px;
    min-height: 50px;
    max-height: 50px;
  }

  .clip-slot,
  .scene-launch-btn {
    height: 38px;
    min-height: 38px;
    max-height: 38px;
    padding: 0 0.45rem;
  }

  .clip-roman {
    font-size: 0.64rem;
    letter-spacing: 0.08em;
  }
}

@media (max-width: 880px) {
  .clip-slot,
  .scene-launch-btn {
    padding: 0 0.25rem;
  }
}

/* ==========================================================================
   15. Phone (≤ 680px)
   Row 1: play · stop · tempo · ½ · menu — row 2: the 5 mood icons.
   8 tracks across; ECHO / SPACE under the faders; the 9th column becomes a
   master panel below (PING · 3/16 · a long SPACE length · LOW CUT).
   ========================================================================== */
@media (max-width: 680px) {
  /* the incense lives on the opening screen instead */
  .sanctuary-hero { display: none; }

  /* moods at the top: free icons, no frames — the lit one is bright with a line under it */
  .daw-transport-bar {
    padding: 0;
    margin-bottom: 10px;
    border-bottom: none;
  }

  .daw-transport-bar > .mood-bar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }

  .mood-btn,
  .mood-btn:hover,
  .mood-btn.is-on {
    position: relative;
    height: 38px;
    padding: 0;
    background: transparent;
    border-color: transparent;
    color: var(--mb-cream);
  }

  .mood-random { border-style: solid; }

  .mood-name { display: none; }

  .mood-ico {
    width: 24px;
    height: 24px;
    opacity: 0.4;
    transition: opacity 0.25s ease;
  }

  .mood-btn.is-on .mood-ico { opacity: 1; }

  .mood-btn.is-on::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 2px;
    width: 16px;
    height: 1px;
    background: var(--mb-cream);
    transform: translateX(-50%);
  }

  /* play · stop · tempo · ½ · menu: one slim bar fixed at the bottom */
  .daw-transport-bar::before {
    content: "";
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(58px + env(safe-area-inset-bottom));
    background: rgba(11, 10, 9, 0.94);
    border-top: 1px solid var(--mb-line);
    z-index: -1;
  }

  .daw-transport-bar > .transport-group:first-child,
  .daw-transport-bar > .transport-group:last-child {
    position: fixed;
    bottom: calc(11px + env(safe-area-inset-bottom));
    flex-wrap: nowrap;
    gap: 6px;
  }

  .daw-transport-bar > .transport-group:first-child { left: 12px; }

  .daw-transport-bar > .transport-group:last-child {
    left: 96px;
    right: 12px;
    justify-content: space-between;
  }

  .btn-transport-stop,
  .btn-tempo-mod,
  .btn-sanctuary-menu,
  .daw-bpm-strip {
    background: transparent;
    border-color: transparent;
  }

  .btn-transport-play { border-color: transparent; }

  .daw-bpm-strip {
    flex: 1;
    min-width: 0;
    justify-content: space-between;
    padding: 0 0.5rem;
    gap: 0.4rem;
  }

  .daw-bpm-strip label { display: none; }

  .bpm-slider {
    flex: 1;
    min-width: 40px;
  }

  .btn-tempo-mod {
    width: 34px;
    font-size: 0.64rem;
  }

  /* the settings menu opens upward from the bottom bar */
  .sanctuary-menu {
    top: auto;
    bottom: calc(100% + 14px);
    width: min(320px, calc(100vw - 24px));
  }

  /* workspace: room above for the hidden top menu, room below for the bar */
  .session-workspace {
    min-height: 0;
    justify-content: flex-start;
    padding-top: 80px;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
    scroll-margin-top: -72px;
  }

  /* board: 8 tracks across */
  .session-matrix-board {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 3px;
  }

  .track-column {
    gap: 3px;
  }

  .track-header {
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    padding: 0.2rem;
  }

  .track-symbol {
    width: 20px;
    height: 20px;
  }

  .track-symbol svg {
    width: 18px;
    height: 18px;
  }

  .clips-rack {
    gap: 3px;
  }

  /* pads shrink a little on shorter phones so the whole instrument fits one screen */
  .clip-slot {
    --pad-h: clamp(26px, calc((100svh - 446px) / 8), 36px);
    height: var(--pad-h);
    min-height: var(--pad-h);
    max-height: var(--pad-h);
    padding: 0 0.15rem;
    gap: 2px;
  }

  .clip-roman {
    font-size: 0.56rem;
    letter-spacing: 0.04em;
  }

  .track-mixer-strip {
    min-height: 82px;
  }

  /* ECHO / SPACE move under the volume squares, taller and easier to grab */
  .track-column .track-mixer-strip { order: 5; }
  .track-column .track-fx-row { order: 6; }

  .track-fx-row:not(.master-fx-row) .fx-send { height: 34px; }

  .fx-send-label {
    font-size: 0.4rem;
    letter-spacing: 0.06em;
  }

  /* the 9th column becomes the master panel below the tracks */
  .master-scene-column {
    grid-column: 1 / -1;
    padding-left: 0;
    margin-top: 6px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 76px;
    gap: 6px;
    overflow: visible;
  }

  .master-scene-column .scene-header,
  .master-scene-column .scenes-rack { display: none; }

  .master-scene-column .master-fx-row {
    grid-column: 1;
    grid-row: 1;
    gap: 6px;
  }

  .master-fx-row .fx-master-split { gap: 6px; }

  .master-fx-row .fx-master-btn { height: 34px; }

  .master-fx-row .fx-send.fx-decay { height: 40px; }

  .master-fx-row .fx-send-label,
  .master-fx-row .fx-master-btn {
    font-size: 0.6rem;
    letter-spacing: 0.12em;
  }

  .master-scene-column .master-strip-rack {
    grid-column: 2;
    grid-row: 1;
    height: auto;
    min-height: 80px;
  }
}

/* phone portrait + landscape: the top menu slides away while scrolling down */
@media (max-width: 680px), (orientation: landscape) and (max-height: 500px) {
  /* no snapping: the page stays where the finger leaves it */
  html:has(body.session-body) { scroll-snap-type: none; }

  .mb-header-wrap {
    transition: transform 0.3s ease, opacity 0.3s ease;
  }

  body.header-hidden .mb-header-wrap {
    transform: translateY(-140%);
    opacity: 0;
  }
}

/* ==========================================================================
   16. Phone landscape (wide but short): one transport row, and the whole
       8x8 + mixer fits one screen
   ========================================================================== */
@media (orientation: landscape) and (max-height: 500px) {
  .mb-header-wrap { top: 0.4rem; }
  .mb-header-pill { height: 46px; }

  /* the incense lives on the opening screen instead */
  .sanctuary-hero { display: none; }

  .session-workspace {
    scroll-margin-top: -72px;
    min-height: 100vh;
    justify-content: flex-start;
    padding: 80px max(14px, env(safe-area-inset-right)) 12vh max(14px, env(safe-area-inset-left));
  }

  /* play · stop · moods (icons) · tempo · ½ · menu */
  .daw-transport-bar {
    flex-wrap: nowrap;
    gap: 6px;
    margin-bottom: 6px;
    padding-bottom: 6px;
  }

  .daw-transport-bar > .mood-bar {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .mood-btn { height: 34px; padding: 0 0.6rem; }
  .mood-name { display: none; }
  .mood-ico { width: 20px; height: 20px; }
  .daw-bpm-strip label { display: none; }

  .btn-transport-play,
  .btn-transport-stop,
  .btn-tempo-mod { height: 34px; }

  /* short rows so all 8 stages + the faders fit */
  .session-matrix-board,
  .track-column,
  .master-scene-column { gap: 3px; }

  .track-header,
  .scene-header { height: 30px; min-height: 30px; }

  .track-header .track-symbol img,
  .scene-header .track-symbol img { height: 18px !important; }

  .clip-slot,
  .scene-launch-btn {
    height: 27px;
    min-height: 27px;
    max-height: 27px;
  }

  .track-mixer-strip,
  .master-strip-rack { height: 50px; min-height: 50px; }

  .track-fx-row:not(.master-fx-row) .fx-send { height: 20px; }

  /* master: PING | 3/16 side by side, SPACE length below = same rows as ECHO / SPACE */
  .master-fx-row .fx-master-btn,
  .master-fx-row .fx-send { height: 20px; }

  .lowcut-label { top: 3px; font-size: 0.42rem; }
}

/* ==========================================================================
   17. Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  body[data-trip] .session-matrix-board { filter: none !important; transform: none !important; }
  body[data-trip] .track-symbol img { animation: none !important; }
  body[data-trip] .daw-transport-bar,
  body[data-trip] .daw-transport-bar * { animation: none !important; transform: none !important; }
  .sanctuary-menu { animation: none !important; }
  .obe-starfield { display: none; }
  .mb-fog { display: none; }
  .mbl .in path,
  .mbl .in circle { animation: none; stroke-dashoffset: 0; }
  .mbl .dot { animation: none; opacity: 1; }
}
