/* ==========================================================================
   SuperDance · Design System v3
   - 视频主导布局：mobile 视频 ~80vh，桌面居中铺
   - Dock：4 chip popover 驱动
   - 节拍轴：折叠/展开态
   ========================================================================== */

@import url('https://rsms.me/inter/inter.css');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-7: 32px; --s-8: 48px;

  --fs-xs: 11px; --fs-sm: 12px; --fs-base: 13px; --fs-md: 14px;
  --fs-lg: 16px; --fs-xl: 20px; --fs-2xl: 26px; --fs-3xl: 36px;

  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-full: 9999px;

  --bg-0: #08090b;
  --bg-1: rgba(255, 255, 255, 0.025);
  --bg-2: rgba(255, 255, 255, 0.05);
  --bg-3: rgba(255, 255, 255, 0.085);
  --bg-hover: rgba(255, 255, 255, 0.07);

  --fg-1: rgba(255, 255, 255, 0.95);
  --fg-2: rgba(255, 255, 255, 0.6);
  --fg-3: rgba(255, 255, 255, 0.38);

  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);

  --accent: #ff4775;
  --accent-soft: rgba(255, 71, 117, 0.14);
  --accent-2: #6ea0ff;
  --accent-2-soft: rgba(110, 160, 255, 0.16);
  --warn: #ffbd5e;
  --warn-soft: rgba(255, 189, 94, 0.18);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 8px 32px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 24px 60px rgba(0, 0, 0, 0.6);

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-snappy: cubic-bezier(0.4, 1.4, 0.5, 1);
  --t-fast: 100ms;
  --t-base: 180ms;
  --t-slow: 280ms;

  --header-h: 52px;
  --dock-h: 64px;
  --max-w: 1600px;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior-y: none; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC',
               'Helvetica Neue', sans-serif;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  font-size: var(--fs-base);
  line-height: 1.45;
  background: var(--bg-0);
  color: var(--fg-1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  letter-spacing: -0.005em;
}
button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* 全局去掉 iOS 点击蓝色高亮（修复点视频/按钮蓝闪一下） */
*, *::before, *::after { -webkit-tap-highlight-color: transparent; }
button, a, [role="button"] { -webkit-tap-highlight-color: transparent; }

/* HTML hidden 属性必须比 display: inline-flex 优先 */
[hidden] { display: none !important; }
.mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace; font-variant-numeric: tabular-nums; }

@media (max-width: 1099px) {
  .hide-mobile { display: none !important; }
}

/* ==========================================================================
   Header
   ========================================================================== */
.header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: rgba(8, 9, 11, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0 var(--s-3);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 500;
  font-size: var(--fs-md);
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--fg-1);
  position: relative;
}
.brand-mark::before {
  content: '';
  position: absolute;
  inset: 5px 8px;
  background: var(--bg-0);
  border-radius: 1px;
}
.brand-mark::after {
  content: '';
  position: absolute;
  top: 5px; bottom: 5px; left: 50%;
  width: 2px; transform: translateX(-50%);
  background: var(--accent);
  border-radius: 1px;
}
@media (max-width: 1099px) {
  .brand span { display: none; }
}
.header-spacer { flex: 1; }
.status {
  font-size: var(--fs-xs);
  color: var(--fg-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 38vw;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 34px;
  padding: 0 var(--s-3);
  background: var(--bg-2);
  color: var(--fg-1);
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.btn:hover { background: var(--bg-3); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: var(--fg-1);
  color: var(--bg-0);
  font-weight: 600;
}
.btn.primary:hover { background: white; }
.btn.ghost { background: transparent; color: var(--fg-2); }
.btn.ghost:hover { background: var(--bg-2); color: var(--fg-1); }
.btn.icon { width: 34px; padding: 0; }
.btn.sm { height: 28px; padding: 0 var(--s-3); font-size: var(--fs-sm); }

.select {
  height: 34px;
  padding: 0 var(--s-7) 0 var(--s-3);
  background: var(--bg-2);
  color: var(--fg-1);
  border: 0;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2.5 4l2.5 2.5L7.5 4' stroke='%23ffffff66' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
}
.select:hover { background-color: var(--bg-3); }

/* ==========================================================================
   Layout shell
   ========================================================================== */
.shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-3);
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding-bottom: calc(var(--dock-h) + var(--s-3) + env(safe-area-inset-bottom));
}

