:root {
  --bg-primary: #070a13;
  --bg-secondary: rgba(15, 23, 42, 0.65);
  --bg-tertiary: rgba(30, 41, 59, 0.5);
  
  --color-text-primary: #f8fafc;
  --color-text-secondary: #94a3b8;
  --color-text-muted: #64748b;
  
  --accent-primary: #6366f1; /* Indigo */
  --accent-primary-glow: rgba(99, 102, 241, 0.4);
  
  --color-target: #06b6d4; /* Cyan */
  --color-target-glow: rgba(6, 182, 212, 0.25);
  --color-current: #f97316; /* Orange */
  --color-current-glow: rgba(249, 115, 22, 0.25);
  
  /* Status Colors */
  --status-perfect: #10b981; /* Emerald */
  --status-perfect-glow: rgba(16, 185, 129, 0.4);
  --status-warning: #f59e0b; /* Amber */
  --status-warning-glow: rgba(245, 158, 11, 0.4);
  --status-danger: #f43f5e; /* Rose */
  --status-danger-glow: rgba(244, 63, 94, 0.4);

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Noto Sans TC", "Segoe UI", Roboto, sans-serif;
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  --border-radius-lg: 20px;
  --border-radius-md: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-primary);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
  line-height: 1.6;
}

/* Background Glowing Orbs */
body::before, body::after {
  content: "";
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(160px);
  z-index: -1;
  opacity: 0.12;
  pointer-events: none;
}
body::before {
  top: -150px;
  left: -150px;
  background: var(--accent-primary);
}
body::after {
  bottom: -150px;
  right: -150px;
  background: var(--color-target);
}

header {
  padding: 24px 40px;
  background: rgba(7, 10, 19, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--color-target), var(--accent-primary));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.logo-icon svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

.logo-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(to right, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text p {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.badge-version {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
}

main {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 30px;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 30px;
}

@media (max-width: 1100px) {
  main {
    grid-template-columns: 1fr;
  }
}

/* Glassmorphism Panel Common Styles */
.panel {
  background: var(--bg-secondary);
  border: var(--glass-border);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(16px);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
  position: relative;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 16px;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Interactive Canvas Area */
.canvas-container {
  position: relative;
  width: 100%;
  background: #020408;
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  min-height: 480px;
  cursor: crosshair;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

#image-canvas {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.canvas-container.is-zoomed {
  cursor: grab;
  touch-action: none;
}

.canvas-container.is-panning {
  cursor: grabbing;
}

.image-zoom-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.6);
}

.zoom-btn,
.zoom-reset-btn {
  min-width: 42px;
  min-height: 42px;
  border: 1px solid rgba(129, 140, 248, 0.32);
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.12);
  color: #e0e7ff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.zoom-btn {
  font-size: 1.35rem;
  line-height: 1;
}

.zoom-reset-btn {
  padding: 0 12px;
  font-size: 0.78rem;
}

.zoom-btn:disabled,
.zoom-reset-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.zoom-btn:focus-visible,
.zoom-reset-btn:focus-visible {
  outline: 2px solid #a5b4fc;
  outline-offset: 2px;
}

.zoom-level {
  min-width: 54px;
  color: #a5b4fc;
  font-size: 0.85rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.zoom-touch-hint {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: 0.72rem;
}

/* Control Buttons Bar */
.control-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  background: var(--bg-tertiary);
  border: var(--glass-border);
  color: var(--color-text-primary);
  padding: 10px 20px;
  border-radius: var(--border-radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), #4f46e5);
  border: none;
  box-shadow: 0 4px 15px var(--accent-primary-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

/* Canvas Mode Switcher */
.mode-toggle {
  display: flex;
  background: #0f172a;
  border-radius: 10px;
  padding: 4px;
  border: var(--glass-border);
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.mode-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Hidden Upload Inputs */
#file-upload,
#camera-upload {
  display: none;
}

/* Right Dashboard Styling */
.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ΔE Ring & Value Card */
.de-display-card {
  display: flex;
  align-items: center;
  gap: 24px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--border-radius-md);
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.de-ring-wrapper {
  position: relative;
  width: 100px;
  height: 100px;
  flex-shrink: 0;
}

.de-ring-svg {
  width: 100px;
  height: 100px;
  transform: rotate(-90deg);
}

.de-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.05);
  stroke-width: 8;
}

