: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;
}

.upload-box {
  width: 100%;
  min-height: 220px;
  display: grid;
  place-items: center;
  gap: 8px;
  text-align: center;
  border: 1.5px dashed rgba(255,255,255,.24);
  border-radius: 28px;
  background: rgba(255,255,255,.05);
}

.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%;
  height: 100dvh;
  display: grid;
  grid-template-rows: calc(62px + env(safe-area-inset-top)) 1fr calc(76px + env(safe-area-inset-bottom));
  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 {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 34;
  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; }

@media (max-height: 620px) {
  .beat-strip-panel {
    bottom: calc(78px + env(safe-area-inset-bottom));
    padding: 8px;
  }
  .beat-strip-inner {
    min-height: 56px;
  }
  .bs-cell {
    grid-template-rows: 13px 20px 19px;
  }
  .bs-main .bs-label {
    width: 20px;
    height: 20px;
    font-size: 11px;
  }
}

/* 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);
}


/* V1.6.2: Beat Strip must be below the bottom operation bar, not over the video. */
.practice-screen {
  grid-template-rows:
    calc(62px + env(safe-area-inset-top))
    minmax(0, 1fr)
    calc(76px + env(safe-area-inset-bottom))
    auto !important;
}

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

.beat-strip-inner {
  min-height: 58px !important;
}

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

.bs-main .bs-label {
  width: 25px !important;
  height: 25px !important;
  font-size: 13px !important;
  border-radius: 999px;
  transition: transform 90ms ease-out, background 90ms ease-out, box-shadow 90ms ease-out;
}

/* Current beat should behave like a moving/bouncing circle. */
.bs-active .bs-label {
  background: #3b82f6 !important;
  color: #fff !important;
  box-shadow: 0 0 14px rgba(59,130,246,.85) !important;
  animation: beatCircleBounce 220ms ease-out;
}

@keyframes beatCircleBounce {
  0% { transform: scale(.82); }
  45% { transform: scale(1.24); }
  100% { transform: scale(1); }
}

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

.beat-strip-note {
  margin-top: 4px !important;
  font-size: 10px !important;
}

@media (max-height: 650px) {
  .beat-strip-panel {
    padding-top: 6px !important;
    padding-bottom: calc(6px + env(safe-area-inset-bottom)) !important;
  }

  .beat-strip-inner {
    min-height: 50px !important;
  }

  .bs-cell {
    grid-template-rows: 11px 18px 19px !important;
  }

  .bs-main .bs-label {
    width: 21px !important;
    height: 21px !important;
    font-size: 11px !important;
  }

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