:root {
  --bg-primary: #121418;
  --bg-surface: #1e222b;
  --bg-surface-elevated: #282e3a;
  --border-color: #363d4e;
  --text-main: #f0f3f8;
  --text-muted: #9aa5b8;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --highlight-measure: rgba(59, 130, 246, 0.28);
  --highlight-playing: rgba(16, 185, 129, 0.4);
  --highlight-border: #3b82f6;
  --highlight-playing-border: #10b981;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* App Header */
.app-header {
  height: 52px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  user-select: none;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.project-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.project-title-input:hover, .project-title-input:focus {
  border-color: var(--border-color);
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  outline: none;
}

/* Header Buttons & Tabs */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  background-color: var(--bg-surface-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn:hover {
  background-color: var(--border-color);
}

.btn-primary {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  color: #fff;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-success {
  background-color: var(--success-color);
  border-color: var(--success-color);
  color: #fff;
}

.mode-segmented-control {
  display: flex;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 2px;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 5px 12px;
  font-size: 0.82rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  background: var(--accent-color);
  color: #fff;
  font-weight: 600;
}

/* Main Layout */
.app-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.app-sidebar {
  width: 380px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, width 0.25s ease;
  z-index: 50;
}

.app-sidebar.hidden {
  transform: translateX(-100%);
  width: 0;
  position: absolute;
  height: 100%;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
}

.sidebar-tab-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  text-align: center;
}

.sidebar-tab-btn.active {
  color: var(--text-main);
  border-bottom-color: var(--accent-color);
  font-weight: 600;
  background: var(--bg-surface);
}

.sidebar-content-view {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 雙獨立面板設計：上方面板固定，下方面板獨立滾動 */
.sidebar-fixed-top-panel {
  flex-shrink: 0;
  padding: 12px;
  background: var(--bg-surface);
  border-bottom: 2px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

.sidebar-scrollable-bottom-panel {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 16px 12px;
  display: flex;
  flex-direction: column;
}

/* Tree View */
.tree-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tree-node-page, .tree-node-line {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.tree-header {
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  transition: background 0.15s;
}

.tree-header:hover {
  background: var(--border-color);
}

.tree-toggle-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  margin-right: 4px;
}

.tree-toggle-arrow.collapsed {
  transform: rotate(-90deg);
}

.tree-children {
  padding: 4px 8px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tree-children.collapsed {
  display: none;
}

.measure-tree-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.measure-tree-item:hover {
  border-color: var(--accent-color);
}

.measure-tree-item.selected {
  border-color: var(--accent-color);
  background: rgba(59, 130, 246, 0.15);
}

/* Measure Property Panel */
.measure-property-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.property-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent-color);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.form-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.form-input, .form-select {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 0.82rem;
  flex: 1;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent-color);
  outline: none;
}

/* Seq Table View */
.seq-table-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.seq-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.seq-table th, .seq-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border-color);
  text-align: center;
}

.seq-table th {
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
  font-weight: 600;
}

.seq-row {
  cursor: pointer;
  transition: background 0.15s;
}

.seq-row:hover {
  background: var(--bg-surface-elevated);
}

.seq-row.active {
  background: rgba(59, 130, 246, 0.15);
  font-weight: 600;
}

/* 正在等待樂譜點選帶入的小節欄位呼吸閃爍高亮 */
.seq-cell-blinking {
  animation: seqCellBlink 0.75s infinite alternate ease-in-out !important;
  border-radius: 4px;
  font-weight: 700 !important;
}

@keyframes seqCellBlink {
  0% {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    box-shadow: inset 0 0 0 1.5px rgba(16, 185, 129, 0.4);
  }
  100% {
    background: rgba(16, 185, 129, 0.45);
    color: #ffffff;
    box-shadow: inset 0 0 0 2px #10b981, 0 0 8px rgba(16, 185, 129, 0.6);
  }
}

.btn-seq-action {
  padding: 3px 6px;
  font-size: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.btn-seq-action.btn-edit-seq {
  background: var(--bg-surface-elevated);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-seq-action.btn-edit-seq:hover {
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}

.btn-seq-action.btn-edit-seq.editing {
  background: #10b981 !important;
  color: #fff !important;
  border-color: #10b981 !important;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.7);
}

/* Sheet View / Canvas Area (支援垂直與水平雙向自由滾動 H-Scroll) */
.app-sheet-container {
  flex: 1;
  background-color: #0b0d10;
  overflow-y: auto;
  overflow-x: auto; /* 開啟水平滾動條 */
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  position: relative;
}

/* 深色高質感自訂水平/垂直捲軸 */
.app-sheet-container::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.app-sheet-container::-webkit-scrollbar-track {
  background: #121418;
}

.app-sheet-container::-webkit-scrollbar-thumb {
  background: #363d4e;
  border-radius: 5px;
  border: 2px solid #121418;
}

.app-sheet-container::-webkit-scrollbar-thumb:hover {
  background: #4b5563;
}

.sheet-page-wrapper {
  position: relative;
  background: #ffffff;
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.7);
  border-radius: 2px;
  user-select: none;
  flex-shrink: 0; /* 放大時維持實際縮放尺寸，不被父容器強行擠壓 */
  transition: width 0.15s ease, height 0.15s ease;
}

.sheet-pdf-canvas {
  display: block;
}

.sheet-measure-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
}

/* 只顯示原譜模式：徹底隱藏所有小節覆蓋層與編輯線條 */
.pure-sheet-mode .sheet-measure-overlay {
  display: none !important;
}

/* Line Block Container on Canvas */
.line-block {
  position: absolute;
  background: transparent;
  box-sizing: border-box;
  /* 讓行外框在平時與拖拉時均清晰可見，利於樂手視覺精準對位 */
  border: 1.5px dashed rgba(59, 130, 246, 0.55);
  transition: border-color 0.15s ease;
}

.line-block.selected-line,
.line-block:hover {
  border: 1.5px dashed rgba(139, 92, 246, 0.95);
  background: rgba(139, 92, 246, 0.04);
}

/* 正在移動整行或拉伸高度時：鮮豔黃色實線實體外框 + 陰影光暈，對齊樂譜清晰醒目 */
.line-block.dragging-line {
  border: 2.5px solid #f59e0b !important;
  background: rgba(245, 158, 11, 0.14) !important;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.65) !important;
  z-index: 9999 !important;
  will-change: transform !important;
  transition: none !important; /* 拖曳期間嚴禁過渡動畫延遲視覺跟隨 */
}