.de-ring-progress {
  fill: none;
  stroke: var(--status-perfect);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}

.de-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-text-primary);
}

.de-info-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.de-status-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  animation: pulse-glow 2s infinite ease-in-out;
}

.de-status-perfect {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--status-perfect);
  box-shadow: 0 0 12px var(--status-perfect-glow);
}

.de-status-warning {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--status-warning);
  box-shadow: 0 0 12px var(--status-warning-glow);
}

.de-status-danger {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.3);
  color: var(--status-danger);
  box-shadow: 0 0 12px var(--status-danger-glow);
}

.de-description {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

/* Color Compare Swatches */
.compare-swatches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.swatch-card {
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: var(--transition-smooth);
}

.swatch-card:hover {
  background: rgba(255, 255, 255, 0.04);
}

.swatch-title {
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch-target { color: var(--color-target); }
.swatch-current { color: var(--color-current); }

.color-block {
  height: 90px;
  border-radius: 8px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s ease;
  position: relative;
  overflow: hidden;
}

.color-block::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 60%);
  pointer-events: none;
}

.color-values {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.color-values span {
  display: flex;
  justify-content: space-between;
}

.value-label {
  color: var(--color-text-muted);
}

/* Tuning Instructions Box */
.instructions-card {
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.03);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.instructions-header {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.instructions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.instruction-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  padding: 12px;
  border-left: 3px solid var(--accent-primary);
  animation: slide-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.instruction-item.perfect {
  border-left-color: var(--status-perfect);
  background: rgba(16, 185, 129, 0.04);
}

.instruction-item.tune-up {
  border-left-color: var(--accent-primary);
}

.instruction-item.tune-down {
  border-left-color: #64748b;
}

/* 待處理軸卡片：灰色虛線，表示本輪不動作、下一輪再處理 */
.instruction-item.pending {
  border-left-style: dashed;
  border-left-color: #64748b;
  opacity: 0.65;
}

.instruction-item.pending .instruction-content {
  color: #94a3b8;
}

/* 乾燥比對提醒卡：琥珀色，與調色動作指令做視覺區隔 */
.instruction-item.note {
  border-left-color: #f59e0b;
  background: rgba(245, 158, 11, 0.05);
}

.instruction-item.note .instruction-number {
  border-color: rgba(245, 158, 11, 0.4);
  color: #f59e0b;
}

.instruction-number {
  background: var(--bg-tertiary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.instruction-content {
  font-size: 0.85rem;
  font-weight: 500;
  color: #e2e8f0;
}

/* LAB Differences visual comparison */
.lab-axis-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.axis-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.axis-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
}

.axis-label-name {
  color: var(--color-text-secondary);
}

.axis-label-val {
  font-family: monospace;
}

.axis-bar-bg {
  height: 8px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.axis-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease, left 0.4s ease;
  position: absolute;
}

.axis-center-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(255, 255, 255, 0.2);
  z-index: 2;
}

/* Demo Images Drawer */
.demo-drawer {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.demo-drawer::-webkit-scrollbar {
  height: 6px;
}

.demo-drawer::-webkit-scrollbar-track {
  background: transparent;
}

.demo-drawer::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.demo-card {
  width: 70px;
  height: 50px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  transition: var(--transition-smooth);
}

.demo-card:hover {
  transform: scale(1.05);
}

.demo-card.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px var(--accent-primary-glow);
}

/* Instructions and help info */
.tip-box {
  background: rgba(99, 102, 241, 0.03);
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(99, 102, 241, 0.1);
  padding: 16px;
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

.tip-icon {
  color: var(--accent-primary);
  font-size: 1.1rem;
  flex-shrink: 0;
}

.tip-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tip-content strong {
  color: var(--color-text-primary);
}

/* Selection Boxes visual rendering overlay on canvas container */
.selection-box-overlay {
  position: absolute;
  pointer-events: auto; /* 允許滑鼠與觸控事件，啟用選框拖曳與縮放 */
  border: 2px dashed #fff;
  border-radius: 4px;
  z-index: 10;
  box-sizing: border-box;
  touch-action: none;
}

.selection-box-overlay::before {
  content: attr(data-label);
  position: absolute;
  top: -24px;
  left: -2px;
  background: inherit;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px 4px 0 0;
  white-space: nowrap;
}

.selection-box-target {
  border-color: var(--color-target);
  box-shadow: 0 0 8px var(--color-target-glow);
}

.selection-box-target::before {
  background: var(--color-target);
}

.selection-box-current {
  border-color: var(--color-current);
  box-shadow: 0 0 8px var(--color-current-glow);
}

.selection-box-current::before {
  background: var(--color-current);
}

.selection-box-white {
  border-color: #e5e7eb;
  border-style: dotted;
  box-shadow: 0 0 8px rgba(229, 231, 235, 0.4);
}

.selection-box-white::before {
  background: #6b7280;
}

/* Drag Handles for manual rectangle selection adjustments */
.drag-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 1px solid #000;
  border-radius: 50%;
  pointer-events: auto;
  z-index: 15;
}

/* Animations */
@keyframes pulse-glow {
  0%, 100% {
    opacity: 0.9;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.02);
  }
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

footer {
  text-align: center;
  padding: 30px;
  border-top: var(--glass-border);
  color: var(--color-text-muted);
  font-size: 0.8rem;
  background: rgba(7, 10, 19, 0.9);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Color Science & System Diagnostic Console */
.debug-panel {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(239, 68, 68, 0.25) !important;
  box-shadow: 0 10px 40px rgba(239, 68, 68, 0.1) !important;
  margin-top: 30px;
}

#debug-log-console::-webkit-scrollbar {
  width: 6px;
}

#debug-log-console::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.4);
}

#debug-log-console::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

#debug-log-console::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Animations for loading spinners */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.animate-spin {
  animation: spin 1.2s linear infinite;
}

