:root {
  --bg: #07070c;
  --panel: rgba(18, 18, 29, 0.96);
  --panel2: rgba(38, 38, 54, 0.96);
  --text: #fff;
  --muted: #a8a8b7;
  --border: rgba(255,255,255,0.1);
  --accent: #8b5cf6;
  --accent2: #6d28d9;
  --danger: #ef4444;
  --warning: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}

button {
  border: 0;
  border-radius: 15px;
  min-height: 46px;
  padding: 8px 8px;
  background: var(--panel2);
  color: var(--text);
  font-size: 13px;
  font-weight: 850;
  touch-action: manipulation;
}

button.active {
  outline: 2px solid #fff;
  background: #4f46e5;
}

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}

button.danger {
  background: rgba(239, 68, 68, 0.28);
  color: #fecaca;
}

.hidden { display: none !important; }

.app {
  width: 100%;
  min-height: 100dvh;
  background: #000;
}

.start-screen {
  min-height: 100dvh;
  display: grid;
  align-content: center;
  gap: 22px;
  max-width: 620px;
  margin: 0 auto;
  padding: 24px 14px;
  background: var(--bg);
}

.brand h1 {
  margin: 0;
  font-size: clamp(30px, 8vw, 46px);
  letter-spacing: -0.05em;
}

.brand h1 span {
  font-size: 0.52em;
  color: var(--muted);
}

.brand p, .note, .muted {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.start-modes {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 600px) {
  .start-modes {
    flex-direction: row;
  }
}

.upload-box {
  flex: 1;
  width: 100%;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  border: 1.5px dashed rgba(255,255,255,.24);
  border-radius: 28px;
  background: rgba(255,255,255,.05);
  transition: background 0.2s, transform 0.2s;
  cursor: pointer;
  padding: 20px;
}

.upload-box:active {
  background: rgba(255,255,255,.1);
  transform: scale(0.98);
}

.upload-icon { font-size: 52px; }
.upload-title { font-size: 22px; font-weight: 950; }
.upload-subtitle { font-size: 13px; color: var(--muted); }

.file-input {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-info {
  color: var(--muted);
  font-size: 13px;
}

.practice-screen {
  width: 100%;
  background: #000;
  overflow: hidden;
}

.topBar {
  display: grid;
  grid-template-columns: .7fr 1.25fr 1fr 1fr .85fr .85fr .85fr;
  gap: 5px;
  padding: calc(7px + env(safe-area-inset-top)) 7px 7px;
  background: rgba(10,10,16,.96);
  border-bottom: 1px solid var(--border);
}

.topBtn, .dockBtn {
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 15px;
  min-height: 44px;
  font-size: 12px;
  padding: 6px 4px;
}

.playerCard {
  height: 100%;
  width: 100%;
  min-height: 0;
  background: #000;
}

.player-shell {
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
}

.video-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: #000;
  overflow: hidden;
  touch-action: none;
}

video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}

#beatOverlay {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 10;
  font-size: clamp(58px, 17vw, 112px);
  line-height: 1;
  font-weight: 950;
  color: #ff3b30;
  text-shadow:
    4px 4px 0 #000,
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000,
    2px 2px 0 #000;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 75ms linear, transform 75ms linear;
  pointer-events: none;
}

#beatOverlay.show {
  opacity: 1;
  transform: scale(1);
}

.overlay-badges {
  position: absolute;
  right: 10px;
  top: 12px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-end;
  pointer-events: none;
}

.overlay-badges span {
  background: rgba(0,0,0,.56);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 12px;
}

.warning {
  position: fixed;
  top: calc(70px + env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  z-index: 80;
  background: rgba(245,158,11,.18);
  border: 1px solid rgba(245,158,11,.55);
  color: #facc15;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 13px;
}

.bottomBar {
  display: grid;
  grid-template-columns: .9fr 1.55fr 1.25fr .8fr;
  gap: 6px;
  padding: 7px 7px calc(7px + env(safe-area-inset-bottom));
  background: rgba(10,10,16,.96);
  border-top: 1px solid var(--border);
}

.dockBtn.main {
  font-size: 20px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.32);
}

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 70dvh;
  overflow: auto;
  padding: 12px 14px calc(18px + env(safe-area-inset-bottom));
  background: rgba(18,18,29,.98);
  border-radius: 28px 28px 0 0;
  border: 1px solid var(--border);
  box-shadow: 0 -18px 44px rgba(0,0,0,.45);
}

.sheet-handle {
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.28);
  margin: 0 auto 12px;
}

.sheet-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.bottom-sheet h2 {
  margin: 0;
  font-size: 20px;
}

.small-muted {
  color: var(--muted);
  font-size: 12px;
}