/* Line Horizontal Boundary Resize Handles (頂部與底部獨立水平邊界線) */
.line-resize-handle {
  position: absolute;
  height: 20px;
  cursor: row-resize;
  z-index: 70;
  touch-action: none;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}

.line-handle-top {
  top: -10px;
}

.line-handle-bottom {
  bottom: -10px;
}

/* 水平邊界實體線條 (預設為清晰可見的藍色實線) */
.line-resize-handle::after {
  content: '';
  width: 100%;
  height: 3px;
  background: #3b82f6;
  border-radius: 1px;
  transition: background 0.15s, height 0.15s;
  pointer-events: none;
}

/* 當被選中、懸停或正在拖曳時變為鮮豔黃色 */
.line-block.selected-line .line-resize-handle::after {
  background: #8b5cf6;
  height: 3.5px;
}

.line-resize-handle:hover::after, .line-resize-handle.dragging::after {
  height: 6px !important;
  background: #f59e0b !important;
  box-shadow: 0 0 12px #f59e0b !important;
}

.line-move-handle {
  position: absolute;
  top: -18px;
  left: 0;
  background: #3b82f6;
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 2px;
  cursor: move !important;
  z-index: 41;
  font-weight: 600;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
  touch-action: none !important;
}

/* 全域拖曳移動中狀態：鎖定游標為 move 且禁止任何文字反白，防止游標變形為系統預設箭頭 */
body.global-dragging-line-active,
body.global-dragging-line-active * {
  cursor: move !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

.line-block.selected-line .line-move-handle {
  background: #8b5cf6;
}

/* Vertical Barline Divider inside Line Block (左右邊界線與小節線) */
.barline-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20px;
  transform: translateX(-50%); /* 絕對物理中心對齊，消滅任何 offset 偏差 */
  cursor: col-resize;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.barline-divider::after {
  content: '';
  width: 2px;
  height: 100%;
  background: #3b82f6;
  transition: background 0.15s, width 0.15s;
  pointer-events: none;
}

.barline-divider:hover::after, .barline-divider.dragging::after {
  background: #f59e0b;
  width: 5px;
  box-shadow: 0 0 10px #f59e0b;
}

/* 行最左與最右垂直邊界線 */
.barline-divider.edge-line::after {
  background: #8b5cf6;
  width: 3.5px;
}

/* Measure Boxes on Canvas (小節區塊：無多餘邊框干擾，純淨透明) */
.measure-box {
  position: absolute;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.12s ease;
  box-sizing: border-box;
}

.measure-box:hover {
  background: rgba(59, 130, 246, 0.12);
}

.measure-box.selected-editing {
  background: rgba(59, 130, 246, 0.2);
}

/* 方案 2：紅色鮮明純外框（內部 100% 透明，完全零遮擋樂譜音符，3.5px 鮮紅粗框） */
.measure-box.active-playing,
.performance-mode .measure-box.active-playing,
.playback-active .measure-box.active-playing,
body.playback-active .measure-box.active-playing,
body.performance-mode .measure-box.active-playing {
  background: transparent !important;
  border: 3.5px solid #ef4444 !important; /* 鮮紅色醒目實線外框 (線條加粗醒目) */
  box-sizing: border-box !important;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.45) !important;
  border-radius: 3px !important;
  position: absolute !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 9999 !important;
  pointer-events: auto !important;
}

