         }
     }
     
+    func updateLength() {
+        countdown.length = (countdownMinutes.rounded() * 60) + countdownSeconds.rounded()
+        
+        if countdownSeconds > 59 {
+            countdownMinutes = CountdownTimer.shared.length / 60
+            countdownSeconds = CountdownTimer.shared.length.truncatingRemainder(dividingBy: 60)
+        }
+    }
+    
     func plusOne() {
         #warning("Re-enable the reset button if not yet started")
         countdown.add(60)

    @ObservedObject var countdown = CountdownTimer.shared
    @ObservedObject var appearance = Appearance.shared
    
    @State private var lengthInMinutes = CountdownTimer.shared.length / 60
    @State private var isPresentingAppearance = false
    var hasDisplayConnected = false
    

                .padding(.horizontal)
            
            HStack {
                Text("Length:")
                TextField("", value: $countdownMinutes, formatter: NumberFormatter())
                    .keyboardType(.numbersAndPunctuation)
                    .multilineTextAlignment(.trailing)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                    .frame(width: 40)
                    .onChange(of: countdownMinutes) { _ in
                        updateLength()
                    }
                Text("minutes")
                    .font(.subheadline)
                    .padding(.trailing)
                TextField("", value: $countdownSeconds, formatter: NumberFormatter())
                    .keyboardType(.numbersAndPunctuation)
                    .multilineTextAlignment(.trailing)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                    .frame(width: 40)
                    .onChange(of: countdownSeconds) { _ in
                        updateLength()
                    }
                Text("seconds")
                    .font(.subheadline)
            }
            
            Spacer()