/* ==========================================================================
   Stage / Video
   ========================================================================== */
.stage { display: flex; flex-direction: column; }
.video-wrap {
  position: relative;
  background: black;
  border-radius: var(--r-md);
  overflow: hidden;
  width: 100%;
  /* 移动端：65vh 高度 = 视频区域占视口的 60-70% */
  height: 65dvh;
  box-shadow: var(--shadow-2);
}
@media (min-width: 1100px) {
  .video-wrap {
    height: auto;
    aspect-ratio: 16 / 9;
    max-height: 70vh;
  }
}
#video {
  width: 100%; height: 100%;
  object-fit: contain;
  object-position: center center;
  display: block;
  background: black;
  cursor: pointer;
  transition: transform var(--t-base) var(--ease);
  transform-origin: center center;
}
#video.mirrored { transform: scaleX(-1); }

.video-wrap.zoomed::after {
  content: "拖动画面 · 双指缩放";
  position: absolute;
  left: 50%;
  top: var(--s-3);
  transform: translateX(-50%);
  padding: 5px 10px;
  border-radius: var(--r-full);
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: var(--fs-xs);
  z-index: 8;
  pointer-events: none;
}

/* 跟练分屏：移动端上下，桌面/横屏左右 */
.practice-pane {
  display: none;
  position: relative;
  min-height: 0;
  background: #050507;
  border-left: 1px solid rgba(255,255,255,0.08);
}
body.practice-active .video-wrap {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
}
body.practice-active #video,
body.practice-active .practice-pane {
  width: 100%;
  height: 100%;
  min-height: 0;
}
body.practice-active .practice-pane { display: flex; flex-direction: column; }
@media (min-width: 900px), (orientation: landscape) {
  body.practice-active .video-wrap {
    grid-template-rows: none;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}
.practice-head {
  position: absolute;
  top: 8px; left: 8px; right: 8px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  font-size: var(--fs-xs);
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
.practice-close {
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  background: rgba(0,0,0,0.55);
}
.practice-stage {
  position: relative;
  flex: 1;
  min-height: 0;
}
.practice-live,
.practice-replay {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scaleX(-1);
  background: #050507;
}
.practice-replay { transform: none; }
.practice-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--fg-3);
  font-size: var(--fs-sm);
  pointer-events: none;
}
.practice-actions {
  display: flex;
  gap: var(--s-2);
  padding: var(--s-2);
  background: rgba(8,9,11,0.86);
  border-top: 1px solid rgba(255,255,255,0.08);
}
body.practice-active .fs-toggle,
body.practice-active .overlay-beat {
  right: auto;
}

/* 加载覆盖层 */
.video-busy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  background: rgba(8, 9, 11, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
  pointer-events: auto;
  color: white;
}
.busy-spinner {
  width: 32px; height: 32px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.busy-title { font-size: var(--fs-md); font-weight: 500; }
.busy-sub { font-size: var(--fs-xs); color: var(--fg-2); font-feature-settings: 'tnum'; }
.busy-progress {
  width: min(260px, 72vw);
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.busy-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--warn));
  transition: width 180ms var(--ease);
}
.busy-progress-text {
  min-width: 48px;
  margin-top: calc(var(--s-3) * -1 + 2px);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.76);
  text-align: center;
  font-feature-settings: 'tnum';
}

/* 视觉播放图标（pointer-events: none） */
.video-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-base) var(--ease);
  z-index: 3;
}
.video-icon.visible { opacity: 1; }
#videoIconSvg {
  width: 64px; height: 64px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: var(--r-full);
  padding: 14px;
  color: white;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.4));
}
@media (max-width: 1099px) {
  #videoIconSvg { width: 56px; height: 56px; padding: 12px; }
}

/* 左上角拍数 */
.overlay-beat {
  position: absolute;
  top: var(--s-3);
  left: var(--s-3);
  right: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 40px;
  font-weight: 700;
  color: white;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 6px 12px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-variant-numeric: tabular-nums;
  min-width: 58px;
  text-align: center;
  line-height: 1.1;
  pointer-events: none;
  z-index: 4;
}
@media (max-width: 1099px) {
  .overlay-beat { font-size: 34px; padding: 6px 13px; min-width: 54px; }
}