.measure-box.active-playing::before {
  content: none !important;
}

/* 換行或跨躍預讀：綠色方塊 Highlight (鮮明翡翠綠，3.5px 粗線，內部 100% 透明零遮擋) */
.measure-box.active-lookahead,
.performance-mode .measure-box.active-lookahead,
.playback-active .measure-box.active-lookahead,
body.playback-active .measure-box.active-lookahead,
body.performance-mode .measure-box.active-lookahead {
  background: transparent !important;
  border: 3.5px solid #10b981 !important; /* 鮮綠色預讀外框 */
  box-sizing: border-box !important;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.45) !important;
  border-radius: 3px !important;
  position: absolute !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 9998 !important;
  pointer-events: auto !important;
}

.measure-box.active-lookahead::before {
  content: none !important;
}

/* 預讀導引指標：紅框上方或下方的閃爍跳躍箭號 (朝向下一小節方向) */
.measure-direction-arrow {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: #10b981;
  font-size: 22px;
  line-height: 1;
  pointer-events: none !important;
  z-index: 10000 !important;
  text-shadow: 0 0 8px rgba(16, 185, 129, 0.9), 0 2px 4px rgba(0, 0, 0, 0.8);
  filter: drop-shadow(0 0 3px rgba(16, 185, 129, 0.8));
}

.measure-direction-arrow.arrow-down {
  bottom: -28px;
  animation: arrowBounceDown 0.6s infinite alternate ease-in-out;
}

.measure-direction-arrow.arrow-up {
  top: -28px;
  animation: arrowBounceUp 0.6s infinite alternate ease-in-out;
}

@keyframes arrowBounceDown {
  0% {
    transform: translateX(-50%) translateY(0);
    opacity: 0.5;
  }
  100% {
    transform: translateX(-50%) translateY(5px);
    opacity: 1;
  }
}

