body {
  font-family: Arial, sans-serif;
  max-width: 800px;
  margin: 40px auto;
  padding: 20px;
  padding-top: 60px;
  background: #f9f9f9;
  box-sizing: border-box; /* 新增：防止 padding 撑破宽度 */
}

input[type="text"],
input[type="password"] {
  margin-left: 10px;
  padding: 5px;
  border: 1px solid #ccc;
  border-radius: 4px;
  width: 100%;
  max-width: 100px;
  min-width: 0; /* 新增：允许在 flex 容器中收缩，不撑出边界 */
  box-sizing: border-box; /* 新增 */
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

input[type="range"] {
  flex: 1;
  min-width: 60px; /* 改小，给手机留更多收缩空间 */
  max-width: none;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

button {
  padding: 10px 20px;
  font-size: 14px;
  margin: 4px 4px;
  margin-left: auto;
  cursor: pointer;

  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;

  line-height: 1.2;
  height: 40px;
  white-space: nowrap; /* 新增：按钮文字不折行 */

  &:hover {
    background-color: #0056b3;
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.2);
  }

  &:active {
    transform: translateY(1px);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
  }
}

.control-group {
  border: 2px solid #e5e5e5;
  border-radius: 8px;
  padding: 8px;
  background-color: #f9f9f9;
  box-sizing: border-box; /* 新增：确保宽度计算一致 */
  width: 100%; /* 新增：明确占满父容器 */
}

.row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap; /* 新增：内容过多时自动换行，不溢出 */
  gap: 4px; /* 新增：wrap 后各项有间距 */
}

/* ============================================================
   图片预览：改为响应式宽度，与 control-group 对齐
   ============================================================ */
.preview-box {
  width: min(380px, 100%); /* 原来是固定 380px，现在最多 380px，不超出容器 */
  height: 300px;
  border: 2px dashed #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-sizing: border-box; /* 新增 */
}

.preview-box img {
  max-width: 100%;
  max-height: 100%;
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
}

.preview-box .placeholder {
  color: #999;
  pointer-events: none;
}

#imagePreviewsContainer {
  display: flex;
  gap: 16px;
  margin: 10px 0;
  flex-wrap: wrap;
  justify-content: center;
}

@media (max-width: 640px) {
  #imagePreviewsContainer {
    flex-direction: column;
    align-items: stretch; /* 改为 stretch，让预览框撑满列宽 */
  }

  /* 手机上预览框撑满宽度，高度适度缩小 */
  .preview-box {
    width: 100%;
    height: 220px;
  }
}

/* ============================================================
   调色板颜色块
   ============================================================ */
.palette-item {
  width: 24px;
  height: 24px;
  border: 2px solid #ccc;
  cursor: pointer;
  border-radius: 4px;
  transition:
    transform 0.2s,
    border-color 0.2s;
}

.palette-item:hover {
  transform: scale(1.1);
}

.palette-item.selected {
  border-color: #007bff;
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
  outline: 2px solid #007bff;
}

/* ============================================================
   状态栏：固定在底部，修复手机溢出问题
   ============================================================ */
#status {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;

  margin: 0;
  padding: 10px;
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid #ddd;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);

  height: 150px;
  overflow-y: auto;
  font-size: 12px;
  box-sizing: border-box;

  /* 新增：防止长文本或长 URL 撑出屏幕宽度 */
  overflow-x: hidden;
  word-break: break-all;
  overflow-wrap: break-word;
}

/* ============================================================  
   顶部状态条  
   ============================================================ */
#topStatusBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e0e0e0;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
}

/* ============================================================  
   状态按钮组  
   ============================================================ */
#statusButtons {
  display: flex;
  gap: 12px;
}

.status-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(130, 130, 130, 0.85);
  border: none;
  border-radius: 20px;
  font-size: 13px;
  color: #ccc;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: background 0.2s;
}

.status-btn:hover {
  background: rgba(150, 150, 150, 0.9);
}

.status-btn .status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #dc3545;
}

.status-btn .status-dot.connected {
  background-color: #28a745;
  animation: breathe 2s infinite ease-in-out;
}

.status-btn .status-dot.connecting {
  background-color: #ffc107;
}

/* ============================================================  
   状态弹窗  
   ============================================================ */
.status-window {
  position: fixed;
  top: 50px;
  left: 16px;
  z-index: 9998;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  min-width: 320px;
  display: none;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s, transform 0.3s;
}

.status-window.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.status-window form {
  margin: 0;
  padding: 0;
}

.status-window .ble-status {
  margin: 12px 0;
  padding: 8px 12px;
  background-color: #f8f9fa;
  border-radius: 6px;
  font-size: 14px;
}

.status-window #scanBLEBtn,
.status-window #getIPBtn,
.status-window #setWifiBtn {
  padding: 6px 14px;
  font-size: 14px;
  margin: 0;
  white-space: nowrap;
}

