#tool-body {
  --primary: #16baaa;
  --card-bg: #fff;
  --text-color: #333;
  --text-sub: #888;
  --border-color: #e6e6e6;
  --board-bg: #f2f3f5;
  --danger: #ff5c5c;
  --gold: #ffb400;
}
.theme-dark-mode #tool-body {
  --card-bg: #2b2b2b;
  --text-color: #eee;
  --text-sub: #aaa;
  --border-color: #444;
  --board-bg: #1f1f1f;
}

#tool-body #game-box {
  max-width: 620px;
  margin: 0 auto;
  padding: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  color: var(--text-color);
  user-select: none;
}
#tool-body #game-box * { box-sizing: border-box; }

/* 全局禁用長按選中/複製/系統菜單，避免移動端長按放置小牛時彈出選中文字的系統氣泡 */
#tool-body, #tool-body * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
}

#tool-body .top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}
#tool-body .left-btns {
  display: flex;
  gap: 8px;
}
#tool-body .pill {
  background: var(--board-bg);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#tool-body .level-title {
  font-size: 18px;
  font-weight: 700;
}
#tool-body .hearts { color: var(--danger); font-size: 16px; letter-spacing: 2px; }
#tool-body .hearts .lost { opacity: .25; }

#tool-body .rules-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: space-around;
  text-align: center;
}
#tool-body .rules-card b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  margin-right: 4px;
  flex-shrink: 0;
}

#tool-body .board-wrap {
  background: var(--board-bg);
  border-radius: 16px;
  padding: 8px;
  margin: 0 auto 14px;
  max-width: 100%;
}
#tool-body .board {
  display: grid;
  gap: 5px;
  width: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
}
#tool-body .cell {
  position: relative;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(4vw, 22px);
  cursor: pointer;
  transition: transform .08s ease;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
#tool-body .cell.error {
  animation: shake .35s;
  box-shadow: 0 0 0 3px var(--danger) inset;
}
#tool-body .cell.correct{
  animation: pulse 0.35s ease-in-out;
}
#tool-body .cell.was-wrong {
  box-shadow: 0 0 0 2px var(--danger) inset;
}
#tool-body .cell.was-wrong .mark-x { color: var(--danger); }
#tool-body .cell.press-anim { transform: scale(0.9); }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@keyframes pulse {
  0% { transform: scale(1.5);z-index: 1; }
  100% { transform: scale(1);z-index: inherit; }
  /*   50% { transform: scale(1.5);z-index: 10; box-shadow: 0 0 0 3px var(--gold) inset;} */
}
#tool-body .cell .mark-x {
  color: #f8f8f8;
  font-weight: bolder;
  font-size: min(7cqw, 38px);;
  text-shadow: 0 0 3px #999;
}
#tool-body .cell .marker-img {
  width: 72%;
  height: 72%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(7cqw, 38px);;
  line-height: 1;
  pointer-events: none;
}
#tool-body .cell .marker-img img { width: 100%; height: 100%; object-fit: contain; }
#tool-body .cell.hint-glow {
  box-shadow: 0 0 0 3px var(--gold) inset;
}
#tool-body .marker-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 13px;
  line-height: 1;
  vertical-align: -4px;
  margin: 0 1px;
  /*   background: #cdeee9; */
  /*   padding: 2px; */
  /*   border-radius: 5px; */
}
#tool-body .marker-inline img { width: 100%; height: 100%; object-fit: contain; }
#tool-body .help-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--board-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-sub);
}

#tool-body .controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
#tool-body .ctrl-btn {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  min-width: 68px;
  color: var(--text-color);
}
#tool-body .ctrl-btn i { font-size: 18px; color: var(--primary); }
#tool-body .ctrl-btn .badge {
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 0 6px;
}
#tool-body .ctrl-btn:active { opacity: .7; }

#tool-body .overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
#tool-body .overlay.show { display: flex; }
#tool-body .overlay .panel {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px 26px;
  text-align: center;
  width: auto;
  max-width: 90vw;
}
#tool-body .overlay .panel h3 { margin: 0 0 8px; font-size: 20px; }
#tool-body .overlay .panel p { color: var(--text-sub); font-size: 14px; margin: 6px 0 18px; }
#tool-body .overlay .panel .btn-row { display: flex; gap: 10px; }
#tool-body .overlay .panel button {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 10px 0;
  font-size: 14px;
  cursor: pointer;
  background: var(--board-bg);
  color: var(--text-color);
}
#tool-body .overlay .panel button.main {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

#tool-body.fullscreen-mode {
  max-width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--card-bg);
}

#tool-body .footer-tip {
  text-align: center;
  color: var(--text-sub);
  font-size: 12px;
  margin-top: 4px;
}

#tool-body .tutorial-panel { width: 300px; }
#tool-body .mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(3, 40px);
  gap: 4px;
  justify-content: center;
  margin: 14px auto;
}
#tool-body .mini-grid .mg-cell {
  border-radius: 6px;
  background: var(--board-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
#tool-body .mini-grid .mg-center { background: #cdeee9; }
#tool-body .mini-grid .mg-forbid { background: #fbdada; color: var(--danger); font-weight: 700; }
#tool-body .mini-grid .mg-center .marker-inline { width: 22px; height: 22px; }
#tool-body .tip-list {
  text-align: left;
  font-size: 13px;
  color: var(--text-color);
  margin: 10px 0 18px;
  padding: 0 4px;
  list-style: none;
}
#tool-body .tip-list li { margin-bottom: 8px; line-height: 1.5; }

#tool-body .remaining-wrap { text-align: center; margin-bottom: 10px; }
#tool-body .remaining-wrap .pill { display: inline-flex; }

#tool-body .mini-toast {
  position: fixed;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(0,0,0,.8);
  color: #fff;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 10000;
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
  white-space: nowrap;
}
#tool-body .mini-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 關卡選擇彈層 */
#tool-body .levels-panel { width: 300px; }
#tool-body .levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  margin: 14px 0;
  padding: 4px 2px;
}
#tool-body .level-btn {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: var(--board-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-color);
}
#tool-body .level-btn.current {
  background: var(--primary);
  color: #fff;
}
#tool-body .level-btn:active { opacity: .7; }