@keyframes arrowBounceUp {
  0% {
    transform: translateX(-50%) translateY(0);
    opacity: 0.5;
  }
  100% {
    transform: translateX(-50%) translateY(-5px);
    opacity: 1;
  }
}

/* 演奏模式與播放中：極致緊縮頁間距，大幅消除跨頁空白，讓跨頁如同換行，餘光輕鬆可及 */
.performance-mode .app-sheet-container,
.playback-active .app-sheet-container {
  gap: 24px !important;
  padding: 16px 24px !important;
}

/* 演奏模式下長條影像切塊容器 */
.sheet-strip-wrapper {
  position: relative;
  background: #ffffff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
  border-radius: 2px;
  user-select: none;
  flex-shrink: 0;
  margin-bottom: 24px;
}

.sheet-strip-wrapper:last-child {
  margin-bottom: 60px;
}

.sheet-strip-image {
  display: block;
  width: 100%;
  height: 100%;
  /* 樂譜純黑銳利度與對比度增強 (消除縮放泛灰發淡) */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  filter: contrast(1.15) brightness(0.97);
}

/* 原始 PDF 畫布亦同步套用對比增強 */
.sheet-page-canvas {
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  filter: contrast(1.15) brightness(0.97);
}

/* 編輯模式下的 Page Box (演奏顯示範圍框) */
.page-box-container {
  position: absolute;
  border: 1.5px dashed rgba(16, 185, 129, 0.85);
  background: rgba(16, 185, 129, 0.04);
  box-sizing: border-box;
  pointer-events: none;
  z-index: 55;
}

.page-box-label {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 11px;
  color: #10b981;
  background: rgba(0, 0, 0, 0.7);
  padding: 1px 6px;
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
}

/* 四邊與四角調整把手 */
.page-box-handle {
  position: absolute;
  pointer-events: auto;
  z-index: 60;
  box-sizing: border-box;
}

.page-box-handle.handle-top,
.page-box-handle.handle-bottom {
  left: 10%;
  width: 80%;
  height: 14px;
  cursor: row-resize;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-box-handle.handle-top { top: -7px; }
.page-box-handle.handle-bottom { bottom: -7px; }

.page-box-handle.handle-left,
.page-box-handle.handle-right {
  top: 10%;
  height: 80%;
  width: 14px;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-box-handle.handle-left { left: -7px; }
.page-box-handle.handle-right { right: -7px; }

.page-box-handle.handle-top::after,
.page-box-handle.handle-bottom::after {
  content: '';
  width: 50px;
  height: 4px;
  background: #10b981;
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.8);
}

.page-box-handle.handle-left::after,
.page-box-handle.handle-right::after {
  content: '';
  width: 4px;
  height: 50px;
  background: #10b981;
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.8);
}

/* 行高調整鎖定模式 (Lock Line Height)：
   - 僅鎖定水平邊界調整線（.line-resize-handle）：水平外框線清晰顯示以供對位，但禁用上下拉伸 (pointer-events: none)，無 ↕ 游標。
   - 完整保留整行移動手柄（.line-move-handle）：允許自由點擊按住上下平移整行位置！ */
.line-height-locked .line-resize-handle {
  cursor: default !important;
  pointer-events: none !important;
}

.line-height-locked .line-move-handle {
  cursor: move !important;
  pointer-events: auto !important;
  display: block !important;
}

.line-height-locked .line-resize-handle:hover::after {
  height: 3px !important;
  background: #3b82f6 !important;
  box-shadow: none !important;
}

.line-height-locked .line-block.selected-line .line-resize-handle:hover::after {
  background: #8b5cf6 !important;
}

/* 演奏模式與曲式編輯模式 (點擊頂部 ▶️ 演奏模式 或 切換側邊欄「曲式」Tab)：
   徹底隱藏並禁用所有幾何邊界之拖拉與移動游標，滑鼠移至小節線或上下邊界時絕不變形為拖拉符號 */
