 body {
  margin: 0;
  overflow-x: hidden; /* 禁止左右滑動 */
  overflow-y: hidden; /* 禁止上下滑動 */
  background-color: black;
  color: white;
  font-family: Arial, sans-serif;
  font-size: 16px;
  position: relative;
  
  
}
.footer-fixed {
  position: fixed;
  bottom: 5px; /* 🔥加這行，保底 */
  left: 50%;
  transform: translateX(-50%);
  color: gray;
  z-index: 9999;
  text-align: center;
  white-space: nowrap;
}
/* 🔥 音高顯示 */
#currentPitch {
  display: flex;        /* 🔥 讓文字也垂直置中 (如果有多行) */
  align-items: center;  /* 🔥 flex垂直置中 */
  justify-content: center; /* 🔥 flex水平置中 */
  font-size: 24px;
  background: rgba(0,0,0,0.7);
  padding: 5px 10px;
  border-radius: 5px;
  z-index: 10;
   white-space: nowrap; /* 🔥 保證一行內，不換行 */
}

/* 🔥 錯誤訊息 */
#errorMsg {
  position: absolute;
  top: 50px;
  left: 10px;
  background: rgba(0, 0, 0, 0.7);
  padding: 10px;
  border: 1px solid red;
  display: none;
  z-index: 10;
  
}

/* 上傳控制區 */
#uploadSection {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.1);
  padding: 22px;
  border-radius: 10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 700px;
  width: 90%;
  box-sizing: border-box;
  align-items: center; /* 🔥 這樣內部子元素都會置中 */
}

#uploadControls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 30px;
  width: 100%;
}

#backingControl, 
#referenceControl {
  flex: 1 1 300px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#uploadControls > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

#uploadControls label, 
#uploadControls input[type="file"],
.volumeControl span {
  
  color: white;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#uploadControls input[type="file"] {
  color: white;
}
/* 播放控制區 */
#playbackSection {
  width: 100%;
  display: flex;
  flex-direction: column; /* 🔥 加這一行！上下排列 */
  align-items: center;     /* 🔥 置中 */
  gap: 15px;
}

#playbackProgressContainer {
  display: flex;
  align-items: center;
  justify-content: space-between; /* 🔥 用盡空間 */
  gap: 10px;
  width: 100%;
  max-width: 700px; /* 或你想要的最大寬度，比如700px */
  padding: 0 20px; /* 🔥 左右留一點空白，不會貼到邊 */
  box-sizing: border-box;
}

#playbackProgress {
  flex: 1; /* 🔥 撐滿中間剩餘空間 */
  min-width: 0; /* 防止flex元素超出容器 */
  height: 8px; /* 可依喜好調整高度，例如更細一點 */
  border-radius: 5px;
}

#currentTime, 
#remainingTime {
  width: 50px;
  min-width: 50px;
  text-align: center;
}
#uploadContent {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px; /* 🔥🔥 加這行，兩個區塊間距 50px */
  width: 100%;
}


.playback-button, 
.zoom-button,
#helpButton button,
#freezeToggle button {
  background: rgba(255,255,255,0.2);
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1em;
}

 #freezeToggle {
	display: flex;
  flex-wrap: nowrap;       /* 不換行 */
  gap: 10px;               /* 按鈕之間距離 */
  justify-content: center;
  align-items: center;
  }
  
  #freezeToggle button {
  white-space: nowrap; /* 🔥 文字不換行 */
  width: 160px; 
  text-align: center;
}

.playback-button, 
.zoom-button,
#helpButton button{
  min-width: 60px; /* 你可以自己選，比如 60px、70px，想統一多寬 */
  text-align: center; /* 🔥 確保文字置中 */
}

#globalPlaybackControls {
  display: flex;
  gap: 10px; /* 🔥 左右按鈕間距加大到20px */
}


/* 閥值控制 */
#thresholdControl {
  position: absolute;
  bottom: calc(30px + env(safe-area-inset-bottom));
  left: 180px;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.1);
  padding: 10px;
  border-radius: 5px;
  z-index: 10;
  
}

#thresholdContainer {
  position: relative;
  width: 400px;
  height: 20px;
  background: #333;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 5px;
  align-items: center;        /* 🔥 加這行：垂直置中 */
  gap: 10px;                  /* 左右間距 */
}

#volumeBar {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: limegreen;
  width: 0%;
}

#thresholdSlider {
  position: absolute;
  width: 100%;
  height: 100%;
  background: transparent;
}


#thresholdValue {
  margin-top: 10px;
  color: white;
}

/* 放大縮小控制 */
#zoomControls {
  position: absolute;
  bottom: 30px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  z-index: 10;
}

/* 音量控制區 */
.volumeControl {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 250px;
  gap: 5px;
  margin-top: 5px;
}