/* Premium Segmented Control for Material Modes */
.material-segmented-control {
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  position: relative;
  gap: 4px;
}

.material-btn {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 500;
  border: 1px solid transparent;
}

.material-btn:hover {
  color: var(--color-text-primary);
  background: rgba(255, 255, 255, 0.02);
}

/* ==========================================
 * 5. 手機端 (Mobile) 與桌機端響應式介面優化 (v3.5)
 * ========================================== */

/* 預設隱藏手機底部 Tab Bar */
.mobile-tab-bar {
  display: none;
}

@media (max-width: 768px) {
  header {
    padding: 14px 20px !important;
  }
  
  .logo-container {
    gap: 8px !important;
  }
  
  .logo-icon {
    width: 34px !important;
    height: 34px !important;
    border-radius: 8px !important;
  }
  
  .logo-icon svg {
    width: 18px !important;
    height: 18px !important;
  }
  
  .logo-text h1 {
    font-size: 1.05rem !important;
  }
  
  .logo-text p {
    font-size: 0.65rem !important;
    letter-spacing: 0px !important;
  }
  
  .badge-version {
    display: none !important; /* 行動端窄螢幕隱藏版本號，保留空間 */
  }

  main {
    display: block !important;
    padding: 12px !important;
    padding-bottom: 96px !important; /* 為底部 Tab Bar 預留充足空間防止覆蓋 */
    gap: 0 !important;
  }

  .panel {
    padding: 16px !important;
    margin-bottom: 16px !important;
    border-radius: 16px !important;
    gap: 16px !important;
  }

  .panel-header {
    padding-bottom: 12px !important;
    margin-bottom: 4px !important;
  }

  .canvas-container {
    min-height: 320px !important; /* 避免手機上高度過大 */
    max-height: 55vh !important;
  }

  #image-canvas {
    max-height: 50vh !important;
  }

  .image-zoom-toolbar {
    position: sticky;
    bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 30;
    gap: 6px;
    padding: 6px;
    background: rgba(10, 15, 30, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  .zoom-btn,
  .zoom-reset-btn {
    min-height: 44px;
  }

  .zoom-touch-hint {
    display: none;
  }

  .zoom-reset-btn {
    margin-left: auto;
  }

  .drag-handle {
    width: 16px;
    height: 16px;
    margin: -3px;
  }

  /* 底部 Sticky Tab Bar 容器 */
  .mobile-tab-bar {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 66px;
    background: rgba(10, 15, 30, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 9999;
    padding-bottom: env(safe-area-inset-bottom); /* 相容 iPhone 底部 Home 指示條安全區 */
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
    justify-content: space-around;
    align-items: center;
  }

  /* 底部 Tab 按鈕 */
  .tab-item {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    gap: 5px;
    padding: 6px 0;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    -webkit-tap-highlight-color: transparent; /* 消除 iOS 點擊高亮灰色背景 */
  }

  .tab-item svg {
    width: 21px;
    height: 21px;
    stroke: var(--color-text-muted);
    stroke-width: 2.2;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Active 啟動狀態 */
  .tab-item.active {
    color: var(--accent-primary);
  }

  .tab-item.active svg {
    stroke: var(--accent-primary);
    filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.6));
    transform: translateY(-1px);
  }

  /* 手機分頁顯示/隱藏切換與絲滑動畫 */
  .tab-panel {
    display: none;
    animation: slide-up-fade 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }

  .tab-panel.active {
    display: flex;
    flex-direction: column;
  }

  /* 調整對比色區塊，小螢幕下保持良好展示 */
  .compare-swatches {
    gap: 12px !important;
  }
  
  .swatch-card {
    padding: 10px !important;
  }
  
  .color-block {
    height: 75px !important;
  }
  
  /* 行動端調整 LAB 各維度條的文字排版 */
  .axis-label {
    font-size: 0.72rem !important;
  }

  .instructions-list {
    gap: 8px !important;
  }
  
  .instruction-item {
    padding: 10px !important;
  }
}

/* 漸進淡入與微幅上滑動畫 */
@keyframes slide-up-fade {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================
 * 桌機端 (Desktop >= 769px) 版面保全核心機制 (Display Contents Trick)
 * ========================================== */
@media (min-width: 769px) {
  .tab-panel {
    /* 核心佈局魔法：讓 tab-panel 容器本身不參與盒子渲染， */
    /* 其子級卡片 (.panel) 將直接作為 main (CSS Grid) 的子元素參與排版！ */
    /* 如此可完美保全桌機端的雙欄網格設計，不受新增包裝 div 的影響。 */
    display: contents !important;
  }
  
  .mobile-tab-bar {
    display: none !important;
  }
}

/* ==========================================
 * v4.0 任務導向 UI / UX
 * 專業功能保留，預設畫面只呈現當下任務。
 * ========================================== */
:root {
  --bg-primary: #0b0d11;
  --bg-secondary: #15181e;
  --bg-tertiary: #20242c;
  --color-text-primary: #f7f8fa;
  --color-text-secondary: #aeb5c0;
  --color-text-muted: #767f8d;
  --accent-primary: #6d8cff;
  --accent-primary-glow: rgba(109, 140, 255, 0.22);
  --glass-border: 1px solid #292e37;
  --glass-shadow: 0 14px 44px rgba(0, 0, 0, 0.24);
  --border-radius-lg: 18px;
  --border-radius-md: 12px;
}

body {
  background: #0b0d11;
  letter-spacing: 0;
}

body::before,
body::after {
  display: none;
}

header {
  min-height: 68px;
  padding: 14px 28px;
  background: rgba(11, 13, 17, 0.94);
  border-bottom-color: #242830;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.logo-icon {
  box-shadow: none;
  background: linear-gradient(145deg, #58c8d9, #6d8cff);
}

.logo-text h1 {
  font-size: 1.12rem;
  letter-spacing: 0;
  background: none;
  -webkit-text-fill-color: currentColor;
}

.logo-text p {
  margin-top: 1px;
  color: #8f98a6;
}

.badge-version {
  color: #b8c5ff;
  background: #171c29;
  border-color: #303a57;
}

main {
  max-width: 1460px;
  padding: 22px;
  grid-template-columns: minmax(0, 1.12fr) minmax(390px, 0.88fr);
  gap: 20px;
  align-items: start;
}

.panel {
  padding: 20px;
  gap: 16px;
  overflow: visible;
  background: #15181e;
  border-color: #292e37;
  box-shadow: var(--glass-shadow);
  backdrop-filter: none;
}

.panel-header {
  min-height: 46px;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom-color: #282d35;
}

.panel-title {
  min-width: 0;
  font-size: 1rem;
  font-weight: 750;
}

.panel-title > svg {
  display: none;
}

.step-kicker {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 6px;
  background: #252c41;
  color: #b7c4ff;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.mode-toggle {
  display: none;
}

.task-guide {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  order: 1;
}

.task-guide span {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #2b3039;
  border-radius: 10px;
  background: #191d23;
  color: #aab2be;
  font-size: 0.76rem;
  white-space: nowrap;
  text-align: center;
}

.task-guide b {
  display: inline-grid;
  width: 20px;
  height: 20px;
  margin-right: 4px;
  place-items: center;
  border-radius: 50%;
  color: #0b0d11;
  background: #dbe1eb;
  font-size: 0.68rem;
}

#tab-panel-canvas .panel > .panel-header { order: 0; }
#tab-panel-canvas .panel > .control-bar { order: 2; }
#tab-panel-canvas .panel > .canvas-container { order: 3; }
#tab-panel-canvas .panel > .image-zoom-toolbar { order: 4; }
#tab-panel-canvas .panel > .result-cta { order: 5; }
#tab-panel-canvas .panel > .help-details { order: 6; }
#tab-panel-canvas .panel > div:last-child { order: 7; }

.control-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, auto));
  gap: 8px;
}