/* 关闭浏览器在视频区的默认手势（页面滚动 / 长按弹菜单 / 双击放大），
   否则触屏上 pointer/touch 事件经常被原生手势吞掉 */
.video-wrap {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.video-wrap video {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  pointer-events: none; /* 事件交给 wrap 统一处理，避免 iOS Safari 视频吞事件 */
}

/* 喊拍校准面板（?calibrate=1） */
#calibratePanel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: rgba(20, 20, 22, 0.95);
  color: #eee;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  z-index: 300;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#calibratePanel .cal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid rgba(255,255,255,0.08);
  font-weight: 600;
}
#calibratePanel .cal-actions { display: flex; gap: 6px; }
#calibratePanel .cal-btn {
  background: rgba(255,255,255,0.08); color: #eee;
  border: none; border-radius: 5px; padding: 3px 9px; font-size: 12px;
  cursor: pointer;
}
#calibratePanel .cal-btn:hover { background: rgba(255,255,255,0.16); }
#calibratePanel .cal-btn.primary { background: var(--accent, #ff7a00); color: #000; font-weight: 600; }
#calibratePanel .cal-hint {
  padding: 6px 12px; color: #aaa; font-size: 11px;
}
#calibratePanel .cal-rows { padding: 4px 12px 8px; }
#calibratePanel .cal-row {
  display: grid;
  grid-template-columns: 18px 1fr 50px 60px;
  align-items: center; gap: 8px;
  padding: 4px 0;
}
#calibratePanel .cal-name { font-weight: 600; text-align: center; }
#calibratePanel input[type="range"] { width: 100%; accent-color: var(--accent, #ff7a00); }
#calibratePanel .cal-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; text-align: right; color: #fff;
}
#calibratePanel .cal-auto {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: #888; text-align: right;
}
#calibratePanel .cal-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-top: 1px solid rgba(255,255,255,0.08);
}
#calibratePanel .cal-status {
  font-family: 'JetBrains Mono', monospace; font-size: 10px; color: #888;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 重音点标定 overlay (?mark=1) */
#markPanel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 400;
  display: flex; align-items: center; justify-content: center;
  font-family: system-ui, -apple-system, sans-serif;
}
#markPanel .mark-card {
  background: #1a1a1c;
  color: #eee;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 28px 32px;
  width: 480px;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#markPanel .mark-title { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
#markPanel .mark-sub { font-size: 13px; color: #aaa; margin-bottom: 24px; }
#markPanel .mark-current {
  font-size: 96px; font-weight: 700; line-height: 1;
  color: var(--accent, #ff7a00);
  margin: 12px 0;
}
#markPanel .mark-progress {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px; color: #888; margin-bottom: 12px;
}
#markPanel .mark-taps {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px; color: #ccc; min-height: 20px; margin: 8px 0 20px;
  letter-spacing: 0.04em;
}
#markPanel .mark-actions {
  display: flex; gap: 8px; justify-content: center; margin-bottom: 16px;
}
#markPanel .mark-actions .cal-btn {
  padding: 6px 14px; font-size: 13px;
  background: rgba(255,255,255,0.08); color: #eee;
  border: none; border-radius: 6px; cursor: pointer;
}
#markPanel .mark-actions .cal-btn:hover:not(:disabled) { background: rgba(255,255,255,0.16); }
#markPanel .mark-actions .cal-btn.primary { background: var(--accent, #ff7a00); color: #000; font-weight: 600; }
#markPanel .mark-actions .cal-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#markPanel .mark-result {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: #aaa; text-align: left;
  background: rgba(0,0,0,0.4); border-radius: 6px;
  padding: 10px; margin-top: 12px; min-height: 20px;
}
#markPanel .mark-result pre {
  margin: 6px 0; color: #fff; word-break: break-all; white-space: pre-wrap;
}

/* 右上小版本号 */
.app-version {
  position: fixed;
  top: 6px;
  right: 8px;
  z-index: 200;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: rgba(255,255,255,.35);
  letter-spacing: .04em;
  pointer-events: none;
  user-select: none;
}