.volumeControl input[type="range"] {
  flex: 1;
}


#igModal, 
#helpModal {
  font-size: 16px;
}

#igModal button, 
#helpModal button {
  font-size: 18px;
}

footer, 
footer div, 
footer span, 
footer a {
  font-size: 8px;
}


/* 畫布 (Canvas) */
canvas {
  display: block;

}

/* 🔒 禁止任何長按選取文字（包含手機） */
* {
  -webkit-user-select: none; /* Safari */
  -moz-user-select: none;    /* Firefox */
  -ms-user-select: none;     /* IE/Edge */
  user-select: none;         /* 標準語法 */
  touch-action: manipulation; /* 🔥 防止長按出現選取/選單 */
}

/* 🔥🔥 當螢幕寬度小於970px時，threshold + freezeToggle 特別調整 🔥🔥 */
@media (min-width: 600px) and (max-width: 970px) {
  #thresholdControl {
	bottom: calc(30px + env(safe-area-inset-bottom)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }
  
  #thresholdContainer {
    width: 400px !important;
  }
  
  #thresholdContainer,
  #thresholdSlider, 
  #volumeBar {
    height: 25px !important; /* 音量顯示條也縮小 */
  }

  #freezeToggle {
	bottom: calc(110px + env(safe-area-inset-bottom)) !important;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-wrap: nowrap;
  }
  

  /* 🔥 順便讓 ZoomControls (＋－重設)也調整 */
  #zoomControls {
	bottom: calc(30px + env(safe-area-inset-bottom)) !important;
  }
}


/* 支援安全區域 (如 iPhone 瀏海/底部條) */
@supports(padding: max(0px)) {
  #freezeToggle {
    left: 50%;
    transform: translateX(-50%);
  }
  #thresholdControl {
    left: max(160px, env(safe-area-inset-left));
  }
  #zoomControls {
    right: max(10px, env(safe-area-inset-right));
	bottom: calc(30px + env(safe-area-inset-bottom)) !important;
  }
  
#topBar {
  top: calc(10px + env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: env(safe-area-inset-right);
  min-height: 56px; /* 🔥 為選調按鈕保底空間 */
  height: auto;     /* 🔥 自動依內容撐高 */
}


  #helpModal {
    top: env(safe-area-inset-top);
    left: env(safe-area-inset-left);
    right: env(safe-area-inset-right);
    bottom: env(safe-area-inset-bottom);
  }


  
    .footer-fixed {
    bottom: max(5px , env(safe-area-inset-bottom));
  }
  
  #uploadSection {
    top: calc(50px + env(safe-area-inset-top)) !important;
  }
}

/* 手機版直向調整 (小於600px) */
@media (max-width: 600px) {
  body {
    font-size: 10px !important; /* 🔥 小螢幕字體縮小 */
  }

  #igModal, 
  #helpModal {
    font-size: 12px;
  }

  #igModal button, 
  #helpModal button {
    font-size: 12px;
  }

  footer, 
  footer div, 
  footer span, 
  footer a {
    font-size: 14px;
  }

  #currentPitch {
    font-size: 16px;
  }
  
  #uploadSection {
    width: 95%;
    padding: 10px;
  }

  #uploadContent {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center; /* 🔥內部文字、按鈕置中 */
    width: 100%;
    gap: 15px;
  }

  #uploadControls {
    flex-direction: column; /* 🔥 左右改上下 */
    align-items: center;     /* 🔥 每個子項目置中 */
    width: 100%;
  }

  .trackControl {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 250px;
  }

  .trackTitle {
    font-weight: bold;
    text-align: center;
  }

  input[type="file"] {
    color: white;
    width: 100%;
    text-align: center;
  }

  .volumeControl label {
    white-space: nowrap;
  }

  .volumeControl span {
    min-width: 40px;
    text-align: right;
  }

  #playbackSection {
    width: 100%;
    display: flex;
    flex-direction: column; /* 🔥 上下排列 */
    align-items: center;     /* 🔥 置中 */
    gap: 10px;
    padding: 0 10px; /* 🔥 進度條左右留白 */
  }

  #playbackProgressContainer {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 5px;
  }

  #playbackProgress {
    flex: 1;
  }

  #currentTime, 
  #remainingTime {
    width: 30px;
  }

  #globalPlaybackControls {
    display: flex;
    flex-direction: row; /* 🔥 按鈕橫排 */
    flex-wrap: wrap;     /* 🔥 自動換行 */
    justify-content: center;
    gap: 10px;           /* 🔥 按鈕間距 */
    margin-top: 10px;    /* 🔥 跟進度條留距 */
  }

  #thresholdControl {
    bottom: calc(30px + env(safe-area-inset-bottom)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }
  
  #thresholdContainer{
  	width: 195px !important;
	}
  
  #thresholdContainer,
  #thresholdSlider,
  #volumeBar {

    height: 25px !important; /* 🔥 音量顯示條也一起縮小 */
  }

  #freezeToggle {
    bottom: calc(100px + env(safe-area-inset-bottom)) !important;
    left: 50%;
    transform: translateX(-50%);
	display: flex;
	flex-wrap: nowrap;
  }
  
  #freezeToggle button {
  white-space: nowrap; /* 🔥 文字不換行 */
  width: 110px;  
  text-align: center;
}
  .playback-button, 
