:root {
  /* === 主题配置 === */
  --bg-color: #ffffff;
  --theme-color: #333333;
  --accent-color: #555555;
  --ripple-opacity: 0.4;
  --main-stroke-width: 3px;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: var(--bg-color);
  color: var(--theme-color);
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
  overflow: hidden;
}

/* ==================================== */
/* 1. 默认状态 (横向空间不足): 垂直排列 */
/* ==================================== */
.main-container {
  display: flex;
  flex-direction: column;
  /* 默认垂直堆叠 */
  align-items: center;
  /* 垂直时，子项在水平居中 */
  min-height: 300px;
}

.metronome-ui {
  padding: 20px;
  margin: 10px;
  /* 垂直状态下，子项的宽度 */
  width: 90%;
  text-align: center;
  min-width: 384px;

  display: flex;
  /* 启用 Flex 布局 */
  flex-direction: column;
  /* 保持子项（如 beat-controls）垂直堆叠 */
  align-items: center;
  /* 在主轴垂直时，使子项在交叉轴（水平方向）居中 */
  justify-content: center;
  /* （可选）如果您也希望内容在垂直方向上居中 */
}

/* 确保在非常小的高度下，节拍器宽度仍然适应屏幕 */
#metronome {
  height: 100%;
  transition: width 0.5s ease;
}

@media (max-width: 768px) {
  #metronome {
    height: calc(90vh - 110vw);
  }
}

@media (max-width: 500px) {
  .metronome-ui {
    transform: scale(0.8);
  }
}

@media (max-height: 500px) {
  #metronome {
    height: calc(90vh - 30px);
  }

  .metronome-ui {
    transform: scale(0.8);
  }
}

@media (min-width: 768px) {
  .main-container {
    flex-direction: row;
    /* 切换为横向并排 */
    justify-content: center;
    /* 横向时，子项在水平居中 */
    align-items: flex-start;
    /* 保持顶部对齐（可选）*/
  }

  .metronome-ui {
    /* 横向状态下，子项的宽度 */
    width: 45%;
  }
}


/* 通用 SVG 按钮样式 */
.btn-svg {
  cursor: pointer;
  fill: var(--theme-color);
  transition: transform 0.1s, fill 0.2s;
}

.btn-svg:hover {
  fill: var(--accent-color);
}

.btn-svg:active {
  transform: scale(0.9);
}

/* === 顶部：拍数控制区 === */
.beat-controls {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 30px;
  height: 50px;
  /* 稍微增加高度以适应动画 */
}

/* 拍子指示器容器 */
#beat-indicator-svg {
  width: 240px;
  /* 加宽一点以防拍子较多时拥挤 */
  height: 50px;
  overflow: visible;
}

/* === 拍子指示器动画样式 (核心修改) === */
.beat-shape {
  transform-box: fill-box;
  transform-origin: center;
  transition: fill 0.1s;
  fill: none;
  /* 默认空心 */
  stroke: var(--theme-color);
  stroke-width: 2;
}

/* 激活状态：实心 + 弹跳动画 */
.beat-active {
  fill: var(--theme-color) !important;
  animation: beat-pop 0.15s ease-out forwards;
}

@keyframes beat-pop {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.5);
  }

  /* 放大到 1.5 倍 */
  100% {
    transform: scale(1);
  }
}

/* 文本模式样式 (m/n) */
.beat-text {
  font-size: 28px;
  font-weight: bold;
  fill: var(--theme-color);
  text-anchor: middle;
  dominant-baseline: middle;
}

/* 文本也可以有轻微跳动 */
.beat-text-active {
  animation: text-pop-small 0.1s ease-out;
}

@keyframes text-pop-small {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }

  100% {
    transform: scale(1);
  }
}

/* === 中间：BPM 控制区 === */
.bpm-container {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.control-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.bpm-display-wrapper {
  position: relative;
  width: 160px;
  height: 160px;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.bpm-info-text {
  color: var(--accent-color);
}

#bpm-input,
#bpm-value {
  text-align: center;
  font-size: 80px;
  font-weight: bold;
  z-index: 20;
}

.bpm-display {}

.pulse-text {
  animation: text-pop 0.15s ease-out;
}

@keyframes text-pop {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }

  100% {
    transform: scale(1);
  }
}

/* === 底部：播放按钮 === */
.play-controls {
  margin-top: 40px;
}

.footer {
  display: flex;
  margin-top: 20px;
  align-items: center;
}

#about-text {
  margin-left: 10px;
  color: var(--accent-color);
}

/* === 波纹动画效果 === */
.ripple {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 4px solid var(--theme-color);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.ripple-animate {
  animation: ripple-effect 0.6s ease-out forwards;
}

@keyframes ripple-effect {
  0% {
    width: 80px;
    height: 80px;
    opacity: var(--ripple-opacity);
    border-width: 4px;
  }

  100% {
    width: 300px;
    height: 300px;
    opacity: 0;
    border-width: 0px;
  }
}