.status-window .window-row {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}

.status-window .window-row input[type="text"] {
  flex: 1;
  min-width: 150px;
}

.status-window .window-row button {
  flex-shrink: 0;
}

.status-window .window-row:last-child {
  margin-bottom: 0;
}

.status-window .window-row label {
  font-size: 14px;
  color: #333;
  margin: 0;
  min-width: 80px;
}

.status-window .window-row input[type="text"] {
  flex: 1;
  max-width: 180px;
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  margin: 0;
}

.status-window .window-row input[type="text"]:focus {
  outline: none;
  border-color: #007bff;
}

.status-window .window-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.status-window .window-row .toggle-switch {
  transform: scale(0.85);
}

/* ============================================================  
   高级模式切换按钮：修复手机上超出右侧的问题  
   ============================================================ */
#advancedToggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(130, 130, 130, 0.85);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  color: #ccc;
  user-select: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  height: 40px;
  box-sizing: border-box;

  /* 新增：防止自身宽度超出视口 */
  max-width: calc(100vw - 32px);
}

/* ============================================================
   弹窗
   ============================================================ */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
  transition:
    opacity 0.5s ease,
    visibility 0.5s;
  visibility: visible;
  opacity: 1;
}

.loader-container {
  background: #fff;
  padding: 30px;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.spinner {
  position: absolute;
  width: 120px;
  height: 120px;
  animation: rotateSpinner 1.2s linear infinite;
}

.dot {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #e0e0e0;
  border-radius: 50%;
  left: 54px;
  transform-origin: 6px 60px;
}

.dot:nth-child(1) {
  transform: rotate(0deg);
  background: #2ecc71;
}
.dot:nth-child(2) {
  transform: rotate(45deg);
}
.dot:nth-child(3) {
  transform: rotate(90deg);
}
.dot:nth-child(4) {
  transform: rotate(135deg);
}
.dot:nth-child(5) {
  transform: rotate(180deg);
}
.dot:nth-child(6) {
  transform: rotate(225deg);
}
.dot:nth-child(7) {
  transform: rotate(270deg);
}
.dot:nth-child(8) {
  transform: rotate(315deg);
}

@keyframes rotateSpinner {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.loader-text {
  text-align: center;
  font-family: "Arial", sans-serif;
  z-index: 10;
}

#loaderProgress {
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

#loaderTime {
  font-size: 14px;
  color: #888;
  margin-top: 4px;
}

.loader-container.success {
  border: 4px solid #2ecc71;
  background: #f0fff4;
}

.loader-container.warning {
  border: 4px solid #f1c40f;
  background: #fffdf0;
}

.status-msg {
  margin-top: 15px;
  font-size: 16px;
  font-weight: bold;
  display: none;
}

.success .status-msg {
  display: block;
  color: #27ae60;
}
.warning .status-msg {
  display: block;
  color: #d4ac0d;
}

.success .spinner,
.warning .spinner {
  display: none;
}

/* ============================================================
   亮度/对比度调节条
   ============================================================ */
.adjust-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* 色彩增强 checkbox 行：文字靠左，对号靠右 */
.lut-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  cursor: pointer;
}

/* 每行：[label 76px] [−] [滑块弹性] [+] */
.slider-row {
  display: grid;
  grid-template-columns: 76px 24px 1fr 24px;
  align-items: center;
  gap: 6px;
}

.slider-row label {
  display: inline-flex;
  justify-content: space-between;
  white-space: nowrap;
  margin: 0;
}

#brightnessVal,
#contrastVal {
  display: inline-block;
  width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#modelGet {
  max-width: 200px;
}

/* 正常模式下其他按钮隐藏，IP 发送按钮单独右对齐 */
#sendBtnIP {
  display: block;
  margin-left: auto;
}

/* 宽/高最多四位数，BPP 最多两位数，不需要那么宽 */
#width,
#height {
  max-width: 52px;
  min-width: 0;
}

#BPP {
  max-width: 36px;
  min-width: 0;
}

/* ============================================================
   切换开关
   ============================================================ */
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  cursor: pointer;
}

.toggle-switch input {
  display: none;
}

.toggle-thumb {
  position: absolute;
  inset: 0;
  background: #444;
  border-radius: 20px;
  transition: background 0.25s;
}

.toggle-thumb::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.25s;
}

.toggle-switch input:checked + .toggle-thumb {
  background: #4a9eff;
}

.toggle-switch input:checked + .toggle-thumb::after {
  transform: translateX(16px);
}

/* 滑块旁边的 ±1 步进圆按钮 */
.step-btn {
  width: 24px;
  height: 24px;
  min-width: 24px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #e0e0e0;
  color: #333;
  border: none;
  box-shadow: none;
  height: 24px;
  transition: background-color 0.2s;
}