/* 长按竖屏视频进入"绝对拖动"时的反馈：底部出现一条横向高亮 */
.video-wrap.absolute-drag::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent, #ff7a00), #fff);
  z-index: 6;
  pointer-events: none;
  animation: absdrag-pulse 1.2s ease-in-out infinite;
}
@keyframes absdrag-pulse {
  0%, 100% { opacity: .7; }
  50% { opacity: 1; }
}

/* B 站风格大时间码浮层（拖动 / 滑动时显示） */
/* 拖动时间提示：B 站风格——靠下、小、不挡视频内容 */
.seek-overlay {
  position: absolute;
  left: 50%;
  bottom: 14%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
  background: rgba(0, 0, 0, 0.62);
  color: white;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 7;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow-2);
}
.seek-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.seek-delta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  opacity: 0.9;
}
/* 兼容旧 swipe-overlay 引用，无样式即可 */
.swipe-overlay { display: none; }

/* 全屏切换 */
.fs-toggle {
  position: absolute;
  bottom: var(--s-3);
  right: var(--s-3);
  width: 44px; height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--r-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: white;
  z-index: 5;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.fs-toggle:hover, .fs-toggle:active { background: rgba(0, 0, 0, 0.78); transform: scale(0.96); }

/* ==========================================================================
   Progress bar
   ========================================================================== */
.progress-wrap { display: flex; flex-direction: column; gap: 1px; }
.progress-bar {
  position: relative;
  height: 14px;
  background: var(--bg-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.progress-filled {
  position: absolute; inset: 0 auto 0 0;
  width: 0%;
  background: var(--fg-2);
  pointer-events: none;
  transition: background var(--t-fast) var(--ease);
}
.progress-bar:hover .progress-filled { background: var(--fg-1); }
.progress-ticks { position: absolute; inset: 0; pointer-events: none; }
.progress-ticks .tick {
  position: absolute;
  top: 50%; transform: translate(-50%, -50%);
  width: 1px; height: 6px;
  background: rgba(255, 255, 255, 0.18);
}
.progress-ticks .tick.bar-start {
  width: 1px; height: 11px;
  background: rgba(255, 255, 255, 0.55);
}
.progress-downbeat {
  position: absolute; top: -2px; bottom: -2px;
  width: 2px;
  background: var(--warn);
  pointer-events: none;
  display: none;
  box-shadow: 0 0 6px rgba(255, 189, 94, 0.5);
}
.progress-time {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  line-height: 1.1;
  color: var(--fg-3);
  opacity: 0.65;
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
  margin-top: -1px;
}

/* ==========================================================================
   Beats panel (折叠/展开)
   ========================================================================== */
.beats-panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.beats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.beats-bar-info {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  min-width: 0;
}
.beats-bar-label {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.beats-bar-sub {
  font-size: var(--fs-xs);
  color: var(--fg-2);
  font-feature-settings: 'tnum';
}
.beats-bar-actions { display: flex; gap: var(--s-2); }

/* 折叠态：当前 8 拍单行 */
.current-bar {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  min-height: 60px;
}
.current-bar:empty::before {
  content: '加载视频后显示';
  grid-column: 1 / -1;
  color: var(--fg-3);
  font-size: var(--fs-sm);
  text-align: center;
  padding: var(--s-4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
}

/* 展开态：所有拍点 */
.all-bars {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding-top: var(--s-2);
  border-top: 1px solid var(--line);
}
.all-bars-hint {
  font-size: var(--fs-xs);
  color: var(--warn);
  background: var(--warn-soft);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  text-align: center;
}
.all-bars #allBarsContent {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  max-height: 50dvh;
  overflow-y: auto;
  padding-right: var(--s-1);
}
.bar-row { display: flex; flex-direction: column; gap: 4px; }
.bar-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-xs);
  color: var(--fg-3);
  letter-spacing: 0.04em;
  padding-left: 2px;
}
.bar-row.intro .bar-label { color: var(--warn); opacity: 0.85; }
.bar-row.intro .beat-cell { opacity: 0.5; }
.bar {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

/* Beat cell */
.beat-cell {
  position: relative;
  aspect-ratio: 1.4 / 1;
  background: var(--bg-2);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease-snappy);
}
.beat-cell:hover { border-color: rgba(255,255,255,0.18); }
.beat-cell.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  z-index: 1;
}
.beat-cell.in-loop { outline: 1px solid var(--accent-2); outline-offset: -2px; }
.beat-cell.loop-anchor::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--accent-2-soft);
  pointer-events: none;
  z-index: 1;
}
.beat-cell.first-beat {
  border-color: var(--warn);
  box-shadow: 0 0 0 1px var(--warn);
}
.beat-cell.no-thumb { background: var(--bg-3); }
.beat-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.beat-num {
  position: absolute;
  top: 4px; left: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: rgba(255,255,255,0.92);
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  z-index: 2;
}
.beat-time {
  position: absolute;
  bottom: 3px; left: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: rgba(255,255,255,0.55);
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
  z-index: 2;
}
.diff-marker { position: absolute; bottom: 3px; right: 4px; font-size: 12px; z-index: 2; }
.downbeat-flag {
  position: absolute;
  top: 3px; right: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  color: var(--warn);
  z-index: 2;
}

