:root {
  color-scheme: dark;
  --ink: #f7fbff;
  --muted: #a8b3be;
  --panel: rgba(14, 20, 28, 0.78);
  --panel-strong: rgba(21, 30, 42, 0.9);
  --line: rgba(255, 255, 255, 0.14);
  --hot: #ff4f8f;
  --aqua: #19d4ff;
  --lime: #b5ff45;
  --amber: #ffd166;
  --coral: #ff7a59;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 0%, rgba(25, 212, 255, 0.24), transparent 28rem),
    radial-gradient(circle at 86% 12%, rgba(255, 79, 143, 0.2), transparent 30rem),
    linear-gradient(135deg, #071017 0%, #101721 48%, #17140e 100%);
  color: var(--ink);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2vw, 22px);
  height: 100vh;
  min-height: 620px;
  padding: clamp(14px, 2.2vw, 28px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  background:
    linear-gradient(135deg, rgba(255, 79, 143, 0.85), rgba(25, 212, 255, 0.2)),
    #111c27;
  box-shadow:
    inset 0 0 0 6px rgba(255, 255, 255, 0.1),
    0 10px 28px rgba(25, 212, 255, 0.25);
  transform: rotate(8deg);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--aqua);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.4rem);
  line-height: 1;
  letter-spacing: 0;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(104px, 1fr));
  gap: 10px;
  min-width: min(460px, 100%);
}

.score-item {
  min-height: 64px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(16px);
}

.score-item span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.score-item strong {
  font-size: clamp(1.35rem, 2.3vw, 1.9rem);
  line-height: 1;
}

.stage-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: clamp(14px, 2vw, 22px);
  flex: 1;
  min-height: 0;
}

.camera-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(145deg, rgba(25, 212, 255, 0.1), rgba(255, 79, 143, 0.08)),
    #090f15;
  background-size: 72px 72px, 72px 72px, auto, auto;
  box-shadow: var(--shadow);
}

#cameraVideo {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#stageCanvas,
#targetCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

#stageCanvas {
  position: absolute;
  inset: 0;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(5rem, 18vw, 13rem);
  font-weight: 900;
  color: var(--ink);
  text-shadow:
    0 0 28px rgba(25, 212, 255, 0.9),
    0 8px 0 rgba(255, 79, 143, 0.45);
  pointer-events: none;
}

.stage-status {
  position: absolute;
  left: 14px;
  top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stage-status span,
.hit-row span,
.target-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  color: #d7e3ec;
  padding: 7px 10px;
  font-size: 0.8rem;
  line-height: 1;
}

.notice {
  position: absolute;
  right: 14px;
  bottom: 54px;
  width: min(420px, calc(100% - 28px));
  padding: 14px 16px;
  border: 1px solid rgba(255, 209, 102, 0.46);
  border-radius: 8px;
  background: rgba(9, 13, 18, 0.86);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
}

.notice strong {
  display: block;
  margin-bottom: 6px;
  color: var(--amber);
  font-size: 0.95rem;
}

.notice p {
  margin: 0;
  color: #edf5fc;
  font-size: 0.88rem;
  line-height: 1.45;
}

.download-panel {
  position: absolute;
  right: 14px;
  top: 14px;
  width: min(380px, calc(100% - 28px));
  padding: 13px 14px;
  border: 1px solid rgba(25, 212, 255, 0.4);
  border-radius: 8px;
  background: rgba(9, 13, 18, 0.86);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
}

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

.download-head strong {
  color: #edf5fc;
  font-size: 0.92rem;
}

.download-head span {
  color: var(--lime);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.download-bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
}

#downloadFill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--aqua), var(--lime));
  transition: width 150ms ease;
}

.download-panel p {
  margin: 9px 0 0;
  color: #cbd8e2;
  font-size: 0.82rem;
  line-height: 1.35;
}

.beat-lane {
  position: absolute;
  left: 50%;
  bottom: 18px;
  display: grid;
  grid-template-columns: repeat(16, 12px);
  gap: 7px;
  transform: translateX(-50%);
}

.beat-dot {
  width: 12px;
  height: 12px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.11);
  transition:
    transform 120ms ease,
    background 120ms ease,
    border-color 120ms ease;
}

.beat-dot.active {
  border-color: var(--lime);
  background: var(--lime);
  box-shadow: 0 0 18px rgba(181, 255, 69, 0.7);
  transform: scale(1.35);
}

.control-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 14px;
  min-height: 0;
}

.target-panel,
.accuracy-panel,
.controls {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.target-panel {
  position: relative;
  display: grid;
  grid-template-rows: minmax(220px, 1fr) auto;
  min-height: 0;
  overflow: hidden;
}

.reference-video {
  position: absolute;
  inset: 0 0 49px;
  z-index: 0;
  width: 100%;
  height: calc(100% - 49px);
  object-fit: cover;
  opacity: 0.42;
  background: #05080c;
  pointer-events: auto;
}

.target-panel #targetCanvas {
  position: relative;
  z-index: 1;
  grid-row: 1;
  pointer-events: none;
}