.btn {
  min-height: 44px;
  justify-content: center;
  border-radius: 10px;
  padding: 9px 14px;
  border-color: #303640;
  background: #20242b;
  font-size: 0.82rem;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.btn:hover {
  transform: none;
  box-shadow: none;
  border-color: #465064;
  background: #272c35;
}

.btn-primary,
.btn-primary:hover {
  color: #071012;
  border: 1px solid #72cbd7;
  background: #75d2de;
  box-shadow: none;
  font-weight: 750;
}

.canvas-container {
  min-height: 500px;
  border-radius: 14px;
  border-color: #2c313a;
  background-color: #090b0e;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.018) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,.018) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,.018) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.018) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.selection-box-overlay {
  border-width: 2px;
  border-style: solid;
  border-radius: 8px;
}

.selection-box-overlay::before {
  top: -28px;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 18px;
  box-shadow: 0 3px 10px rgba(0,0,0,.28);
}

.drag-handle {
  width: 14px;
  height: 14px;
  border: 2px solid #0b0d11;
  box-shadow: 0 0 0 1px rgba(255,255,255,.65);
}

.image-zoom-toolbar {
  min-height: 48px;
  background: #191d23;
  border-color: #2b3039;
}

.measurement-status {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 54px;
  margin-top: 12px;
  padding: 11px 13px;
  border: 1px solid #2d3748;
  border-radius: 11px;
  color: #cbd5e1;
  background: #181c23;
  transition: border-color .18s ease, background-color .18s ease;
}

.measurement-status-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #75d2de;
  box-shadow: 0 0 0 4px rgba(117, 210, 222, .12);
}

