:root {
  --bg-deep: #070611;
  --bg-surface: rgba(22, 18, 44, 0.78);
  --bg-card: rgba(255, 255, 255, 0.06);
  --border-subtle: rgba(255, 255, 255, 0.12);
  --border-glow: rgba(168, 85, 247, 0.4);

  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --text-gold: #facc15;
  --text-cyan: #38bdf8;
  --text-green: #34d399;
  --text-accent: #e879f9;

  --board-size: min(78vh, 520px);
  --grid-cols: 8;
  --grid-rows: 8;

  /* 物理弹簧移动与慢速沉浸感参数 */
  --anim-swap-speed: 340ms;
  --anim-drop-speed: 460ms;
  --anim-pop-speed: 360ms;

  --ease-swap: cubic-bezier(0.34, 1.35, 0.64, 1);
  --ease-drop: cubic-bezier(0.22, 0.9, 0.35, 1.15);
}

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

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-deep);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-main);
}

.noscript-banner {
  background: #e11d48;
  color: #fff;
  padding: 12px;
  text-align: center;
  font-weight: bold;
}

.app-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px 28px;
  max-width: 1360px;
  margin: 0 auto;
  z-index: 1;
}

.ambient-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(140px);
  pointer-events: none;
  z-index: -1;
  opacity: 0.4;
}
.glow-1 {
  top: -10%;
  left: -5%;
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, #6366f1 0%, transparent 70%);
}
.glow-2 {
  bottom: -15%;
  right: -5%;
  width: 620px;
  height: 620px;
  background: radial-gradient(circle, #ec4899 0%, transparent 70%);
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

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

.home-link {
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  opacity: 0.78;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.home-link:hover,
.home-link:focus-visible {
  opacity: 1;
  transform: translateX(-2px);
}

.home-link span {
  color: var(--text-cyan);
}

.brand-badge {
  background: linear-gradient(135deg, #a855f7, #ec4899);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 1px;
  box-shadow: 0 0 16px rgba(168, 85, 247, 0.4);
}

.brand-title {
  font-size: 1.4rem;
  font-weight: 800;
  background: linear-gradient(90deg, #f8fafc, #d8b4fe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
}

.svg-icon {
  width: 18px;
  height: 18px;
}

.hidden {
  display: none !important;
}

.workbench-layout {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  margin-top: 14px;
  height: calc(100% - 65px);
}

.game-dashboard {
  width: 310px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex-shrink: 0;
}

.dashboard-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(20px);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.level-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.level-num {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--text-gold);
}

.level-stars .star {
  font-size: 1.15rem;
  color: rgba(255, 255, 255, 0.2);
  margin-left: 2px;
}

.level-stars .star.active {
  color: var(--text-gold);
  text-shadow: 0 0 10px rgba(250, 204, 21, 0.9);
}

.level-desc {
  font-size: 0.84rem;
  color: var(--text-dim);
  line-height: 1.4;
}

.card-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  display: block;
  margin-bottom: 10px;
}

.goals-list {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.goal-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 6px 12px;
  transition: all 0.3s ease;
}

.goal-item.done {
  border-color: var(--text-green);
  background: rgba(52, 211, 153, 0.12);
}

.goal-icon-box {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.goal-icon-box svg {
  width: 100%;
  height: 100%;
}

.goal-count {
  font-size: 1.15rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
}

.goal-item.done .goal-count {
  color: var(--text-green);
}

.status-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.metric-block {
  display: flex;
  flex-direction: column;
}

.metric-title {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.metric-number {
  font-size: 1.8rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

.moves-block .metric-number { color: var(--text-green); }
.score-block .metric-number { color: var(--text-gold); }

.side-action-group {
  display: flex;
  gap: 12px;
}

.side-btn {
  flex: 1;
  padding: 13px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 700;
  transition: all 0.2s ease;
}

.hint-btn {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(56, 189, 248, 0.05));
  color: var(--text-cyan);
  border-color: rgba(56, 189, 248, 0.3);
}

.restart-btn {
  background: var(--bg-surface);
  color: var(--text-dim);
}

.side-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.2);
}

/* 棋盘主舞台 */
.stage-section {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.board-container {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background: rgba(14, 11, 32, 0.88);
  border: 2px solid var(--border-subtle);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8), inset 0 0 30px rgba(255, 255, 255, 0.02);
  padding: 10px;
}

.board-grid-bg {
  position: absolute;
  inset: 10px;
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), 1fr);
  grid-template-rows: repeat(var(--grid-rows), 1fr);
  gap: 6px;
  pointer-events: none;
}

.grid-cell-slot {
  background: rgba(255, 255, 255, 0.025);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.board-interactive {
  position: absolute;
  inset: 10px;
  touch-action: none;
}

/* 晶石图元：原生平滑 translate3d 渲染 */
.tile-node {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transform-origin: center center;
  transition: transform var(--anim-swap-speed) var(--ease-swap), opacity 0.25s ease;
  will-change: transform, opacity;
  pointer-events: auto;
}

.tile-node svg {
  width: 88%;
  height: 88%;
  pointer-events: none;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.5));
}

