 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: 15px; /* 🔥 統一各區塊行距，與播放控制區 gap 一致 */
  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;
}
/* 🔥 按鈕互動動畫：所有 button 一律 hover 變亮 + 按下微縮（通用選擇器，涵蓋 inline 樣式的按鈕） */
button {
  font-size: inherit; /* 🔥 統一繼承，避免瀏覽器對 button 的預設字體造成大小不一 */
  transition: background 0.15s ease, transform 0.08s ease, filter 0.15s ease;
}
button:hover {
  filter: brightness(1.35);          /* 對任何底色都變亮，不受 inline background 影響 */
}
button:active {
  transform: scale(0.94);
}

 #freezeToggle {
	display: flex;
  flex-wrap: nowrap;       /* 不換行 */
  gap: 10px;               /* 按鈕之間距離 */
  justify-content: center;
  align-items: center;
  }
  
  #freezeToggle button {
  white-space: nowrap; /* 🔥 文字不換行 */
  min-width: 90px;      /* 🔥 改用 min-width 自適應：短文字(回放)不佔滿 160px，三顆總寬變窄不撞左側 threshold */
  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: 1024px) {
  #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;
  }
  /* 🔥 中等寬度(平板直向)：伴奏／參考音軌強制並排不換行，縮小面板高度，避免撞到底部按鈕列 */
  #uploadControls {
    flex-wrap: nowrap !important;
    gap: 16px !important;
  }
  #uploadControls > div {
    flex: 1 1 0;
    min-width: 0;
  }
  #uploadControls input[type="file"] {
    max-width: 100%;
  }
}

/* 手機版直向調整 (小於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;
    /* 🔥 在「左邊音名(44px)」與「右下 zoom 掣(60px)」之間置中,兩邊都不遮 */
    left: calc(44px + env(safe-area-inset-left)) !important;
    right: 60px !important;
    transform: none !important;
    margin: 0 auto !important;
    width: max-content !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;    /* 🔥 三顆同一行不換行 */
	gap: 5px;
	max-width: 96vw;
  }
  
  #freezeToggle button {
  white-space: nowrap; /* 🔥 文字不換行 */
  width: auto;
  min-width: 0;
  padding: 8px 6px;
  font-size: 0.82em;    /* 🔥 縮小字體讓三顆塞進一排 */
  text-align: center;
}
  .playback-button, 
.zoom-button,
#helpButton button{
  width: 34px !important; /* 🔥 縮小 +/−/重設 按鈕寬度 */
  padding-left: 2px !important;
  padding-right: 2px !important;
}

  #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: wrap;      /* 🔥 塞不下可換行 */
	max-width: 70vw;      /* 🔥 限制寬度，置中時左緣不會延伸撞到左側 threshold */
	bottom: calc(78px + env(safe-area-inset-bottom)) !important; /* 🔥 往上移，與 threshold(30px) 垂直錯開 */
  }
  
  #freezeToggle button {
  white-space: nowrap; /* 🔥 文字不換行 */
  width: auto;          /* 🔥 自適應，不再固定 110px */
  min-width: 60px;
  padding: 6px 10px;
  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 */
  }

  /* 🔥 直向手機:＋/−/重設 收窄一點,騰出空間 */
  .zoom-button {
    width: 26px !important;
    padding-left: 1px !important;
    padding-right: 1px !important;
    font-size: 0.85em !important;
  }

  #freezeToggle {
    bottom: calc(30px + env(safe-area-inset-bottom) + 5px + 10px + 10px + 50px)!important; /* threshold高度約50px */
  }
}


/* 🔥 Scale 彈窗下拉選項在深色下的可讀性 */
#scalePatternSelect option, #scaleSaveAs option {
  background: #1e1e1e;
  color: #fff;
}

/* 🔥 面板 tab */
.panel-tab {
  opacity: 0.55;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}
.panel-tab.active {
  opacity: 1;
  border-bottom-color: #0056B3 !important;
  font-weight: bold;
}

/* 🔥 音階練習預設按鈕（兩行：pattern 大 + 音域bpm 小） */
.scale-preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: rgba(255,255,255,0.2); /* 平常跟播放按鈕一樣 */
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 5px;
  cursor: pointer;
  line-height: 1.2;
  font-size: 1em; /* 🔥 明確基準，與生成按鈕一致（button UA 預設字體不會生效） */
  transition: background 0.15s ease, transform 0.08s ease, filter 0.15s ease;
}
.scale-preset-btn.active {
  background: #0056B3; /* 🔥 選中的那個才藍色 */
}
/* 生成按鈕：與預設按鈕相同 padding／字體／高度（單行文字垂直置中） */
.scale-gen-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.2);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 5px;
  cursor: pointer;
  line-height: 1.2;
  font-size: 1em;
  transition: background 0.15s ease, transform 0.08s ease, filter 0.15s ease;
}
.scale-preset-btn .preset-pattern {
  font-size: 1em;
  white-space: nowrap;
}
.scale-preset-btn .preset-range {
  font-size: 0.72em;
  opacity: 0.85;
  white-space: nowrap;
}