.performance-mode .line-resize-handle,
.performance-mode .barline-divider,
.performance-mode .line-move-handle,
.seq-editing-mode .line-resize-handle,
.seq-editing-mode .barline-divider,
.seq-editing-mode .line-move-handle {
  display: none !important;
  pointer-events: none !important;
  cursor: default !important;
}

.performance-mode .line-block,
.performance-mode .line-block *,
.seq-editing-mode .line-block,
.seq-editing-mode .line-block * {
  cursor: default !important;
}

.performance-mode .measure-box,
.seq-editing-mode .measure-box {
  cursor: pointer !important; /* 保留小節純點選以定位或帶入起訖小節 */
}

/* 演奏進行中時樂譜極致純淨降噪模式 (除當前演奏光標外，完全去除其餘所有添加物、徽章與拖曳變形游標) */
.playback-active .measure-badge,
.playback-active .line-resize-handle,
.playback-active .barline-divider,
.playback-active .line-move-handle {
  display: none !important;
  pointer-events: none !important;
  cursor: default !important;
}

.playback-active .line-block,
.playback-active .line-block * {
  border-color: transparent !important;
  box-shadow: none !important;
  background: transparent !important;
  cursor: default !important;
}

.playback-active .measure-box {
  cursor: default !important;
}

.playback-active .measure-box:not(.active-playing) {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  cursor: default !important;
}

.measure-box.seq-start-point {
  border: 2px solid var(--success-color);
  background: rgba(16, 185, 129, 0.25);
}

.measure-box.seq-end-point {
  border: 2px solid var(--danger-color);
  background: rgba(239, 68, 68, 0.25);
}

.measure-box.seq-in-range {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.4);
}

.measure-badge {
  position: absolute;
  top: -24px; /* 向上浮在頂部藍色水平線上方，絕不與線條疊合 */
  left: 3px;
  background: #1d4ed8; /* 扎實深藍底色 */
  color: #ffffff; /* 純白高對比清晰文字 */
  border: 1px solid #60a5fa; /* 亮藍邊框 */
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 800;
  pointer-events: none;
  z-index: 60;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

/* Bottom Player Controller HUD */
.app-player-hud {
  height: 68px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  position: relative;
  transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1), opacity 0.3s ease;
}

/* 播放進行中：HUD 自動向下隱藏至螢幕外，徹底留出全螢幕樂譜視野 */
body.playback-active .app-player-hud {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.7);
}

/* 當使用者觸控底部感應區或螢幕時暫時喚出 HUD */
body.playback-active .app-player-hud.hud-revealed {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* 播放進行中：全螢幕專注隱藏頂部 Header 與左側 Sidebar */
body.playback-active .app-header,
body.playback-active .app-sidebar {
  display: none !important;
}

/* 底部觸控感應熱區 (Touch Hotspot Trigger)：平常透明，觸控時喚起 HUD */
.hud-touch-hotspot {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  z-index: 99;
  cursor: pointer;
}

body.playback-active .hud-touch-hotspot {
  display: block;
}

/* 全寬播放進度條容器 (貼合在 HUD 頂部邊緣) */
.hud-progress-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  overflow: hidden;
  transition: height 0.15s ease;
}

.hud-progress-wrapper:hover {
  height: 10px;
}

.hud-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.8);
  transition: width 0.08s linear;
  pointer-events: none;
}