.tile-node.selected {
  z-index: 10;
  filter: drop-shadow(0 0 16px rgba(255, 255, 255, 0.95));
}

.tile-node.selected svg {
  transform: scale(1.15);
}

/* 准备消除预警高光（连线识别） */
.tile-node.pre-burst {
  animation: pre-burst-flash 200ms ease-out forwards;
}

@keyframes pre-burst-flash {
  0% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.18); filter: brightness(1.8) drop-shadow(0 0 14px #fff); }
  100% { transform: scale(1.1); filter: brightness(1.5); }
}

/* 消除爆裂 */
.tile-node.exploding {
  z-index: 8;
  animation: explode-out var(--anim-pop-speed) forwards cubic-bezier(0.1, 0.85, 0.3, 1);
}

@keyframes explode-out {
  0% { transform: scale(1.1); opacity: 1; filter: brightness(1.5); }
  35% { transform: scale(1.4) rotate(12deg); opacity: 0.95; filter: brightness(2.5); }
  100% { transform: scale(0) rotate(-24deg); opacity: 0; filter: brightness(3); }
}

/* 下落到位柔和形变 */
.tile-node.bounce-land {
  animation: land-squash 300ms ease-out;
}

@keyframes land-squash {
  0% { transform: scale(1, 1); }
  35% { transform: scale(1.12, 0.88); }
  65% { transform: scale(0.96, 1.04); }
  85% { transform: scale(1.02, 0.98); }
  100% { transform: scale(1, 1); }
}

/* 寻路提示 */
.tile-node.hint {
  z-index: 20;
  animation: hint-super-bounce 0.85s infinite alternate ease-in-out;
}

@keyframes hint-super-bounce {
  0% { filter: brightness(1) drop-shadow(0 0 4px #facc15); }
  100% { filter: brightness(1.6) drop-shadow(0 0 20px #facc15); }
}

.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 22px;
}

.combo-banner {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 28px;
  background: rgba(12, 10, 28, 0.92);
  border: 2px solid var(--text-gold);
  border-radius: 999px;
  color: var(--text-gold);
  font-size: 1.6rem;
  font-weight: 900;
  box-shadow: 0 0 35px rgba(250, 204, 21, 0.6);
  pointer-events: none;
  animation: banner-zoom 900ms forwards ease-out;
  z-index: 25;
}

@keyframes banner-zoom {
  0% { transform: translate(-50%, -30%) scale(0.3); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  75% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -65%) scale(0.8); opacity: 0; }
}

.shuffle-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 30px;
  background: rgba(24, 20, 50, 0.95);
  border: 2px solid var(--text-cyan);
  border-radius: 16px;
  color: var(--text-cyan);
  font-size: 1.2rem;
  font-weight: 800;
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.5);
  z-index: 30;
  pointer-events: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 4, 18, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.level-selector-box {
  max-height: 82vh;
  display: flex;
  flex-direction: column;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  overflow-y: auto;
  max-height: 58vh;
  padding-right: 4px;
}

.modal-box {
  background: #181432;
  border: 1px solid var(--border-subtle);
  border-radius: 22px;
  padding: 26px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.close-x-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.6rem;
  cursor: pointer;
}

.level-card-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.2s ease;
}

.level-card-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: var(--text-cyan);
}

.level-card-btn.locked {
  opacity: 0.35;
  cursor: not-allowed;
}

.level-card-btn .btn-num {
  font-size: 1.05rem;
  font-weight: 800;
}

.level-card-btn .btn-stars {
  font-size: 0.65rem;
  color: var(--text-gold);
}

.result-box {
  text-align: center;
}

.result-badge {
  font-size: 3.2rem;
  margin-bottom: 8px;
}

.result-title {
  font-size: 1.6rem;
  font-weight: 900;
}

.result-stars {
  font-size: 1.6rem;
  color: var(--text-gold);
  margin: 8px 0;
  letter-spacing: 5px;
}

.result-desc {
  font-size: 0.88rem;
  color: var(--text-dim);
  margin-bottom: 22px;
}

.result-stats-card {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 14px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.92rem;
  color: var(--text-dim);
}

.stat-item .num-val {
  font-weight: 800;
  color: var(--text-main);
}

.result-action-row {
  display: flex;
  gap: 12px;
}

.btn-sub, .btn-main {
  flex: 1;
  padding: 14px;
  border-radius: 14px;
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
}

.btn-sub {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.btn-main {
  background: linear-gradient(135deg, #a855f7, #ec4899);
  color: #fff;
  box-shadow: 0 6px 18px rgba(236, 72, 153, 0.4);
}

@media (max-width: 820px) {
  .app-viewport {
    padding: 8px 12px;
  }

  .workbench-layout {
    flex-direction: column;
    justify-content: flex-start;
    gap: 10px;
    margin-top: 6px;
  }

  .game-dashboard {
    width: 100%;
    max-width: var(--board-size);
    gap: 8px;
  }

  .level-card {
    display: none;
  }

  .dashboard-card {
    padding: 10px 14px;
  }

  .metric-number {
    font-size: 1.3rem;
  }

  .side-action-group {
    display: none;
  }

  :root {
    --board-size: min(92vw, 56vh);
  }
}
