:root {
  --bg: #04070d;
  --bg-2: #080d16;
  --line: rgb(120 200 255 / 12%);
  --cyan: #22d3ee;
  --cyan-soft: rgb(34 211 238 / 14%);
  --blue: #3b82f6;
  --text: #e8f4ff;
  --text-dim: rgb(200 225 255 / 58%);
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --font: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/*
 * hidden 属性只是 UA 样式里的 display:none，任何作者写的 display（如 #err 的 grid）
 * 都会把它压过去 —— 层「看似隐藏」其实一直盖在上面，连点击都被它吃掉。
 * 这个坑在 index.html 踩过一次，这里必须一开始就写。
 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ══════════ 首屏 ══════════ */

#intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  z-index: 10;
}

/* 透视网格地板 */
.bg-grid {
  position: absolute;
  inset: -40% -40% -10% -40%;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  transform: perspective(420px) rotateX(58deg);
  transform-origin: 50% 100%;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 70%, #000 10%, transparent 78%);
  animation: gridDrift 9s linear infinite;
}

@keyframes gridDrift {
  to {
    background-position: 0 44px, 44px 0;
  }
}

/* 中央辉光 */
.bg-glow {
  position: absolute;
  width: 120vmin;
  height: 120vmin;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle, rgb(34 211 238 / 16%) 0%, transparent 46%),
    radial-gradient(circle, rgb(59 130 246 / 10%) 0%, transparent 62%);
  filter: blur(12px);
  animation: breathe 6s ease-in-out infinite;
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.75;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
}

.intro-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 28px;
  text-align: center;
}

.mark {
  width: 62px;
  height: 62px;
  color: var(--cyan);
  margin-bottom: 26px;
  filter: drop-shadow(0 0 14px rgb(34 211 238 / 55%));
  animation: markFloat 4.5s ease-in-out infinite;
}

@keyframes markFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.intro-inner h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 500;
  letter-spacing: 0.14em;
  background: linear-gradient(180deg, #fff 0%, #9fd8ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.intro-inner .sub {
  margin: 12px 0 0;
  font-size: 13.5px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

/* 主按钮 */
.cta {
  position: relative;
  margin-top: 52px;
  width: 132px;
  height: 132px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.cta::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgb(34 211 238 / 42%);
  background: radial-gradient(circle, rgb(34 211 238 / 16%), transparent 68%);
  box-shadow:
    0 0 34px rgb(34 211 238 / 26%),
    inset 0 0 26px rgb(34 211 238 / 12%);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cta:active::before {
  transform: scale(0.94);
  box-shadow: 0 0 48px rgb(34 211 238 / 42%), inset 0 0 30px rgb(34 211 238 / 22%);
}

.cta-ring {
  position: absolute;
  inset: -13px;
  border-radius: 50%;
  border: 1px solid rgb(34 211 238 / 22%);
  animation: ringPulse 2.6s ease-out infinite;
}

@keyframes ringPulse {
  0% {
    transform: scale(0.92);
    opacity: 0.85;
  }
  100% {
    transform: scale(1.24);
    opacity: 0;
  }
}

.cta-label {
  position: relative;
  font-size: 17px;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: #d9f4ff;
  text-shadow: 0 0 14px rgb(34 211 238 / 65%);
}

.hint {
  margin-top: 34px;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  color: rgb(200 225 255 / 40%);
}

/* 四角框装饰 */
.corner,
.frame {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 1px solid rgb(34 211 238 / 42%);
  pointer-events: none;
}

.corner.tl,
.frame.tl {
  top: 20px;
  left: 20px;
  border-right: 0;
  border-bottom: 0;
}

.corner.tr,
.frame.tr {
  top: 20px;
  right: 20px;
  border-left: 0;
  border-bottom: 0;
}

.corner.bl,
.frame.bl {
  bottom: 20px;
  left: 20px;
  border-right: 0;
  border-top: 0;
}

.corner.br,
.frame.br {
  bottom: 20px;
  right: 20px;
  border-left: 0;
  border-top: 0;
}

/* ══════════ AR 舞台 ══════════ */

#stage {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
}

#cv {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#hud [data-ui] {
  pointer-events: auto;
}

/* 顶部条 */
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 16px;
  background: linear-gradient(to bottom, rgb(4 7 13 / 72%), transparent);
}