.hud-progress-wrapper:hover .hud-progress-bar {
  background: linear-gradient(90deg, #60a5fa, #34d399);
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.hud-center {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.85rem;
}

.btn-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.beat-indicators {
  display: flex;
  gap: 6px;
  align-items: center;
}

.beat-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  transition: background 0.1s, transform 0.1s;
}

.beat-dot.active-first {
  background: var(--success-color);
  box-shadow: 0 0 10px var(--success-color);
  transform: scale(1.2);
}

.beat-dot.active-sub {
  background: var(--accent-color);
  box-shadow: 0 0 8px var(--accent-color);
  transform: scale(1.15);
}

.progress-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.progress-main {
  font-size: 0.95rem;
  font-weight: 700;
}

.progress-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* =========================================================
   行動裝置與觸控小螢幕專用極簡演奏版面 (Mobile / Touch Screen)
   ========================================================= */

/* 共用行動端精簡樣式 Mixin 規則 */
@media (max-width: 900px), (pointer: coarse) and (max-height: 600px) {
  .app-sidebar {
    position: fixed !important;
    top: 44px;
    bottom: 56px;
    left: 0;
    width: 320px !important;
    max-width: 85vw !important;
    z-index: 25000 !important;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.85);
    background: #181a20 !important;
    transition: transform 0.25s cubic-bezier(0.2, 0, 1) !important;
    display: flex !important;
  }

  .app-sidebar.mobile-drawer-open {
    transform: translateX(0) !important;
  }

  .sidebar-tabs,
  #viewTree {
    display: none !important;
  }

  #viewSeq {
    display: flex !important;
    padding: 10px;
    gap: 8px;
  }

  .mobile-drawer-header {
    display: flex !important;
  }

  .app-header {
    height: 44px;
    padding: 0 10px;
  }

  .brand-title {
    font-size: 0.95rem;
  }

  #projectTitleInput,
  #btnLoadPdf,
  #btnSaveProject,
  #btnCloseProject,
  #btnUndo,
  #btnTogglePureSheet,
  .zoom-controls,
  .mode-segmented-control {
    display: none !important;
  }

  #btnMobilePracticeSeq {
    display: inline-flex !important;
    padding: 4px 10px;
    font-size: 0.8rem;
  }

  .header-actions {
    gap: 6px;
  }

  #btnOpenProject {
    padding: 4px 10px;
    font-size: 0.8rem;
    font-weight: 600;
  }

  /* 底部 HUD：採用三欄 space-between 平衡佈局，Play 控制群組居中 */
  .app-player-hud {
    height: 56px;
    padding: 0 12px;
    gap: 8px;
    justify-content: space-between !important;
  }

  .hud-left {
    gap: 8px;
    flex: 1 1 0%;
    min-width: 0;
    justify-content: flex-start;
  }

  .beat-indicators,
  #hudCountInSelect,
  #hudSeqDisplay,
  #btnToggleSidebar {
    display: none !important;
  }

  .progress-info {
    gap: 0;
  }

  .progress-main {
    font-size: 0.82rem;
  }

  .progress-sub {
    font-size: 0.68rem;
  }

  #hudTimeCounter {
    font-size: 0.78rem !important;
  }

  /* Play 控制鍵群自然居中，左右留白均衡大器 */
  .hud-center {
    gap: 6px;
    flex: 0 0 auto;
    margin: 0 auto;
  }

  .btn-circle {
    width: 36px;
    height: 36px;
    font-size: 0.92rem;
  }

  #btnPlayPause {
    width: 44px !important;
    height: 44px !important;
    font-size: 1.2rem !important;
  }

  /* 右側控制：貼齊右方，速度倍率 + 🔔靜音 + 🔊音量滑桿 */
  .hud-right {
    display: flex !important;
    align-items: center;
    gap: 6px;
    flex: 1 1 0%;
    min-width: 0;
    justify-content: flex-end;
  }

  .metronome-quick-controls {
    display: flex !important;
    align-items: center;
    gap: 6px;
  }

  #btnToggleMetronomeMute {
    display: inline-flex !important;
    padding: 4px 6px !important;
    font-size: 0.78rem !important;
  }

  #hudVolumeSlider {
    display: inline-block !important;
    width: 65px !important;
    height: 6px;
    accent-color: var(--accent-color);
    cursor: pointer;
  }
}