.wide {
  width: 100%;
}

.progress-shell {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,.10);
  margin: 10px 0;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #ec4899);
}

.candidate-grid, .micro-grid, .quick-grid, .more-grid {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.candidate-grid { grid-template-columns: repeat(3, 1fr); }
.micro-grid { grid-template-columns: repeat(2, 1fr); }
.quick-grid { grid-template-columns: repeat(5, 1fr); }
.more-grid { grid-template-columns: repeat(2, 1fr); }

.speed-readout {
  text-align: center;
  font-size: 38px;
  font-weight: 950;
  margin: 8px 0 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.mono {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.small-line {
  margin-top: 10px;
}

@media (max-width: 390px) {
  button { font-size: 11px; }
  .topBar { gap: 4px; padding-left: 5px; padding-right: 5px; }
  .bottomBar { gap: 4px; padding-left: 5px; padding-right: 5px; }
}


.gesture-toast {
  position: absolute;
  z-index: 25;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 116px;
  text-align: center;
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(0,0,0,.68);
  border: 1px solid rgba(255,255,255,.18);
  color: #fff;
  font-size: 18px;
  font-weight: 950;
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.gesture-toast.left {
  left: 27%;
}

.gesture-toast.right {
  left: 73%;
}

.gesture-toast.scrub {
  left: 50%;
  min-width: 210px;
  border-radius: 20px;
  font-size: 17px;
}

.video-stage {
  cursor: pointer;
}

#smartLoopBtn {
  white-space: nowrap;
}

.count-speed-card {
  margin: 10px 0 12px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
}

.count-speed-card label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  margin-bottom: 8px;
}

.count-speed-card select {
  width: 100%;
  min-height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.16);
  background: #1e1e30;
  color: #fff;
  font-size: 16px;
  font-weight: 850;
  padding: 8px 10px;
}

.count-speed-card .small {
  margin-top: 8px;
  font-size: 12px;
}

.video-menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.download-link {
  display: block;
  margin-top: 12px;
  padding: 13px;
  text-align: center;
  color: #fff;
  background: #22c55e;
  border-radius: 16px;
  text-decoration: none;
  font-weight: 900;
}

.beat-strip-panel {
  background: rgba(10,10,22,.94);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 18px;
  padding: 10px 10px 8px;
  box-shadow: 0 -12px 34px rgba(0,0,0,.35);
  backdrop-filter: blur(14px);
}

.beat-strip-inner {
  display: grid;
  grid-template-columns: repeat(32, minmax(10px, 1fr));
  align-items: end;
  gap: 1px;
  min-height: 66px;
  overflow: hidden;
}

.bs-cell {
  display: grid;
  grid-template-rows: 16px 25px 22px;
  justify-items: center;
  align-items: end;
  color: rgba(255,255,255,.30);
  font-size: 10px;
  line-height: 1;
  min-width: 0;
}

.bs-top {
  font-size: 10px;
  color: rgba(255,255,255,.28);
}

.bs-bar {
  width: 2px;
  border-radius: 99px;
  background: rgba(255,255,255,.20);
}

.bs-main .bs-bar { height: 22px; width: 3px; }
.bs-half .bs-bar { height: 15px; }
.bs-qtr .bs-bar { height: 9px; }

.bs-main .bs-label {
  width: 23px;
  height: 23px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
  color: rgba(255,255,255,.44);
}

.bs-kick .bs-bar { background: #fb923c; }
.bs-kick .bs-label { color: #fb923c; }
.bs-snare .bs-bar { background: #f472b6; }
.bs-snare .bs-label { color: #f472b6; }
.bs-other .bs-bar { background: #22d3ee; }
.bs-other .bs-label { color: #22d3ee; }

.bs-active .bs-label {
  background: #3b82f6;
  color: #fff !important;
  box-shadow: 0 0 12px rgba(59,130,246,.75);
}

.beat-strip-legend {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 7px;
  font-size: 11px;
  color: rgba(255,255,255,.45);
}

.beat-strip-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.current { background: #3b82f6; }
.dot.kick { background: #fb923c; }
.dot.snare { background: #f472b6; }
.dot.other { background: #22d3ee; }




/* V1.6 reliable beat strip: structural colors first, possible drum hints second */
.bs-one .bs-bar { background: #ef4444; height: 28px; }
.bs-one .bs-label { color: #ef4444; }

.bs-five .bs-bar { background: #facc15; height: 24px; }
.bs-five .bs-label { color: #facc15; }

.bs-possible-kick .bs-bar {
  background: #fb923c !important;
  box-shadow: 0 0 8px rgba(251,146,60,.55);
}
.bs-possible-kick .bs-label {
  color: #fb923c !important;
}

.bs-possible-snare .bs-bar {
  background: #f472b6 !important;
  box-shadow: 0 0 8px rgba(244,114,182,.55);
}
.bs-possible-snare .bs-label {
  color: #f472b6 !important;
}

.bs-active .bs-label {
  background: #3b82f6;
  color: #fff !important;
  box-shadow: 0 0 12px rgba(59,130,246,.75);
}

.dot.one { background: #ef4444; }
.dot.five { background: #facc15; }
.dot.possible-kick { background: #fb923c; }
.dot.possible-snare { background: #f472b6; }

.beat-strip-note {
  margin-top: 6px;
  text-align: center;
  font-size: 10px;
  line-height: 1.35;
  color: rgba(255,255,255,.35);
}


/* Bouncing beat circle animation */
@keyframes beatCircleBounce {
  0% { transform: scale(.82); }
  45% { transform: scale(1.24); }
  100% { transform: scale(1); }
}

.bs-main .bs-label {
  border-radius: 999px;
  transition: transform 90ms ease-out, background 90ms ease-out, box-shadow 90ms ease-out;
}

.bs-active .bs-label {
  background: #3b82f6;
  color: #fff;
  box-shadow: 0 0 14px rgba(59,130,246,.85);
  animation: beatCircleBounce 220ms ease-out;
}

/* Keep structural colors visible when not active. */
.bs-one:not(.bs-active) .bs-label { color: #ef4444; }
.bs-five:not(.bs-active) .bs-label { color: #facc15; }


.pitch-mode-card {
  margin: 14px 0 10px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
}

.pitch-mode-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 8px;
}

.pitch-mode-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.pitch-mode-buttons button.active {
  outline: 2px solid #fff;
  background: #4f46e5;
}

.pitch-mode-card .small {
  margin-top: 8px;
  font-size: 12px;
}


/* V1.7: keep beat strip lightweight; no layout overlay changes here. */
.pitch-mode-card .muted.small::after {
  content: " 推荐保持“原调优先”；如果设备卡顿，再切“流畅优先”。";
}

/* V2.1: connection loop toggle */
#toggleLoopConnect.active {
  background: #4f46e5;
  color: #fff;
  outline: 2px solid rgba(255,255,255,.65);
}


/* V2.3: Clean device-adaptive layout.
   Layout order: TopBar → Video (fills remaining) → BottomBar → BeatStrip (always visible).
   The video is never cropped or covered. Beat strip is compact and in document flow. */

html, body {
  height: 100%;
  overflow: hidden;
}

.practice-screen {
  height: 100dvh;
  height: 100svh; /* fallback */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Override the earlier grid-template-rows */
  grid-template-rows: none;
}

/* --- Fixed-size bars --- */
.topBar {
  flex: 0 0 auto;
}

.bottomBar {
  flex: 0 0 auto;
}

/* --- Video area: fills ALL remaining vertical space --- */
.playerCard {
  flex: 1 1 0;
  min-height: 0;
  height: auto;
  overflow: hidden;
}

.player-shell {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.video-stage {
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* --- Beat strip: always visible, compact, in document flow below bottomBar --- */
.beat-strip-panel {
  flex: 0 0 auto;
  position: relative;
  z-index: 2;
  width: 100%;
  margin: 0;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  box-shadow: none;
  background: rgba(10,10,22,.98);
  border-top: 1px solid rgba(255,255,255,.10);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  backdrop-filter: blur(14px);
}

.beat-strip-panel.hidden {
  display: none;
}

.beat-strip-inner {
  min-height: 48px;
  display: grid;
  grid-template-columns: repeat(32, minmax(8px, 1fr));
  gap: 1px;
}

/* Compact cells */
.bs-cell {
  grid-template-rows: 11px 18px 18px;
}

.bs-main .bs-label {
  width: 20px;
  height: 20px;
  font-size: 11px;
}

/* Hide verbose legend and note by default to save space */
.beat-strip-legend {
  display: none;
}

.beat-strip-note {
  display: none;
}

/* --- Drum mark panel: compact --- */
.drum-mark-panel {
  margin-top: 4px;
  padding-top: 4px;
}

.drum-mark-status {
  font-size: 10px;
  margin-bottom: 4px;
}

.drum-mark-buttons button {
  min-height: 28px;
  font-size: 10px;
  padding: 4px 3px;
}

/* ============================================================
   Responsive breakpoints
   ============================================================ */

/* Tall screens (desktop, tablets in portrait): show legend, bigger beat strip */
@media (min-height: 800px) {
  .beat-strip-inner {
    min-height: 62px;
  }

  .bs-cell {
    grid-template-rows: 13px 22px 22px;
  }

  .bs-main .bs-label {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .beat-strip-legend {
    display: flex;
  }

  .drum-mark-buttons button {
    min-height: 32px;
    font-size: 11px;
  }
}

/* Very short screens (phones in landscape): ultra-compact beat strip */
@media (max-height: 500px) {
  .topBar {
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .topBtn, .dockBtn {
    min-height: 36px;
    font-size: 11px;
  }

  .bottomBar {
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .beat-strip-panel {
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  }

  .beat-strip-inner {
    min-height: 36px;
  }

  .bs-cell {
    grid-template-rows: 9px 14px 15px;
  }

  .bs-main .bs-label {
    width: 16px;
    height: 16px;
    font-size: 9px;
  }

  .drum-mark-panel {
    display: none;
  }
}

/* Wide screens: cap width */
@media (min-width: 768px) {
  .practice-screen {
    max-width: 1100px;
    margin: 0 auto;
    border-left: 1px solid rgba(255,255,255,.08);
    border-right: 1px solid rgba(255,255,255,.08);
  }

  .beat-strip-inner {
    min-height: 68px;
  }
}

/* Narrow phones */
@media (max-width: 430px) {
  .drum-mark-buttons {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* V2.2: phrase-loop toggle naming */
#toggleLoopConnect.active {
  background: #4f46e5;
  color: #fff;
  outline: 2px solid rgba(255,255,255,.65);
}


/* V2.2.1: hide right-side technical/status overlay.
   Users only need the main controls and beat strip; Engine/BPM/Voice/etc. are debug info. */
.overlay-badges {
  display: none !important;
}

/* ============================================================
   V2.3 FINAL LAYOUT OVERRIDE
   This block MUST be at the very end of the file.
   Uses !important to guarantee it wins over ALL earlier conflicting styles.
   Layout: TopBar → Video (fills rest) → BottomBar → BeatStrip
   ============================================================ */

html, body {
  margin: 0 !important;
  padding: 0 !important;
  height: 100% !important;
  overflow: hidden !important;
}

.practice-screen {
  display: flex !important;
  flex-direction: column !important;
  height: 100dvh !important;
  height: 100svh !important;
  width: 100% !important;
  overflow: hidden !important;
  /* Kill any grid from earlier versions */
  grid-template-rows: none !important;
  grid-template-columns: none !important;
}

/* Fixed-size bars */
.topBar {
  flex: 0 0 auto !important;
}

.bottomBar {
  flex: 0 0 auto !important;
}

.beat-strip-panel {
  flex: 0 0 auto !important;
  position: relative !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  top: auto !important;
  inset: auto !important;
  z-index: 2 !important;
  width: 100% !important;
  margin: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: rgba(10,10,22,.98) !important;
  border-top: 1px solid rgba(255,255,255,.10) !important;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)) !important;
}

/* Video area: fills ALL remaining vertical space */
.playerCard {
  flex: 1 1 0px !important;
  min-height: 0 !important;
  height: auto !important;
  overflow: hidden !important;
}

.player-shell {
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
}

.video-stage {
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Video: contained within its flex area, never overflows */
#danceVideo,
#reviewVideo {
  display: block !important;
  max-width: 100% !important;
  max-height: 100% !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
}

/* Dual Mode Layout */
.video-stage.dual-mode {
  flex-direction: column !important;
}
.video-stage.dual-mode video {
  flex: 1 1 50% !important;
  max-height: 50% !important;
  width: 100% !important;
}

@media (min-width: 768px) {
  .video-stage.dual-mode {
    flex-direction: row !important;
  }
  .video-stage.dual-mode video,
  .video-stage.dual-mode .review-video-overlay {
    flex: 1 1 50% !important;
    max-width: 50% !important;
    max-height: 100% !important;
    height: 100% !important;
  }
}

.review-video-overlay {
  flex: 1 1 50% !important;
  max-height: 50% !important;
  width: 100% !important;
  border-radius: 0 !important;
  border: 1px dashed rgba(255,255,255,0.3) !important;
  z-index: 10 !important;
  min-height: 0 !important;
  margin: 0 !important;
  background: rgba(0,0,0,0.5) !important;
}

/* Review Controls Styles */
.review-bottom-bar {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  gap: 12px;
}

.review-playback-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.review-progress {
  flex: 1;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.2);
  height: 6px;
  border-radius: 3px;
  outline: none;
}

.review-progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

.review-time {
  font-family: monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.review-tools-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}

.volume-slider-row {
  display: flex;
  align-items: center;
  gap: 15px;
  font-size: 14px;
}
.volume-slider-row input[type="range"] {
  flex: 1;
}