.icon-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid rgb(120 200 255 / 26%);
  background: rgb(4 7 13 / 54%);
  backdrop-filter: blur(10px);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 0 rgb(251 191 36 / 60%);
  animation: pulse 1.8s ease-out infinite;
  flex: 0 0 auto;
}

.pulse.ok {
  background: var(--ok);
  box-shadow: 0 0 0 0 rgb(52 211 153 / 60%);
  animation: none;
}

.pulse.bad {
  background: var(--bad);
  animation: none;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgb(251 191 36 / 55%);
  }
  100% {
    box-shadow: 0 0 0 9px rgb(251 191 36 / 0%);
  }
}

.count {
  font: 500 13px/1 var(--mono);
  color: var(--cyan);
  letter-spacing: 0.08em;
  text-shadow: 0 0 10px rgb(34 211 238 / 55%);
}

.count b {
  font-weight: 500;
}

/* 准星 */
.reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 74px;
  height: 74px;
  margin: -37px 0 0 -37px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.reticle.on {
  opacity: 1;
}

.r-ring {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 1px solid rgb(34 211 238 / 62%);
  box-shadow: 0 0 16px rgb(34 211 238 / 34%), inset 0 0 12px rgb(34 211 238 / 18%);
  animation: reticleSpin 7s linear infinite;
  border-top-color: transparent;
  border-right-color: transparent;
}

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

.r-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

.r-tick {
  position: absolute;
  background: rgb(34 211 238 / 78%);
  box-shadow: 0 0 8px rgb(34 211 238 / 55%);
}

.r-tick.t,
.r-tick.b {
  left: 50%;
  width: 1px;
  height: 9px;
  margin-left: -0.5px;
}

.r-tick.t {
  top: 0;
}
.r-tick.b {
  bottom: 0;
}

.r-tick.l,
.r-tick.r {
  top: 50%;
  height: 1px;
  width: 9px;
  margin-top: -0.5px;
}

.r-tick.l {
  left: 0;
}
.r-tick.r {
  right: 0;
}

/* 中央提示 */
.tip {
  position: absolute;
  left: 50%;
  bottom: calc(150px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 80vw;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.05em;
  color: rgb(210 235 255 / 82%);
  background: rgb(4 7 13 / 56%);
  border: 1px solid rgb(120 200 255 / 16%);
  backdrop-filter: blur(10px);
  white-space: nowrap;
  transition: opacity 0.4s ease;
}

.tip.fade {
  opacity: 0;
}

/* 底部 */
.dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(26px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.place-btn {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 1px solid rgb(34 211 238 / 52%);
  background: radial-gradient(circle, rgb(34 211 238 / 20%), rgb(4 7 13 / 66%));
  backdrop-filter: blur(12px);
  color: #dff6ff;
  cursor: pointer;
  display: grid;
  place-items: center;
  gap: 0;
  box-shadow: 0 0 28px rgb(34 211 238 / 28%), inset 0 0 22px rgb(34 211 238 / 10%);
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.2s ease;
}

.place-btn svg {
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 0 8px rgb(34 211 238 / 70%));
}

.place-btn .place-label {
  position: absolute;
  bottom: 17px;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: rgb(210 240 255 / 78%);
}

.place-btn:active:not(:disabled) {
  transform: scale(0.94);
  box-shadow: 0 0 44px rgb(34 211 238 / 48%), inset 0 0 26px rgb(34 211 238 / 20%);
}

.place-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}

.place-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 1px solid rgb(34 211 238 / 20%);
  animation: ringPulse 2.4s ease-out infinite;
}

.place-btn:disabled .place-ring {
  animation: none;
  opacity: 0;
}

.ghost-btn {
  border: 1px solid rgb(120 200 255 / 22%);
  background: rgb(4 7 13 / 56%);
  backdrop-filter: blur(10px);
  color: rgb(200 228 255 / 72%);
  font: 400 11.5px/1 var(--font);
  letter-spacing: 0.08em;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}

/* 放置成功的冲击波 */
.shock {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 1.5px solid var(--cyan);
  pointer-events: none;
  animation: shock 0.65s ease-out forwards;
}

@keyframes shock {
  to {
    transform: scale(11);
    opacity: 0;
  }
}

/* 错误层 */
#err {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 32px;
  text-align: center;
  background: rgb(4 7 13 / 94%);
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

#err b {
  color: var(--bad);
  font-weight: 500;
  font-size: 15px;
}

#err small {
  color: var(--text-dim);
  font-size: 12.5px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
