:root {
  color-scheme: dark;
  --bg: #090909;
  --panel: #141414;
  --panel-2: #1d1d1d;
  --text: #f4f1ea;
  --muted: #a9a39a;
  --line: rgba(244, 241, 234, 0.14);
  --hot: #ff3158;
  --fast: #27e0a3;
  --warn: #f5c84b;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.app {
  min-height: 100vh;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1280px;
  margin: 0 auto 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--fast);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1.05;
}

h2 {
  font-size: 22px;
}

.status {
  min-width: 124px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

.status.ready {
  color: var(--fast);
}

.status.error {
  color: var(--hot);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  max-width: 1280px;
  margin: 0 auto;
}

.stage {
  position: relative;
  min-height: min(72vh, 760px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(255, 49, 88, 0.22), transparent 42%),
    linear-gradient(260deg, rgba(39, 224, 163, 0.18), transparent 48%),
    #101010;
  box-shadow: var(--shadow);
}

#camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0;
  transition: opacity 180ms ease;
}

#camera.live {
  opacity: 1;
}

#poseCanvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
  pointer-events: none;
}

.stageShade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.12) 32%, rgba(0, 0, 0, 0.78)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 86px);
  pointer-events: none;
}

.hud {
  position: absolute;
  z-index: 2;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hudTop {
  top: 18px;
}

.hudBottom {
  bottom: 18px;
  align-items: flex-end;
}

.phase {
  min-width: 120px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 10, 10, 0.72);
  color: var(--text);
  font-weight: 800;
}

.motion {
  display: grid;
  grid-template-columns: auto minmax(120px, 220px);
  gap: 10px;
  align-items: center;
  width: min(46vw, 300px);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 10, 10, 0.72);
  color: var(--muted);
}

.motionTrack {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

#motionBar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--fast);
  transition: width 80ms linear;
}

.centerReadout {
  position: absolute;
  z-index: 2;
  inset: 50% auto auto 50%;
  width: min(86%, 680px);
  transform: translate(-50%, -50%);
  text-align: center;
  text-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
}

.prompt {
  font-size: clamp(42px, 10vw, 116px);
  font-weight: 950;
  line-height: 0.98;
  letter-spacing: 0;
}

.result {
  min-height: 48px;
  margin-top: 12px;
  color: var(--fast);
  font-size: clamp(24px, 5vw, 52px);
  font-weight: 900;
  letter-spacing: 0;
}

.nameField,
.settings label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.nameField input,
.settings select {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 12, 12, 0.84);
  color: var(--text);
  outline: 0;
}

.nameField input {
  width: min(34vw, 190px);
  padding: 0 12px;
}

.nameField input:focus,
.settings select:focus,
.settings input:focus-visible {
  border-color: var(--fast);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.controls button,
.iconButton {
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 120ms ease,
    opacity 120ms ease,
    background 120ms ease;
}

.controls button {
  min-width: 104px;
  padding: 0 16px;
  background: rgba(244, 241, 234, 0.12);
  color: var(--text);
  font-weight: 850;
}

.controls button:hover,
.iconButton:hover {
  transform: translateY(-1px);
}

.controls button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.controls .primaryButton,
#startButton:not(:disabled) {
  background: var(--hot);
  color: white;
}

.sidePanel {
  min-height: min(72vh, 760px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.iconButton {
  width: 42px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 25px;
  line-height: 1;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stats div {
  min-height: 84px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stats strong {
  display: block;
  margin-top: 10px;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}

.leaderboard {
  display: grid;
  gap: 8px;
  min-height: 260px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101010;
}

.leaderboard .rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 49, 88, 0.18);
  color: var(--hot);
  font-weight: 900;
}

.leaderboard .name {
  overflow: hidden;
  color: var(--text);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard .time {
  color: var(--fast);
  font-weight: 900;
}

.emptyBoard {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.settings {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

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

.settings select {
  width: 100%;
  padding: 0 10px;
}

.fault .prompt,
.fault .result {
  color: var(--warn);
}

@media (max-width: 920px) {
  .app {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    margin-bottom: 14px;
  }

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

  .stage {
    min-height: 68vh;
  }

  .sidePanel {
    min-height: auto;
  }
}

@media (max-width: 620px) {
  .topbar,
  .hud,
  .hudBottom,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .status,
  .phase,
  .motion,
  .nameField input,
  .controls button {
    width: 100%;
  }

  .hudTop {
    display: grid;
    grid-template-columns: 1fr;
  }

  .motion {
    grid-template-columns: auto 1fr;
  }

  .centerReadout {
    top: 45%;
  }

  .prompt {
    font-size: clamp(40px, 16vw, 84px);
  }
}
