/*
  功能说明：定义电子木鱼全屏互动原型的画布、启动层和状态 UI。
  职责边界：只负责浏览器视觉呈现，不处理手势识别、音频合成和 Canvas 绘制逻辑。
*/

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #050505;
  color: #fff;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.webcam-source {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.game-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  transform: scaleX(-1);
}

.scene-back-link {
  position: fixed;
  left: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 20;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.74);
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(6px);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.ui-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  pointer-events: none;
}

.ui-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.score-board {
  display: inline-block;
  min-width: 152px;
  padding: 10px 20px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.50);
  backdrop-filter: blur(4px);
}

.score-label {
  color: #fbbf24;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-value {
  margin-top: 4px;
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  transition: transform 150ms ease;
}

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}

.compact-control {
  display: grid;
  grid-template-columns: auto minmax(106px, 138px);
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.74);
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  font-size: 12px;
  font-weight: 800;
}

.compact-control span {
  min-width: 38px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.compact-control select,
.compact-control input {
  min-width: 0;
  accent-color: #f59e0b;
}

.compact-control select {
  height: 22px;
  border: 0;
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.94);
  background: rgba(0, 0, 0, 0.36);
  font-size: 12px;
}

.ghost-button {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.20);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.90);
  background: rgba(255, 255, 255, 0.10);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.ghost-button:hover {
  border-color: rgba(251, 191, 36, 0.85);
  background: rgba(251, 191, 36, 0.28);
}

.bottom-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 12px;
}

.bottom-hint {
  grid-column: 2;
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.50);
  font-size: 14px;
  text-align: center;
}

.ambient-toggle {
  grid-column: 3;
  justify-self: end;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.82);
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(6px);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  pointer-events: auto;
}

.ambient-toggle[aria-pressed="true"] {
  border-color: rgba(251, 191, 36, 0.74);
  color: #fde68a;
  background: rgba(120, 76, 18, 0.50);
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.18);
}

.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(5px);
  transition: opacity 500ms ease, visibility 500ms ease;
}

.start-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-overlay h1 {
  margin: 0 0 8px;
  font-size: clamp(34px, 8vw, 52px);
  line-height: 1;
  letter-spacing: 0.08em;
}

.start-overlay p {
  width: min(100%, 440px);
  max-width: 440px;
  margin: 0 0 30px;
  color: rgba(255, 255, 255, 0.64);
  line-height: 1.55;
  text-align: center;
  overflow-wrap: break-word;
}

.start-button {
  min-height: 58px;
  padding: 16px 40px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.40);
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.start-button:active {
  transform: scale(0.96);
}

.loader {
  width: 40px;
  height: 40px;
  margin-bottom: 20px;
  border: 4px solid rgba(255, 255, 255, 0.10);
  border-left-color: #f59e0b;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.hidden {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error-message {
  margin-top: 16px;
  color: #f87171;
  font-size: 13px;
}

.tutorial-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 280px;
  padding: 30px 50px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 24px;
  background: rgba(0, 0, 0, 0.60);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.50);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 450ms ease;
}

.tutorial-hint.is-visible {
  opacity: 1;
}

.gesture-demo {
  position: relative;
  width: 100px;
  height: 100px;
  margin-bottom: 16px;
}

.gesture-target,
.gesture-ripple {
  position: absolute;
  left: 30px;
  top: 30px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.gesture-target {
  border: 2px dashed #f59e0b;
  background: rgba(255, 255, 255, 0.18);
}

.gesture-ripple {
  border: 2px solid #f59e0b;
  animation: hint-ripple 1.5s infinite ease-out;
}

.gesture-palm {
  position: absolute;
  right: 0;
  top: 10px;
  width: 30px;
  height: 50px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.50);
  transform-origin: bottom center;
  animation: strike 1.5s infinite cubic-bezier(0.25, 1, 0.5, 1);
}

.tutorial-title {
  color: rgba(255, 255, 255, 0.90);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

@keyframes strike {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
  40% {
    transform: translate(-30px, 20px) rotate(-20deg);
  }
}

@keyframes hint-ripple {
  0%,
  35% {
    opacity: 0;
    transform: scale(1);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(2.5);
  }
}

@media (max-width: 640px) {
  .ui-layer {
    padding: 14px;
  }

  .ui-top {
    align-items: flex-start;
  }

  .score-board {
    min-width: 126px;
    padding: 9px 14px;
  }

  .score-value {
    font-size: 34px;
  }

  .top-actions {
    gap: 6px;
  }

  .compact-control {
    grid-template-columns: auto minmax(74px, 96px);
    padding: 5px 7px;
    font-size: 10px;
  }

  .compact-control span {
    min-width: 30px;
  }

  .tutorial-hint {
    width: min(86vw, 330px);
    min-width: 0;
    padding: 26px 24px;
  }

  .bottom-hint {
    grid-column: 1 / -1;
    order: 2;
    font-size: 12px;
  }

  .bottom-bar {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 8px;
  }

  .ambient-toggle {
    grid-column: 1;
    justify-self: end;
    order: 1;
  }

  .start-overlay p {
    width: min(100%, 310px);
    font-size: 15px;
  }
}
