#tool-body {
  --primary: #16baaa;
  --primary-light: #e8f8f7;
  --card-bg: #fff;
  --card-border: #e8e8e8;
  --text-main: #333;
  --text-muted: #888;
  --maze-bg: #f0f0f0;
  --maze-wall: #555;
  --maze-path: #fff;
  --maze-visited: #c8ede9;
  --btn-hint-bg: #ff9800;
  --hint-arrow: #ff5722;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.theme-dark-mode #tool-body {
  --card-bg: #252525;
  --card-border: #3a3a3a;
  --text-main: #eee;
  --text-muted: #999;
  --maze-bg: #3c3c3c;
  --maze-wall: #bbb;
  --maze-path: #2d2d2d;
  --maze-visited: #2a4a48;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --primary-light: #1a3535;
}

#tool-body * { box-sizing: border-box; }

/* ====== 佈局 ====== */
#tool-body .maze-layout {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  flex-wrap: wrap;
}
#tool-body .maze-main { flex: 1 1 280px; min-width: 0; }
#tool-body .maze-side { width: 230px; flex-shrink: 0; }

@media (max-width: 768px) {
  #tool-body .maze-side { width: 100%; order: 2; }
  #tool-body .maze-main { width: 100%; order: 1; }
  #tool-body .maze-layout { flex-direction: column; gap: 0; }
  #tool-body .side-dpad-card { display: none !important; }
  #tool-body .mobile-dpad-bar { display: flex !important; }
  #tool-body .tip-desktop { display: none !important; }
  #tool-body .maze-wrap { max-height: 50vh;}
}
@media (min-width: 769px) {
  #tool-body .tip-mobile { display: none !important; }
  #tool-body .mobile-dpad-bar { display: none !important; }
}

/* ====== 卡片 ====== */
#tool-body .card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
#tool-body .card-title {
  font-size: 12px;
  font-weight: bold;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ====== 狀態欄 ====== */
#tool-body .status-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
#tool-body .stat-item {
  flex: 1;
  min-width: 70px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 8px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}
#tool-body .stat-val {
  font-size: 18px;
  font-weight: bold;
  color: var(--primary);
  line-height: 1.2;
}
#tool-body .stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ====== canvas 容器 ====== */
#tool-body .maze-wrap {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  /*       display: flex; */
  /*       justify-content: center; */
  /*       align-items: center; */
  min-height: 180px;
  overflow: auto;
  position: relative;
}
#tool-body #maze-canvas {
  display: block;
  cursor: default;
  /*   touch-action: none; */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  margin: 0px auto;
}

/* ====== 提示箭頭 ====== */
@keyframes tb-hint-bounce {
  0%   { transform: translate(-50%,-50%) scale(1);    opacity:1; }
  40%  { transform: translate(-50%,-50%) scale(1.3);  opacity:.9; }
  70%  { transform: translate(-50%,-50%) scale(.95);  opacity:1; }
  100% { transform: translate(-50%,-50%) scale(1);    opacity:1; }
}
#tb-hint-arrow {
  position: absolute;
  pointer-events: none;
  display: none;
  line-height: 1;
  z-index: 100;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.55));
  animation: tb-hint-bounce .6s ease forwards;
}
#tb-hint-arrow.show { display: block; }

/* ====== 控制提示條 ====== */
#tool-body .control-tip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--primary-light);
  border-radius: 6px;
  font-size: 12px;
  color: var(--primary);
  margin-bottom: 10px;
}
#tool-body .control-tip .tip-icon { font-size: 14px; flex-shrink: 0; }

/* ====== 手機端底部方向鍵 ====== */
#tool-body .mobile-dpad-bar {
  display: none;
  justify-content: space-evenly;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  margin-bottom: 8px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
#tool-body .mobile-dpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 36px);
  grid-template-rows: repeat(3, 36px);
  gap: 4px;
}
#tool-body .dpad-btn {
  width: 36px; height: 36px;
  background: var(--primary-light);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 18px;
  color: var(--primary);
  user-select: none;
  transition: background .1s, transform .08s;
  -webkit-tap-highlight-color: transparent;
}
#tool-body .dpad-btn:active {
  background: var(--primary);
  color: #fff;
  transform: scale(.9);
}
#tool-body .dpad-center { background: transparent !important; border: none !important; cursor: default; }
#tool-body .dpad-center:active { transform: none !important; }

/* 滑動模式切換按鈕 */
#tool-body .swipe-toggle-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 10px;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 10px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.3;
  min-width: 52px;
  text-align: center;
}
#tool-body .swipe-toggle-btn .swipe-icon { font-size: 22px; }
#tool-body .swipe-toggle-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
/* 滑動模式時在迷宮上方顯示提示 */
#tool-body .swipe-mode-tip {
  display: none;
  text-align: center;
  padding: 5px;
  font-size: 12px;
  color: var(--btn-hint-bg);
  background: var(--primary-light);
  border-radius: 6px;
  margin-bottom: 8px;
}
#tool-body .swipe-mode-tip.show { display: block; }

/* ====== 側欄方向鍵（桌面端） ====== */
#tool-body .dpad-wrap { display: flex; justify-content: center; padding: 4px 0; }
#tool-body .dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 4px;
}
#tool-body .side-dpad .dpad-btn { width: 44px; height: 44px; font-size: 17px; }