.step-btn:hover {
  background-color: #bbb;
  box-shadow: none;
}

.step-btn:active {
  background-color: #999;
  transform: scale(0.92);
  box-shadow: none;
}

[hidden] {
  display: none !important;
}

/* 蓝牙状态指示器样式 */
.ble-status {
  display: flex;
  align-items: center;
  margin: 10px 0;
  padding: 8px 12px;
  border-radius: 6px;
  background-color: #f8f9fa;
  font-size: 14px;
}

.status-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  background-color: #dc3545; /* 红色：未连接 */
  transition: background-color 0.3s ease;
}

.status-dot.connected {
  background-color: #28a745; /* 绿色：已连接 */
  /* 呼吸动画效果 */
  animation: breathe 2s infinite ease-in-out;
}

.status-dot.connecting {
  background-color: #ffc107; /* 黄色：连接中 */
}

@keyframes breathe {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.status-text {
  color: #e9e3e3;
}

/* ── 图片操作区域 ──────────────────────────────────────────── */
#imageSection {
  margin: 12px 0;
}

#imageToolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#imageToolbar button {
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
}

#imagePreviews {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  #imagePreviews {
    flex-direction: column;
    align-items: center;
  }

  .square-box {
    width: 100%;
    max-width: 400px;
    height: 240px;
  }
}

/* 通用正方形容器 */
.square-box {
  position: relative;
  width: 240px;
  height: 240px;
  border: 1px dashed #888;
  border-radius: 6px;
  overflow: hidden;
  background: #1a1a2e;
  flex-shrink: 1;
  min-width: 180px;
}

.square-box .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 15px;
  pointer-events: none;
  gap: 8px;
  z-index: 1;
}

/* Cropper 容器：让库的 canvas 层级正常 */
#cropperBox {
  /* Cropper 内部会生成 .cropper-container 铺满父元素 */
}

#cropperBox img {
  display: block;
  /* Cropper 接管后会设置 display:none 并生成自己的 canvas */
  max-width: 100%;
  max-height: 100%;
}

/* 量化预览图铺满正方形 */
#quantizedBox img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

#cropDimLabel {
  font-size: 12px;
  color: #aaa;
}

/* 量化中闪烁效果 */
#quantizedBox.updating::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  animation: qpulse 0.5s ease-in-out infinite alternate;
  z-index: 10;
  pointer-events: none;
}

@keyframes qpulse {
  from {
    background: rgba(0, 0, 0, 0.1);
  }

  to {
    background: rgba(0, 0, 0, 0.45);
  }
}

/* ============================================================
   文字编辑预览
   ============================================================ */
#textEditBox {
  cursor: default;
}

#textEditCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

#textToolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

#textToolbar button {
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
}

#textToolbar label {
  white-space: nowrap;
}

/* ============================================================
   步骤向导
   ============================================================ */

/* 步骤指示器 */
#stepNav {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 16px;
  user-select: none;
}

.step-indicators {
  display: flex;
  align-items: center;
  gap: 0;
}

.step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ddd;
  color: #888;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.3s ease;
  cursor: pointer;
  flex-shrink: 0;
}

.step-dot.active {
  background: #007bff;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.4);
}

.step-dot.done {
  background: #28a745;
  color: #fff;
}

.step-line {
  width: 60px;
  height: 3px;
  background: #ddd;
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.step-line.active {
  background: #007bff;
}

.step-line.done {
  background: #28a745;
}

.step-labels {
  display: flex;
  align-items: center;
  margin-top: 6px;
  font-size: 13px;
  color: #999;
}

.step-labels span {
  width: 80px;
  text-align: center;
  transition: color 0.3s ease;
}

.step-labels span.active {
  color: #007bff;
  font-weight: bold;
}

.step-labels span.done {
  color: #28a745;
}

/* 步骤面板 */
.step-panel {
  display: none;
  animation: stepFadeIn 0.3s ease;
}

.step-panel.active {
  display: block;
}

@keyframes stepFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 步骤预览区：让 square-box 居中且更大 */
.step-preview {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 12px 0;
}

.step-preview .square-box {
  width: min(100%, 480px);
  height: 320px;
  max-height: 50vh;
}

@media (max-width: 640px) {
  .step-preview .square-box {
    height: 260px;
  }

  .step-line {
    width: 40px;
  }

  .step-labels span {
    width: 56px;
    font-size: 12px;
  }
}

/* 步骤导航按钮 */
#stepActions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

#prevStepBtn {
  background-color: #6c757d;
}

#prevStepBtn:hover {
  background-color: #5a6268;
}

#nextStepBtn {
  background-color: #007bff;
}

#sendStepBtn {
  background-color: #28a745;
  font-size: 16px;
  padding: 10px 28px;
}

#sendStepBtn:hover {
  background-color: #218838;
}