.reference-play-button {
  position: absolute;
  left: 50%;
  top: 45%;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-sizing: border-box;
  width: min(250px, calc(100% - 48px));
  max-width: calc(100% - 48px);
  min-width: 0;
  min-height: 58px;
  padding: 0 20px;
  border: 1px solid rgba(181, 255, 69, 0.72);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(181, 255, 69, 0.96), rgba(25, 212, 255, 0.94));
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.38),
    0 0 32px rgba(25, 212, 255, 0.44);
  color: #071017;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0;
  touch-action: manipulation;
  transform: translate(-50%, -50%);
  -webkit-tap-highlight-color: transparent;
}

.reference-play-button[hidden] {
  display: none;
}

.reference-play-button svg {
  width: 24px;
  height: 24px;
  stroke-width: 3;
}

.reference-play-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.target-meta {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.target-meta strong {
  color: var(--lime);
  font-size: 1.25rem;
  letter-spacing: 0;
}

.accuracy-panel {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 12px;
}

.accuracy-ring {
  position: relative;
  display: grid;
  width: 92px;
  height: 92px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--hot) 0deg, var(--aqua) 0deg, rgba(255, 255, 255, 0.12) 0deg);
}

.accuracy-ring::after {
  position: absolute;
  inset: 9px;
  border-radius: inherit;
  background: #101821;
  content: "";
}

.accuracy-ring span {
  position: relative;
  z-index: 1;
  font-size: 1.55rem;
  font-weight: 900;
}

.meter {
  position: relative;
  width: 100%;
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
}

#meterFill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--coral), var(--amber), var(--lime));
  transition: width 120ms ease;
}

.hit-row {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.controls {
  display: grid;
  gap: 10px;
  padding: 10px;
}

.track-picker {
  display: grid;
  gap: 7px;
}

.track-picker span {
  color: var(--muted);
  font-size: 0.78rem;
}

.track-picker select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
  font-weight: 800;
}

.track-picker option {
  background: #111821;
  color: var(--ink);
}

.primary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition:
    transform 130ms ease,
    background 130ms ease,
    border-color 130ms ease;
}

.primary-button {
  gap: 9px;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button.accent {
  background: linear-gradient(135deg, rgba(255, 79, 143, 0.92), rgba(25, 212, 255, 0.76));
}

.primary-button.secondary {
  background: rgba(181, 255, 69, 0.12);
  border-color: rgba(181, 255, 69, 0.34);
}

.icon-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.icon-button {
  padding: 0;
}

button svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.4;
}

button:not(:disabled):hover {
  border-color: rgba(255, 255, 255, 0.48);
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.flash-perfect {
  animation: flashPerfect 260ms ease;
}

@keyframes flashPerfect {
  0% {
    box-shadow: 0 0 0 rgba(181, 255, 69, 0);
  }
  55% {
    box-shadow: 0 0 0 8px rgba(181, 255, 69, 0.24);
  }
  100% {
    box-shadow: 0 0 0 rgba(181, 255, 69, 0);
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100svh;
  }

  .topbar,
  .stage-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .score-strip {
    min-width: 0;
  }

  .stage-layout {
    display: flex;
    flex-direction: column;
    flex: none;
  }

  .camera-stage {
    flex: 0 0 auto;
    height: clamp(430px, 62vh, 560px);
    height: clamp(430px, 62svh, 560px);
    min-height: 0;
  }

  .control-panel {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    min-height: 0;
  }

  .target-panel {
    flex: 0 0 auto;
    height: clamp(360px, 112vw, 520px);
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }

  .score-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .score-item {
    min-height: 58px;
    padding: 9px;
  }

  .score-item strong {
    font-size: 1.2rem;
  }

  .camera-stage {
    height: clamp(410px, 60vh, 540px);
    height: clamp(410px, 60svh, 540px);
    min-height: 0;
  }

  .target-panel {
    height: clamp(360px, 118vw, 500px);
  }

  .beat-lane {
    grid-template-columns: repeat(16, 9px);
    gap: 5px;
  }

  .beat-dot {
    width: 9px;
    height: 9px;
  }

  .notice {
    right: 10px;
    bottom: 38px;
    padding: 12px;
  }

  .download-panel {
    left: 10px;
    right: 10px;
    top: 52px;
    width: auto;
    padding: 12px;
  }

  .accuracy-panel {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .accuracy-ring {
    width: 76px;
    height: 76px;
  }

  .hit-row {
    grid-column: 1 / -1;
  }
}