.zoom-button,
#helpButton button{
  width: 40px !important; /* 你可以自己選，比如 60px、70px，想統一多寬 */

}

  #keySelectButton {
    left: 20px !important;
	
  }


  #helpModal > div {
    padding: 5px 20px !important; /* 🔧 左右縮窄，讓文字不貼邊 */
  }
}

/* 手機版橫向調整  */
@media (orientation: landscape) and (max-height: 600px) {
  body {
    font-size: 10px !important; /* 🔥 小螢幕字體縮小 */
  }

  #igModal, 
  #helpModal {
    font-size: 12px;
  }

  #igModal button, 
  #helpModal button {
    font-size: 12px;
  }

  footer, 
  footer div, 
  footer span, 
  footer a {
    font-size: 14px;
  }

  #currentPitch {
    font-size: 16px;
  }

  #uploadSection {
    width: 95%;
    padding: 10px;
  }

  #uploadContent {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center; /* 🔥內部文字、按鈕置中 */
    width: 100%;
    gap: 15px;
  }

  #uploadControls {
    align-items: center;     /* 🔥 每個子項目置中 */
    width: 100%;
  }

  .trackControl {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 250px;
  }

  .trackTitle {
    font-weight: bold;
    text-align: center;
  }

  input[type="file"] {
    color: white;
    width: 100%;
    text-align: center;
  }

  .volumeControl label {
    white-space: nowrap;
  }

  .volumeControl span {
    min-width: 40px;
    text-align: right;
  }

  #playbackSection {
    width: 100%;
    display: flex;
    align-items: center;     /* 🔥 置中 */
    gap: 10px;
    padding: 0 10px; /* 🔥 進度條左右留白 */
  }

  #playbackProgressContainer {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 5px;
  }

  #playbackProgress {
    flex: 1;
  }

  #currentTime, 
  #remainingTime {
    width: 30px;
  }

  #globalPlaybackControls {
    display: flex;
    flex-direction: row; /* 🔥 按鈕橫排 */
    flex-wrap: wrap;     /* 🔥 自動換行 */
    justify-content: center;
    gap: 10px;           /* 🔥 按鈕間距 */
    margin-top: 10px;    /* 🔥 跟進度條留距 */
  }

#zoomControls,
#helpButton {

  right: calc(env(safe-area-inset-right) + 10px) !important;

}
  
  #thresholdContainer{
  	width: 200px !important;
	}
  
  #thresholdContainer,
  #thresholdSlider,
  #volumeBar {

    height: 25px !important; /* 🔥 音量顯示條也一起縮小 */
  }

  #freezeToggle {
	display: flex;
	flex-wrap: nowrap;
	bottom: calc(30px + env(safe-area-inset-bottom)) !important; 
  }
  
  #freezeToggle button {
  white-space: nowrap; /* 🔥 文字不換行 */
  width: 110px;  
  text-align: center;
}
  
  .playback-button, 
.zoom-button,
#helpButton button{
  width: 52px !important; /* 你可以自己選，比如 60px、70px，想統一多寬 */
}


 #keySelectButton {
  left: 20px !important;
  /*top: max(10px, env(safe-area-inset-top)) !important; */
}
#thresholdControl {

  left: calc(142px + env(safe-area-inset-left))!important;

}
#zoomControls,#thresholdControl,#freezeToggle{
	  bottom: calc(22px + env(safe-area-inset-bottom))!important;
}
 
#thresholdContainer{
	width: 182px !important;
}

  canvas {
    width: 100vw;
    height: 100dvh;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    box-sizing: border-box;
    display: block;
  }

}

/* 🔥🔥 手機垂直時，讓 threshold 和 freezeToggle 根據 footer 動態調整 🔥🔥 */
@media (orientation: portrait) and (max-width: 600px) {
  #thresholdControl, #zoomControls{
    bottom: calc(30px + env(safe-area-inset-bottom)) !important; /* footer高度約5px + 10px */
  }

  #freezeToggle {
    bottom: calc(30px + env(safe-area-inset-bottom) + 5px + 10px + 10px + 50px)!important; /* threshold高度約50px */
  }
}