/* current-bar (折叠态)中的 cell 大一点，aspect 1:1 */
.current-bar .beat-cell { aspect-ratio: 1 / 1; }

@media (max-width: 1099px) {
  .bar { gap: 3px; }
  .current-bar { gap: 3px; }
  .beat-cell { border-radius: 4px; }
  .all-bars #allBarsContent .beat-cell { aspect-ratio: 1 / 1; }
  .beat-num { font-size: 10px; top: 2px; left: 4px; }
  .beat-time { display: none; }
  .diff-marker { font-size: 11px; bottom: 2px; right: 2px; }
  .downbeat-flag { font-size: 10px; top: 2px; right: 2px; }
}

/* ==========================================================================
   Dock — 4 个 chip popover 驱动
   ========================================================================== */
.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--dock-h);
  z-index: 10000;
  background: rgba(8, 9, 11, 0.88);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.dock-inner {
  height: var(--dock-h);
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0 var(--s-3);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.dock-inner::-webkit-scrollbar { display: none; }
.dock-fade {
  position: absolute;
  top: 1px; bottom: env(safe-area-inset-bottom);
  right: 0;
  width: 32px;
  background: linear-gradient(90deg, transparent, rgba(8, 9, 11, 0.95));
  pointer-events: none;
}

/* chip - 一个独立小框 */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 4px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  flex-shrink: 0;
}
.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 var(--s-3);
  background: transparent;
  color: var(--fg-1);
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease);
}
.chip-btn:hover { background: var(--bg-2); }
.chip.active .chip-btn { color: var(--accent); }
.chip-label {
  color: var(--fg-3);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
}
.chip-value {
  font-family: 'JetBrains Mono', monospace;
  color: var(--fg-1);
  font-size: var(--fs-base);
  font-weight: 600;
}
.chip-icon { color: var(--fg-2); }
.chip.active .chip-icon { color: var(--accent); }

/* 帧 chip 内部两个迷你按钮 */
.chip-btn-mini {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--fg-1);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.chip-btn-mini:hover { background: var(--bg-2); }
.chip-btn-mini:active { transform: scale(0.92); }

.frame-chip { padding-left: var(--s-3); }
.frame-chip .chip-label { margin-right: var(--s-1); }

/* Popover — 防御性隐藏：display + visibility + opacity 三道保险 */
.pop {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  background: rgba(20, 22, 28, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: var(--s-2);
  box-shadow: var(--shadow-2);
  display: none !important;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10020;
}
.pop.open {
  display: block !important;
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  z-index: 10020;
}
.pop.mobile-sheet {
  max-width: calc(100vw - 24px);
  white-space: normal;
  border-radius: 18px;
  padding: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.18), var(--shadow-3);
}
.pop.mobile-sheet .pop-row,
.pop.mobile-sheet#popSpeed {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.pop.mobile-sheet .pop-item {
  justify-content: center;
  height: 42px;
  padding: 0 8px;
  background: rgba(255,255,255,0.06);
}
.pop.mobile-sheet .pop-item.active {
  background: white;
}
.pop-wide { min-width: 220px; }
.pop-row { display: flex; gap: 4px; flex-wrap: wrap; }
.pop-info {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-xs);
  color: var(--fg-2);
  padding: var(--s-2) var(--s-1) 0;
}
.pop-hint {
  font-size: var(--fs-xs);
  color: var(--fg-3);
  padding: var(--s-1);
  margin-top: var(--s-1);
}
.pop-item {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 var(--s-3);
  background: transparent;
  color: var(--fg-1);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease);
}
.pop-item:hover { background: var(--bg-2); }
.pop-item.active {
  background: var(--fg-1);
  color: var(--bg-0);
}