/* ============================================================
   🔥 回放控制列（playbackBar）：放在底部控制項上方一點，各斷點微調 bottom 貼近不重疊。
   ============================================================ */
#playbackBar {
  bottom: calc(88px + env(safe-area-inset-bottom)) !important; /* 桌面 */
}
@media (min-width: 600px) and (max-width: 1024px) {
  #playbackBar { bottom: calc(158px + env(safe-area-inset-bottom)) !important; max-width: 72vw !important; }
}
@media (max-width: 600px) {
  #playbackBar { bottom: calc(150px + env(safe-area-inset-bottom)) !important; }
}
@media (orientation: landscape) and (max-height: 600px) {
  #playbackBar { bottom: calc(124px + env(safe-area-inset-bottom)) !important; max-width: 72vw !important; }
}

/* 🔥 超窄比例(如 Galaxy Z Fold 摺疊 ~344px):只針對呢種極窄屏 */
@media (max-width: 380px) {
  /* 面板加高度上限 + 內部捲動,避免蓋住底部按鈕/threshold */
  #uploadSection {
    max-height: calc(100dvh - 180px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  /* footer 縮字,避免 nowrap 被裁走 */
  .footer-fixed {
    font-size: 10px !important;
  }
}

/* ===== 設定彈窗 ===== */
#settingsModal { font-size: 16px; }
#settingsModal .settingsGroup {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
}
/* 設定內的音量列：整行拉滿、左標籤右數值 */
#settingsModal .volumeControl.setFull {
  max-width: none;
  width: 100%;
  margin-top: 0;
}
#settingsModal .volumeControl.setFull label {
  width: 8em;
  flex: 0 0 8em;      /* 固定寬 → 各列冒號對齊、滑桿起點一致 */
  white-space: nowrap;
  text-align: right;  /* 靠右 → 冒號(末字)排在同一線 */
  color: #f0f0f0;
}
#settingsModal .volumeControl.setFull input[type="range"] { flex: 1; accent-color: #4a9eff; }
#settingsModal .volumeControl.setFull span {
  min-width: 54px;
  text-align: right;
  color: #f0f0f0;
  overflow: visible;
}
#settingsModal .settingsButtons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}
#settingsModal .settingsContact {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 16px;
}
.set-btn {
  border: none;
  border-radius: 5px;
  padding: 10px 14px;
  cursor: pointer;
  color: white;
  font-size: 15px;
  line-height: 1.35;
}
.set-btn-blue { background: #007bff; }
.set-btn-gray { background: gray; }
.set-btn-red  { background: #c0392b; }
.set-btn-ig   { background: #d63384; width: 45%; }
.set-btn-wa   { background: #43a047; width: 45%; }

/* ===== 設定彈窗：手機窄螢幕收邊距(參考 helpModal RWD) ===== */
@media (max-width: 600px) {
  #settingsModal { font-size: 12px; }
  #settingsModal button { font-size: 13px; }
  #settingsModal > div {
    padding: 12px 14px !important;   /* 卡片左右/上下縮窄 */
  }
  #settingsModal .settingsGroup { gap: 9px; }
  #settingsModal .volumeControl.setFull label { min-width: 56px; }
  #settingsModal .volumeControl.setFull span { min-width: 46px; }
  #settingsModal .settingsButtons { gap: 8px; margin-top: 14px; }
  #settingsModal .settingsContact { gap: 10px; margin-top: 12px; }
  #settingsModal .set-btn { padding: 9px 10px; font-size: 13px; }
}

@media (max-width: 380px) {
  #settingsModal > div { padding: 10px 10px !important; }
  #settingsModal .settingsButtons,
  #settingsModal .settingsContact { gap: 6px; }
  #settingsModal .set-btn { padding: 8px 8px; font-size: 12px; }
  #settingsModal .set-btn-ig,
  #settingsModal .set-btn-wa { width: 47%; }
}

/* 手機橫向(矮螢幕)：卡片可捲動並收邊距，避免超出畫面 */
@media (orientation: landscape) and (max-height: 600px) {
  #settingsModal { font-size: 12px; }
  #settingsModal button { font-size: 13px; }
  #settingsModal > div { padding: 10px 16px !important; max-height: 92%; }
  #settingsModal .settingsGroup { gap: 8px; }
}