.measurement-status-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.measurement-status-copy strong {
  color: #eef2f7;
  font-size: .82rem;
  line-height: 1.35;
}

.measurement-status-copy span {
  color: #9ca6b4;
  font-size: .74rem;
  line-height: 1.45;
}

.measurement-status.is-dragging,
.measurement-status.is-checking {
  border-color: rgba(109, 140, 255, .55);
  background: rgba(73, 94, 165, .12);
}

.measurement-status.is-dragging .measurement-status-dot,
.measurement-status.is-checking .measurement-status-dot {
  background: #8ea5ff;
  box-shadow: 0 0 0 4px rgba(142, 165, 255, .14);
  animation: measurement-pulse 1s ease-in-out infinite;
}

.measurement-status.is-warning {
  border-color: rgba(246, 199, 111, .55);
  background: rgba(122, 87, 31, .13);
}

.measurement-status.is-warning .measurement-status-dot {
  background: #f6c76f;
  box-shadow: 0 0 0 4px rgba(246, 199, 111, .13);
}

.selection-box-overlay.is-unreliable {
  border-color: #f6c76f;
  box-shadow: 0 0 0 3px rgba(246, 199, 111, .18), 0 0 14px rgba(246, 199, 111, .28);
}

.selection-box-overlay.is-unreliable::before {
  background: #a66b13;
}

