:root {
  --bg-0: #080b18;
  --bg-1: #0f1330;
  --primary: #7c3aed;
  --primary-soft: #a78bfa;
  --accent: #f43f5e;
  --gold: #ffc94d;
  --text: #eef2ff;
  --text-dim: #98a6cc;
  --line: rgba(150, 140, 255, 0.18);
  --panel: rgba(18, 22, 48, 0.72);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg-0);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px calc(10px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(56, 78, 190, 0.28), transparent 62%),
    linear-gradient(180deg, #0c1024 0%, #080b18 60%, #05070f 100%);
}

/* ---------- 顶部 HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud .spacer {
  flex: 1;
}

.level {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px 0 10px;
  border-radius: 13px;
  background: linear-gradient(160deg, #8b5cf6 0%, #6d28d9 55%, #4c1d95 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 6px rgba(30, 8, 70, 0.6),
    0 6px 18px -8px rgba(124, 58, 237, 0.9);
}

.level svg {
  width: 16px;
  height: 16px;
  flex: none;
  opacity: 0.9;
}

.level span {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.72);
}

.level b {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
  height: 38px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.stat span {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.stat b {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat b.bump {
  animation: bump 0.32s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.stat.score b {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 201, 77, 0.45);
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  transition: transform 0.14s ease, background 0.18s ease, border-color 0.18s ease;
}

.icon-btn img {
  width: 20px;
  height: 20px;
  display: block;
  opacity: 0.92;
}

.icon-btn:hover {
  background: rgba(124, 58, 237, 0.22);
  border-color: rgba(167, 139, 250, 0.5);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn:focus-visible,
.prop:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--primary-soft);
  outline-offset: 2px;
}

/* ---------- 棋盘 ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 24px;
  overflow: hidden;
  background:
    radial-gradient(115% 70% at 50% -10%, rgba(124, 58, 237, 0.26), transparent 60%),
    radial-gradient(90% 60% at 50% 112%, rgba(244, 63, 94, 0.16), transparent 62%),
    linear-gradient(180deg, #131a38 0%, #0b1024 55%, #070a18 100%);
  border: 1px solid var(--line);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -40px 60px -40px rgba(0, 0, 0, 0.9),
    0 24px 60px -30px rgba(76, 29, 149, 0.85);
}

/* 背景网格点 */
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(150, 160, 220, 0.16) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(120% 90% at 50% 40%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(120% 90% at 50% 40%, #000 20%, transparent 78%);
  pointer-events: none;
}

/* 顶部高光线 */
.stage::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 170, 255, 0.75), transparent);
  pointer-events: none;
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

/* 缓慢扫过的光带 */
.sheen {
  position: absolute;
  inset: -20% -10%;
  background: linear-gradient(
    112deg,
    transparent 40%,
    rgba(180, 200, 255, 0.05) 46%,
    rgba(210, 225, 255, 0.13) 50%,
    rgba(180, 200, 255, 0.05) 54%,
    transparent 60%
  );
  transform: translateX(-75%);
  pointer-events: none;
  z-index: 1;
}

/* 倒计时圆环 */
.timer {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    conic-gradient(from -90deg, var(--primary-soft) calc(var(--p, 100) * 1%), rgba(255, 255, 255, 0.1) 0);
  box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.9);
  transition: background 0.3s linear;
}

.timer::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #1b2350, #0b1024 75%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.timer b {
  position: relative;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.timer.warn {
  background: conic-gradient(from -90deg, var(--accent) calc(var(--p, 100) * 1%), rgba(255, 255, 255, 0.1) 0);
}

/* ---------- 道具栏 ---------- */
.dock {
  display: flex;
  gap: 9px;
}

.prop {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 64px;
  padding: 8px 0 7px;
  border-radius: 17px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #2b3060 0%, #1b1f40 60%, #141830 100%);
  color: #dbe3ff;
  font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 4px 0 #0b0e20,
    0 10px 20px -12px rgba(0, 0, 0, 0.95);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s ease, border-color 0.2s ease;
}

.prop img {
  width: 30px;
  height: 30px;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.prop:hover {
  border-color: rgba(167, 139, 250, 0.5);
}

.prop:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 1px 0 #0b0e20,
    0 4px 10px -8px #000;
}

.prop.disabled {
  opacity: 0.45;
  filter: grayscale(0.55);
  cursor: not-allowed;
}

.prop.disabled:active {
  transform: none;
}