@media (min-width: 1100px) {
  /* 桌面端：dock 静态嵌入，不固定底部 */
  .dock { position: static; height: auto; padding: 0; border: 0; background: transparent; }
  .dock-inner { padding: 0; height: auto; flex-wrap: wrap; overflow: visible; }
  .dock-fade { display: none; }
  .pop { bottom: auto; top: calc(100% + 8px); }
  .shell { padding-bottom: var(--s-4); }
  .video-wrap { aspect-ratio: 16 / 9; max-height: none; }
  /* 桌面：节拍轴在视频右侧 */
  .shell {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    grid-template-areas:
      "stage beats"
      "progress beats"
      "dock beats";
    align-items: start;
  }
  .stage { grid-area: stage; }
  .progress-wrap { grid-area: progress; }
  .dock { grid-area: dock; }
  .beats-panel { grid-area: beats; align-self: stretch; }
}

/* ==========================================================================
   Side dock (全屏沉浸模式)
   ========================================================================== */
.side-dock {
  position: absolute;
  top: 50%;
  right: var(--s-3);
  transform: translateY(-50%);
  display: none;
  flex-direction: column;
  gap: 6px;
  z-index: 6;
}
.side-btn {
  width: 44px; height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--r-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.92);
  transition: background var(--t-fast) var(--ease);
}
.side-btn:hover, .side-btn:active { background: rgba(0, 0, 0, 0.85); }
.side-btn.active {
  background: var(--fg-1);
  color: var(--bg-0);
  border-color: var(--fg-1);
}
.side-btn-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-sm);
  font-weight: 600;
}

/* 沉浸模式下的进度条容器（默认隐藏） */
.fs-progress-wrap {
  position: absolute;
  left: var(--s-3);
  right: var(--s-3);
  bottom: 80px;  /* 给底部 strip 让位 */
  z-index: 5;
  display: none;
  padding-bottom: 8px;
}
.stage.fs-mode .fs-progress-wrap { display: block; }
.progress-bar.fs {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}
.progress-bar.fs:hover { height: 8px; }
.progress-bar.fs .progress-filled { background: white; }
.progress-bar.fs .progress-ticks .tick { background: rgba(255,255,255,0.5); height: 4px; }
.progress-bar.fs .progress-ticks .tick.bar-start { height: 8px; background: white; }

/* 沉浸模式：顶部提示（调节首拍 / A·B 循环 共用样式基底） */
.fs-adjust-hint, .fs-loop-hint {
  position: absolute;
  top: var(--s-4);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 8px 16px;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  font-weight: 500;
  z-index: 7;
  box-shadow: var(--shadow-2);
  white-space: nowrap;
}
.fs-adjust-hint { background: var(--warn); color: #1a1300; }
.fs-loop-hint   { background: var(--accent-2); color: white; }
.fs-hint-done {
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
}

/* Toast 提示 */
.toast {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 22, 28, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line-strong);
  color: var(--fg-1);
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  z-index: 10030;
  box-shadow: var(--shadow-2);
  max-width: calc(100vw - 32px);
  word-break: break-all;
}

/* 加载视频入口 */
.load-panel {
  position: fixed;
  top: 66px;
  right: var(--s-4);
  width: min(320px, calc(100vw - 32px));
  z-index: 10025;
}
.load-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-2);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--r-lg);
  background: rgba(18, 20, 24, 0.96);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.load-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg-1);
  text-align: left;
}
.load-option:active { transform: scale(0.99); }
.load-option-title { font-size: var(--fs-sm); font-weight: 650; }
.load-option-sub { font-size: var(--fs-xs); color: var(--fg-2); }

