/* ==================================================================
   纸面 + 整体布局
   ================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  color: inherit;
}

/* ---------------------------------------------------------------- 纸面 */

.paper {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.paper::before {
  content: "";
  position: absolute;
  inset: -6%;
  background:
    radial-gradient(120% 90% at 10% -12%, #fffefb 0%, rgba(255, 254, 251, 0) 55%),
    radial-gradient(90% 80% at 104% 108%, #e6e0ce 0%, rgba(230, 224, 206, 0) 58%),
    radial-gradient(70% 60% at 84% -4%, #fbf8f0 0%, rgba(251, 248, 240, 0) 52%),
    linear-gradient(168deg, #fdfbf5 0%, #f6f2e7 46%, #fbf8f0 100%);
}

/* 褶皱贴图：启动时由 paper.js 注入，纯静态图片，不参与每帧重绘 */
.paper__crumple {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  opacity: 0.66;
  transform: translateZ(0);
}

.paper__vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    128% 112% at 50% 42%,
    rgba(255, 255, 255, 0) 48%,
    rgba(74, 62, 36, 0.1) 100%
  );
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ---------------------------------------------------------------- 布局 */

.app {
  position: relative;
  z-index: 1;
  /* 老版微信内置浏览器不认 dvh，先给一个 vh 兜底 */
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(4px, 0.9vh, 12px);
  padding: clamp(10px, 1.5vh, 18px) clamp(12px, 2.4vw, 40px) clamp(8px, 1.1vh, 14px);
}

/* 显式指定行号：顶栏在矮屏会被 display:none 隐藏，
   如果靠自动排布，底栏就会顶到 1fr 那一行、把卡片区挤没。 */
.stage {
  grid-row: 2;
}

.dock {
  grid-row: 3;
}

/* 顶栏 */
.topbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 30px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: var(--ink);
  color: var(--paper-hi);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: -0.04em;
  transform: rotate(-3deg);
}

.brand__text {
  display: flex;
  flex-direction: column;
  font-weight: 800;
  font-size: 12px;
  line-height: 1.15;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand__text em {
  font-style: normal;
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--ink-mute);
}

.tag {
  display: inline-block;
  padding: 4px 11px;
  border: var(--bw-thin) solid var(--ink);
  background: var(--paper-hi);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: 2px 2px 0 var(--ink);
}

/* 主舞台 */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.1vh, 14px);
  min-height: 0;
  padding-inline: clamp(8px, 2.6vw, 40px);
}

/* ---------------------------------------------------------------- 装饰 */

.decor {
  pointer-events: none;
}

.decor svg {
  display: block;
  width: 100%;
  height: auto;
}

.decor--megaphone {
  justify-self: start;
  width: clamp(62px, 8.4vw, 126px);
  transform: rotate(-7deg);
  margin-bottom: -0.5vw;
}

.decor--bolts {
  justify-self: end;
  width: clamp(62px, 8.6vw, 128px);
  transform: rotate(5deg);
  margin-bottom: -0.3vw;
}

.decor--bang {
  position: absolute;
  left: clamp(-40px, -2.4vw, -14px);
  bottom: 1%;
  width: clamp(17px, 2.3vw, 32px);
  transform: rotate(-9deg);
}

.decor--bulb {
  position: absolute;
  right: clamp(-44px, -2.7vw, -16px);
  bottom: -1.5%;
  width: clamp(40px, 5.1vw, 78px);
  transform: rotate(6deg);
}

/* ---------------------------------------------------------------- 节拍条 */

.beatstrip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.5vw, 20px);
  min-height: clamp(26px, 3.8vh, 40px);
}

.beatdots {
  display: flex;
  gap: clamp(4px, 0.5vw, 7px);
}

.beatdots i {
  display: block;
  width: clamp(8px, 0.85vw, 12px);
  height: clamp(8px, 0.85vw, 12px);
  border: var(--bw-thin) solid var(--ink);
  background: transparent;
  border-radius: 1px;
  transition: background-color 0.08s linear;
}

.beatdots i.is-on {
  background: var(--yellow);
}

.beatdots i.is-hit {
  animation: dotHit 0.26s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes dotHit {
  0% {
    transform: scale(1.55);
  }
  100% {
    transform: scale(1);
  }
}

.beatmsg {
  font-size: clamp(11px, 1.15vw, 15px);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
  white-space: nowrap;
  transition: color 0.15s linear;
}

.beatmsg[data-tone="silence"] {
  color: var(--red);
}

/* 开始 / 结算时，把游戏区收起来，只留一张纸 */
body.is-menu .board-frame,
body.is-menu .beatstrip,
body.is-menu .dock {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s linear;
}

.board-frame,
.beatstrip,
.dock {
  transition: opacity 0.22s linear;
}

/* ---------------------------------------------------------------- 窄屏 */

@media (max-width: 860px) {
  .decor {
    display: none;
  }

  .brand__text em {
    display: none;
  }

  .beatmsg {
    letter-spacing: 0;
  }
}

@media (max-height: 520px) {
  .topbar {
    display: none;
  }
}

/* 手机横屏：垂直空间很紧，把四周留白和节拍条压到最小，剩下的全给卡片 */
@media (orientation: landscape) and (max-height: 560px) {
  .app {
    gap: 2px;
    padding: 4px clamp(8px, 2vw, 18px) 3px;
  }

  .stage {
    gap: 3px;
    padding-inline: clamp(6px, 2vw, 18px);
  }

  .beatstrip {
    min-height: 18px;
    gap: 8px;
  }

  .beatmsg {
    font-size: 11px;
    letter-spacing: 0;
  }

  .beatdots i {
    width: 8px;
    height: 8px;
  }

  .decor {
    display: none;
  }
}