.prop i {
  position: absolute;
  top: 5px;
  right: 6px;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 10px;
  background: linear-gradient(180deg, #ff6b81, #e11d48);
  color: #fff;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
  box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 20%;
  transform: translate(-50%, -12px) scale(0.96);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(16, 20, 44, 0.94);
  border: 1px solid rgba(167, 139, 250, 0.35);
  box-shadow: 0 14px 34px -16px #000, inset 0 1px 0 rgba(255, 255, 255, 0.1);
  color: #eef2ff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.2, 1.3, 0.4, 1);
  z-index: 40;
  max-width: 80vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

/* ---------- 弹窗 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(4, 6, 16, 0.68);
  backdrop-filter: blur(8px);
  z-index: 50;
  animation: fade 0.18s ease;
}

.overlay[hidden] {
  display: none;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet {
  width: min(400px, 100%);
  padding: 22px 20px 18px;
  border-radius: 26px;
  background:
    radial-gradient(120% 80% at 50% -20%, rgba(124, 58, 237, 0.45), transparent 60%),
    linear-gradient(180deg, #1d2450 0%, #121735 100%);
  border: 1px solid rgba(167, 139, 250, 0.32);
  box-shadow: 0 30px 80px -30px #000, inset 0 1px 0 rgba(255, 255, 255, 0.12);
  animation: pop 0.24s cubic-bezier(0.2, 1.2, 0.4, 1);
}

@keyframes pop {
  from { transform: translateY(14px) scale(0.94); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.sheet h2 {
  margin: 0 0 10px;
  font-size: 19px;
  letter-spacing: 0.01em;
}

.sheet p {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.75;
  color: #aebbe0;
  white-space: pre-line;
  max-height: 44vh;
  overflow: auto;
}

.sheet small {
  display: block;
  margin-top: 10px;
  color: #7d8bb5;
  font-size: 11px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.btn {
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
  color: #e8eeff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease;
}

.btn:hover {
  filter: brightness(1.12);
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  border: none;
  background: linear-gradient(160deg, #a78bfa 0%, #7c3aed 45%, #5b21b6 100%);
  box-shadow: 0 8px 20px -10px rgba(124, 58, 237, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  color: #fff;
}

/* ---------- 广告演示 ---------- */
.ad-sheet {
  text-align: center;
  padding: 30px 24px 24px;
}

.ad-ring {
  width: 54px;
  height: 54px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 3px solid rgba(167, 139, 250, 0.25);
  border-top-color: #a78bfa;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- 主页面 ---------- */
.main-menu {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(56, 78, 190, 0.28), transparent 62%),
    linear-gradient(180deg, #0c1024 0%, #080b18 60%, #05070f 100%);
}

.menu-card {
  width: min(400px, 88vw);
  padding: 28px 22px 24px;
  border-radius: 26px;
  background:
    radial-gradient(120% 80% at 50% -20%, rgba(124, 58, 237, 0.45), transparent 60%),
    linear-gradient(180deg, #1d2450 0%, #121735 100%);
  border: 1px solid rgba(167, 139, 250, 0.32);
  box-shadow: 0 30px 80px -30px #000, inset 0 1px 0 rgba(255, 255, 255, 0.12);
  text-align: center;
  animation: pop 0.24s cubic-bezier(0.2, 1.2, 0.4, 1);
}

.menu-header {
  margin-bottom: 18px;
}

.menu-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  margin: 0;
}

.menu-subtitle {
  font-size: 12px;
  letter-spacing: 0.16em;
  color: #a78bfa;
  margin: 4px 0 0;
  text-transform: uppercase;
}

.menu-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 22px 0 24px;
}

.menu-progress div {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #aebbe0;
}

.menu-progress b {
  color: #e8eeff;
  font-variant-numeric: tabular-nums;
}

.btn-primary {
  height: 48px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(160deg, #a78bfa 0%, #7c3aed 45%, #5b21b6 100%);
  box-shadow: 0 8px 20px -10px rgba(124, 58, 237, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease;
  margin-bottom: 12px;
}

.btn-primary:hover {
  filter: brightness(1.12);
}

.btn-primary:active {
  transform: scale(0.97);
}

.menu-extra {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 14px;
}

.menu-btn {
  flex: 1;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
  color: #e8eeff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease;
}

.menu-btn:hover {
  filter: brightness(1.12);
}

.menu-btn:active {
  transform: scale(0.97);
}

.menu-tip {
  font-size: 11px;
  color: #7d8bb5;
}

/* 在主页面时隐藏游戏 UI */
body.in-menu .hud,
body.in-menu .stage,
body.in-menu .dock {
  display: none !important;
}

.main-menu[hidden] {
  display: none;
}

@media (max-width: 380px) {
  .level, .stat { height: 34px; padding: 0 9px; }
  .level b { font-size: 15px; }
  .stat b { font-size: 14px; }
  .icon-btn { width: 34px; height: 34px; }
  .prop img { width: 26px; height: 26px; }
  .prop { min-height: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  .app::before,
  .app::after,
  .timer.warn,
  .ad-ring,
  .sheen {
    animation: none;
  }

  .sheet,
  .stat b.bump {
    animation-duration: 0.01ms;
  }
}