.selection-box-overlay.is-dragging {
  border-style: dashed;
}

body.is-adjusting-selection #de-value,
body.is-adjusting-selection #mobile-de-value,
body.is-adjusting-selection #btn-view-result {
  opacity: .38;
}

@keyframes measurement-pulse {
  0%, 100% { opacity: .58; transform: scale(.86); }
  50% { opacity: 1; transform: scale(1); }
}

.zoom-btn,
.zoom-reset-btn {
  border-color: #37405a;
  background: #20273a;
}

.result-cta {
  display: flex;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border: 1px solid #6d8cff;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, #536fda, #6d8cff);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(77, 104, 210, 0.18);
}

.help-details {
  border: 1px solid #2b3039;
  border-radius: 11px;
  background: #181b21;
  color: #aeb5c0;
}

.help-details summary {
  min-height: 46px;
  padding: 11px 14px;
  color: #c7ced8;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
}

.help-details ul {
  padding: 0 20px 14px 34px !important;
}

.demo-title {
  margin-bottom: 8px;
  color: #858e9c;
  font-size: 0.78rem;
  font-weight: 600;
}

.panel-actions {
  display: flex;
  gap: 7px;
  margin-left: auto;
}

.panel-action-btn {
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid #343a45;
  border-radius: 9px;
  color: #c8ced7;
  background: #1d2128;
  font: inherit;
  font-size: 0.73rem;
  font-weight: 650;
  cursor: pointer;
}

#settings-summary {
  display: block;
  color: #8993a3;
  font-size: 0.62rem;
  font-weight: 500;
}

.dashboard-grid {
  gap: 12px;
}

.dashboard-grid > .de-display-card { order: 0; }
.dashboard-grid > .primary-instruction-card { order: 1; }
.dashboard-grid > .compare-swatches { order: 2; }
.dashboard-grid > .advanced-option { order: 3; }
.dashboard-grid > .technical-analysis-card { order: 4; }
.dashboard-grid > .tuning-log-card { order: 5; }

.advanced-option {
  display: none !important;
}

#tab-panel-recipe .panel.settings-open .advanced-option {
  display: flex !important;
}

#btn-toggle-settings[aria-expanded="true"] {
  border-color: #657bd0;
  color: #dbe3ff;
  background: #252d45;
}

.de-display-card {
  padding: 14px 16px;
  gap: 16px;
  background: #191d23;
  border-color: #2b3039;
}

.de-ring-wrapper,
.de-ring-svg {
  width: 82px;
  height: 82px;
}

.de-ring-svg {
  overflow: visible;
  transform: translate(-9px, -9px) rotate(-90deg) scale(.82);
  transform-origin: center;
}

.de-number {
  font-size: 1.4rem;
}

.de-status-badge {
  animation: none;
  letter-spacing: 0;
  text-transform: none;
}