/* 历史视频 */
.history-panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--s-4);
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10020;
}
.history-card {
  width: min(420px, 92vw);
  max-height: min(620px, 78vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--r-lg);
  background: rgba(18, 20, 24, 0.96);
  box-shadow: var(--shadow-lg);
}
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.history-title { font-size: var(--fs-md); font-weight: 650; }
.history-sub { margin-top: 2px; font-size: var(--fs-xs); color: var(--fg-2); }
.history-close {
  width: 32px; height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg-1);
  font-size: 20px;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3);
  overflow: auto;
}
.history-empty {
  padding: var(--s-5) var(--s-3);
  text-align: center;
  color: var(--fg-2);
  font-size: var(--fs-sm);
}
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-3);
  align-items: center;
  padding: var(--s-3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.04);
}
.history-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-sm);
  font-weight: 600;
}
.history-meta {
  margin-top: 4px;
  color: var(--fg-2);
  font-size: 11px;
  font-feature-settings: 'tnum';
}
.history-actions { display: flex; gap: var(--s-2); }
.history-open, .history-remove {
  border: 0;
  border-radius: var(--r-sm);
  padding: 8px 10px;
  color: var(--fg-1);
  font-size: var(--fs-xs);
}
.history-open { background: var(--accent); color: #111; font-weight: 650; }
.history-remove { background: rgba(255, 255, 255, 0.08); }

/* 喊拍 chip active 状态 */
.chip.count-on .chip-value { color: var(--accent); }

.beats-strip {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: none;
  padding: var(--s-5) var(--s-4) calc(var(--s-3) + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.58) 34%, rgba(0,0,0,0.86) 100%);
  z-index: 4;
}
.strip-toggle {
  position: absolute;
  left: var(--s-4);
  bottom: calc(74px + env(safe-area-inset-bottom));
  display: none;
  z-index: 6;
  padding: 6px 10px;
  border-radius: var(--r-full);
  background: rgba(0,0,0,0.62);
  color: white;
  border: 1px solid rgba(255,255,255,0.12);
  font-size: var(--fs-xs);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.strip-track {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-behavior: smooth;
}
.strip-track::-webkit-scrollbar { display: none; }
.strip-cell {
  flex: 0 0 56px;
  height: 56px;
  background: rgba(255,255,255,0.08);
  border-radius: var(--r-sm);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid transparent;
}
.strip-cell.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.strip-cell img { width: 100%; height: 100%; object-fit: cover; }
.strip-cell .num {
  position: absolute;
  bottom: 2px; left: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
}
.strip-cell.bar-start::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 2px; height: 100%;
  background: rgba(255,255,255,0.28);
}
.strip-cell.first-beat::before { background: var(--warn); }

/* A·B 循环视觉：起始/结束标签 + 范围底色 */
.strip-cell.loop-a, .strip-cell.loop-b {
  outline: 2px solid var(--accent-2);
  outline-offset: -2px;
  z-index: 2;
}
.strip-cell.in-loop {
  background: var(--accent-2-soft);
}
.strip-cell .loop-tag {
  position: absolute;
  top: 2px; right: 2px;
  background: var(--accent-2);
  color: white;
  font-size: 9px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.05em;
  text-shadow: none;
  z-index: 3;
}

/* fs-mode CSS-only: 视频铺满视口 */
.stage.fs-mode .video-wrap {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100vw;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
  z-index: 99;
  aspect-ratio: auto;
}
.stage.fs-mode #video { object-position: center center; }
body.fs-active.portrait-video .stage.fs-mode #video { object-position: center top; }
.stage.fs-mode .side-dock { display: flex; }
.stage.fs-mode .beats-strip { display: block; }
.stage.fs-mode .strip-toggle { display: block; }
body.strip-collapsed .stage.fs-mode .beats-strip { display: none; }
body.strip-collapsed .stage.fs-mode .strip-toggle { bottom: calc(var(--s-4) + env(safe-area-inset-bottom)); }
body.strip-collapsed .stage.fs-mode .fs-progress-wrap { bottom: calc(52px + env(safe-area-inset-bottom)); }
.stage.fs-mode .fs-toggle { display: none; }
body.fs-active { overflow: hidden; }
body.fs-active .header,
body.fs-active .progress-wrap,
body.fs-active .beats-panel,
body.fs-active .dock { display: none !important; }
