:root {
  --bg: #0e1520;
  --bg-soft: #141d2b;
  --panel: #182334;
  --panel-edge: #27364d;
  --text: #e8eef7;
  --muted: #93a3ba;
  --accent: #4cc9f0;
  --ok: #54d68a;
  --bad: #ff6b7a;
  --warn: #f7c75c;
  --warm: #ffb86b;
  --cool: #6fc1ff;
  --blk: #2a3442;
  --empty: #1e2a3a;
  --w1: #7cc4f8;
  --w2: #7ed9a2;
  --w3: #f7d36b;
  --w4: #f7a95c;
  --w5: #f47f9a;
  --w6: #b48cf5;
  --cell: 88px;
  --cell-gap: 10px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui,
    sans-serif;
  background: radial-gradient(1200px 640px at 50% -14%, #1d3049 0%, var(--bg) 60%)
      no-repeat,
    var(--bg);
  color: var(--text);
}

button,
.cell,
.ball {
  touch-action: manipulation;
}

.cell,
.ball,
.stepper button {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.hero {
  padding: 32px 20px 8px;
  width: min(1140px, 96vw);
  margin: 0 auto;
  text-align: center;
}

.hero h1 {
  display: inline-flex;
  align-items: center;
  gap: 22px;
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 5px;
  color: #f4f9ff;
  text-shadow: 0 0 30px rgba(76, 201, 240, 0.35);
}

.hero h1::before,
.hero h1::after {
  content: "";
  width: 64px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(76, 201, 240, 0.7));
}

.hero h1::after {
  background: linear-gradient(90deg, rgba(76, 201, 240, 0.7), transparent);
}

.hero .play-hint {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 中央舞台 / 控制台 ---------- */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px max(24px, env(safe-area-inset-bottom));
}

.console {
  width: min(1140px, 96vw);
  padding: 22px 28px 24px;
  border-radius: 26px;
  background: linear-gradient(180deg, #1a2740 0%, #131d2d 70%);
  border: 1px solid #2d4059;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.console-head {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
  position: relative;
}

.lang-toggle {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px 14px;
  min-height: 32px;
  font-size: 13px;
  color: var(--muted);
}

.status {
  padding: 10px 26px;
  border-radius: 999px;
  font-size: 15px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 92%;
  text-align: center;
}

.status.idle {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-color: var(--panel-edge);
}

.status.running {
  background: rgba(76, 201, 240, 0.12);
  color: var(--accent);
  border-color: rgba(76, 201, 240, 0.4);
}

.status.ok {
  background: rgba(84, 214, 138, 0.12);
  color: var(--ok);
  border-color: rgba(84, 214, 138, 0.4);
}

.status.err {
  background: rgba(255, 107, 122, 0.12);
  color: var(--bad);
  border-color: rgba(255, 107, 122, 0.4);
}

.status.warn {
  background: rgba(247, 199, 92, 0.1);
  color: var(--warn);
  border-color: rgba(247, 199, 92, 0.4);
}

.console-body {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 264px;
  gap: 30px;
  align-items: center;
  justify-items: center;
}

.console-foot {
  display: flex;
  justify-content: center;
  margin-top: 22px;
}

/* ---------- 棋盘区域 ---------- */
.board-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 0;
  perspective: 900px;
}

.board-shell {
  padding: 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, #1c2a40, #141f30);
  border: 1px solid #2f425e;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.board-shell.sway {
  animation: board-sway 1.9s ease-in-out infinite;
}

@keyframes board-sway {
  0%,
  100% {
    transform: rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
  }
  25% {
    transform: rotateX(calc(var(--tilt-x) + 2deg)) rotateY(calc(var(--tilt-y) - 2deg));
  }
  75% {
    transform: rotateX(calc(var(--tilt-x) - 2deg)) rotateY(calc(var(--tilt-y) + 2deg));
  }
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--cols), var(--cell));
  gap: var(--cell-gap);
  transform-style: preserve-3d;
}

.board.n4 { --cols: 4; --cell: 104px; --cell-gap: 12px; }
.board.n5 { --cols: 5; --cell: 88px; --cell-gap: 10px; }
.board.n6 { --cols: 6; --cell: 66px; --cell-gap: 7px; }

.cell {
  border-radius: 15px;
  border: 1px solid #365070;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  background: var(--empty);
  color: #101a26;
  padding: 0;
  transform: translateZ(10px);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.32);
}

.board.n4 .cell { font-size: 42px; }
.board.n6 .cell { font-size: 30px; }
.board.n4 .cell.blocked::after { font-size: 34px; }
.board.n6 .cell.blocked::after { font-size: 24px; }

.cell .dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #5c718f;
  opacity: 0.6;
}

.cell:hover {
  transform: translateZ(18px) scale(1.04);
  border-color: var(--accent);
}

.cell.blocked {
  background: var(--blk);
  border-color: #3d4c61;
  color: #75849a;
  cursor: pointer;
}