.primary-instruction-card {
  padding: 16px;
  border: 1px solid #3a4564;
  background: linear-gradient(145deg, #1d2434, #181d28);
}

.primary-instruction-card .instructions-header {
  color: #cdd7ff;
  font-size: 0.86rem;
}

.primary-instruction-card .instruction-item:first-child {
  padding: 15px;
  border-left: 0;
  border: 1px solid rgba(109, 140, 255, 0.34);
  background: rgba(109, 140, 255, 0.11);
}

.primary-instruction-card .instruction-item:first-child .instruction-content {
  color: #fff;
  font-size: 0.92rem;
  line-height: 1.65;
}

.primary-instruction-card .instruction-item.pending,
.primary-instruction-card .instruction-item.note {
  padding-block: 9px;
}

.compare-swatches {
  gap: 10px;
}

.swatch-card {
  padding: 10px;
  border-color: #2b3039;
  background: #181b21;
}

.color-block {
  height: 64px;
}

.color-values {
  opacity: .72;
  font-size: .68rem;
}

.instructions-card {
  border-color: #2b3039;
  background: #181b21;
}

.tuning-log-card {
  border-color: #2d3c37 !important;
  background: #171d1b !important;
}

.debug-panel {
  display: none !important;
}

footer {
  padding: 20px;
  border-color: #242830;
  background: #0b0d11;
}

@media (min-width: 769px) {
  #tab-panel-canvas > .panel { order: 1; }
  #tab-panel-recipe > .panel { order: 2; }
  #tab-panel-ambient > .panel { order: 3; grid-column: 1 / -1; }
}

@media (max-width: 1100px) and (min-width: 769px) {
  main {
    grid-template-columns: 1fr;
    max-width: 860px;
  }

  #tab-panel-ambient > .panel { grid-column: auto; }
}

@media (max-width: 768px) {
  header {
    min-height: 56px;
    padding: 9px 14px !important;
  }

  .logo-text h1 {
    font-size: .98rem !important;
  }

  .logo-text p {
    display: none;
  }

  main {
    padding: 8px !important;
    padding-bottom: calc(86px + env(safe-area-inset-bottom)) !important;
  }

  .panel {
    padding: 12px !important;
    gap: 12px !important;
    margin-bottom: 8px !important;
    border-radius: 14px !important;
    box-shadow: none;
  }

  .panel-header {
    min-height: 40px;
    padding-bottom: 9px !important;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .panel-title {
    font-size: .94rem;
  }

  .step-kicker {
    font-size: .56rem;
  }

  .task-guide {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .task-guide span {
    padding: 7px 9px;
    text-align: left;
    white-space: normal;
  }

  .control-bar {
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }

  .control-bar .btn {
    width: 100%;
    min-height: 47px;
    padding: 8px;
    font-size: .78rem;
  }

  .control-bar .btn-primary {
    font-size: .84rem;
  }

  .canvas-container {
    min-height: 300px !important;
    max-height: 50vh !important;
    border-radius: 11px;
  }

  #image-canvas {
    max-height: 48vh !important;
  }

  .selection-box-overlay::before {
    top: -27px;
    font-size: 11px;
  }

  .drag-handle {
    width: 22px;
    height: 22px;
  }

  .measurement-status {
    min-height: 50px;
    margin-top: 8px;
    padding: 9px 10px;
  }

  .image-zoom-toolbar {
    position: static;
    min-height: 46px;
    padding: 4px;
  }

  .zoom-btn,
  .zoom-reset-btn {
    min-height: 42px;
  }

  .result-cta {
    min-height: 50px;
  }

  .help-details summary {
    min-height: 44px;
  }

  .panel-actions {
    width: 100%;
    margin-left: 0;
  }

  .panel-action-btn {
    flex: 1;
    min-height: 42px;
  }

  .dashboard-grid {
    gap: 9px;
  }

  .de-display-card {
    padding: 12px;
  }

  .de-description {
    font-size: .78rem;
    line-height: 1.5;
  }

  .primary-instruction-card {
    padding: 12px;
  }

  .primary-instruction-card .instruction-item:first-child .instruction-content {
    font-size: .88rem;
  }

  .compare-swatches {
    gap: 7px !important;
  }

  .swatch-card {
    padding: 8px !important;
    gap: 7px;
  }

  .swatch-title {
    font-size: .72rem;
  }

  .color-values span:nth-child(1),
  .color-values span:nth-child(2) {
    display: none;
  }

  .tuning-log-card {
    padding: 12px !important;
  }

  .mobile-tab-bar {
    height: calc(68px + env(safe-area-inset-bottom));
    padding: 5px 6px env(safe-area-inset-bottom) !important;
    gap: 4px;
    border-top-color: #2a2e36;
    background: rgba(16, 18, 23, .96);
    box-shadow: 0 -8px 24px rgba(0,0,0,.34);
  }

  .tab-item {
    position: relative;
    height: 56px;
    border-radius: 12px;
    font-size: .66rem;
    gap: 2px;
  }

  .tab-item.active {
    color: #d9e0ff;
    background: #252d45;
  }

  .tab-item.active svg {
    stroke: #9eb1ff;
    filter: none;
  }

  .tab-metric {
    position: absolute;
    top: 4px;
    right: 16px;
    min-width: 24px;
    padding: 1px 5px;
    border-radius: 99px;
    color: #111318;
    background: #f6c76f;
    font-size: .58rem;
    line-height: 16px;
  }

  footer {
    display: none;
  }
}
