:root {
  --hrd-bg-1: rgba(15, 23, 42, 0.03);
  --hrd-bg-2: rgba(255, 255, 255, 0);
}

/* 防止手机浏览器“三连点选中文字”导致按钮点击失灵 */
.header h1,
#ruleText,
.hrdStatus {
  user-select: none;
  -webkit-user-select: none;
}

.hrdHud {
  margin: 10px 0 12px;
  border-radius: 16px;
  padding: 12px 12px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: linear-gradient(180deg, var(--hrd-bg-1), var(--hrd-bg-2));
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.hrdLeft {
  display: grid;
  gap: 4px;
}

.hrdTopRow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hrdStatus {
  font-weight: 1000;
  font-size: 14px;
  color: rgba(15, 23, 42, 0.9);
}

.hrdProb {
  display: grid;
  grid-template-columns: 64px 10px auto;
  align-items: baseline;
  font-weight: 900;
  color: rgba(15, 23, 42, 0.72);
}
.hrdProbLabel,
.hrdProbSep {
  font-size: 12px;
  font-weight: 1000;
  text-align: center;
}
.hrdProbVal {
  font-size: 12px;
  font-weight: 1000;
}
.hrdProb.isLow {
  color: rgba(239, 68, 68, 0.95);
}
.hrdProb.isMid {
  color: rgba(245, 158, 11, 0.95);
}
.hrdProb.isHigh {
  color: rgba(34, 197, 94, 0.95);
}

.hrdMeta {
  font-size: 12px;
  font-weight: 900;
  color: rgba(100, 116, 139, 0.95);
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.hrdSep {
  opacity: 0.7;
}

.hrdBoardWrap {
  width: min(560px, 100%);
  margin: 0 auto;
  position: relative;
}

.hrdControls {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.hrdControls .btn {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
}

.hrdBoard {
  --cols: 4;
  --rows: 5;
  --gap: 10px;
  --cell: clamp(62px, 18vw, 92px);
  --pad: 12px;

  width: 100%;
  aspect-ratio: 4 / 5;
  border-radius: 18px;
  border: 2px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.65);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  position: relative;

  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: var(--gap);
  padding: var(--pad);
  box-sizing: border-box;
}

.hrdBoard::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(59, 130, 246, 0.08), transparent 55%),
    radial-gradient(circle at 80% 20%, rgba(245, 158, 11, 0.08), transparent 55%),
    radial-gradient(circle at 70% 85%, rgba(34, 197, 94, 0.08), transparent 60%);
  pointer-events: none;
}

.hrdCellHint {
  position: absolute;
  inset: var(--pad);
  border-radius: 14px;
  pointer-events: none;
  opacity: 0.0;
}

.hrdPiece {
  appearance: none;
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 12px 26px rgba(2, 6, 23, 0.10);
  cursor: grab;
  user-select: none;
  touch-action: none;
  display: grid;
  place-items: center;
  font-weight: 1000;
  color: rgba(15, 23, 42, 0.86);
  letter-spacing: 0.2px;
  position: absolute;
  transition: left 120ms ease, top 120ms ease, transform 120ms ease;
  z-index: 3; /* 保证箭头/目标框不会挡住棋子文字 */
}

.hrdPiece:active {
  cursor: grabbing;
  transform: scale(0.99);
}

.hrdPiece.isSel {
  outline: 4px solid rgba(59, 130, 246, 0.22);
}
.hrdPiece.isHint {
  outline: 4px solid rgba(245, 158, 11, 0.34);
  animation: hrdHintPulse 720ms ease-in-out 2;
}

/* 提示一步：目标位置框 */
.hrdHintTarget {
  position: absolute;
  border-radius: 18px;
  border: 3px dashed rgba(245, 158, 11, 0.92);
  box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.12);
  background: rgba(245, 158, 11, 0.06);
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 1;
}
.hrdHintTarget.isOn {
  opacity: 1;
  transform: translateY(0);
}

.hrdHintArrow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease;
  z-index: 1;
}
.hrdHintArrow.isOn {
  opacity: 1;
}

@keyframes hrdHintPulse {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(0.985);
  }
  100% {
    transform: scale(1);
  }
}

.hrdPiece.isCao {
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.92), rgba(220, 38, 38, 0.92));
  color: rgba(255, 255, 255, 0.95);
  border-color: rgba(239, 68, 68, 0.35);
}

.hrdPiece.isGuan {
  background: linear-gradient(180deg, rgba(34, 197, 94, 0.88), rgba(16, 185, 129, 0.88));
  color: rgba(255, 255, 255, 0.95);
  border-color: rgba(34, 197, 94, 0.35);
}

.hrdPiece.isSoldier {
  background: linear-gradient(180deg, rgba(148, 163, 184, 0.90), rgba(100, 116, 139, 0.90));
  color: rgba(255, 255, 255, 0.96);
  border-color: rgba(148, 163, 184, 0.35);
}

.hrdExit {
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%);
  width: 54%;
  height: 28px;
  border-radius: 999px;
  border: 2px dashed rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.10);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 1000;
  color: rgba(245, 158, 11, 0.95);
  pointer-events: none;
}

@media (max-width: 420px) {
  .hrdControls {
    grid-template-columns: 1fr;
  }
}