.cell.blocked::after {
  content: "✕";
  font-size: 32px;
}

.cell.w1 { background: var(--w1); }
.cell.w2 { background: var(--w2); }
.cell.w3 { background: var(--w3); }
.cell.w4 { background: var(--w4); }
.cell.w5 { background: var(--w5); }
.cell.w6 { background: var(--w6); }

.cell.solved {
  cursor: pointer;
  box-shadow:
    0 5px 12px rgba(0, 0, 0, 0.32),
    inset 0 3px 8px rgba(255, 255, 255, 0.24);
}

.cell.dragging {
  opacity: 0.55;
}

.cell.drop-target {
  border-color: var(--ok);
  box-shadow: 0 0 0 3px rgba(84, 214, 138, 0.45), inset 0 0 14px rgba(84, 214, 138, 0.22);
}

.board-shell.drag-active .cell:not(.blocked):not(.solved) {
  border-style: dashed;
  border-color: rgba(84, 214, 138, 0.7);
  background: rgba(84, 214, 138, 0.06);
}

/* ---------- 平衡指示器 ---------- */
.b-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--panel-edge);
  min-width: 168px;
}

.b-chip .arr {
  font-size: 22px;
  line-height: 1;
}

.b-chip .lbl {
  font-size: 14px;
  color: var(--muted);
}

.b-chip .num {
  margin-left: auto;
  font-size: 25px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.b-chip.up .arr,
.b-chip.up .num {
  color: var(--warm);
}

.b-chip.down .arr,
.b-chip.down .num {
  color: var(--cool);
}

.b-chip.left .arr,
.b-chip.left .num {
  color: var(--warm);
}

.b-chip.right .arr,
.b-chip.right .num {
  color: var(--cool);
}

.balance-vert {
  display: grid;
  gap: 12px;
  justify-self: end;
}

.balance-horiz {
  display: flex;
  gap: 12px;
  align-items: stretch;
  justify-content: center;
  flex-wrap: wrap;
}

.b-net {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.035);
  font-size: 14px;
}

.b-net .lbl {
  color: var(--muted);
}

.b-net .num {
  font-weight: 800;
  font-size: 21px;
  font-variant-numeric: tabular-nums;
}

.b-net .arr {
  font-weight: 800;
  font-size: 22px;
  line-height: 1;
}

.b-net.neutral {
  color: var(--muted);
}

.b-net.balanced {
  border-color: rgba(84, 214, 138, 0.6);
  background: rgba(84, 214, 138, 0.09);
  box-shadow: 0 0 18px rgba(84, 214, 138, 0.22);
}

.b-net.balanced .num,
.b-net.balanced .arr {
  color: var(--ok);
}

.b-net.unbalanced {
  border-color: rgba(255, 107, 122, 0.6);
  background: rgba(255, 107, 122, 0.09);
}

.b-net.unbalanced .num,
.b-net.unbalanced .arr {
  color: var(--bad);
}

.balance-vert .b-net {
  min-width: 168px;
}

/* ---------- 引导提示 ---------- */
/* ---------- 气球库存（右侧竖列） ---------- */
.inventory {
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-self: start;
  width: 100%;
  padding: 18px 16px 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, #1b2940, #141f30);
  border: 1px solid var(--panel-edge);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.35);
}

.inventory-title {
  font-size: 16px;
  letter-spacing: 2px;
  text-align: center;
  color: var(--text);
}

.balloon-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.balloon-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  padding: 9px 12px;
}

.ball {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 23px;
  font-weight: 800;
  color: #101a26;
  position: relative;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: element;
}

.ball::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 8px;
  width: 13px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  filter: blur(0.5px);
}