/* ====== 按鈕 ====== */
#tool-body .action-btns { display: flex; flex-direction: column; gap: 7px; }
#tool-body .btn-new {
  width: 100%; padding: 9px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 6px;
  font-size: 14px; font-weight: bold; cursor: pointer;
  transition: opacity .15s;
}
#tool-body .btn-new:hover { opacity: .85; }
#tool-body .btn-hint {
  width: 100%; padding: 8px;
  background: var(--btn-hint-bg); color: #fff;
  border: none; border-radius: 6px;
  font-size: 13px; cursor: pointer;
  transition: opacity .15s;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
#tool-body .btn-hint:hover { opacity: .85; }

/* ====== 難度 ====== */
#tool-body .diff-btns { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }
#tool-body .diff-btn {
  flex: 1; min-width: 44px; padding: 5px 3px;
  font-size: 12px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card-bg); color: var(--text-main);
  cursor: pointer; text-align: center; transition: all .15s;
}
#tool-body .diff-btn:hover,
#tool-body .diff-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 自定義尺寸 */
#tool-body .custom-size {
  display: flex; gap: 5px; align-items: center;
  margin-top: 7px; font-size: 12px; color: var(--text-muted);
}
#tool-body .custom-size input {
  width: 42px; border: 1px solid var(--card-border);
  border-radius: 4px; padding: 3px 5px;
  font-size: 12px; background: var(--card-bg); color: var(--text-main); text-align: center;
}

/* ====== 設置開關行 ====== */
#tool-body .toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 0; font-size: 13px; color: var(--text-main);
  border-bottom: 1px solid var(--card-border);
}
#tool-body .toggle-row:last-child { border-bottom: none; }

/* ====== 分享區（改版） ====== */
#tool-body .share-code-row {
  display: flex;
  gap: 5px;
  align-items: center;
  margin-bottom: 6px;
}
#tool-body .share-code-box {
  flex: 1; font-size: 13px; font-weight: bold;
  color: var(--primary); letter-spacing: 1px;
  background: var(--primary-light);
  border: 1px solid var(--card-border);
  border-radius: 6px; padding: 6px 8px;
  cursor: pointer; word-break: break-all;
  transition: opacity .15s;
}
#tool-body .share-code-box:hover { opacity: .8; }
#tool-body .share-btns-row {
  display: flex;
  gap: 5px;
  margin-bottom: 7px;
}
#tool-body .share-input-row { display: flex; gap: 5px; align-items: center; }
#tool-body .share-input {
  flex: 1; border: 1px solid var(--card-border);
  border-radius: 6px; padding: 5px 7px;
  font-size: 12px; background: var(--card-bg); color: var(--text-main);
}
#tool-body .btn-sm {
  padding: 5px 9px; font-size: 12px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 6px; cursor: pointer;
  transition: opacity .15s; white-space: nowrap;
}
#tool-body .btn-sm:hover { opacity: .85; }
#tool-body .btn-sm-outline {
  padding: 5px 9px; font-size: 12px;
  background: transparent; color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 6px; cursor: pointer;
  transition: all .15s; white-space: nowrap;
  flex: 1; text-align: center;
}
#tool-body .btn-sm-outline:hover { background: var(--primary); color: #fff; }

/* ====== 最佳記錄 ====== */
#tool-body .best-row {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-muted); padding: 3px 0;
}
#tool-body .best-row span:last-child { color: var(--primary); font-weight: bold; }

/* ====== 勝利彈窗 ====== */
#tool-body .win-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 9999;
  justify-content: center; align-items: center;
}
#tool-body .win-overlay.show { display: flex; }
#tool-body .win-box {
  background: var(--card-bg); border-radius: 16px;
  padding: 28px 24px; text-align: center;
  max-width: 310px; width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
#tool-body .win-emoji { font-size: 48px; line-height: 1.2; }
#tool-body .win-title { font-size: 20px; font-weight: bold; color: var(--primary); margin: 8px 0 4px; }
#tool-body .win-stats { font-size: 13px; color: var(--text-muted); margin-bottom: 18px; line-height: 1.9; }
#tool-body .win-btns { display: flex; gap: 8px; justify-content: center; }
#tool-body .win-btn { padding: 9px 18px; border-radius: 8px; border: none; cursor: pointer; font-size: 14px; font-weight: bold; }
#tool-body .win-btn-primary { background: var(--primary); color: #fff; }
#tool-body .win-btn-secondary { background: var(--primary-light); color: var(--primary); }

/* 分享碼小標籤 */
#tool-body .win-share { margin-top: 12px; }
#tool-body .win-share-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
#tool-body .win-share-code {
  font-size: 13px; font-weight: bold; color: var(--primary);
  background: var(--primary-light); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; display: inline-block;
  letter-spacing: 1px;
}

#tool-body .win-share-qrcode{
  margin-top: 5px;
}
#tool-body .win-share-qrcode img{
  max-width: 150px;
}
/* 滑動模式開啓時，禁止頁面滾動 */
body.swipe-mode,
body.swipe-mode #tool-body .maze-wrap
{
  overflow: hidden;
  touch-action: none;
}