/* 明確指定 body.mobile-mode 時強制生效 (無視螢幕寬度) */
body.mobile-mode .app-sidebar {
  position: fixed !important;
  top: 44px;
  bottom: 56px;
  left: 0;
  width: 320px !important;
  max-width: 85vw !important;
  z-index: 25000 !important;
  transform: translateX(-100%);
  box-shadow: 4px 0 24px rgba(0,0,0,0.85);
  background: #181a20 !important;
  transition: transform 0.25s cubic-bezier(0.2, 0, 1) !important;
  display: flex !important;
}

body.mobile-mode .app-sidebar.mobile-drawer-open {
  transform: translateX(0) !important;
}

body.mobile-mode .sidebar-tabs,
body.mobile-mode #viewTree {
  display: none !important;
}

body.mobile-mode #viewSeq {
  display: flex !important;
  padding: 10px;
  gap: 8px;
}

body.mobile-mode .mobile-drawer-header {
  display: flex !important;
}

body.mobile-mode .app-header {
  height: 44px;
  padding: 0 10px;
}

body.mobile-mode .brand-title {
  font-size: 0.95rem;
}

body.mobile-mode #projectTitleInput,
body.mobile-mode #btnLoadPdf,
body.mobile-mode #btnSaveProject,
body.mobile-mode #btnCloseProject,
body.mobile-mode #btnUndo,
body.mobile-mode #btnTogglePureSheet,
body.mobile-mode .zoom-controls,
body.mobile-mode .mode-segmented-control {
  display: none !important;
}

body.mobile-mode #btnMobilePracticeSeq {
  display: inline-flex !important;
  padding: 4px 10px;
  font-size: 0.8rem;
}

body.mobile-mode .header-actions {
  gap: 6px;
}

body.mobile-mode #btnOpenProject {
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}

body.mobile-mode .app-player-hud {
  height: 56px;
  padding: 0 12px;
  gap: 8px;
  justify-content: space-between !important;
}

body.mobile-mode .hud-left {
  gap: 8px;
  flex: 1 1 0%;
  min-width: 0;
  justify-content: flex-start;
}

body.mobile-mode .beat-indicators,
body.mobile-mode #hudCountInSelect,
body.mobile-mode #hudSeqDisplay,
body.mobile-mode #btnToggleSidebar {
  display: none !important;
}

body.mobile-mode .progress-info {
  gap: 0;
}

body.mobile-mode .progress-main {
  font-size: 0.82rem;
}

body.mobile-mode .progress-sub {
  font-size: 0.68rem;
}

body.mobile-mode #hudTimeCounter {
  font-size: 0.78rem !important;
}

/* Play 控制鍵群自然居中，左右留白均衡大器 */
body.mobile-mode .hud-center {
  gap: 6px;
  flex: 0 0 auto;
  margin: 0 auto;
}

body.mobile-mode .btn-circle {
  width: 36px;
  height: 36px;
  font-size: 0.92rem;
}

body.mobile-mode #btnPlayPause {
  width: 44px !important;
  height: 44px !important;
  font-size: 1.2rem !important;
}

/* 右側控制：貼齊右方，速度倍率 + 🔔靜音 + 🔊音量滑桿 */
body.mobile-mode .hud-right {
  display: flex !important;
  align-items: center;
  gap: 6px;
  flex: 1 1 0%;
  min-width: 0;
  justify-content: flex-end;
}

body.mobile-mode .metronome-quick-controls {
  display: flex !important;
  align-items: center;
  gap: 6px;
}

body.mobile-mode #btnToggleMetronomeMute {
  display: inline-flex !important;
  padding: 4px 6px !important;
  font-size: 0.78rem !important;
}

body.mobile-mode #hudVolumeSlider {
  display: inline-block !important;
  width: 65px !important;
  height: 6px;
  accent-color: var(--accent-color);
  cursor: pointer;
}