.ball.w1 {
  background: radial-gradient(circle at 34% 28%, #bde1ff, var(--w1) 62%);
  box-shadow: 0 5px 16px rgba(124, 196, 248, 0.4);
}

.ball.w2 {
  background: radial-gradient(circle at 34% 28%, #c9f4d6, var(--w2) 62%);
  box-shadow: 0 5px 16px rgba(126, 217, 162, 0.4);
}

.ball.w3 {
  background: radial-gradient(circle at 34% 28%, #fff0bb, var(--w3) 62%);
  box-shadow: 0 5px 16px rgba(247, 211, 107, 0.4);
}

.ball.w4 {
  background: radial-gradient(circle at 34% 28%, #ffd8b0, var(--w4) 62%);
  box-shadow: 0 5px 16px rgba(247, 169, 92, 0.4);
}

.ball.w5 {
  background: radial-gradient(circle at 34% 28%, #ffc3cf, var(--w5) 62%);
  box-shadow: 0 5px 16px rgba(244, 127, 154, 0.4);
}

.ball.w6 {
  background: radial-gradient(circle at 34% 28%, #dcc8ff, var(--w6) 62%);
  box-shadow: 0 5px 16px rgba(180, 140, 245, 0.4);
}

.ball.dim {
  opacity: 0.32;
  cursor: not-allowed;
  filter: grayscale(0.7);
}

.ball.dragging {
  opacity: 0.55;
}

.ball.selected {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 20px rgba(76, 201, 240, 0.55);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  justify-content: flex-end;
}

.stepper button {
  width: 31px;
  height: 31px;
  border-radius: 9px;
  border: 1px solid var(--panel-edge);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.stepper button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.stepper button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stepper input[type="number"] {
  width: 52px;
  height: 31px;
  text-align: center;
  border: 1px solid var(--panel-edge);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -moz-appearance: textfield;
  appearance: textfield;
}

.stepper input[type="number"]::-webkit-outer-spin-button,
.stepper input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stepper input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}

.summary-line {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.summary-line b {
  color: var(--text);
}

.summary-line.bad {
  color: var(--bad);
}

.summary-line.bad b {
  color: var(--bad);
}

.msg {
  min-height: 16px;
  font-size: 12px;
  color: var(--bad);
  text-align: center;
}

/* ---------- 按钮 ---------- */
.actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  border: 1px solid var(--panel-edge);
  background: var(--bg-soft);
  color: var(--text);
  padding: 11px 26px;
  border-radius: 12px;
  font-size: 15px;
  cursor: pointer;
  transition: border-color 0.15s ease, filter 0.15s ease;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: linear-gradient(135deg, #2c9fce, #1d7fb0);
  border-color: #35b2e2;
  color: #fff;
  font-weight: 700;
  letter-spacing: 4px;
}

button.primary:hover {
  filter: brightness(1.08);
}

.diff-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--muted);
}

.diff-select select {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  cursor: pointer;
}

.diff-select select:hover {
  border-color: var(--accent);
}

.foot {
  padding: 0 20px 18px;
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.foot a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.foot a:hover {
  color: var(--accent);
}

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .board.n4 { --cell: 84px; }
  .board.n5 { --cell: 70px; }
  .board.n6 { --cell: 56px; }
  .console-body {
    grid-template-columns: 176px minmax(0, 1fr) 232px;
    gap: 22px;
  }
  .cell {
    font-size: 30px;
    border-radius: 12px;
  }
  .cell.blocked::after {
    font-size: 26px;
  }
  .b-chip {
    min-width: 148px;
    padding: 11px 13px;
  }
  .b-chip .num {
    font-size: 21px;
  }
  .ball {
    width: 46px;
    height: 46px;
    font-size: 20px;
  }
}

@media (max-width: 820px) {
  .console {
    padding: 16px;
  }
  .console-body {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .balance-vert {
    grid-row: 1;
    justify-self: center;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .board-zone {
    grid-row: 2;
  }
  .inventory {
    grid-row: 3;
    justify-self: center;
    max-width: 430px;
  }
  .balloon-col {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  .balloon-item {
    width: 100%;
    max-width: 340px;
    padding: 10px 12px;
  }
  .board.n4 { --cell: 70px; --cell-gap: 8px; }
  .board.n5 { --cell: 58px; --cell-gap: 6px; }
  .board.n6 { --cell: 46px; --cell-gap: 5px; }
  .cell {
    font-size: 26px;
    border-radius: 10px;
  }
  .board.n4 .cell { font-size: 30px; }
  .board.n6 .cell { font-size: 22px; }
  .cell.blocked::after {
    font-size: 20px;
  }
  .b-chip {
    min-width: 0;
    padding: 8px 12px;
  }
  .b-chip .num {
    font-size: 18px;
  }
  .stepper button {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  .stepper input[type="number"] {
    width: 56px;
    height: 40px;
    font-size: 16px;
  }
  .actions button {
    min-height: 44px;
    padding: 10px 18px;
  }
  .diff-select select {
    min-height: 44px;
    padding: 10px 12px;
  }
  .status {
    font-size: 13px;
  }
  .hero .play-hint {
    font-size: 12px;
    line-height: 1.6;
  }
  .hero h1 {
    font-size: 22px;
    letter-spacing: 3px;
    gap: 14px;
  }
  .hero h1::before,
  .hero h1::after {
    width: 30px;
  }
}

@media (max-width: 640px) {
  .hero {
    padding-top: 24px;
  }
}

@media (max-width: 480px) {
  .console {
    padding: 12px;
    border-radius: 18px;
  }
  .board-shell {
    padding: 10px;
    border-radius: 16px;
  }
  .status {
    width: 100%;
    padding: 9px 12px;
  }
  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .actions button {
    width: 100%;
  }
  .actions .primary {
    grid-column: 1 / -1;
  }
  .diff-select {
    display: flex;
    justify-content: center;
    min-width: 0;
  }
  .diff-select select {
    flex: 1;
    min-width: 0;
    width: 100%;
  }
  .hero h1 {
    font-size: 19px;
  }
  .hero .play-hint {
    font-size: 11.5px;
  }
  .b-chip {
    padding: 6px 10px;
  }
  .b-chip .num {
    font-size: 17px;
  }
}
