/* App shell: topbar, stage + control panel, responsive drawers. */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

/* Keep controls clear of notches and home indicators on fullscreen iOS. */
@supports (padding: env(safe-area-inset-bottom)) {
  .topbar {
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  .workspace {
    padding-bottom: calc(var(--gap) + env(safe-area-inset-bottom));
  }
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  min-height: var(--topbar-h);
  background: linear-gradient(180deg, rgba(21, 25, 34, 0.94), rgba(11, 14, 19, 0.94));
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: relative;
  z-index: 30;
}

.topbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 0 0 auto;
}

.topbar-view {
  flex: 0 0 auto;
}

.topbar-tabs {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  padding: 2px 0;
}

.topbar-tabs::-webkit-scrollbar {
  display: none;
}

.topbar-right {
  margin-left: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-right: 4px;
  flex: 0 0 auto;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-hi), var(--accent-lo));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 5px;
  box-shadow: 0 4px 14px var(--accent-soft), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.brand-mark span {
  border-radius: 1px;
  background: rgba(0, 0, 0, 0.55);
}

.brand-mark span:nth-child(2),
.brand-mark span:nth-child(4),
.brand-mark span:nth-child(9) {
  background: rgba(0, 0, 0, 0.18);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand-name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.brand-sub {
  font-size: 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 700;
}

/* --------------------------------------------------------------- workspace */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: var(--gap);
  padding: var(--gap);
}

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 30%), var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

.panel-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.drawer-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}

.drawer-head .side-title {
  margin-bottom: 0;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 55;
}

.scrim[hidden] {
  display: none;
}

/* ------------------------------------------------------------- breakpoints */

@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
}

/* Portrait phones and narrow tablets: the panel becomes a drawer. */
@media (max-width: 1080px) and (orientation: portrait) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(360px, 92vw);
    z-index: 60;
    border-radius: 0;
    border-right: 0;
    transform: translateX(105%);
    transition: transform var(--med) var(--ease);
    box-shadow: var(--shadow-2);
    padding: 12px;
  }

  .panel.is-open {
    transform: none;
  }

  .panel .drawer-head {
    display: flex;
  }
}

@media (max-width: 860px) {
  .workspace {
    padding: 6px;
    gap: 6px;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 6px;
  }

  .topbar-group {
    gap: 4px;
  }

  .topbar-view {
    order: 2;
  }

  .topbar-tabs {
    order: 3;
    flex: 1 1 auto;
  }

  .topbar-right {
    order: 1;
    margin-left: auto;
  }

  /* Edit and focus are desktop affordances. Phones are already in focus mode
     and the play grid is a performance surface, so both are dead weight. */
  .topbar-view .btn {
    display: none;
  }

  /* Secondary chrome shrinks; the transport, scale and octave stay large. */
  .btn {
    height: 28px;
    padding: 0 8px;
    font-size: 10px;
  }

  .btn-sm {
    height: 24px;
    padding: 0 6px;
    font-size: 9px;
  }

  .btn-icon {
    width: 28px;
  }

  .btn-icon.btn-sm {
    width: 24px;
  }

  .panel-tab {
    height: 26px;
    padding: 0 7px;
    font-size: 9px;
  }

  .play-btn {
    width: 38px;
    height: 38px;
  }

  .play-btn svg {
    width: 15px;
    height: 15px;
  }

  .dragnum {
    min-width: 42px;
    height: 32px;
    padding: 0 5px;
  }

  .dragnum-value {
    font-size: 11px;
  }

  .meter {
    display: none;
  }

  .brand-mark {
    width: 24px;
    height: 24px;
    padding: 4px;
  }

  .stage-hint {
    display: none;
  }
}

@media (max-width: 520px) {
  .brand-text {
    display: none;
  }

  .topbar {
    gap: 6px;
  }

  /* Play toggles, so the separate stop button is redundant on phones. */
  .transport .btn-icon {
    display: none;
  }
}

/* Landscape phones: keep the panel on screen and give the grid the rest. */
@media (orientation: landscape) and (max-height: 600px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 250px;
    padding: 6px;
    gap: 6px;
  }

  .panel {
    position: static;
    transform: none;
    width: auto;
    border-radius: var(--radius);
    padding: 8px;
  }

  .panel .drawer-head {
    display: none;
  }

  .topbar {
    flex-wrap: nowrap;
    padding: 4px 8px;
    gap: 6px;
    min-height: 0;
  }

  .topbar-view,
  .topbar-tabs,
  .topbar-right {
    order: 0;
  }

  .topbar-tabs {
    flex: 1 1 auto;
  }

  .brand-text {
    display: none;
  }

  .stage-hint {
    display: none;
  }

  .scrim {
    display: none !important;
  }
}

/* The scrim only exists for the portrait drawer. */
@media (min-width: 1081px) {
  .scrim {
    display: none !important;
  }
}

/* ------------------------------------------------------- forced landscape */

/* The web cannot change the OS orientation, so a forced landscape rotates the
   shell instead. This only applies while the viewport is portrait: turn the
   phone and the rotation drops away on its own, so nothing is ever rotated
   twice. `pointer: coarse` keeps a narrow desktop window from rotating. */
@media (orientation: portrait) and (max-width: 900px) and (pointer: coarse) {
  html[data-rotate="cw"] body,
  html[data-rotate="ccw"] body {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vh;
    width: 100dvh;
    height: 100vw;
    height: 100dvw;
    transform-origin: top left;
    overflow: hidden;
  }

  html[data-rotate="cw"] body {
    transform: translateX(100vw) rotate(90deg);
    transform: translateX(100dvw) rotate(90deg);
  }

  html[data-rotate="ccw"] body {
    transform: translateY(100vh) rotate(-90deg);
    transform: translateY(100dvh) rotate(-90deg);
  }

  /* The shell is landscape-shaped now, so use the landscape layout even though
     the media query still reports portrait. */
  html[data-rotate] .app {
    height: 100%;
  }

  html[data-rotate] .workspace {
    grid-template-columns: minmax(0, 1fr) 250px;
    padding: 6px;
    gap: 6px;
  }

  html[data-rotate] .panel {
    position: static;
    transform: none;
    width: auto;
    border-radius: var(--radius);
    border-right: 1px solid var(--line-soft);
    padding: 8px;
  }

  html[data-rotate] .panel .drawer-head {
    display: none;
  }

  html[data-rotate] .scrim {
    display: none !important;
  }

  html[data-rotate] .topbar {
    flex-wrap: nowrap;
    padding: 4px 8px;
    gap: 6px;
    min-height: 0;
  }

  html[data-rotate] .topbar-view,
  html[data-rotate] .topbar-tabs,
  html[data-rotate] .topbar-right {
    order: 0;
  }

  html[data-rotate] .topbar-tabs {
    flex: 1 1 auto;
  }

  html[data-rotate] .brand-text,
  html[data-rotate] .stage-hint {
    display: none;
  }
}
